Esempio n. 1
0
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;
}
Esempio n. 2
0
int main(void)
{
    OCI_Connection *cn;
    OCI_Statement *st;
    int i;

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

    cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);
 
    st = OCI_StatementCreate(cn);
   
    OCI_SetBindAllocation(st, OCI_BAM_INTERNAL);

    OCI_Prepare(st, "insert into test_array values (:tab)");

    OCI_BindArraySetSize(st, NB_ELEMS);

    OCI_BindArrayOfDates(st, ":tab", NULL, 0);
    {
        OCI_Date ** tab = (OCI_Date **) OCI_BindGetData(OCI_GetBind(st, 1));

        for (i=0; i < NB_ELEMS; i++)
        {
            OCI_DateSysDate(tab[i]);
        }

        OCI_Execute(st);
    }

    OCI_Commit(cn); 

    OCI_Cleanup();
 
    return EXIT_SUCCESS;
}
Esempio n. 3
0
void Statement::setBindArraySize(unsigned int size)
{
    OCI_BindArraySetSize(ociStmt, size);
    DbUtil::checkForOciError(this);
}