Re: ORA-3106 Error with Proc*C

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: 1998/01/13
Message-ID: <34c45d25.88274632_at_inet16>#1/1


On Mon, 12 Jan 1998 16:01:22 -0500, "Paul B. Feole" <paul_feole_at_merck.com> wrote:

>ORACLE: 7.1.3
>OpenVMS AXP: 6.2
>
>First of all, many thanks to everyone who answered my previous post
>regarding using Pro*C to insert long data. You might recognize some of
>your code in the attached function. Anyways, I've got the insert part
>of the program working, now the select function just doesn't want to
>work.
>
>The parameters are passed in via an DCL comfile which then executes the
>C program. Everything works fine until I get the error message:
>"ORA-03106: fatal two-task communication protocol error" just after the
>printf statement which echoes the libkey data value. This error occurs
>when trying to select the long into a buffer.
>
>Am I missing something ?

An malloc() for sure. The 3106 is being raised due to memory corruption. You are fetching into sbuffer below but you have never allocated any memory for it. You are responsible for allocating the memory to fetch into. You are passing an uninitialized pointer to the select into and its just writing stuff into random memory.

You need to allocate storage for sbuffer for this to work. I usually suggest that people store the LONG and the size of the long in the database so when they want to get it back out in proc, they fetch the rowid and the size out of the database -- malloc sufficient storage for the long in memory -- and then select the long out by rowid into the buffer they just allocated...

>
>TIA,
>Cliff Buetikofer
>(clifford_buetikofer_at_merck.com)
>(noodles_at_aol.com)
>
>Below is the C Function which actually does the select
>[---------------------------------------------------------]
>/*---------------------------------*/
>/*GET_FILE FUNCTION */
>/*Takes output file name and */
>/*creates the file. */
>/*---------------------------------*/
>
>int get_file(char file_name[])
>{
>
>EXEC SQL BEGIN DECLARE SECTION;
>typedef struct rec_my_long
>{
> long len;
> unsigned char arr[1];
>} my_long;
>
>EXEC SQL TYPE my_long IS LONG VARCHAR(1000) REFERENCE;
>
>my_long * sbuffer;
>int i;
>int size;
>FILE * output;
>
>EXEC SQL END DECLARE SECTION;
>
> EXEC SQL WHENEVER SQLERROR GOTO error;
> EXEC SQL WHENEVER NOT FOUND GOTO not_found;
>
> printf("Selecting scheme data for libkey: %s\n",libkey.arr);
>
>/*WORKS UP TO HERE */
>
> EXEC SQL SELECT RXN_SCHEME INTO :sbuffer
> FROM LIBRARY_RXN_SCHEMES
> WHERE LIBKEY = :libkey;
>
> printf("Got through buffer select...\n");
>
>
> if ((output = fopen(file_name,"w")) == NULL)
> {
> goto error;
> }
> printf("file_name pointer value: %s\n",output);
>
> sbuffer->len = sizeof sbuffer->arr;
> printf("Buffer Size: %ld\n",sbuffer->len);
>
> fwrite(sbuffer->arr, 1, sbuffer->len, output);
> printf("Writing string buffer to file\n");
>
> fclose(output);
>
> memset ( sbuffer->arr, 0, size);
>
> return (PASS);
>
> not_found:
> error:
> error_index++;
> strcpy(error_msg[error_index].text, sqlca.sqlerrm.sqlerrmc);
> strcat(error_msg[error_index].text," File Write Failed");
> strcat(error_msg[error_index].text," - libkey.arr: ");
> strcat(error_msg[error_index].text,libkey.arr);
>
> if ((output = fopen(file_name,"r")) == NULL)
> strcat(error_msg[error_index].text," - File WRITE Failed");
>
> printf("%s\n", error_msg[error_index].text);
>
> return (FAIL);
>
>}
>
>
>
>
> The contents of this message express only the sender's opinion.
> This message does not necessarily reflect the policy or views of
> my employer, Merck & Co., Inc. All responsibility for the statements
> made in this Usenet posting resides solely and completely with the
> sender.
 

Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government
Bethesda MD  

http://govt.us.oracle.com/ -- downloadable utilities  



Opinions are mine and do not necessarily reflect those of Oracle Corporation  

Anti-Anti Spam Msg: if you want an answer emailed to you, you have to make it easy to get email to you. Any bounced email will be treated the same way i treat SPAM-- I delete it. Received on Tue Jan 13 1998 - 00:00:00 CET

Original text of this message