Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Q: Oracle 7.3 ODBC problems (BLOBs)
On Mon, 20 Apr 1998 11:41:28 GMT, marktoml_at_gdi.net (mark tomlinson)
wrote:
>Sure, bind a variable and do the insert/update/whatever. You simply
>can't use a SQL literal when doing this.
Then Bogdan Stepien <stepien_at_tpg.pl> wrote:
>
>Thank you for your reply, but unfortunately I am quite new to PL/SQL.
>Could you tell me more about "binding to variable"? What do you mean
>by bind a variable? Recall, that I have trouble with accessing LONG
>variable values (longer than 2000) through the ODBC interface.
>
>Thx for any info.
>BS
So what does this have to do with PL/SQL?Are you trying to use ODBC or PL/SQL? Here is an example using the ODBC API from C.
/*** This sample requires a binary file named INPUT.EXE to be placed ** in the C:\TEMP directory and it will create an OUTPUT.EXE from ** a fetch of the inserted rawdata.** ** You must create the following table in user SCOTT's schema: ** CREATE TABLE testlraw (c1 NUMBER, c2 LONG RAW);*/#include<windows.h>
long int nData; // Number Column char rData[16000]; // Long Raw Column FILE* fileptr; unsigned long filelen; SDWORD pcbValue; SDWORDpcbValue2;
(unsigned char*)"SCOTT", SQL_NTS, (unsigned
char*)"TIGER", SQL_NTS ); RCODE
if (retcode == SQL_SUCCESS_WITH_INFO) { goto errhndl; } else
{ printf("\n%s","Successful SQLConnect"); }
// Prepare and execute the insert statement
retcode = SQLAllocStmt(hdbc, &hstmt); RCODE fileptr = fopen("C:\\TEMP\\INPUT","rb"); filelen = _filelength(_fileno(fileptr));printf("\nFile is %i bytes long",filelen); nData = 10; retcode = SQLSetParam( hstmt, 1, SQL_C_LONG, SQL_INTEGER, 0, 0, &nData, &pcbValue2 ); RCODE
&pcbValue ); RCODE printf("\n%s","Successful
SQLSetParam");
retcode = SQLExecDirect(hstmt,
(unsigned char*)"INSERT INTO SCOTT.TESTLRAW VALUES (?,
?)", SQL_NTS);
printf("\n%s","Successful SQLExecute");
// Note the SQLParamData delimits the piecewise insert
retcode = SQLParamData( hstmt, &pToken ); i=0; do {
fread(rData, 1, 16000, fileptr); SQLPutData( hstmt, &rData,
SQL_NTS );
i+=16000; } while (i < filelen); fclose(fileptr);
retcode = SQLParamData( hstmt, &pToken );
printf("\n%s","Successful SQLPutData"); SQLTransact(henv, hstmt,
SQL_COMMIT);
SQLFreeStmt(hstmt, SQL_DROP); // Prepare and execute the data
fetch
retcode = SQLAllocStmt(hdbc, &hstmt); RCODE
retcode = SQLPrepare ( hstmt, (unsigned char*)"SELECT C2 FROM
SCOTT.TESTLRAW WHERE C1 = ?",
SQL_NTS ); RCODE printf("\n%s","Successful
SQLPrepare");
retcode = SQLSetParam( hstmt, 1, SQL_C_LONG, SQL_INTEGER, 15, 0,
&nData, &pcbValue2 ); RCODE
printf("\n%s","Successful SQLSetParam"); retcode =
SQLExecute(hstmt); RCODE
printf("\n%s","Successful SQLExecute"); retcode = SQLFetch(hstmt);
RCODE
printf("\n%s","Successful SQLFetch"); fileptr =
fopen("OUTPUT.EXE","wb");
i=0; do { SQLGetData( hstmt, 1, SQL_C_BINARY, &rData, 16000,
&pcbValue );
if ( i < filelen ) if (filelen >= 16000) fwrite(rData, 1, 16000, fileptr); else fwrite(rData, 1, filelen, fileptr); else fwrite(rData, 1, (filelen - i), fileptr); i+=16000; }while ( i < filelen); fclose(fileptr); printf("\n%s","Successful SQLGetData"); SQLFreeStmt(hstmt, SQL_CLOSE);
strcpy(str,"ODBC Message:\n"); strcat(str,(char*)sqlstate); strcat(str,"\n"); strcat(str,(char*)error_msg); printf("\n%s",str,"Fatal Error"); exit(1);}Received on Tue Apr 21 1998 - 07:22:53 CDT