Subject Re: [firebird-support] Re: GPRE/API Different with FB 1.5?
Author Thad Humphries
Eric,

My code is below your comment. The PREPARE TRANSACTION is working else I
would be forwarded to the 'whoops' tag because of the 'EXEC SQL WHENEVER
SQLERROR GO TO whoops;' in my line 29.

BTW, I'm going to be out a few days (leaving soon). I'll pick this up when I
get back. In the meanwhile, I'll send you the note I tried sending to
firebirds@.... I doubt that I'll find out who to send it
to before I have to leave.

Thad

On Wednesday 03 March 2004 12:41, Eric Boyajian wrote:
> ...
> I think you misunderstand. The program does not crash at the
> PREPARE, it simply fails to prepare the SQL select statement and the
> FB 1.5 server (API?) returns a failure code (-901). The PREPARE
> should succeed and return a 0 (zero) in the isc_status vector and
> SQLCODE. Are you printing the value of SQLCODE after the
> isc_embed_dsql_prepare()? What is it?
>...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "ibase.h"

/* For FB 1.0 use employee.gdb, and link with gds32_ms.lib.
for FB 1.5 use employee.fdb, and link with fbclient_ms.lib. */

EXEC SQL BEGIN DECLARE SECTION;
char db_name[256];
EXEC SQL
SET DATABASE mydb = COMPILETIME "/opt/firebird/examples/employee.fdb"
RUNTIME :db_name;
EXEC SQL END DECLARE SECTION;

/*
* DATABASE DB = COMPILETIME "/opt/firebird/examples/employee.fdb"
* RUNTIME db_name;
*
* EXEC SQL
* INCLUDE SQLCA;
*/
int main(int argc, char** argv)
{
EXEC SQL BEGIN DECLARE SECTION;
char sqlString[256];
EXEC SQL END DECLARE SECTION;
EXEC SQL WHENEVER SQLERROR GO TO whoops;
EXEC SQL WHENEVER NOT FOUND GO TO whoops;
XSQLDA* sqlda;

/*
* // Set database name
*/
strcpy(db_name, "/opt/firebird/examples/employee.fdb");

/*
*
* // Open database and start tansaction
*/
EXEC SQL CONNECT mydb USER 'SYSDBA' PASSWORD 'masterkey';

isc_tr_handle gds_trans = (isc_tr_handle) 0;
EXEC SQL
SET TRANSACTION NAME gds_trans;

/*
* // Set up SQLDA for SELECTs, allow up to 150 fields to be selected
*/
sqlda = (XSQLDA*) malloc(XSQLDA_LENGTH(150));
sqlda->version = SQLDA_VERSION1;
sqlda->sqln = 150;

/*
* // Prepare a query
*/
strcpy(sqlString, "SELECT * FROM COUNTRY");

printf( "ready to call PREPARE\n" );

EXEC SQL
PREPARE TRANSACTION gds_trans Q1 INTO sqlda FROM :sqlString;

printf( "PREPARE called; ready to call COMMIT\n" );

EXEC SQL
COMMIT TRANSACTION gds_trans RELEASE;

printf( "COMMIT called\n" );

return 0;

whoops:

if ( SQLCODE ) {
char err_buf[256];
ISC_STATUS *vector;

printf( "Failure with error %d\n", SQLCODE );

if ( SQLCODE < -1 ) {
vector = isc_status;
isc_interprete( err_buf, &vector );
printf( "SQL (Firebird): %d: '%s'\n", SQLCODE, err_buf );
while ( isc_interprete( err_buf, &vector ) ) {
printf( "\t'%s'\n", err_buf );
};
}
else {
isc_sql_interprete( SQLCODE, err_buf, sizeof(err_buf) );
printf( "SQL (Firebird): %d: '%s'\n", SQLCODE, err_buf );
}
}

return SQLCODE;

}