• Welcome to Theos PowerBasic Museum 2017.

OCILIB Translation to PB

Started by Eckhard Seibel, April 14, 2009, 11:07:48 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Eckhard Seibel

Hi José,
while working with Oracle i'm searching for a more "native" way to work with the database. I found this at: http://sourceforge.net/projects/orclib
"OCILIB is an open source and cross platform Oracle Driver that delivers really fast and reliable access to Oracle databases. It offers a rich, full featured and easy to use API. Written in ISO C on top of OCI, OCILIB runs on all Oracle platforms."
Would you please so kind as looking at the includefile "ocilib.h" and telling me if it's possible to tranlate this into PB?
best regards
Eckhard

José Roca

 
Yes, it can be translated. I will post the translation this afternoon or evening.

Eckhard Seibel

Hi José,
you're incredible ;D
thanks a million
Eckhard

José Roca

#3
 
The attached file contains ociliba.inc, the translated headers for ociliba.dll, the ansi version of ocilib.

Can't test them because I don't have Oracle.

P. W. Neilson

#4
Hi Mr. Roca, I have been experimenting with a very basic PB application to make use of your ociliba.inc file that I downloaded from an email to Eckhard from this thread.  I am asking for any assistance you can provide to get this very basic application to compile and return some rows from my Oracle database.

sample application I am using:


1 #include "ocilib.h"
2
3 int main(int argc, char *argv[])
4 {
5    OCI_Connection* cn;
6    OCI_Statement* st;
7    OCI_Resultset* rs;
8
9    OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT);
10   cn = OCI_ConnectionCreate("db", "user", "pwd", OCI_SESSION_DEFAULT);
11   st = OCI_StatementCreate(cn);
12
13   OCI_ExecuteStmt(st, "select table_name,num_rows from user_tables order by 1");
14    rs = OCI_GetResultset(st);
15
16    while (OCI_FetchNext(rs)) {
17       printf("table %-30s : %10i rows\n", OCI_GetString(rs,1),OCI_GetInt(s, 2));
18    }
19
20    OCI_Cleanup();
21    return EXIT_SUCCESS;


my application so far:


#DIM ALL

#INCLUDE  "C:\Program Files\PowerBASIC Compiler 9.0\PowerBASIC Compiler 9.0\WinAPI\ociliba.inc"

FUNCTION PBMAIN () AS LONG

   DIM cn AS OCI_Connection
   DIM st AS OCI_Statement
   DIM rs AS OCI_Resultset

   MSGBOX "start..."

   CALL OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT)

   cn = OCI_ConnectionCreate("ORACLE11", "scott", "tiger", OCI_SESSION_DEFAULT)

   st = OCI_StatementCreate(cn)

   OCI_ExecuteStmt(st, "select empno from emp")

   rs = OCI_GetResultset(st)

   DO WHILE (OCI_FetchNext(rs))
       #DEBUG PRINT("%i - %s\n") ', OCI_GetInt(rs, 1), OCI_GetString(rs,2))
   LOOP

   OCI_Cleanup()

   MSGBOX "end..."

END FUNCTION


As you can see, I have a ways to go... I have searched your site to see if there is any sample code for using your OCILIBA.INC file with  PowerBasic.  Could you possibly take a look at this code and suggest where I would have to do to... I am unsure of how to use the OCILIBA library and would be very appreciative of any assistance you could provide.  Thanks very much in advance.

José Roca

 
There are no examples in my forum because, as noted above, I have no means of testing it, as I don't have Oracle.

However, the C example that you have posted can be translated as follows:


FUNCTION PBMAIN () AS LONG

    DIM cn AS DWORD
    DIM st AS DWORD
    DIM rs AS DWORD
    DIM psz AS ASCIIZ PTR
    DIM s AS STRING

    OCI_Initialize(%NULL, BYVAL %NULL, %OCI_ENV_DEFAULT)
    cn = OCI_ConnectionCreate("ORACLE11", "scott", "tiger", %OCI_SESSION_DEFAULT)
    st = OCI_StatementCreate(cn)
    OCI_ExecuteStmt(st, "select empno from emp")
    rs = OCI_GetResultset(st)
    DO WHILE (OCI_FetchNext(rs))
        #DEBUG PRINT STR$(OCI_GetInt(rs, 1))
        psz = OCI_GetString(rs,2)
        IF psz THEN s = @psz
        #DEBUG PRINT s
    LOOP
    OCI_Cleanup

END FUNCTION


P. W. Neilson

Hi Mr. Roca, thanks so much for the code... you are THE MAN!  just a few things to note to get your sample code to compile and execute:

(1) add a #INCLUDE for the path to the ociliba.inc file
(2) add a DIM statement for the NULL values (e.g. DIM NULL as INTEGER)
(3) make the first NULL BYVAL too

after I made these updates,  the code compiled and all of the correct values are being returned from my Oracle11 database instance.  Thanks again, I really appreciate your assistance.  This gives me the ability to write and debug PB apps that use your translation of the OCILIB library.

thanks again, Pete