Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> HELP: Dynamic SQL/Pro*C++ core dumps
I am new to Oracle Dynamic SQL and I am having trouble getting a
small test program up and running. (I'm using Oracle 7.3.3 on Solaris
2.5.1 and it compiles and links cleanly after running cleanly with
Pro*C 2.2.3.0.0.)
PROBLEM: The attached program core dumps while opening the cursor (i.e. line "EXEC SQL OPEN curs1 USING DESCRIPTOR sqlda_bv;"). It fails on the line "sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn);" which is part of the OPEN cursor block inserted by the Pro*C++ precompiler. The debugger gives the following message:
program terminated by signal SEGV (no mapping at the fault address)
dbx: warning: Can't find function symbol for 'main' :
/home/kdougan/oracle2/libs/catalog/dynam_ex1:main.cc stab #940
main:F(0,3);(0,3);(0,24)=*(33,17)
dbx: warning: undefined type number (0,24) at
/home/kdougan/oracle2/libs/catalog/dynam_ex1:main.cc stab #943
argv:p(0,24),
assuming type `int {assumed}'
Current function is main
633 sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn);
All addresses of the above variables are valid and appear to contain reasonable data. (I've attached the values for each argument.)
If anyone can shed some light on this I would be extremely grateful!!
Thanks.
Ken
(dbx) print sqlctx
sqlctx = 307331U
(dbx) print sqlstm
sqlstm = {
sqlvsn = 8U arrsiz = 3U iters = 1U offset = 60U selerr = 61308U sqlety = 0 unused = 0 cud = 0x930c0 sqlest = 0x95360 "" stmt = 0x931fd "" sqphsv = 0xeffff11c sqphsl = 0xeffff128 sqpind = 0xeffff134 sqparm = 0xeffff140 sqparc = 0xeffff14c sqhstv = (0xc1870 "", 0xef7eb8e8 "", 0xef7eb8e8 "") sqhstl = (0, 26U, 4016510332U) sqindv = ((nil), 0xef7ec950, (nil)) sqharm = (0, 0, 4016510072U) sqharc = ((nil), (nil), 0x4994866)
fillen = 12U
filnam = "dynam_ex1.pc"
}
CC -c -o ./sparc-solaris25/dynam_ex1.o -g
-I/home/kumayri/sw30/swdev/include
-I/home/burma3/Ora701/app/oracle/product/7.3.3/precomp/public -I. -I./..
-I./../../include -ptrsparc-solaris25 -I/home/rpe/include
-I/home/rpe/support_libs/temp_stl/ospace/std
-I/home/rpe/support_libs/temp_stl -DFUNCPROTO=3 -D_REENTRANT
-D_XOPEN_SOURCE -g -DDEBUG dynam_ex1.cc
CC -o ./sparc-solaris25/dynam_ex1 ./sparc-solaris25/dynam_ex1.o
./sparc-solaris25/Extent.o ./sparc-solaris25/Catalog.o
./sparc-solaris25/DatumRec.o ./sparc-solaris25/main.o
-L./sparc-solaris25 -lappframe -lpreference -llicense -lmessage -lfile
-lutil -lport -lpscmath -L/home/kumayri/sw30/swdev/lib -qoption ld
-zmuldefs -lsdl -lowcomm -lowenv /opt/SUNWspro/SC4.0/lib/libF77.a
/opt/SUNWspro/SC4.0/lib/libV77.a /opt/SUNWspro/SC4.0/lib/libM77.a
-L/home/apps/solaris25/flexlm/v5.12/sun4_u5 -llmgr -llmgr_as -llmgr_pic
-llmgr_s -llmgrd -llmutil -lintl -lsocket -lnsl
-L/home/burma3/Ora701/app/oracle/product/7.3.3/lib -lclntsh -lxa -lsql
-lsqlnet -lncr -lsqlnet -lclient -lcommon -lgeneric -lsqlnet -lncr
-lsqlnet -lclient -lcommon -lgeneric -lepc -lnlsrtl3 -lc3v6 -lcore3
-lnlsrtl3 -lcore3 -lnlsrtl3 -L../../support_libs/temp_stl/lib -lospace
`cat /home/burma3/Ora701/app/oracle/product/7.3.3/rdbms/lib/sysliblist`
-ptrsparc-solaris25 -L./sparc-solaris25 -L./../../lib/sparc-solaris25
-L/home/rpe/lib/sparc-solaris25 -lstdc++ -lsunmath -lgen -lw -lm
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <malloc.h>
extern "C" {
EXEC SQL INCLUDE sqlca;
EXEC SQL INCLUDE sqlda;
EXEC SQL INCLUDE sqlcpr;
extern void sqlclu( struct SQLDA* );
extern SQLDA *sqlald(int, unsigned int, unsigned int);
extern void sqlnul( unsigned short*, unsigned short*, int* );
extern void sqlprc( unsigned long*, int*, int*);
};
int main( int argc, char** argv )
{
char vtest[50];
int _type;
int v_int;
long v_long;
float v_float;
double v_double;
int v_bv_int = 1;
int i; /* counter variable */ int nullok; /* holder variable for sqlnul() return */ int prec; /* holder variable for sqlprec() */ int scale; /* holder variable for sqlprec() */ SQLDA* sqlda_bv; /* declare sqlda for bind variables */ SQLDA* sqlda_sli; /* declare sqlda for select list items */
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR username[21];
VARCHAR password[21];
EXEC SQL END DECLARE SECTION;
strcpy((char*)username.arr, "ken");
username.len = strlen((const char*)username.arr);
strcpy((char*)password.arr, "ken");
password.len = strlen((const char*)password.arr);
EXEC SQL CONNECT :username IDENTIFIED BY :password;
/* sqlald(max # of SLI items, max SLI name length, max BV name length)
*/
/* NB: When allocating for a select decriptor always set param 3 to
'0' */
sqlda_bv = sqlald(3,10,10);
sqlda_sli = sqlald(4,10,0);
/* set max # of BVs */
sqlda_bv->N=3;
/* set max # of SLIs */
sqlda_sli->N=4;
EXEC SQL PREPARE stmt1 FROM "select i, l, f, d from foo where i = :id";
EXEC SQL DECLARE curs1 CURSOR FOR stmt1;
EXEC SQL DESCRIBE BIND VARIABLES FOR stmt1 INTO sqlda_bv;
/* Allocate storage for BVs */
sqlda_bv->N=sqlda_bv->F; /* reset N to the value in F */
for(i=1;i<sqlda_bv->F+1;i++) {
/* Setup the I (Indicator Variable) value */ sqlda_bv->I[i-1]=(short *)malloc(sizeof(short *)); *sqlda_bv->I[i-1]=0; /* or set to -1 if NULL value */ /* Setup the T (Datatype) value */ /* sqlda_bv->T[i-1]=1; */ sqlda_bv->T[i-1]=3; /* integer */ /* Setup the L (Length) value */ /* sqlda_bv->L[i-1]=strlen((const char*)v_bv_val); */ sqlda_bv->L[i-1]= sizeof(int); /* Setup the V (Value/Address) value */ /* sqlda_bv->V[i-1]=v_bv_val; */ sqlda_bv->V[i-1]=(char*)v_bv_int;}
EXEC SQL OPEN curs1 USING DESCRIPTOR sqlda_bv;
EXEC SQL DESCRIBE SELECT LIST FOR stmt1 INTO sqlda_sli;
/* printf("\nHere's the value:\t%i",sqlca.sqlerrd[2]); */ /* exit(0); */
/* Allocate storage for SLIs */
sqlda_sli->N=sqlda_sli->F; /* reset N to the value in F */
for(i=1;i<sqlda_sli->F+1;i++)
{
/* Reset the null bit value */ sqlnul((unsigned short*)&sqlda_sli->T[i-1], (unsigned short*)&sqlda_sli->T[i-1], &nullok); /* Setup the I (Indicator Variable) value */ sqlda_sli->I[i-1]=(short *)malloc(sizeof(short *)); if (i == 1) _type = 3; /* INTEGER */ if (i == 2) _type = 8; /* LONG */ if (i == 3) _type = 4; /* FLOAT */ if (i == 4) _type = 2; /* NUMBER */ /* Setup the L (Length) value and the T (Datatype) value */ switch( _type ) { /* VARCHAR2 */ case 1: sqlda_sli->T[i-1] = 1; break; /* NUMBER -- FLOAT into double */ case 2: sqlprc((unsigned long*)&sqlda_sli->L[i-1],&prec,&scale); /* sqlda_sli->L[i-1] = sizeof(int); */ sqlda_sli->L[i-1] = sizeof(double); sqlda_sli->T[i-1] = 4; sqlda_sli->V[i-1]=(char*) &v_double; break; /* INTEGER */ case 3: /* sqlda_sli->L[i-1] = sizeof(int); */ sqlda_sli->L[i-1] = sizeof(int); sqlda_sli->T[i-1] = 3; sqlda_sli->V[i-1]=(char*) &v_int; break; /* FLOAT (this is never the case since 4 never occurs */ case 4: sqlprc((unsigned long*)&sqlda_sli->L[i-1],&prec,&scale); sqlda_sli->L[i-1] = sizeof(float); sqlda_sli->T[i-1] = 4; /* Store to a variable */ sqlda_sli->V[i-1]=(char*) &v_float; /* Store to a sqlda */ /* sqlda_sli->V[i-1]=(char *)malloc((size_t)sqlda_sli->L[i-1]); */ break; /* PACKED DECIMAL */ case 7: break; /* LONG */ case 8: sqlprc((unsigned long*)&sqlda_sli->L[i-1],&prec,&scale); /* sqlda_sli->L[i-1] = sizeof(int); */ sqlda_sli->L[i-1] = sizeof(long); sqlda_sli->T[i-1] = 8; sqlda_sli->V[i-1]=(char*) &v_long; break; /* LONG RAW */ case 24: sqlda_sli->L[i-1] = 240; break; } /* Setup the V (Value/Address) value (check for numbers!!) */ if (sqlda_sli->T[i-1]!=2 && sqlda_sli->T[i-1]!=4) sqlda_sli->V[i-1]=(char *)malloc((size_t)sqlda_sli->L[i-1]);}
EXEC SQL FETCH curs1 USING DESCRIPTOR sqlda_sli;
v_int = *((int*)(sqlda_sli->V[0]));
printf( "sli int: %i", *((int*)(sqlda_sli->V[0])) );
printf( " v_int: %i", v_int );
v_long = *((long*)(sqlda_sli->V[1]));
printf( "sli long: %l", *((long*)(sqlda_sli->V[1])) );
printf( " v_long: %l", v_long );
v_float = *((float*)(sqlda_sli->V[2]));
printf( "sli float: %l", *((float*)(sqlda_sli->V[2])) );
printf( " v_float: %l", v_float );
v_double = *((double*)(sqlda_sli->V[3]));
printf( "sli double: %f", *((double*)(sqlda_sli->V[3])) );
printf( " v_double: %f", v_double );
/* Deallocate storage for SLIs, BVs, and SQLDAs */
/* Handle SLI deallocations */
for(i=1;i<sqlda_sli->F+1;i++)
{
free(sqlda_sli->V[i-1]); free(sqlda_sli->I[i-1]);
/* Handle BV deallocations */
for(i=1;i<sqlda_bv->F+1;i++)
{
free(sqlda_bv->V[i-1]); free(sqlda_bv->I[i-1]);
/* Handle sqlda deallocations */
sqlclu(sqlda_bv);
sqlclu(sqlda_sli);
EXEC SQL CLOSE curs1;
return 0;
}
Received on Mon Feb 08 1999 - 12:18:42 CST
![]() |
![]() |