Subject API C++
Author mautec2000 <mautec2000@yahoo.com>
Hello everybody!

I don't know if this is the right place for this
and if is not please redirect to another list :)

I am having a hard time trying to execute the following code:
It compiles ok but I am getting an segmentation fault and
with some changes no error but a null value for DATEI in table TEST.
Does anyone?

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

#define ERREXIT(status, rc) {isc_print_status(status); return
rc;}
#define MAXLEN 256
#define PARAMETROS 1


int cleanup (void);

isc_db_handle DB = NULL; /* database handle */
isc_tr_handle trans = NULL; /* transaction handle */
long status[20]; /* status vector */
char Db_name[128];
XSQLDA * isqlda;
char ISC_FAR * dpb = NULL; /* DB parameter buffer */
int dpb_length;
char username[31], password[31];

int main (int argc , char ** argv )
{


ISC_DATE datei;
struct tm datec;
char prep_str [ MAXLEN ];

isc_stmt_handle stmt_handler = NULL; /* statement handle*/



dpb = ( char * ) malloc ( 20 );

memset (&datec, '\0', sizeof ( datec ) );

strptime ("16/8/1971", "%d/%m/%Y", &datec);

datec.tm_mon++;
datec.tm_year += 1900;



strcpy ( Db_name, "/home/mau/interbase/sql/novo.gdb" );
strcpy ( username, "SYSDBA" );
strcpy ( password, "masterkey" );

dpb_length = 0;

isc_expand_dpb ( &dpb, ( short ISC_FAR * ) &dpb_length,
isc_dpb_user_name, username,
isc_dpb_password, password, NULL );



if ( isc_attach_database ( status, 0, Db_name, &DB, dpb_length,
dpb ) ) {
ERREXIT ( status, 1 );
}


/*
this is how the table was created:
CREATE TABLE TEST ( DATEI DATE );
*/

strcpy ( prep_str, "INSERT INTO TEST ( DATEI ) VALUES ( ? )" );

if ( isc_dsql_allocate_statement ( status, &DB, &stmt_handler ) ) {
ERREXIT ( status, 1 );
}

if ( isc_start_transaction ( status, &trans, 1, &DB, 0, NULL ) ) {
ERREXIT ( status, 1 );
}

if ( isc_dsql_prepare ( status, &trans, &stmt_handler, 0, prep_str,
3, NULL ) ) {
ERREXIT ( status, 1 );
}

isqlda = ( XSQLDA * ) malloc ( XSQLDA_LENGTH ( PARAMETROS ) );

isqlda -> version = SQLDA_VERSION1;
isqlda -> sqln = PARAMETROS;
isqlda -> sqld = PARAMETROS;


isc_encode_sql_date ( &datec, &datei );

isqlda -> sqlvar [0].sqltype = SQL_DATE;
isqlda -> sqlvar [0].sqllen = sizeof ( datei );
isqlda -> sqlvar [0].sqldata = ( ISC_DATE *) datei;




printf ( "\nExecuting statement:\n");



if ( isc_dsql_execute ( status, &trans, &stmt_handler, 3, isqlda ) )
{
ERREXIT ( status, 1 );
}

if ( isc_commit_transaction ( status, &trans ) ) {
ERREXIT ( status, 1 );
}

if ( isc_detach_database ( status, &DB ) ) {
ERREXIT ( status, 1 );
}

return 0;
}