Beispiel #1
0
static HB_ERRCODE ocilibExecute( SQLDDCONNECTION * pConnection, PHB_ITEM pItem )
{
   OCI_Statement * st = OCI_StatementCreate( ( ( SDDCONN * ) pConnection->pSDDConn )->pConn );
   void *          hStatement;
   char *          szError;
   HB_ERRCODE      errCode;

   if( ! st )
   {
      szError = ocilibGetError( &errCode );
      hb_errRT_OCIDD( EG_OPEN, ESQLDD_STMTALLOC, szError, hb_itemGetCPtr( pItem ), errCode );
      hb_xfree( szError );
      return HB_FAILURE;
   }

   if( OCI_ExecuteStmt( st, M_HB_ITEMGETSTR( pItem, &hStatement, NULL ) ) )
   {
      hb_strfree( hStatement );

      /* TODO: new id */
      hb_rddsqlSetError( 0, NULL, hb_itemGetCPtr( pItem ), NULL, ( unsigned long ) OCI_GetAffectedRows( st ) );
      OCI_StatementFree( st );
      return HB_SUCCESS;
   }
   else
      hb_strfree( hStatement );

   szError = ocilibGetError( &errCode );
   hb_rddsqlSetError( errCode, szError, hb_itemGetCPtr( pItem ), NULL, 0 );
   hb_xfree( szError );
   OCI_StatementFree( st );
   return HB_FAILURE;
}
Beispiel #2
0
QueryResult Statement::doExecute()
{
    Q_ASSERT(connection);
    if(connection->mutex.tryLock()){
        print("Statement::doExecute called with unlocked mutex. This is a bug. The program will exit.");
        exit(1);
    }

    Q_ASSERT(prepared);
    Q_ASSERT(ociStmt);

    if(useScrollableResultsets){
        OCI_SetFetchMode(ociStmt, OCI_SFM_SCROLLABLE);
    }

    int execResult=OCI_Execute(ociStmt);

    if(!execResult){
        DbUtil::checkForOciError(this);
    }

    QueryResult queryResult;

    if(this->verb.isEmpty()){
        this->verb=toQString(OCI_GetSQLVerb(ociStmt));
    }

    if(this->statementType==OraExp::QueryTypeUnknown){
        this->statementType=determineStatementType();
    }

    if(statementType==OraExp::QueryTypeUpdate || statementType==OraExp::QueryTypeDelete || statementType==OraExp::QueryTypeInsert){

        this->affectedRecordCount=OCI_GetAffectedRows(ociStmt);

    }//else if(statementType==OraExp::QueryTypeBegin || statementType==OraExp::QueryTypeDeclare){

        collectParamResultsets();

    //}

    DbUtil::checkForOciError(this);

    if(statementType==OraExp::QueryTypeSelect){
        OCI_Resultset *ociResultSet=OCI_GetResultset(ociStmt);
        if(ociResultSet==NULL){
            DbUtil::checkForOciError(this);
        }
        OCI_SetPrefetchSize(ociStmt, DB_PREFETCH_SIZE);
        OCI_SetFetchSize(ociStmt, DB_PREFETCH_SIZE);

        Q_ASSERT(this->resultsets.isEmpty());
        this->resultsets.append(new Resultset(ociResultSet, connection, this));
    }

    queryResult.statement=this;

    return queryResult;
}
int main(void)
{
    OCI_Connection *cn;
    OCI_Statement  *st;
    OCI_Error      *err;

    int tab_int[1000];
    char tab_str[1000][21];

    int i;

    if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT | OCI_ENV_CONTEXT))
        return EXIT_FAILURE;

    /* ... create connection and statement ... */

    cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);
    st = OCI_StatementCreate(cn);
 
    /* binding */

    OCI_Prepare(st, "insert into products values(:i, :s)");
    OCI_BindArraySetSize(st, 1000);
    OCI_BindArrayOfInts(st, ":i", (int*) tab_int, 0);
    OCI_BindArrayOfStrings(st, ":s", (char*) tab_str, 20, 0);

    /* filling arrays */

    for(i=0;i<1000;i++)
    {
        tab_int[i] = i+1;
        sprintf(tab_str[i],"Name %d",i+1);
    }

    /* execute */

    if (!OCI_Execute(st))
    {
        printf("Number of DML array errors : %d\n", OCI_GetBatchErrorCount(st));       

        err = OCI_GetBatchError(st);

        while (err)
        {
            printf("Error at row %d : %s\n", OCI_ErrorGetRow(err), OCI_ErrorGetString(err));       

            err = OCI_GetBatchError(st);
        }
    }
 
    printf("row processed : %d\n", OCI_GetAffectedRows(st));

    OCI_Commit(cn);

    OCI_Cleanup();

    return EXIT_SUCCESS;
}