Recent News

OCILIB v3.4.1 coming on November, Monday 23th !

Posted by Vincent Rogier on November 20th, 2009

Hello !

OCILIB v3.4.1 will be available by next monday (2009-11-23).

The SourceForge SVN will be updated with the last sources this weekend and release packages available on SourceForge by monday.

This release only contains bug fixes and minor changes that could not wait for v3.5.0 that has been developed for last few month.

Here is the changelog of the 3.4.1 :

2009-11-23 Version 3.4.1 Vincent Rogier vince.rogier@gmail.com
 
    * Native 64 bits fixes
 
      - Fixed Direct Path API
      - Added casts + modified some variables types
 
    * PL/SQL support fixes
      - Segmentation fault could happen when using OCI_Date binds in PL/SQL statements
      - Binds values for OCI_Date and big_int variable where not updated after OCI_Execute for PL/SQL
      - OCI_ServerGetOutput() : ouput was broken if statements PL/LSQL statmeent/blocks were re-executed
      - OCI_ServerGetOutput() : trash string was returned if the number of amonut of output lines was greater than the value of the  <arrsize> parameter of OCI_ServerEnableOutput()
 
    * Miscellaneous fixes
 
      - OCI_ImmediateFmt(), OCI_PrepareFmt(), OCI_ExecuteStmtFmt():  trailing character of formatted string representation of dates was missing on non windows plaftorms
      - OCI_ObjectGetColl() : the internal OCI Collection handle of the returned OCI_Coll object was invalid and thus caused segfault when calling OCI_Coll functions afterward for these objects
      - OCI_DateNextDay() : On unixes platforms+Unicode builds -> wrong value passed to the OCI internal call
 
    * Miscellaneous  changes
 
      - OCI_RefToText() : parameter size is now if type <unsigned int> instead of <int>
      - Modified : OCI_BIND_MAX (maximum number of binds for a statement) is now 1024 by default instead of 512
      - Added Oracle spatial demo source (demo/geometry.c)

Next version, v3.5.0, is a massive internal rewrite for handling different types of strings.

At the moment, OCILIB handles string as :

- char *  (OCI_CHARSET_ANSI)
- wchar_t * (OCI_CHARSET_UNICODE)
- mixed mode for char * statements and wchar_t * user data (OCI_CHARSET_MIXED)

I implemented a portable way to use wchar_t on all platforms (but a real pain internally!) as OCI handles Unicode string as fixed 2 bytes UTF16.

On MS windows, that’s good because Microsoft C runtime implements wchar_t as UTF16.
On most of unixes, wchart_t is 4 bytes and OCILIB uses internal buffers when talking to OCI and pack/unpack data from/to user strings.

All of that works well…. But when working in Unicode mode on unixes with big resultsets or binds, performance can suffer of internal conversions (even if the internal routines are quite efficient)

So, I decided to refactor OCILIB charset modes as follow :

OCI_CHARSET_ANSI
OCI_CHARSET_UTF8
OCI_CHARSET_UTF16
OCI_CHARSET_UTF32

For backwards compatibility, OCILIB v3.5.0 defines :

OCI_CHARSET_UTF16 if user has defined OCI_CHARSET_UNICODE on MS Windows
OCI_CHARSET_UTF32 if user has defined OCI_CHARSET_UNICODE on unixes

The new mode OCI_CHARSET_UTF8 internally initializes OCI in UTF16 and performs conversion on the fly when needed to not loose surrogates.

These new modes would allow an Unix programmer to pass its own UTF16 strings (from a third party lib or from its own implementation) to OCILIB with better performances.
And a programmer that want to use native wchar_t would still be able to do so (using the actual OCILIB implementation).

To summarize, OCILIB users will be able to chose the type of strings that they want to use between ANSI, UTF8, UTF16 and UTF32 whatever the platform

Have a nice week end !

Working with Oracle spatial types …

Posted by Vincent Rogier on July 27th, 2009

Few days ago, I saw thread in OTN Oracle Call Interface forum about how to handle Oracle Spacial SDO_GEOMETRY in OCI.

I decided to show how it could be done with OCILIB :)

Here is the writegeom sample app from Oracle rewritten with OCILIB :

  • number of lines reduced by factor 4-5
  • much easier code to read
  • the whole sdo_object is binded to the statement

Here is the code :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "ocilib.h"
 
#define NB_ELEM 500
 
void error(OCI_Error *err)
{
    printf("msg   : %s\n", OCI_ErrorGetString(err));
    exit(EXIT_FAILURE);
}
 
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;
}

Support for 11g remote Instance management in OCILIB v3.4.0

Posted by Vincent Rogier on July 27th, 2009

Hello,

OCILIB v3.4.0 is coming soon :)

This release fixes 3 bugs and adds support for Oracle 11g remote Instance startup/shutdown.

Here is a sample app that startups a remote instance and then shuts it down :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "ocilib.h"
 
int main(int argc, char **argv)
{ 
    OCI_Initialize(error, NULL,  OCI_ENV_DEFAULT);
 
    /* start remote instance */
 
    OCI_DatabaseStartup("db", 
                        "sys_user", 
                        "sys_pwd",                
                        OCI_SESSION_SYSDBA, 
                        OCI_DB_SPM_FULL,
                        OCI_DB_SPF_DEFAULT,
                        NULL);
 
 
     /* shutdown remote instance */
 
    OCI_DatabaseShutdown("db", 
                        "sys_user", 
                        "sys_pwd", 
                         OCI_SESSION_SYSDBA,
                         OCI_DB_SDM_FULL,
                         OCI_DB_SDF_DEFAULT);
 
    OCI_Cleanup();
 
    return EXIT_SUCCESS;
}

