Subject Re: [ib-support] API C++
Author Sudheer Palaparambil
Hi,

Things will be more easy if you are using IBPP
available at www.sourceforge.net.

Sudheer.

--- "mautec2000 <mautec2000@...>"
<mautec2000@...> wrote:
<HR>
<html><body>


<tt>
Hello everybody!<BR>
<BR>
I don't know if this is the right place for this<BR>
and if is not please redirect to another list :)<BR>
<BR>
I am having a hard time trying to execute the
following code:<BR>
It compiles ok but I am getting an segmentation fault
and<BR>
with some changes no error but a null value for DATEI
in table TEST.<BR>
Does anyone?<BR>
<BR>
#include <stdlib.h><BR>
#include <time.h><BR>
#include <string.h><BR>
#include <stdio.h><BR>
#include <ibase.h><BR>
<BR>
#define ERREXIT(status,
rc)     
{isc_print_status(status); return <BR>
rc;}<BR>
#define MAXLEN      256<BR>
#define PARAMETROS  1<BR>
<BR>
<BR>
int cleanup (void);<BR>
<BR>
isc_db_handle    DB =
NULL;     /* database handle
*/<BR>
isc_tr_handle    trans =
NULL;      /* transaction
handle */<BR>
long            
status[20];       
/* status vector */<BR>
char            
Db_name[128];<BR>
XSQLDA     
      * isqlda;<BR>
char ISC_FAR *   dpb =
NULL;    /* DB parameter buffer */<BR>
int     
      dpb_length;<BR>
char     
      username[31],
password[31];          
<BR>
<BR>
int main (int argc , char ** argv )<BR>
{<BR>
<BR>
<BR>
ISC_DATE       datei;<BR>
struct tm       datec;<BR>
char       
      prep_str [ MAXLEN
];<BR>
<BR>
isc_stmt_handle stmt_handler = NULL;   /*
statement handle*/<BR>
<BR>
<BR>
<BR>
dpb = ( char * ) malloc ( 20 );<BR>
      <BR>
memset (&datec, '\0', sizeof ( datec ) );<BR>
<BR>
strptime ("16/8/1971", "%d/%m/%Y",
&datec);<BR>
<BR>
datec.tm_mon++;<BR>
datec.tm_year += 1900;<BR>
<BR>
<BR>
<BR>
strcpy ( Db_name,
"/home/mau/interbase/sql/novo.gdb" );<BR>
strcpy ( username, "SYSDBA" );<BR>
strcpy ( password, "masterkey" );<BR>
<BR>
dpb_length = 0;<BR>
<BR>
isc_expand_dpb ( &dpb, ( short ISC_FAR * )
&dpb_length,<BR>
                 
isc_dpb_user_name, username,<BR>
                 
isc_dpb_password, password,  NULL );<BR>
<BR>
<BR>
<BR>
if ( isc_attach_database ( status, 0, Db_name,
&DB, dpb_length, <BR>
dpb ) ) {<BR>
         ERREXIT (
status, 1 );<BR>
         
   }<BR>
<BR>
      <BR>
/* <BR>
this is how the table was created:<BR>
CREATE TABLE TEST ( DATEI  DATE ); <BR>
*/<BR>
<BR>
strcpy ( prep_str, "INSERT INTO TEST ( DATEI )
VALUES ( ? )" );<BR>
<BR>
if ( isc_dsql_allocate_statement ( status, &DB,
&stmt_handler ) ) {<BR>
          
ERREXIT ( status, 1 );<BR>
         
   }<BR>
<BR>
if ( isc_start_transaction ( status, &trans, 1,
&DB, 0, NULL ) ) {<BR>
          
ERREXIT ( status, 1 );<BR>
         
   }<BR>
<BR>
if ( isc_dsql_prepare ( status, &trans,
&stmt_handler, 0, prep_str, <BR>
3, NULL ) ) {<BR>
          
ERREXIT ( status, 1 );<BR>
          
}<BR>
      <BR>
isqlda = ( XSQLDA * ) malloc ( XSQLDA_LENGTH (
PARAMETROS ) );<BR>
<BR>
isqlda -> version = SQLDA_VERSION1;<BR>
isqlda -> sqln    = PARAMETROS;<BR>
isqlda -> sqld    = PARAMETROS;<BR>
<BR>
<BR>
isc_encode_sql_date ( &datec, &datei );<BR>
<BR>
isqlda -> sqlvar [0].sqltype = SQL_DATE;<BR>
isqlda -> sqlvar [0].sqllen  = sizeof ( datei
);<BR>
isqlda -> sqlvar [0].sqldata = ( ISC_DATE *)
datei;<BR>
      <BR>
<BR>
<BR>
<BR>
printf ( "\nExecuting statement:\n");<BR>
<BR>
<BR>
<BR>
if ( isc_dsql_execute ( status, &trans,
&stmt_handler, 3, isqlda ) ) <BR>
{<BR>
         
   ERREXIT ( status, 1 );<BR>
          
}<BR>
<BR>
if ( isc_commit_transaction ( status, &trans ) )
{<BR>
          
ERREXIT ( status, 1 );<BR>
         }<BR>
<BR>
if ( isc_detach_database ( status, &DB ) ) {<BR>
          
ERREXIT ( status, 1 );<BR>
         }<BR>
<BR>
return 0;<BR>
}<BR>
<BR>
</tt>


<br>
<tt>
To unsubscribe from this group, send an email to:<BR>
ib-support-unsubscribe@egroups.com<BR>
<BR>
</tt>
<br>

<br>
<tt>Your use of Yahoo! Groups is subject to the <a
href="http://docs.yahoo.com/info/terms/">Yahoo! Terms
of Service</a>.</tt>
</br>

</body></html>


__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com