Subject | XSQLDA && error code = -804 |
---|---|
Author | stoneoldrock |
Post date | 2013-05-11T19:20Z |
Hi, all
I am coming into a XSQLDA problem, would anyone of you like to point out where is wrong in the following code?
It runs on Linux Fedora 14 with FB superserver 2.1.3
The database is FB's sample database employee.fdb
It is always:
Dynamic SQL Error
-SQL error code = -804
-Incorrect values within SQLDA structure
many thanks in advance.
yours o'rock
/*************************************************
*
* this function will UPDATE one BLOB column
* with one parameter as the blob content
*
* "update job set job_requirement = ? where job_code = 'CEO' "
*
**************************************************/
void fb_import_file_to_blob(char *sqlcmd)
{
//char *sqlcmd =
//"update job set job_requirement = ? where job_code = 'CEO'";
isc_tr_handle trans = NULL ;
isc_blob_handle blob_handle=NULL;
memset(&blob_handle,0,sizeof(isc_blob_handle));
ISC_QUAD blob_id ;
memset(&blob_id,0,sizeof(ISC_QUAD));
char *blob_buffer=NULL;
blob_buffer = (char*) malloc (strlen("AAAAA")+1);
blob_buffer = strcpy(blob_buffer, "AAAAA");
XSQLDA *in_sqlda = NULL;
in_sqlda = (XSQLDA *)malloc(XSQLDA_LENGTH(1));
in_sqlda->version = SQLDA_VERSION1;
in_sqlda->sqln = 1;
in_sqlda->sqld = 1;
memset ((void*)(in_sqlda->sqlvar), 0, ( 1 * sizeof(XSQLVAR)));
//in_sqlda->sqlvar[0].sqldata =
//(char *) malloc (sizeof(blob_id));
//in_sqlda->sqlvar[0].sqldata =
//(ISC_QUAD *)malloc (sizeof( blob_id)) ;
in_sqlda->sqlvar[0].sqldata = (char *) &blob_id;
in_sqlda->sqlvar[0].sqltype = SQL_BLOB+1;
in_sqlda->sqlvar[0].sqllen = strlen(blob_buffer);
// strlen(blob_buffer)+1;
in_sqlda->sqlvar[0].sqlind = NULL;
// or any other ways just to get connected ...
fb_db_info dbinfo;
strcpy(dbinfo.user,"sysdba");
strcpy(dbinfo.passw,"masterkey");
strcpy(dbinfo.dbname,"localhost:/home/employee.fdb");
strcpy(dbinfo.role,"firebird");
dbinfo.db1 = 0L;
if (fb_do_connect(&dbinfo)) {
printf("DB connected!\n");
} else return;
if (dbinfo.db1 == NULL)
printf("un-valid DB handle\n");
else printf("got DB handle\n");
isc_start_transaction(dbinfo.status_vector ,
&trans, 1, &dbinfo.db1, 0, NULL);
if (dbinfo.status_vector[0] == 1 && dbinfo.status_vector[1]) {
isc_print_status(dbinfo.status_vector);
printf("start transaction ERROR!\n");
return;
}else printf("start transaction OK\n");
if (trans == NULL){
printf("un-valid transaction handle!\n");
return;
} else printf("got transaction handle OK!\n");
isc_create_blob2(dbinfo.status_vector,
&dbinfo.db1 , &trans, &blob_handle, &blob_id,0,NULL);
if (dbinfo.status_vector[0] == 1 && dbinfo.status_vector[1]) {
isc_print_status(dbinfo.status_vector);
printf("create blob2 ERROR!\n");
return;
} else printf("create blob2 OK\n");
if (blob_handle == NULL){
printf("un-valid blob_handle!\n");
return;
} else printf("got blob_handle OK!\n");
if (&blob_id == NULL){
printf("blob_id = NULL!\n");
} else printf("got blob_id OK!\n");
isc_put_segment(dbinfo.status_vector,
&blob_handle,
strlen(blob_buffer), // sizeof(blob_buffer)
// strlen(blob_buffer)+1;
(char *)blob_buffer);
if (dbinfo.status_vector[0] == 1 && dbinfo.status_vector[1]) {
isc_print_status(dbinfo.status_vector);
printf("put segment ERROR!\n");
return;
}else printf("put segment OK\n");
isc_close_blob ( dbinfo.status_vector, &blob_handle);
if (dbinfo.status_vector[0] == 1 && dbinfo.status_vector[1]) {
isc_print_status(dbinfo.status_vector);
printf("close blob ERROR!\n");
return;
}else printf("close blob OK\n");
isc_dsql_execute_immediate( dbinfo.status_vector,
&dbinfo.db1, &trans,
0, // indicates string to execute is null-terminated
sqlcmd, // UPDATE statement string to be executed
1, // XSQLDA version number
in_sqlda // XSQLDA supplying parameters to UPDATE statement
);
if (dbinfo.status_vector[0] == 1 && dbinfo.status_vector[1]) {
printf("execute immediate ERROR!\n");
isc_print_status(dbinfo.status_vector);
return;
}else printf("execute immediate OK\n");
if (in_sqlda != NULL) free (in_sqlda);
if (in_sqlda->sqlvar[0].sqldata != NULL)
free(in_sqlda->sqlvar[0].sqldata);
if (blob_buffer != NULL) free(blob_buffer);
}
running result:
DB connected!
got DB handle
start transaction OK
got transaction handle OK!
create blob2 OK
got blob_handle OK!
got blob_id OK!
put segment OK
close blob OK
execute immediate ERROR!
Dynamic SQL Error
-SQL error code = -804
-Incorrect values within SQLDA structure
SQL Query:
UPDATE JOB set JOB_REQUIREMENT = ? where JOB_CODE = 'CEO'
free Query memory OK!
disconnected!
I am coming into a XSQLDA problem, would anyone of you like to point out where is wrong in the following code?
It runs on Linux Fedora 14 with FB superserver 2.1.3
The database is FB's sample database employee.fdb
It is always:
Dynamic SQL Error
-SQL error code = -804
-Incorrect values within SQLDA structure
many thanks in advance.
yours o'rock
/*************************************************
*
* this function will UPDATE one BLOB column
* with one parameter as the blob content
*
* "update job set job_requirement = ? where job_code = 'CEO' "
*
**************************************************/
void fb_import_file_to_blob(char *sqlcmd)
{
//char *sqlcmd =
//"update job set job_requirement = ? where job_code = 'CEO'";
isc_tr_handle trans = NULL ;
isc_blob_handle blob_handle=NULL;
memset(&blob_handle,0,sizeof(isc_blob_handle));
ISC_QUAD blob_id ;
memset(&blob_id,0,sizeof(ISC_QUAD));
char *blob_buffer=NULL;
blob_buffer = (char*) malloc (strlen("AAAAA")+1);
blob_buffer = strcpy(blob_buffer, "AAAAA");
XSQLDA *in_sqlda = NULL;
in_sqlda = (XSQLDA *)malloc(XSQLDA_LENGTH(1));
in_sqlda->version = SQLDA_VERSION1;
in_sqlda->sqln = 1;
in_sqlda->sqld = 1;
memset ((void*)(in_sqlda->sqlvar), 0, ( 1 * sizeof(XSQLVAR)));
//in_sqlda->sqlvar[0].sqldata =
//(char *) malloc (sizeof(blob_id));
//in_sqlda->sqlvar[0].sqldata =
//(ISC_QUAD *)malloc (sizeof( blob_id)) ;
in_sqlda->sqlvar[0].sqldata = (char *) &blob_id;
in_sqlda->sqlvar[0].sqltype = SQL_BLOB+1;
in_sqlda->sqlvar[0].sqllen = strlen(blob_buffer);
// strlen(blob_buffer)+1;
in_sqlda->sqlvar[0].sqlind = NULL;
// or any other ways just to get connected ...
fb_db_info dbinfo;
strcpy(dbinfo.user,"sysdba");
strcpy(dbinfo.passw,"masterkey");
strcpy(dbinfo.dbname,"localhost:/home/employee.fdb");
strcpy(dbinfo.role,"firebird");
dbinfo.db1 = 0L;
if (fb_do_connect(&dbinfo)) {
printf("DB connected!\n");
} else return;
if (dbinfo.db1 == NULL)
printf("un-valid DB handle\n");
else printf("got DB handle\n");
isc_start_transaction(dbinfo.status_vector ,
&trans, 1, &dbinfo.db1, 0, NULL);
if (dbinfo.status_vector[0] == 1 && dbinfo.status_vector[1]) {
isc_print_status(dbinfo.status_vector);
printf("start transaction ERROR!\n");
return;
}else printf("start transaction OK\n");
if (trans == NULL){
printf("un-valid transaction handle!\n");
return;
} else printf("got transaction handle OK!\n");
isc_create_blob2(dbinfo.status_vector,
&dbinfo.db1 , &trans, &blob_handle, &blob_id,0,NULL);
if (dbinfo.status_vector[0] == 1 && dbinfo.status_vector[1]) {
isc_print_status(dbinfo.status_vector);
printf("create blob2 ERROR!\n");
return;
} else printf("create blob2 OK\n");
if (blob_handle == NULL){
printf("un-valid blob_handle!\n");
return;
} else printf("got blob_handle OK!\n");
if (&blob_id == NULL){
printf("blob_id = NULL!\n");
} else printf("got blob_id OK!\n");
isc_put_segment(dbinfo.status_vector,
&blob_handle,
strlen(blob_buffer), // sizeof(blob_buffer)
// strlen(blob_buffer)+1;
(char *)blob_buffer);
if (dbinfo.status_vector[0] == 1 && dbinfo.status_vector[1]) {
isc_print_status(dbinfo.status_vector);
printf("put segment ERROR!\n");
return;
}else printf("put segment OK\n");
isc_close_blob ( dbinfo.status_vector, &blob_handle);
if (dbinfo.status_vector[0] == 1 && dbinfo.status_vector[1]) {
isc_print_status(dbinfo.status_vector);
printf("close blob ERROR!\n");
return;
}else printf("close blob OK\n");
isc_dsql_execute_immediate( dbinfo.status_vector,
&dbinfo.db1, &trans,
0, // indicates string to execute is null-terminated
sqlcmd, // UPDATE statement string to be executed
1, // XSQLDA version number
in_sqlda // XSQLDA supplying parameters to UPDATE statement
);
if (dbinfo.status_vector[0] == 1 && dbinfo.status_vector[1]) {
printf("execute immediate ERROR!\n");
isc_print_status(dbinfo.status_vector);
return;
}else printf("execute immediate OK\n");
if (in_sqlda != NULL) free (in_sqlda);
if (in_sqlda->sqlvar[0].sqldata != NULL)
free(in_sqlda->sqlvar[0].sqldata);
if (blob_buffer != NULL) free(blob_buffer);
}
running result:
DB connected!
got DB handle
start transaction OK
got transaction handle OK!
create blob2 OK
got blob_handle OK!
got blob_id OK!
put segment OK
close blob OK
execute immediate ERROR!
Dynamic SQL Error
-SQL error code = -804
-Incorrect values within SQLDA structure
SQL Query:
UPDATE JOB set JOB_REQUIREMENT = ? where JOB_CODE = 'CEO'
free Query memory OK!
disconnected!