Currently, the OPEN statement works correct together with long columns only if it is specified as a mass command.
So, change the line EXEC SQL OPEN cursupd USING DESCRIPTOR KEEP; to EXEC SQL FOR 1 OPEN cursupd USING DESCRIPTOR KEEP; which is in fact the same as the first OPEN statement. This is a workaround for a bug which will be fixed. Regards, Thomas Simenec SAP Labs Berlin -----Original Message----- From: Claus-Thomas Buhl [mailto:[EMAIL PROTECTED] Sent: Freitag, 18. Juli 2003 15:20 To: Simenec, Thomas Cc: [EMAIL PROTECTED] Subject: Re: Storing binary data in LONG (BYTE) columns in ESQL/C Find the source of the program and a Make appended. Showing the table X afterwards gives me a weird value for column f: [EMAIL PROTECTED]:~/proddb$ ./show_table.sh PRODDB HEIDEMO DEMO X dbmcli on localhost : PRODDB>OK --- dbmcli on localhost : PRODDB>OK END 'U?�f<f��<@P���' --- dbmcli on localhost : PRODDB It doesn't matter whether the data inserted with PUTVAL is binary or not. Regards, CTB "Simenec, Thomas" schrieb: > > The initialisation of the host variable seems to be okay. Perhaps the param[i].size > does not match the real size of param[i].buf for some i? > > For further analysis please send your cpc program and a corresponding precompiler > trace. > > Regards, > > Thomas Simenec > SAP Labs Berlin > > -----Original Message----- > From: Claus-Thomas Buhl [mailto:[EMAIL PROTECTED] > Sent: Donnerstag, 17. Juli 2003 18:06 > To: [EMAIL PROTECTED] > Cc: Simenec, Thomas > Subject: Re: Storing binary data in LONG (BYTE) columns in ESQL/C > > Ok, I converted my procedure to use a cursor and fixed allocation and > initialisation for the SQLLongDesc (see below for what I did in detail). > Now my program sometimes crashes in the PUTVAL statement with stack > being: > > Program received signal SIGSEGV, Segmentation fault. > 0x402421af in memcpy () from /lib/libc.so.6 > #1 0x40961793 in pr04LongPutData () > #2 0x40961fde in pr04LongInsertLongVarchar () > #3 0x40962616 in pr04LongPutvalData () > #4 0x409629cd in pr04LongPutvalInput () > #5 0x4094fa22 in pr01cEnd () > #6 0x40957832 in pr01SQLExecute () > #7 0x40954ffb in pr01PrecomExecute () > #8 0x4094cb98 in sqlCPCExecute () > > I suspect the error in the initialisation of the host variable for the > long column or it may also be a bug: > > ldesc->szBuf = param[i].buf; > ldesc->cbBufMax = param[i].size; > ldesc->cbBufLen = param[i].size; > ldesc->cbColLen = param[i].size; > > ha->hostvartype=sqlvlongdesc; > ha->hostvaraddr=ldesc; > ha->hostcolsize = sizeof (SQLLongDesc); > ha->collength = sizeof (SQLLongDesc); > > Here my changes in detail: > > 1. added > EXEC SQL DECLARE cursupd CURSOR FOR stmtupd; > if (sqlca.sqlcode!=0){return;} > between the PREPARE and DESCRIBE statement > > 2. replaced > SQLLongDesc *ldesc = (SQLLongDesc *)alloca(sizeof(SQLLongDesc)); > by > SQLLongDesc *ldesc = (SQLLongDesc *)malloc(sizeof(SQLLongDesc)); > > 3. added > ldesc->cbColLen = param[i].size; > > 4. replaced > EXEC SQL EXECUTE stmtupd USING DESCRIPTOR; > by > EXEC SQL OPEN cursupd USING DESCRIPTOR KEEP; > and > > 5. replaced > EXEC SQL PUTVAL stmtupd USING DESCRIPTOR; > by > EXEC SQL PUTVAL cursupd USING DESCRIPTOR; > > Regards, > > CTB > > "Simenec, Thomas" schrieb: > > > > Hi, > > > > you have to use a cursor to use long data operations with sqlda. > > > > E.g. use the following sequence: > > > > EXEC SQL PREPARE stmtupd from :stmt; > > EXEC SQL DECLARE :C1 CURSOR FOR stmtupd; > > EXEC SQL DESCRIBE stmtupd; > > EXEC SQL OPEN :C1 USING DESCRIPTOR KEEP; > > EXEC SQL PUTVAL :C1 USING DESCRIPTOR; > > > > The keyword KEEP at the end of the OPEN statement keeps the long columns open > > for inserting data by the use of following PUTVALs. > > > > Regards, > > > > Thomas Simenec > > SAP Labs Berlin > > > > -----Original Message----- > > From: Claus-Thomas Buhl [mailto:[EMAIL PROTECTED] > > Sent: Mittwoch, 16. Juli 2003 18:32 > > To: [EMAIL PROTECTED] > > Subject: Storing binary data in LONG (BYTE) columns in ESQL/C > > > > I am using the C/C++ precompiler of SAP DB 7.3.0.34 and want > > to store binary data in LONG (BYTE) columns. > > I have the following ESQL/C code snippet, there are no database errors > > at runtime, but the data isn't stored. What am I doing wrong ? > > > > int Update (char * sqlstmt, tparam param[], int nparam) { > > EXEC SQL BEGIN DECLARE SECTION; > > char * stmt; > > char stmtupd[8]; > > EXEC SQL END DECLARE SECTION; > > sqlvartype *ha; > > int longcols=0; > > > > stmt = sqlstmt; > > EXEC SQL PREPARE stmtupd FROM :stmt; > > if (sqlca.sqlcode!=0){return 1;} > > > > EXEC SQL DESCRIBE stmtupd; > > if (sqlca.sqlcode!=0){return 1;} > > > > for (i=0;i<nparam;i++){ > > ha = &sqlda.sqlvar[i]; > > if (ha->col.colislong) { > > SQLLongDesc *ldesc = (SQLLongDesc *)alloca(sizeof(SQLLongDesc)); > > ldesc->szBuf = param[i].buf; > > ldesc->cbBufMax = param[i].size; > > ldesc->cbBufLen = param[i].size; > > > > ha->hostvartype=sqlvlongdesc; > > ha->hostvaraddr=ldesc; > > ha->hostcolsize = sizeof (SQLLongDesc); > > ha->collength = sizeof (SQLLongDesc); > > > > longcols = 1; > > } else { > > ... > > } > > } > > > > EXEC SQL EXECUTE stmtupd USING DESCRIPTOR; > > if (sqlca.sqlcode!=0 && sqlca.sqlcode!=100) {return 1;} > > > > if (longcols) { > > EXEC SQL PUTVAL stmtupd USING DESCRIPTOR; > > if (sqlca.sqlcode!=0 && sqlca.sqlcode!=100){return 1;} > > } > > > > return 0; > > } > > > > Regards, > > > > CTB > > -- > > _______ > > \o/|\o/ Claus-Thomas Buhl > > | Diplom-Informatiker > > \_____/ mailto:[EMAIL PROTECTED] > > > > H.E.I. GmbH | Wimpfener Strasse 23 | D-68259 Mannheim > > Fon: +49-(0)621-795141 | Fax: +49-(0)621-795161 | mailto:[EMAIL PROTECTED] > > http://www.h-e-i.de && http://www.hei.biz && http://www.radpage.com > > _______________________________________________ > > sapdb.general mailing list > > [EMAIL PROTECTED] > > http://listserv.sap.com/mailman/listinfo/sapdb.general > > -- > _______ > \o/|\o/ Claus-Thomas Buhl > | Diplom-Informatiker > \_____/ mailto:[EMAIL PROTECTED] > > H.E.I. GmbH | Wimpfener Strasse 23 | D-68259 Mannheim > Fon: +49-(0)621-795141 | Fax: +49-(0)621-795161 | mailto:[EMAIL PROTECTED] > http://www.h-e-i.de && http://www.hei.biz && http://www.radpage.com -- _______ \o/|\o/ Claus-Thomas Buhl | Diplom-Informatiker \_____/ mailto:[EMAIL PROTECTED] H.E.I. GmbH | Wimpfener Strasse 23 | D-68259 Mannheim Fon: +49-(0)621-795141 | Fax: +49-(0)621-795161 | mailto:[EMAIL PROTECTED] http://www.h-e-i.de && http://www.hei.biz && http://www.radpage.com _______________________________________________ sapdb.general mailing list [EMAIL PROTECTED] http://listserv.sap.com/mailman/listinfo/sapdb.general
