1 Reply Latest reply: Jan 6, 2012 9:25 AM by 894085 RSS

    OCIStmtExecute fails with ORA03001 : Unimplemented feature

    user4928701
      Below is my program for inserting a value into a table. The OCIStmtExecute fails with ORA03001 : Unimplemented feature. Please help why this is happening.

      <code>
      #include <stdio.h>
      #include <stdlib.h>
      #include <string.h>
      #include <oci.h>
      #include<conio.h>
      static text username = (text ) "mrs_user";
      static text password = (text ) "mrs_user";

      /* Define SQL statements to be used in program. */
      static text selquery = (text )"insert into tgt_char_table values :1";

      static OCIEnv *envhp;
      static OCIError *errhp;
      static void checkerr();
      static void cleanup();

      int main();

      static sword status;

      int main(argc, argv)
      int argc;
      char *argv[];
      {

      sb4 srchlen = 10;
      sb4 rtvlen = 10;
      text *srchstrng;

      OCISession authp = (OCISession ) 0;
      OCIServer *srvhp;
      OCISvcCtx *svchp;
      OCIStmt *stmthp;
      OCIDefine defnp = (OCIDefine ) 0;
      OCIBind bndp = (OCIBind ) 0;

      (void) OCIInitialize((ub4) OCI_DEFAULT, (dvoid *)0,
      (dvoid * (*)(dvoid *, size_t)) 0,
      (dvoid * (*)(dvoid *, dvoid *, size_t))0,
      (void (*)(dvoid *, dvoid *)) 0 );

      (void) OCIEnvInit( (OCIEnv **) &envhp, OCI_DEFAULT, (size_t) 0,
      (dvoid **) 0 );

      (void) OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &errhp, OCI_HTYPE_ERROR,
      (size_t) 0, (dvoid **) 0);

      /* server contexts */
      (void) OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &srvhp, OCI_HTYPE_SERVER,
      (size_t) 0, (dvoid **) 0);

      (void) OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &svchp, OCI_HTYPE_SVCCTX,
      (size_t) 0, (dvoid **) 0);

      (void) OCIServerAttach( srvhp, errhp, (text *)"xe", strlen("xe"), 0);

      /* set attribute server context in the service context */
      (void) OCIAttrSet( (dvoid *) svchp, OCI_HTYPE_SVCCTX, (dvoid *)srvhp,
      (ub4) 0, OCI_ATTR_SERVER, (OCIError *) errhp);

      (void) OCIHandleAlloc((dvoid *) envhp, (dvoid **)&authp,
      (ub4) OCI_HTYPE_SESSION, (size_t) 0, (dvoid **) 0);

      (void) OCIAttrSet((dvoid *) authp, (ub4) OCI_HTYPE_SESSION,
      (dvoid *) username, (ub4) strlen((char *)username),
      (ub4) OCI_ATTR_USERNAME, errhp);

      (void) OCIAttrSet((dvoid *) authp, (ub4) OCI_HTYPE_SESSION,
      (dvoid *) password, (ub4) strlen((char *)password),
      (ub4) OCI_ATTR_PASSWORD, errhp);

      checkerr(errhp, OCISessionBegin ( svchp, errhp, authp, OCI_CRED_RDBMS,
      (ub4) OCI_DEFAULT));

      (void) OCIAttrSet((dvoid *) svchp, (ub4) OCI_HTYPE_SVCCTX,
      (dvoid *) authp, (ub4) 0,
      (ub4) OCI_ATTR_SESSION, errhp);

      checkerr(errhp, OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &stmthp,
      OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0));


      /* Allocating buffer for the search string and Retrieved string */
      srchstrng = (text * ) malloc ( (size_t)srchlen + 1);

      /* Preparing statement */
      checkerr(errhp, OCIStmtPrepare(stmthp, errhp, selquery,(ub4) strlen((char *) selquery),(ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT));

      /* Define the output variable for the select-list. */
      /* if (status = OCIDefineByPos(stmthp, &defnp, errhp, 1,(dvoid *) retrievedstring, rtvlen+1, SQLT_AFC,(dvoid *) 0, (ub2 *) 0, (ub2 *) 0, OCI_DEFAULT))
      {
      checkerr(errhp, status);
      cleanup();
      return OCI_ERROR;
      }*/


      printf("Enter the name to be inserted: ");
      scanf("%[^\n]", srchstrng);
      printf("The name entered is \"%s\" and length is %d\n",srchstrng,strlen(srchstrng));

           /* Bind the placeholder in the "selquery" statement. */
           if (status = OCIBindByPos(stmthp, &bndp, errhp, 1,
                     (dvoid *) srchstrng, (sword) srchlen,SQLT_AVC,
                     (dvoid *) 0, (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT))
           {
                checkerr(errhp, status);
                cleanup();
                return OCI_ERROR;
           }

      if ((status = OCIStmtExecute(svchp, stmthp, errhp, (ub4) 1, (ub4) 0,
      (CONST OCISnapshot *) NULL, (OCISnapshot *) NULL, OCI_DEFAULT)) && (status != OCI_NO_DATA))
      {
      checkerr(errhp, status);
      cleanup();
      return OCI_ERROR;
      }
      if (status == OCI_NO_DATA)
      printf("The name entered doesn't exist. ");
           
           getche();
           return 0;
           
      } /* End Main */


      void checkerr(errhp, status)
      OCIError *errhp;
      sword status;
      {
      text errbuf[512];
      sb4 errcode = 0;
      switch (status)
      {
      case OCI_SUCCESS:
      break;
      case OCI_SUCCESS_WITH_INFO:
      (void) printf("Error - OCI_SUCCESS_WITH_INFO\n");
      break;
      case OCI_NEED_DATA:
      (void) printf("Error - OCI_NEED_DATA\n");
      break;
      case OCI_NO_DATA:
      (void) printf("Error - OCI_NODATA\n");
      break;
      case OCI_ERROR:
      (void) OCIErrorGet((dvoid *)errhp, (ub4) 1, (text *) NULL, &errcode,
      errbuf, (ub4) sizeof(errbuf), OCI_HTYPE_ERROR);
      (void) printf("Error - %.*s\n", 512, errbuf);
      break;
      case OCI_INVALID_HANDLE:
      (void) printf("Error - OCI_INVALID_HANDLE\n");
      break;
      case OCI_STILL_EXECUTING:
      (void) printf("Error - OCI_STILL_EXECUTE\n");
      break;
      case OCI_CONTINUE:
      (void) printf("Error - OCI_CONTINUE\n");
      break;
      default:
      break;
      }
      }

      void cleanup()
      {
      if (envhp)
      (void) OCIHandleFree((dvoid *) envhp, OCI_HTYPE_ENV);
      return;
      }
      </code>