Isn’t cool ?

Have a nice day..

OCILIB 3.2.0 available soon !

Posted by Vincent Rogier on March 17th, 2009

OCILIB 3.2.0 will be available soon (beginning of April 09)… This release :

  • adds support for direct path interface
  • extends binding capabilities (rebinding, update of array size, …)
  • extends objects API
  • adds Miscellaneous changes and fixes

Here is an example of an full program that loads data into a table with direct path loading.
It shows some possibilities of the direct path implementation :

#include "ocilib.h"
 
#define SIZE_TAB  1000
#define SIZE_COL1 5
#define SIZE_COL2 10
#define SIZE_COL3 6
#define NUM_COLS  3
 
int main(void)
{
    OCI_Connection *cn;
    OCI_DirPath    *dp;
 
    char arrval1[SIZE_TAB][SIZE_COL1+1];
    char arrval2[SIZE_TAB][SIZE_COL2+1];
    char arrval3[SIZE_TAB][SIZE_COL3+1];
 
    int arrsize1[SIZE_TAB];
    int arrsize2[SIZE_TAB];
    int arrsize3[SIZE_TAB];
 
    int i;
 
    if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT))
        return EXIT_FAILURE;
 
    cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);
    dp = OCI_DirPathCreate(cn, "usr", "test_dp", NULL, NUM_COLS, SIZE_TAB);
 
    /* optionnal attributes to set */
 
    OCI_DirPathSetBufferSize(dp, 128000);
    OCI_DirPathEnableCache(dp, TRUE);
    OCI_DirPathSetCacheSize(dp, 1000);
    OCI_DirPathSetNoLog(dp, TRUE);
    OCI_DirPathSetParallel(dp, TRUE);
 
    /* describe the target table */
 
    OCI_DirPathSetColumn(dp, 1, "VAL1", SIZE_COL1, NULL    , 0, 0, FALSE);
    OCI_DirPathSetColumn(dp, 2, "VAL2", SIZE_COL2, NULL    , 0, 0, FALSE);
    OCI_DirPathSetColumn(dp, 3, "VAL3", SIZE_COL3, "DDMMYY", 0, 0, FALSE);
 
    OCI_DirPathPrepare(dp);
 
    /******* method 1 : set each array entry  ******/
 
    for (i = 0; i < SIZE_TAB; i++)
    {
        /* fill test values */
 
        sprintf(arrval1[i], "%d", i);
        sprintf(arrval2[i], "val %05d", i);
        sprintf(arrval3[i], "130309");
 
        OCI_DirPathSetEntry(dp, i, 1, arrval1[i], -1, TRUE);
        OCI_DirPathSetEntry(dp, i, 2, arrval2[i], (int) strlen(arrval2[i]), TRUE);
        OCI_DirPathSetEntry(dp, i, 3, arrval3[i], (int) SIZE_COL3, TRUE);
    }
 
    /* load data to the server */
 
    OCI_DirPathConvert(dp);
    OCI_DirPathLoad(dp);
 
    /* reset path stream */
 
    OCI_DirPathReset(dp);
 
    /****** method 2 : pass arrays in one call ******/
 
    for (i = 0; i < SIZE_TAB; i++)
    {
       /* fill test values */
 
        sprintf(arrval1[i], "%d", i);
        sprintf(arrval2[i], "val %05d", i);
        sprintf(arrval3[i], "130309");
 
        /* setup sizes */
 
        arrsize1[i] = -1;
        arrsize2[i] = (int) strlen(arrval2[i]);
        arrsize3[i] = SIZE_COL3;
 
    }
 
    OCI_DirPathSetArray(dp, 1, arrval1, arrsize1);
    OCI_DirPathSetArray(dp, 2, arrval2, arrsize2);
    OCI_DirPathSetArray(dp, 3, arrval3, arrsize3);
 
    /* load data to the server */
 
    OCI_DirPathConvert(dp);
    OCI_DirPathLoad(dp);
 
    /* commit data */
 
    OCI_DirPathFinish(dp);
 
    /* free direct path object */
 
    OCI_DirPathFree(dp);
 
    OCI_Cleanup();
}

OCILIB SVN repository has been updated (2008-12-09)

Posted by Vincent Rogier on December 9th, 2008

The current development snapshot of v3.1.0 has been updated.

You can browse the repository on sourceforge here
The temporary v3.1.0 changelog is available here

New in this v3.1.0 development snapshot update :

  • Oracle Ref datatype support
  • Exented Objects And Collection Elements support
  • Added some tracing features
  • Miscelleanous changes and fixes

This update is really close the final release (might add subscriptions limited to DCN features ?).

On non Windows platforms, be sure to call ./reconf before any ./configure…

Have a nice day

Recent Comments | Recent Posts

Copyright © OCILIB | OCILIB Logo designed by WolfHound (Developpez.com)
Theme based on Wordpress AngelicDesign by: Website Builder
bottom