Home > database >  Por * c programming connection oracle database successful, but why can't always SELECT query? B
Por * c programming connection oracle database successful, but why can't always SELECT query? B

Time:09-25

I use por * c programming for the ORACLE database query operations, the database to have, but can't SELECT queries, and no other error, consult everybody a great god, and what is the reason? Platform is under WINDOWS VS2013, the code is as follows:
# include
# include
# include
# include
# include
# include
# define PATHPAR ".. \ \.. \ \ parameter. TXT "
# define LENLINE 1000
# define NUMID 1000
# define the DEBUG

Phase/* * * that * * */
The EXEC SQL BEGIN DECLARE SECTION;
/* */login variable
VARCHAR userid [40].
VARCHAR password [40];
VARCHAR db_name [40].
The EXEC SQL END DECLARE SECTION;

SQL communication area/* * * * * */
The EXEC SQL INCLUDE sqlca;

/* * * * * * body/
The main ()
{
Void query_all ();
/* * * open and reads the parameter file parameter. TXT/* * *
The FILE * fppar;
Errno_t errpar;
Errpar=fopen_s (& amp; Fppar PATHPAR, "r");
/* read parameter. TXT in the IP address, user name and password */
Char strline [LENLINE], struse [LENLINE];
Int lenstr=0, numline=0;
Int I, j;
While (the fgets (strline LENLINE, fppar)!=NULL)
{
If (feof (fppar)) break;
Lenstr=strlen (strline);/* get using part of the string */
If (strline [lenstr - 1]=='\ n') strline] [lenstr - 1='\ 0';
For (I=0, j=0; i If (j!=0)
{
For (I=j + 1; i }
The else {
Printf (" input file read error! \n");
exit(0);
}
Numline++;/* read in a line, line number 1 */
/* get information of the line */
If (numline==1)/* get database */
{
Strcpy_s (db_name. Arr, LENDAB struse);
Db_name. Len=strlen (db_name. Arr);
Printf (" database: % s \ n ", db_name. Arr);
}
Else if (numline==2)/* get user id */
{
Strcpy_s (userid. Arr, LENDAB struse);
Userid. Len=strlen (userid. Arr);
User: printf (" % s \ n ", userid. Arr);
}
Else if (numline==3)/* get password */
{
Strcpy_s (password. Arr, LENDAB struse);
Password. Len=strlen (password. Arr);
Printf (" password: % s \ n ", password. Arr);
}
The else {
Printf (" error: parameter. TXT file read error! \n");
}

}
The fclose (fppar);

/* * * * * * login to ORACLE/
The EXEC SQL WHENEVER SQLERROR GOTO logon_error;
/* login to the remote node of a non-default database */
The EXEC SQL CONNECT: userid IDENTIFIED BY: password USING: db_name;
/* for landing error */
If (sqlca. Sqlcode==0) {
Printf (" connected to the ORACLE database: % s, user name: % s, \ n ", db_name. Arr, userid. Arr);
Else if (sqlca sqlcode & gt; 0 {
Printf (" connected to the ORACLE database: % s, user name: % s. But there is warning! \ nsqlca sqlcode: % ld, the sqlca sqlerrm. Sqlerrmc: % s \ n ", db_name. Arr, userid. Arr, sqlca. Sqlcode, (char *) the sqlca. Sqlerrm. Sqlerrmc);
The else
Printf (" the sqlca sqlcode: % ld, the sqlca. Sqlerrm. Sqlerrmc: % s \ n ", the sqlca. Sqlcode, (char *) the sqlca. Sqlerrm. Sqlerrmc);

/* * * * * * query information/
Query_all ();
/* * * * end processing/
The EXEC SQL COMMIT WORK RELEASE;
exit(0);
/* error handling */
Logon_error:
Printf (" \ n user name or password error! \n");
Printf (" \ n % s \ n 70 ", the sqlca. Sqlerrm. Sqlerrmc);
The EXEC SQL WHENEVER SQLERROR CONTINUE;
The EXEC SQL ROLLBACK RELEASE;
The exit (1);
}


Void query_all ()
{/SQL explain period of * * * * * */
The EXEC SQL BEGIN DECLARE SECTION;
Char datestart [LENLINE];
Char dateend [LENLINE];
Int staid [1000].
Int pointid [1000].
Int tiemid [1000].
Int sample [1000];
The EXEC SQL END DECLARE SECTION;
/* * * SQL communication area, local * * */
The EXEC SQL INCLUDE sqlca;
/* * * * * * query product data/
Int n=0;
The EXEC SQL WHENEVER SQLERROR GOTO query_error;
The EXEC SQL WHENEVER the NOT FOUND GOTO notfound.
# ifdef DEBUG
Printf (" start query \ n ");
# endif
The EXEC SQL SELECT STATIONID
INTO: staid
The FROM QZDATA. QZ_DICT_STATIONITEMS
WHERE STATIONID=32044/* ORDER BY 1 */.
N=the sqlca. Sqlerrd [2].
/* * * * * */output query results
int i=0;
For (I=0; i Printf (" query results output end, \ n ");
return;
/* * * * * */query is less than
Notfound:
Printf (" warning: under the condition of the query is less than, \ n ");
return;/*?????? */
/* * * * * * error handling/
Query_error:
Printf (" \ n query error: % 70 s \ n ", the sqlca. Sqlerrm. Sqlerrmc);
The EXEC SQL WHENEVER SQLERROR CONTINUE;
The EXEC SQL ROLLBACK.
The exit (1);
}

The main function there should be no problem, mainly query_all function anyway, the query is less than what table what conditions can query, heart, but Treasury has obviously! Please much guidance from
The code above is based on the original code cut, or not put, the original code without grammar question, the if there is I delete too much...

CodePudding user response:

Query the where condition and database can't lead to query data

CodePudding user response:

Rewritten to select 1 INTO first: staid from dual check for data, if it didn't be sure it is your written proc has a problem

CodePudding user response:

 CONNECT: userid IDENTIFIED BY: password USING: db_name; 
To use the userid and PWD db_name, then execute
SQL SELECT STATIONID
The FROM QZDATA. QZ_DICT_STATIONITEMS
WHERE STATIONID=32044

Confirm whether there is data

CodePudding user response:

I log in successfully, landing without error,
I do not set any conditions
The EXEC SQL SELECT STATIONID
INTO: staid
The FROM QZDATA. QZ_DICT_STATIONITEMS;
Also won't be able to query,
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related