Subject Re: [firebird-support] Re: GPRE/API Different with FB 1.5?
Author Thad Humphries
Sorry. I've included my code below and am posting to the list for others.

Thanks for looking at this. I haven't found where to submit an "official" bug
report but I see your name under 'Rabbit Holes'.

On Wednesday 03 March 2004 12:50, Frank Schlottmann-Gödde wrote:
> Thad Humphries wrote:
> > ...
> > I seem to get by the PREPARE just fine but die in COMMIT. I've modified
> > your code for C and Linux (see support.e attached).
>
> As the attachment didn't made it through the list, would you please mail
> it to my private mail-address.
>...

#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.gdb"
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.gdb");

/*
*
* // 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;

}