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

    int code;

    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_Prepare(st, "delete from test_fetch where code = :code");
    OCI_BindInt(st, ":code", &code);
    
    code = 5;
    OCI_Execute(st);

    code = 12;
    OCI_Execute(st);
   
    OCI_Commit(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 *cn;
    OCI_Statement  *st;
    OCI_Resultset  *rs;

    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_Prepare(st, "update products set code = code+10 returning code into :i");
    OCI_RegisterInt(st, ":i");
    OCI_Execute(st);
  
    rs = OCI_GetResultset(st);

    while (OCI_FetchNext(rs))
        printf("%i\n", OCI_GetInt(rs, 1));
 
    printf("count : %i\n", OCI_GetRowCount(rs));
  
    OCI_Commit(cn);
    OCI_Cleanup();

    return EXIT_SUCCESS;
}
Exemplo n.º 4
0
int main(void)
{ 
    OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT);

    /* start remote instance */

    OCI_DatabaseStartup("db", 
                        "sys_usr", 
                        "sys_pwd", 
                        OCI_SESSION_SYSDBA, 
                        OCI_DB_SPM_FULL,
                        OCI_DB_SPF_FORCE,
                        NULL);


     /* shutdown remote instance */

    OCI_DatabaseShutdown("db", 
                         "sys_usr", 
                         "sys_pwd",  
                         OCI_SESSION_SYSDBA,
                         OCI_DB_SDM_FULL,
                         OCI_DB_SDF_ABORT);
    OCI_Cleanup();
    
    return EXIT_SUCCESS;
}   
Exemplo n.º 5
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.º 6
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.º 7
0
void start_oracle_db() {
  
	OCI_Initialize(NULL, NULL, OCI_ENV_CONTEXT | OCI_ENV_THREADED | OCI_ENV_EVENTS);
  
	GKeyFile *keyfile = NULL;
	GError *error = NULL;
	char *database, *user, *passwd;

	keyfile = g_key_file_new();
	check_gerror(error);

	g_key_file_load_from_file(keyfile, "sagrcache.conf", G_KEY_FILE_NONE, &error);
	check_gerror(error);
	
	database = g_key_file_get_string(keyfile, "oracle", "database", &error);
	check_gerror(error);

	user = g_key_file_get_string(keyfile, "oracle", "user", &error);
	check_gerror(error);

	passwd = g_key_file_get_string(keyfile, "oracle", "passwd", &error);
	check_gerror(error);

	oracledb = OCI_CreateConnection(database, user, passwd, OCI_SESSION_DEFAULT);
	check_ociliberror(oracledb);

	fprintf(stdout, "Conectado com oracle.\n");


}
Exemplo n.º 8
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;
}
Exemplo n.º 9
0
static void hb_ocidd_init( void * cargo )
{
   HB_SYMBOL_UNUSED( cargo );

   OCI_Initialize( NULL, NULL, OCI_ENV_DEFAULT | OCI_ENV_CONTEXT | OCI_ENV_THREADED );

   if( ! hb_sddRegister( &ocidd ) )
      hb_errInternal( HB_EI_RDDINVALID, NULL, NULL, NULL );
}
Exemplo n.º 10
0
int main(void)
{
    if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT))
        return EXIT_FAILURE;

    /* ... application code here ... */

    OCI_Cleanup();

 
    return EXIT_SUCCESS;
}
int main(void)
{
    OCI_Connection *cn;
    OCI_Statement  *st;
    OCI_Resultset  *rs;

    product_t     prd;
    product_ind_t ind;
 
    char buf[100];

    int i = 0;

    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_ExecuteStmt(st, "select * from products");

    rs = OCI_GetResultset(st);

    OCI_SetStructNumericType(rs, 1,  OCI_NUM_INT);
    OCI_SetStructNumericType(rs, 3,  OCI_NUM_DOUBLE);
   
    while (OCI_FetchNext(rs))
    {
        i++;

        OCI_GetStruct(rs, &prd, &ind);

        OCI_DateToText(prd.creation, "DD-MM-YYYY", 100, buf); 
        
        printf("row #%d              \n"
               "...prd.code     : %d \n"
               "...prd.name     : %s \n"
               "...prd.price    : %g \n"
               "...prd.creation : %s \n"
               "                     \n",
               i, prd.code, prd.name, prd.price, buf
              );
    }

    printf("\n\n%d row(s) fetched\n", OCI_GetRowCount(rs));

    OCI_Cleanup();

    return EXIT_SUCCESS;
}
Exemplo n.º 12
0
int main(void)
{
    OCI_Connection *cn;
    OCI_Statement *st;
    OCI_Resultset *rs;
    OCI_Lob *lob1, *lob2;

    char temp[SIZE_BUF+1];
    int code, n;

    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_ExecuteStmt(st, "select code, content from test_lob for update");

    rs = OCI_GetResultset(st);
    
    while (OCI_FetchNext(rs))
    {
        code = OCI_GetInt(rs, 1);
        lob1 = OCI_GetLob(rs, 2);
        lob2 = OCI_LobCreate(cn, OCI_CLOB);

        n = OCI_LobWrite(lob1, "Today, ", 7);
        OCI_LobSeek(lob1, n, OCI_SEEK_SET);
       
        n = OCI_LobWrite(lob2, "I'm going to the cinema !", 25);
       
        OCI_LobAppendLob(lob1, lob2);
        OCI_LobSeek(lob1, 0, OCI_SEEK_SET);
        
        n = OCI_LobRead(lob1, temp, SIZE_BUF);
        temp[n] = 0;

        printf("code: %i, action : %s\n", code, temp);
            
        OCI_LobFree(lob2);
    }

    printf("\n%d row(s) fetched\n", OCI_GetRowCount(rs));

    OCI_Cleanup();

    return EXIT_SUCCESS;
}
Exemplo n.º 13
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.º 14
0
int main(void)
{
    OCI_Connection *cn;

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

    cn = OCI_ConnectionCreate("wrong_db", "wrong_usr", "wrong_pwd", 
                              OCI_SESSION_DEFAULT);

    /* ... application code here ... */

    OCI_Cleanup();

 
    return EXIT_SUCCESS;
}
Exemplo n.º 15
0
static char ociw_oci_init()
{
	static char doneit = 0;
	if (doneit) return 1;
	doneit = 1;
	char const * libPath =
		//"/home/ora10/OraHome1/lib"
		NULL
		;
	if (! OCI_Initialize(oci_err_handler,
			             libPath,
			             OCI_SESSION_DEFAULT | OCI_ENV_CONTEXT))
		/* reminder: by passing OCI_ENV_CONTEXT we are supposed to get
		   instance-/thread-specific error information via
		   OCI_GetLastError(), but that's not what i'm seeing. i get fed
		   error info via oci_err_handler, but using
		   OCI_GetLastError() still returns no error info.
		   That might be due to this wording from the OCI docs:

		   OCI_GetLastError (void):
		   Retrieve the last error occurred within the last OCILIB call.

		   The problem with that is, we cannot be certain that the
		   error code collection is called immediately after the
		   command which fails (e.g. there might be a
		   cleanup/finalization in between the failure and error
		   collection). OCI is probably re-setting the error state on
		   successfull API calls (e.g. statement finalization, which
		   is one of the corner cases where i say the error state
		   shouldn't be touched).

		   After a short discussion with Andreas, i will implement
		   "the ugly workaround" for the short-term, in which we
		   harvest the information statically from oci_err_handler(),
		   and access that shared/static info from all db_wrap OCI
		   instances.
		*/
	{
		lerr("Could not initialize OCI driver!");
		return 0;
	}
	atexit(ociw_atexit);
	return 1;
}
Exemplo n.º 16
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.º 17
0
int main(void)
{
    OCI_Connection *cn;
    OCI_Statement  *st;
    OCI_Resultset  *rs;
 
    int code = 1;
    char name[50];
  
    if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT))
        return EXIT_FAILURE;

    cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);
    st = OCI_StatementCreate(cn);
 
    /* sql format with params ----------------------------------------------- */

    OCI_ExecuteStmtFmt(st, "select article from test_fetch where code = %i", code);

    rs = OCI_GetResultset(st);

    while (OCI_FetchNext(rs))
        printf("article : %s\n", OCI_GetString(rs, 1));

    /* sql immediate (parse, exec, one fetch) ------------------------------- */

    OCI_Immediate(cn, "select code, article from test_fetch where code = 1", 
                  OCI_ARG_INT, &code, OCI_ARG_TEXT, name);

    printf("article : %s - code %i\n", name, code);

    /* sql immediate (parse, exec, one fetch) with params ------------------- */

    
    OCI_ImmediateFmt(cn, "select article from test_fetch where code = %i", 
                          code, OCI_ARG_TEXT, name);

    printf("article : %s\n", name);

    OCI_Cleanup();
 
    return EXIT_SUCCESS;
}
Exemplo n.º 18
0
int main(void)
{
    OCI_Connection *cn;

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

    OCI_EnableWarnings(TRUE);

    cn = OCI_ConnectionCreate("db", "usr", "expired_pwd_in_grace_period", 
                              OCI_SESSION_DEFAULT);

    /* ... application code here ... */

    OCI_Cleanup();

 
    return EXIT_SUCCESS;
}
Exemplo n.º 19
0
int main(void)
{
    OCI_Connection *cn;
    OCI_Statement  *st;
    OCI_Resultset  *rs;
    OCI_Ref       *ref;

    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_ExecuteStmt(st, "select ref(e) from table_obj e");
    rs = OCI_GetResultset(st);

    printf("\n\n=> fetch refs from object table\n\n");

    while (OCI_FetchNext(rs))
    {
        dump_ref(OCI_GetRef(rs, 1));
    }

    printf("\n\n=> bind a local ref object to a PL/SQL statement\n\n");

    ref = OCI_RefCreate(cn, OCI_TypeInfoGet(cn, "ARTICLE_T", OCI_TIF_TYPE));

    OCI_Prepare(st, "begin "
                    "  select ref(e) into :r from table_obj e where e.id = 1; "
                    "end; ");
    
    OCI_BindRef(st, ":r", ref);
    OCI_Execute(st);

    dump_ref(ref);

    OCI_RefFree(ref);

    OCI_Cleanup();

    return EXIT_SUCCESS;
}
Exemplo n.º 20
0
int main(void)
{
    OCI_Date *d1, *d2;

    char str[SIZE_STR+1];
   
    if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT))
        return EXIT_FAILURE;

    d1 = OCI_DateCreate(NULL);
    d2 = OCI_DateCreate(NULL);

    strcpy(str, "13041978 20:20:12");

    OCI_DateFromText(d1, str, "DDMMYYYY HH24:MI:SS");
    OCI_DateToText(d1, "DD/MM/YYYY HH24:MI:SS", SIZE_STR, str);
    printf("\nDate is %s\n", str);

    OCI_DateSysDate(d1);
    OCI_DateToText(d1, "DD/MM/YYYY HH24:MI:SS", SIZE_STR, str);
    printf("\nSysdate is %s\n", str);

    OCI_DateAddDays(d1, 5);
    OCI_DateAddMonths(d1, 2);
    OCI_DateToText(d1, "DD/MM/YYYY HH24:MI:SS", SIZE_STR, str);
    printf("\nDate + 5 days and 2 months is %s\n", str);

    OCI_DateAssign(d2, d1);
    OCI_DateLastDay(d1);
    OCI_DateToText(d1, "DD/MM/YYYY HH24:MI:SS", SIZE_STR, str);
    printf("\nLast day of the month : %s\n", str);

    printf("\nNumber of days until the end of the months : %i\n",
            OCI_DateDaysBetween(d1, d2));

    OCI_DateFree(d1);
    OCI_DateFree(d2);

    OCI_Cleanup();
 
    return EXIT_SUCCESS;
}
Exemplo n.º 21
0
int main(void)
{
   OCI_Connection *cn;

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

    cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);
    evt = CreateEvent(0, TRUE, FALSE, 0);

    _beginthread(long_oracle_call, 0, cn);

    if (WaitForSingleObject(evt, 10000) != WAIT_OBJECT_0)
    {
        OCI_Break(cn);
        Sleep(2000);
    }

    OCI_Cleanup();

 
    return EXIT_SUCCESS;
}
Exemplo n.º 22
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;
}
Exemplo n.º 23
0
int main(void)
{
    OCI_Thread *th[MAX_THREADS];
    OCI_ConnPool *pool;

    int i;

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

    /* create pool */

    pool = OCI_PoolCreate("db", "usr", "pwd", OCI_POOL_CONNECTION, OCI_SESSION_DEFAULT, 0, MAX_CONN, 1);

    /* create threads */

    for (i = 0; i < MAX_THREADS; i++)
    {
        th[i] = OCI_ThreadCreate();
        OCI_ThreadRun(th[i], worker, pool);
    }
  
    /* wait for threads and cleanup */

    for (i = 0; i < MAX_THREADS; i++)
    {
       OCI_ThreadJoin(th[i]);
       OCI_ThreadFree(th[i]);
    }

    OCI_PoolFree(pool);

    OCI_Cleanup();

 
    return EXIT_SUCCESS;
}
Exemplo n.º 24
0
int main(void)
{
    OCI_Connection *cn;
    OCI_TypeInfo *tbl;
    int i,n;

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

    cn  = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);
    tbl = OCI_TypeInfoGet(cn, "products", OCI_TIF_TABLE);

    if (tbl != NULL)
    {
        printf ("Column Name         Type      Length  Prec.   Scale   Null ?\n");
        printf ("----------------------------  ------------------------------\n");

        n = OCI_TypeInfoGetColumnCount(tbl);
   
        for(i = 1; i <= n; i++)
        {
            OCI_Column *col = OCI_TypeInfoGetColumn(tbl, i);

            printf("%-20s%-10s%-8i%-8i%-8i%-s\n",
                    OCI_GetColumnName(col),
                    OCI_GetColumnSQLType(col),
                    OCI_GetColumnSize(col),
                    OCI_GetColumnPrecision(col),
                    OCI_GetColumnScale(col),
                    OCI_GetColumnNullable(col) == TRUE ? "Y" : "N");
        }
    }

    OCI_Cleanup();

    return EXIT_SUCCESS;
}
Exemplo n.º 25
0
int main(int argc, char **argv)
{
    OCI_Connection *cn;
    OCI_Statement  *st;
    OCI_Object     *obj_sdo;
    OCI_Coll       *coll_inf,  *coll_ord;
    OCI_Elem       *elem_inf,  *elem_ord;
    OCI_TypeInfo   *tif_inf,   *tif_ord, *tif_sdo;
 
    int i;
 
    /* check command line */
    if (argc < 3) 
    {
        fprintf(stderr, "Usage: %s user password\n", argv[0]);
        return EXIT_FAILURE;
    }
 
    /* init OCILIB */
    if (OCI_Initialize(error, NULL, OCI_ENV_DEFAULT))
    {
        /* connect to oracle */
        if (cn = OCI_ConnectionCreate(NULL, argv[1], argv[2], OCI_SESSION_DEFAULT))
        {
            printf ("\nConnected to Oracle.\n");
 
            /* retreive type info */
            tif_sdo = OCI_TypeInfoGet(cn, "MDSYS.SDO_GEOMETRY", OCI_TIF_TYPE);
            tif_inf = OCI_TypeInfoGet(cn, "MDSYS.SDO_ELEM_INFO_ARRAY", OCI_TIF_TYPE);
            tif_ord = OCI_TypeInfoGet(cn, "MDSYS.SDO_ORDINATE_ARRAY", OCI_TIF_TYPE);
 
            /* create sdo object */
            obj_sdo = OCI_ObjectCreate(cn, tif_sdo);
 
            /* create sub arrays */
            coll_inf = OCI_CollCreate(tif_inf);
            coll_ord = OCI_CollCreate(tif_ord);
 
            /* create sub array element accessors */
            elem_inf = OCI_ElemCreate(tif_inf);
            elem_ord = OCI_ElemCreate(tif_ord);
 
            /* build ordinates collection with test values */
            for (i = 0; i < NB_ELEM; i++)
            {
                OCI_ElemSetDouble(elem_ord, (double) i);
                OCI_CollAppend(coll_ord, elem_ord);
                OCI_CollAppend(coll_ord, elem_ord);
            }
 
            /* setup information collection attribute 'starting_offset' */
            OCI_ElemSetUnsignedInt(elem_inf, 1);
            OCI_CollAppend(coll_inf, elem_inf);
 
            /* setup information collection attribute 'element_type' */
            OCI_ElemSetUnsignedInt(elem_inf, 1);
            OCI_CollAppend(coll_inf, elem_inf);
 
            /* setup information collection attribute 'interpretation' */
            OCI_ElemSetUnsignedInt(elem_inf, 1);
            OCI_CollAppend(coll_inf, elem_inf);
 
 
            /* set sdo object member attributes */
            OCI_ObjectSetInt(obj_sdo,  "SDO_GTYPE", 4);
            OCI_ObjectSetNull(obj_sdo, "SDO_SRID");
            OCI_ObjectSetNull(obj_sdo, "SDO_POINT");
            OCI_ObjectSetColl(obj_sdo, "SDO_ELEM_INFO", coll_inf);
            OCI_ObjectSetColl(obj_sdo, "SDO_ORDINATES", coll_ord);
 
            /*create statement object */
            st = OCI_StatementCreate(cn);
 
            /* prepare, bind and excute statement then commit*/
            OCI_Prepare(st, "INSERT INTO test_insert (gid, geometry) VALUES (1, :sdo)");
            OCI_BindObject(st, "sdo", obj_sdo);
            OCI_Execute(st);
            OCI_Commit(cn);
 
            /* free local objects */
            OCI_ObjectFree(obj_sdo);
            OCI_CollFree(coll_inf);
            OCI_CollFree(coll_ord);
            OCI_ElemFree(elem_inf);
            OCI_ElemFree(elem_ord);
        }
    }
 
    /* disconnect from oracle and cleanup OCILIB */
    OCI_Cleanup();
 
    printf ("\nDisconnected from Oracle.\n");
 
    return EXIT_SUCCESS;
}
Exemplo n.º 26
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.º 27
0
int main(void)
{
    OCI_Connection *cn;
    OCI_Statement *st;
    OCI_Resultset *rs;
    OCI_Coll *coll;
    OCI_Iter *iter;
    OCI_Elem *elem;
    OCI_TypeInfo *type;
    OCI_Object *obj;
    int i, n;

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

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


    /* Varray binding -------------------------------------------------------- */

    st = OCI_StatementCreate(cn);

    /* create the collection */

    type = OCI_TypeInfoGet(cn, "Varray_type", OCI_TIF_TYPE);
    coll = OCI_CollCreate(type);

    /* bind the local collection to a PL/SQL procedure */
    
    OCI_Prepare(st, "begin load_array(:array); end;");
    OCI_BindColl(st, ":array", coll);
    OCI_Execute(st);
 
    /* the procedure has filled the collection and 
       we can iterate it using an iterator */
    
    iter = OCI_IterCreate(coll);
    elem = OCI_IterGetNext(iter);

    while (elem != NULL)
    {
        printf("value %s\n", OCI_ElemGetString(elem));
        elem = OCI_IterGetNext(iter);
    }

    OCI_IterFree(iter);
    OCI_CollFree(coll);
 
    /* Varray SQL fetch ------------------------------------------------------- */
  
    /* query on a table with varray column */
 
    OCI_ExecuteStmt(st, "SELECT * from table_article");

    rs = OCI_GetResultset(st);

    while (OCI_FetchNext(rs))
    {
        /* iterate the collection using an iterator */

        coll = OCI_GetColl(rs, 2);

        iter = OCI_IterCreate(coll);
        elem = OCI_IterGetNext(iter);

        printf("article #%d\n", OCI_GetInt(rs, 1));

        while (elem != NULL)
        {
            obj = OCI_ElemGetObject(elem);
            printf(".... code %d, name%s \n", OCI_ObjectGetInt(obj, "ID"),
                                              OCI_ObjectGetString(obj, "NAME"));
            elem = OCI_IterGetNext(iter);
        }

        OCI_IterFree(iter);
    }

    /* Nested table fetch ------------------------------------------------------- */
    
    /* query on a table with nested table column */
 
    OCI_ExecuteStmt(st, "SELECT * from table_sales");

    rs = OCI_GetResultset(st);

    while (OCI_FetchNext(rs))
    {
        coll = OCI_GetColl(rs, 2);

        printf("Sale #%d\n", OCI_GetInt(rs, 1));

        /* iterate the collection by accessing element by index */
   
        n = OCI_CollGetSize(coll);

        for(i = 1; i <= n; i++)
        {
            elem = OCI_CollGetAt(coll, i);
            obj  = OCI_ElemGetObject(elem);

            printf(".... employee %s, amount %s \n", OCI_ObjectGetString(obj, "EMP"),
                                                     OCI_ObjectGetString(obj, "AMOUNT"));
        }
    }

    OCI_Cleanup();
    
    return EXIT_SUCCESS;
}
Exemplo n.º 28
0
int main(void)
{
    OCI_Connection *cn;
    OCI_DirPath    *dp;
    OCI_TypeInfo   *tbl;

    char val1[SIZE_COL1 + 1];
    char val2[SIZE_COL2 + 1];
    char val3[SIZE_COL3 + 1];

    int i = 0, j = 0, nb_rows = SIZE_ARRAY;
    boolean res = TRUE;

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

    cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);
    tbl = OCI_TypeInfoGet(cn, "dirpath_data", OCI_TIF_TABLE);
    dp = OCI_DirPathCreate(tbl, NULL, NUM_COLS, nb_rows);

    /* optional attributes to set */

    OCI_DirPathSetBufferSize(dp, 64000);
    OCI_DirPathSetNoLog(dp, TRUE);
    OCI_DirPathSetParallel(dp, TRUE);

    /* describe the target table */

    OCI_DirPathSetColumn(dp, 1, "val_int", SIZE_COL1, NULL);
    OCI_DirPathSetColumn(dp, 2, "val_str", SIZE_COL2, NULL);
    OCI_DirPathSetColumn(dp, 3, "val_date", SIZE_COL3, "YYYYMMDD");

    /* prepare the load */

    OCI_DirPathPrepare(dp);

    nb_rows = OCI_DirPathGetMaxRows(dp);

    for (i = 0; i < NB_LOAD; i++)
    {
        OCI_DirPathReset(dp);

        for (j = 1; j <= nb_rows; j++)
        {
            /* fill test values */

            sprintf(val1, "%04d", i + (i * 100));
            sprintf(val2, "value %05d", j + (i * 100));
            sprintf(val3, "%04d%02d%02d", (j % 23) + 1 + 2000, (j % 11) + 1, (j % 23) + 1);

            OCI_DirPathSetEntry(dp, j, 1, val1, (unsigned int)strlen(val1), TRUE);
            OCI_DirPathSetEntry(dp, j, 2, val2, (unsigned int)strlen(val2), TRUE);
            OCI_DirPathSetEntry(dp, j, 3, val3, (unsigned int)strlen(val3), TRUE);
        }

        /* load data to the server */

        while (res)
        {
            int state = OCI_DirPathConvert(dp);

            if ((state == OCI_DPR_FULL) || (state == OCI_DPR_COMPLETE))
                res = OCI_DirPathLoad(dp);

            if (state == OCI_DPR_COMPLETE)
                break;
        }
    }

    /* commits changes */

    OCI_DirPathFinish(dp);

    printf("%04d row(s) loaded\n", OCI_DirPathGetRowCount(dp));

    /* free direct path object */

    OCI_DirPathFree(dp);

    OCI_Cleanup();

    return EXIT_SUCCESS;
}
Exemplo n.º 29
-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;
}