Piecewise insert using OCI 7.3

From: Martin Haneferd <NOSPAMmartin_at_systemplan.no>
Date: Fri, 15 Oct 1999 12:15:40 +0100
Message-ID: <7u6udm$42t$1_at_news.netpower.no>



Do anyone have a successful code-snip on how to insert a text-string (CString) into a long col. in oracle 7.3 ... I've tried to use the example with inserting Binary-field into a long raw col. and translate it to use a zeroterminated string instead, but the program (oexec call) just continuing to ask for more pieces after I'v tell it that I've sent the last piece..
I use VisualC 6
please respond to my email aswell.. martin_at_systemplan.no

A little code-sniplet that does'nt work:
#ifdef _ORACLE_

extern "C"{

#define OCI_EXIT_FAILURE 0
#define OCI_MORE_INSERT_PIECES 3129

void put_tekst(Lda_Def *lda, const char* szTable, const char* szTekstField,const char* szTekstValue, const char* szFilter) {
 ub4 piecesize = 10;
 Cda_Def cdda;
 Cda_Def *cda = &cdda;

  text  *longbuf;      // buffer to hold long column on insert
  ub4    len_longbuf;                     // length of longbuf
  ub2    col_rcode;                       file://Column return code
  char *context = "context pointer";
  char* p=NULL;
  ub1 piece;
  ub4 iteration;
  ub4 plsqltable;
  ub1 cont = (ub1)1;
  text *sqlstmt = (text*) malloc(100);
  char buff[100];
  sprintf(buff,"UPDATE %s SET %s = :filecontent WHERE %s",szTable,szTekstField,szFilter);
  p= buff;
  int i=0;
  while(*p != '\0')
  {
 sqlstmt[i] = *p;
 p++;
 i++;
  }
 sqlstmt[i] = '\0';

text* tp=NULL;

// text *sqlstmt = (text *) "UPDATE BT SET TEKST=:filecontent";

  if (oopen(cda, lda, (text *)0, -1, -1, (text *)0, -1))     exit(OCI_EXIT_FAILURE);

  text* jj = (text*)malloc(strlen(szTekstValue)+1);   i = 0;
  int iLen = strlen(szTekstValue);
  while(i<iLen )
  {
   jj[i] = szTekstValue[i];
   i++;
  }
 jj[i] = '\0';
 // strcpy(jj,szTekstValue);

                    file://Allocate memory for storage of one piece
  len_longbuf = piecesize;
  longbuf     = (text *)malloc(len_longbuf);
  if (longbuf == (text *)NULL)
    exit(1);

  if (oparse(cda, (text *)sqlstmt, (sb4)-1, 0, (ub4)1))     exit(OCI_EXIT_FAILURE);

  if (obindps(cda, 0, (text* )":filecontent",

              strlen(":filecontent"), (ub1 *)context, len_longbuf,
              SQLT_LBI, (sword)0, (sb2 *)0,
              (ub2 *)0, &col_rcode, 0, 0, 0, 0,
              0, (ub4 *)0, (text *)0, 0, 0))
    exit(OCI_EXIT_FAILURE);

  tp = jj;
  int pnt = 0;
  while (cont)
  {
    oexec(cda);
    switch (cda->rc)
    {

    case 0:                           // operation is finished
      cont = 0;
      break;
    case OCI_MORE_INSERT_PIECES:      file://ORA-03129 was returned

/* int i=0;

    while(i<(len_longbuf))
   {
    longbuf[i] = *tp;
    i++;
    tp++;
    if(*tp == '\0' && (len_longbuf)>i)
    {
   longbuf[i] = *tp;
   len_longbuf = i;
   break;
    }
   }
   longbuf[i]='\0';*/
   if(pnt+len_longbuf > strlen(szTekstValue))     len_longbuf = strlen(szTekstValue)-pnt;

   pnt+=len_longbuf;

//    longbuf--;
//   strncpy(longbuf,p,len_longbuf);
//   len_longbuf = strlen(longbuf);
//    p+=len_longbuf;

   ogetpi(cda, &piece, (dvoid **)&context, &iteration,     &plsqltable);

   if (len_longbuf < piecesize) file://last piece?    {
  piece = OCI_LAST_PIECE;
   }

      osetpi(cda, piece, tp, &len_longbuf);     tp+=len_longbuf;
     break;
    default:

      file://err_report(lda, cda);
      exit(OCI_EXIT_FAILURE);

    }
  }
  ocom(lda);                               file://Commit the insert
  if (oclose(cda))                         //     close cursor
    exit(OCI_EXIT_FAILURE);
  free(sqlstmt);
  free(longbuf);
  free(jj);

}
} file://Extern "C" Received on Fri Oct 15 1999 - 13:15:40 CEST

Original text of this message