Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: OCI OBINDPS(), etc...
On Tue, 2 Dec 1997 14:14:15 -0500, "Tim Steiger" <tsteiger_at_ctron.com> wrote:
>Hi:
>
> I am trying to follow the example in the OCI manual for using obindps in
>the C language. I keep getting GPF's when I execute the first fetch. I
>tried
>using oexfet() instead of oexec() followed by ofen(), but to no avail... I
>would greatly appreciate any insight that can be given.
>
>Thanks,
>Tim
>
Here is another example. Hope this helps (i know this one works, i use it all
the time...)
#include <stdio.h> #include <string.h> #include <stdlib.h>
#include "load.h"
#define DEFER_PARSE 1 /* oparse flags */ #define NATIVE 1 #define VERSION_7 2 #define OCI_MORE_INSERT_PIECES -3129 #define OCI_EXIT_FAILURE 1 /* exit flags */ #define OCI_EXIT_SUCCESS 0
void load_image( char * filename, char * mime_type, char * tname ) {
text longbuf[65536]; ub4 len_longbuf = sizeof(longbuf); ub4 piecesize = sizeof(longbuf); text img_size[20]; ub2 col_rcode; /* Column return code */ FILE * input;
printf("\nOpening source file %s\n", filename); if (!(input=fopen( filename, "rb" )) ) { perror( "fopen: " ); exit(1); } fseek( input, 0, SEEK_END ); sprintf( img_size, "%ld", ftell( input ) ); fseek( input, 0, SEEK_SET ); printf( "File is %s bytes...\n", img_size ); sprintf( sqlstmt, "INSERT INTO %s ( name, mime_type, img_size, image ) \VALUES (:name, :mime_type, :img_size, :image )", tname?tname:"image" );
if (oparse(&cda, sqlstmt, (sb4)-1, 0, (ub4)VERSION_7)) { printf( oerr_cda() ); exit(1); } if (obndrv(&cda, (text *)":name", -1, filename, -1, SQLT_STR, -1, (sb2 *)0, (ub1 *)0, -1, -1)) { printf( oerr_cda() ); exit(1); } if (obndrv(&cda, (text *)":mime_type", -1, mime_type, -1, SQLT_STR, -1, (sb2 *)0, (ub1 *)0, -1, -1)) { printf( oerr_cda() ); exit(1); } if (obndrv(&cda, (text *)":img_size", -1, img_size, -1, SQLT_STR, -1, (sb2 *)0, (ub1 *)0, -1, -1)) { printf( oerr_cda() ); exit(1); } if (obindps(&cda, 0, (text *)":image", strlen(":image"), (ub1 *)context, 999999999, SQLT_LBI, (sword)0, (sb2 *)0, (ub2 *)0, &col_rcode, 0, 0, 0, 0, 0, (ub4 *)0, (text *)0, 0, 0)) { printf( oerr_cda() ); exit(1); } while (cont) { oexec(&cda); printf( "return code %d\n", cda.rc ); switch (-cda.rc) { case 0: /* operation is finished */ cont = 0; break; case OCI_MORE_INSERT_PIECES: /* ORA-03129 was returned */ if ((len_longbuf = fread(longbuf, 1, len_longbuf, input)) == -1) { perror( "fread: " ); exit(1); } printf( "read %ld\n", len_longbuf ); if ( ogetpi(&cda, &piece, (dvoid**)&context, &iteration,&plsqltable) ) { printf( "ogetpi %s\n", oerr_cda() ); exit(1); } if (len_longbuf < piecesize) /* last piece? */ { piece = OCI_LAST_PIECE; printf( "Setting piece to last piece..\n" ); } if (osetpi(&cda, piece, longbuf, &len_longbuf)) { printf( "osetpi %s\n", oerr_cda() ); exit(1); } break; default: printf( "return code %d\n", cda.rc ); printf( oerr_cda() ); exit(1); } } ocom(&lda); /* Commit the insert */ fclose(input); if (oclose(&cda)) /* close cursor */ { printf( oerr_cda() ); exit(1); }
Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government
Bethesda MD
http://govt.us.oracle.com/ -- downloadable utilities
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 Dec 02 1997 - 00:00:00 CST