Exemplo n.º 1
0
int main(void)
{
    OCI_Connection *cn;
    OCI_Statement *st;
    OCI_Resultset *rs;

    char rowid[OCI_SIZE_ROWID + 1] = "";

    if (!OCI_Initialize(err_handler, NULL, OCI_ENV_DEFAULT))
    {
        return EXIT_FAILURE;
    }

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

    OCI_Immediate(cn, "select rowid from products where code = 1", OCI_ARG_TEXT, rowid);

    OCI_Prepare(st, "select code, name, rowid from products where rowid = :id");
    OCI_BindString(st, ":id", rowid, (unsigned int) strlen(rowid));
    OCI_Execute(st);
    rs = OCI_GetResultset(st);
    OCI_FetchNext(rs);
    printf("code [%d], name [%s], rowid [%s]", OCI_GetInt(rs, 1), OCI_GetString(rs, 2), OCI_GetString(rs, 3));

    OCI_StatementFree(st);
    OCI_ConnectionFree(cn);
    OCI_Cleanup();

    return EXIT_SUCCESS;
}
Exemplo n.º 2
0
int main(void)
{
    OCI_Connection *cn;
    OCI_Statement  *st;
    int res = 0;

    if (!OCI_Initialize(err_handler, NULL, OCI_ENV_DEFAULT))
    {
        return EXIT_FAILURE;
    }

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

    /* pl/sql call */

    OCI_Prepare(st, "begin :res := trunc(sysdate+1)-trunc(sysdate-1); end;");
    OCI_BindInt(st, ":res", &res);
    OCI_Execute(st);

    printf("result : %i\n", res);
 
    OCI_StatementFree(st);
    OCI_ConnectionFree(cn);
    OCI_Cleanup();

    return EXIT_SUCCESS;
}
Exemplo n.º 3
0
int main(void)
{
    OCI_Connection *con = NULL;

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

    con = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);

    /* Nominal test */
    do_load(con, FALSE, FALSE, FALSE, FALSE, "TEST BASE         - DEFAULT MODE");

    /* insufficient stream buffer size tests */
    do_load(con, FALSE, FALSE, TRUE, FALSE, "TEST SMALL BUFFER - DEFAULT MODE");
    do_load(con, FALSE, FALSE, TRUE, TRUE, "TEST SMALL BUFFER - FORCE   MODE");

    /* conversion error tests */
    do_load(con, TRUE, FALSE, FALSE, FALSE, "TEST CONV   ERROR - DEFAULT MODE");
    do_load(con, TRUE, FALSE, FALSE, TRUE, "TEST CONV   ERROR - FORCE   MODE");

    /* loading error tests */
    if (partionning_enabled)
    {
        do_load(con, FALSE, TRUE, FALSE, FALSE, "TEST LOAD   ERROR - DEFAULT MODE");
        do_load(con, FALSE, TRUE, FALSE, TRUE, "TEST LOAD   ERROR - FORCE   MODE");
    }

    OCI_ConnectionFree(con);
    OCI_Cleanup();

    return EXIT_SUCCESS;
}
Exemplo n.º 4
0
static HB_ERRCODE ocilibDisconnect( SQLDDCONNECTION * pConnection )
{
   HB_ERRCODE errCode;

   errCode = OCI_ConnectionFree( ( ( SDDCONN * ) pConnection->pSDDConn )->pConn ) ? HB_SUCCESS : HB_FAILURE;
   hb_xfree( pConnection->pSDDConn );
   return errCode;
}
Exemplo n.º 5
0
int ociw_cleanup(db_wrap * self)
{
	IMPL_DECL(DB_WRAP_E_BAD_ARG);
	if (dbimpl->conn)
	{
		OCI_ConnectionFree(dbimpl->conn);
	}
	free(self->impl.data);
	*self = db_wrap_empty;
	return 0;
}
Exemplo n.º 6
0
void check_results(OCI_Connection *con, OCI_DirPath *dp, int expected, int result, char *str)
{
    if (result != expected)
    {
        printf("FAILED : %s - expected  %d - result %d\n", str, expected, result);
        OCI_DirPathFree(dp);
        drop_table(con);
        OCI_ConnectionFree(con);
        OCI_Cleanup();
        exit(EXIT_FAILURE);
    }
}
Exemplo n.º 7
0
int main(int argc, char *argv[])
{
    OCI_Connection *con;
    OCI_Enqueue    *enq;
    OCI_Dequeue    *deq;
    OCI_Msg        *msg;
    OCI_TypeInfo   *inf;
    OCI_Object     *obj;
   
    OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT);
     
    con = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);

    inf = OCI_TypeInfoGet(con, "MY_MESSAGE", OCI_TIF_TYPE);
    
    enq = OCI_EnqueueCreate(inf, "my_queue");
    deq = OCI_DequeueCreate(inf, "my_queue");
    
    msg = OCI_MsgCreate(inf);
    obj = OCI_ObjectCreate(con, inf);

    OCI_ObjectSetString(obj, "TITLE", "NEXT MEETING");
    OCI_ObjectSetString(obj, "CONTENT", "12:00 PM IN STARBUCKS");

    OCI_MsgSetObject(msg, obj);

    OCI_EnqueuePut(enq, msg);

    OCI_MsgFree(msg);
    OCI_ObjectFree(obj);

    OCI_Commit(con);
    
    msg = OCI_DequeueGet(deq);
    obj = OCI_MsgGetObject(msg);

    printf("MSG '%s' => %s\n",  OCI_ObjectGetString(obj, "TITLE"),
                                OCI_ObjectGetString(obj, "CONTENT"));

    OCI_EnqueueFree(enq);
    OCI_DequeueFree(deq);
    OCI_ConnectionFree(con);

    OCI_Cleanup();

   return EXIT_SUCCESS;
}
Exemplo n.º 8
0
void worker(OCI_Thread *thread, void *data)
{
    OCI_Connection *cn = OCI_PoolGetConnection(data, NULL);
    char str[SIZE_STR+1];

    /* application work here */

    str[0] = 0;

    OCI_Immediate(cn, "select to_char(sysdate, 'YYYYMMDD HH24:MI:SS') from dual", OCI_ARG_TEXT, str);
    
    printf("%s\n", str);
    
    /* ... */

    OCI_ConnectionFree(cn);
}
Exemplo n.º 9
0
int main(void)
{
    OCI_Connection *cn;
    OCI_Statement *st;
    OCI_Object *racing_car;
    OCI_TypeInfo *vehicule_type_inf;
    OCI_TypeInfo *car_type_inf;
    OCI_TypeInfo *racing_car_type_inf;

    char buffer[512];
    unsigned int size = sizeof(buffer) - 1;

    if (!OCI_Initialize(err_handler, NULL, OCI_ENV_DEFAULT))
    {
        return EXIT_FAILURE;
    }

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

    racing_car = OCI_ObjectCreate(cn, OCI_TypeInfoGet(cn, "racing_car_type", OCI_TIF_TYPE));

    OCI_Prepare(st, "begin :obj := racing_car_type(1,'Formula1', 123456789, 300); end;");
    OCI_BindObject(st, "obj", racing_car);
    OCI_Execute(st);
    OCI_ObjectToText(racing_car, &size, buffer);
    printf("Object => %s\n", buffer);

    racing_car_type_inf = OCI_ObjectGetTypeInfo(racing_car);
    car_type_inf = OCI_TypeInfoGetSuperType(racing_car_type_inf);
    vehicule_type_inf = OCI_TypeInfoGetSuperType(car_type_inf);

    printf("Is type '%s' final => %d\n", OCI_TypeInfoGetName(racing_car_type_inf), OCI_TypeInfoIsFinalType(racing_car_type_inf));
    printf("Is type '%s' final => %d\n", OCI_TypeInfoGetName(car_type_inf), OCI_TypeInfoIsFinalType(car_type_inf));
    printf("Is type '%s' final => %d\n", OCI_TypeInfoGetName(vehicule_type_inf), OCI_TypeInfoIsFinalType(vehicule_type_inf));

    OCI_ObjectFree(racing_car);
    OCI_StatementFree(st);
    OCI_ConnectionFree(cn);
    
    OCI_Cleanup();

    return EXIT_SUCCESS;
}
Exemplo n.º 10
0
boolean OCI_SubscriptionClose
(
    OCI_Subscription *sub
)
{
    boolean res = TRUE;

    OCI_CHECK_PTR(OCI_IPC_NOTIFY, sub, FALSE);

#if OCI_VERSION_COMPILE >= OCI_10_2

    /* deregister the subscription if connection still alive */

    if (sub->subhp != NULL)
    {
        OCI_Connection * con = NULL;

        if (sub->con == NULL)
        {
            con = OCI_ConnectionCreate(sub->saved_db, sub->saved_user,
                                       sub->saved_pwd, OCI_SESSION_DEFAULT);

            sub->con = con;
        }

        if (sub->con != NULL)
        {
            OCI_CALL3
            (
                res, sub->err,

                OCISubscriptionUnRegister(sub->con->cxt, sub->subhp,
                                          sub->err,(ub4) OCI_DEFAULT)
            )
        }

        if (con != NULL)
        {
            OCI_ConnectionFree(con);
        }
    }
Exemplo n.º 11
0
void create_table(OCI_Connection *con)
{
    /* create a partitioned table (for loading error) */
    boolean res = OCI_ImmediateFmt(con, "create table %m(val_int int not null, val_str varchar2(30), val_date date) partition by range(val_int) ( partition test_dp_1 values less than (501),  partition test_dp_2 values less than (1001))", TABLE_NAME);

    /* in case partitioning is not available, create a regular table and disable loading errtests */
    if (!res)
    {
        partionning_enabled = FALSE;
        res = OCI_ImmediateFmt(con, "create table %m(val_int int not null, val_str varchar2(30), val_date date)", TABLE_NAME);
    }

    /* exit tests if table cannot be created */
    if (!res)
    {
        printf("FAILED : table cannot be created\n");
        drop_table(con);
        OCI_ConnectionFree(con);
        OCI_Cleanup();
        exit(EXIT_FAILURE);
    }
}
Exemplo n.º 12
0
int main(int argc, char *argv[])
{
    OCI_Connection *con;
    OCI_Enqueue    *enq;
    OCI_Dequeue    *deq1;
    OCI_Dequeue    *deq2;
    OCI_Msg        *msg;
    OCI_TypeInfo   *inf;
    OCI_Object     *obj;
    OCI_Agent      *agents[2];

    OCI_Initialize(err_handler, NULL, OCI_ENV_DEFAULT | OCI_ENV_THREADED |OCI_ENV_EVENTS);

    con = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);
    
    OCI_Immediate(con, "create type my_message as object (title varchar2(50), content varchar2(50)) ");

    OCI_QueueTableCreate(con, "my_queue_table", "my_message", NULL, NULL, TRUE, FALSE, NULL, 0,0,NULL);
    OCI_QueueCreate(con, "my_queue", "my_queue_table", OCIT_NORMAL, 0, 0, 0, 0, NULL);
    OCI_QueueStart(con, "my_queue", TRUE, TRUE);

    agents[0] = OCI_AgentCreate(con, "C1", NULL);
    agents[1] = OCI_AgentCreate(con, "C2", NULL);

    inf = OCI_TypeInfoGet(con, "MY_MESSAGE", OCI_TIF_TYPE);

    enq = OCI_EnqueueCreate(inf, "my_queue");
    deq1 = OCI_DequeueCreate(inf, "my_queue");
    deq2 = OCI_DequeueCreate(inf, "my_queue");

    OCI_DequeueSetConsumer(deq1, "C1");
    OCI_DequeueSetNavigation(deq1, OCI_ADN_FIRST_MSG);
    OCI_DequeueSetConsumer(deq2, "C2");
    OCI_DequeueSetNavigation(deq2, OCI_ADN_FIRST_MSG);

    OCI_DequeueSubscribe(deq1, 9998, 0, on_message);
    OCI_DequeueSubscribe(deq2, 9999, 0, on_message);

    msg = OCI_MsgCreate(inf);
    obj = OCI_ObjectCreate(con, inf);

    OCI_ObjectSetString(obj, "TITLE", "NEXT MEETING");
    OCI_ObjectSetString(obj, "CONTENT", "12:00 PM IN STARBUCKS");

    OCI_MsgSetObject(msg, obj);
    OCI_MsgSetConsumers(msg, agents, 2);

    OCI_EnqueuePut(enq, msg);

    OCI_MsgFree(msg);
    OCI_ObjectFree(obj);

    OCI_Commit(con);

    getchar();

    OCI_DequeueUnsubscribe(deq1);    
    OCI_DequeueUnsubscribe(deq2);    

    OCI_AgentFree(agents[0]);
    OCI_AgentFree(agents[1]);
    OCI_EnqueueFree(enq);
    OCI_DequeueFree(deq1);
    OCI_DequeueFree(deq2);
 
    OCI_QueueStop(con, "my_queue", TRUE, TRUE, 0);
    OCI_QueueDrop(con, "my_queue");
    OCI_QueueTableDrop(con, "my_queue_table", TRUE);
    OCI_Immediate(con, "drop type my_message");

    OCI_ConnectionFree(con);

    OCI_Cleanup();

    return EXIT_SUCCESS;
}
Exemplo n.º 13
0
void cleanup(OCI_Connection *con, OCI_DirPath *dp)
{
    OCI_DirPathFree(dp);
    OCI_ConnectionFree(con);
    OCI_Cleanup();
}
Exemplo n.º 14
-1
int main(void)
{
    OCI_Connection *cn;
    OCI_Statement *st;
    OCI_Thread *th;

    if (!OCI_Initialize(NULL, NULL, OCI_ENV_THREADED | OCI_ENV_CONTEXT))
    {
        return EXIT_FAILURE;
    }

    th = OCI_ThreadCreate();
    cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);
    st = OCI_StatementCreate(cn);

    OCI_ThreadRun(th, long_oracle_call, st);

    sleep(1);
    OCI_Break(cn);

    OCI_ThreadJoin(th);
    OCI_ThreadFree(th);

    OCI_StatementFree(st);
    OCI_ConnectionFree(cn);
    OCI_Cleanup();

    return EXIT_SUCCESS;
}