Page 1 of 1

OCILIB Help requested!

Posted: Fri Aug 22, 2014 12:56 am
by Jagermeister
This is from gnozal at http://www.purebasic.fr/english/viewtop ... 13&t=47397 which appears to originate from http://pbasic.spb.ru/phpBB3ex/viewtopic ... ebfabbff76

I try running with F5 and get "OCI ERROR 0 (Cannot load OCI symbols from shared library)". I have libocilibw.a and set temp executable to same directory as source along with ocilibw.dll and ocilibw.lib. Do I have to set environment variables somewhere? I'm am only starting to use libraries and such. Please point me in the right direction.

From the OCILIB site under Download > "Installation":
copy ocilib\include\ocilib.h to any place located in your include’s path ( It's not in gnozal's example. Is this necessary?)
copy ocilib\lib32|64\ocilib[x].lib to any place located in your libraries path (does this mean C:\Program Files (x86)\PureBasic\PureLibraries\UserLibraries or \Windows\Libraries ?)
copy ocilib\lib32|64\ocilib[x].dll to any place located in your windows path (C:\Windows\System32 or same location as source?)

Code: Select all

;
;{ OCI LIB [C Driver for Oracle](http://orclib.sourceforge.net)
;
Import "libocilibw.a" ; libociliba.a = ANSI, libocilibw.a = UNICODE
  OCI_Initialize(*ErrorHandler, *LibPath, Mode) As "_OCI_Initialize@12" ; Initialize the OCI library - Returns TRUE on success otherwise FALSE
  OCI_ConnectionCreate(Database$, User$, Password$, Mode) As "_OCI_ConnectionCreate@16" ; Create a physical connection to an Oracle database server - Connection handle on success or NULL on failure
  OCI_StatementCreate(hConnection) As "_OCI_StatementCreate@4" ; Create a statement object - Returns a statement handle on success otherwise NULL
  OCI_StatementFree(hStatement) As "_OCI_StatementFree@4" ; Free a statement and all resources associated to it (resultsets ...)
  OCI_ExecuteStmt(hStatement, SQL$) As "_OCI_ExecuteStmt@8" ; Execute a SQL statement or PL/SQL block - Returns TRUE on success otherwise FALSE
  OCI_GetResultset(hStatement) As "_OCI_GetResultset@4" ; Retrieve the resultset handle from an executed statement - Returns a resultset handle on success otherwise NULL
  OCI_GetColumnCount(hResultSet) As "_OCI_GetColumnCount@4" ; Return the number of columns in the resultset
  OCI_FetchNext(hResultSet) As "_OCI_FetchNext@4" ; Fetch the next row of the resultset - Returns TRUE on success otherwise FALSE (empty, last row already fetched, an error occurred)
  OCI_GetString_Pointer(hResultSet, ColumnIndex) As "_OCI_GetString@8" ; Return the current string value of the column at the given index in the resultset or NULL if index is out of bounds
  OCI_Cleanup() As "_OCI_Cleanup@0" ; Clean up all resources allocated by the library
  OCI_ErrorGetOCICode(hError) As "_OCI_ErrorGetOCICode@4" ; Retrieve Oracle Error code from error handle
  OCI_ErrorGetString(hError) As "_OCI_ErrorGetString@4" ; Retrieve error message from error handle
EndImport
Procedure.s OCI_GetString(hResultSet, ColumnIndex) ; Return the current string value of the column at the given index in the resultset or '' if index is out of bounds
  ;
  Protected OCI_Result, ReturnValue.s
  ;
  OCI_Result = OCI_GetString_Pointer(hResultSet, ColumnIndex)
  If OCI_Result
    ReturnValue = PeekS(OCI_Result)
  EndIf
  ;
  ProcedureReturn ReturnValue
  ;
EndProcedure
ProcedureC OCI_ErrorHandler(hError) ; OCI error handler MUST be a ProcedureC !!!
  ;
  Shared OCI_ErrorNumber, OCI_ErrorString.s
  If hError
    OCI_ErrorNumber = OCI_ErrorGetOCICode(hError)
    OCI_ErrorString = PeekS(OCI_ErrorGetString(hError))
    OCI_ErrorString = RemoveString(OCI_ErrorString, Chr(10))
  EndIf
  Debug "+++ OCI ERROR " + Str(OCI_ErrorNumber) + " (" + OCI_ErrorString + ") +++"
  ;
EndProcedure
; 
#OCI_ENV_DEFAULT =                    0
#OCI_ENV_THREADED =                   1
#OCI_ENV_CONTEXT =                    2
#OCI_ENV_EVENTS =                     4
#OCI_SESSION_DEFAULT =                0
#OCI_SESSION_XA =                     1
#OCI_SESSION_SYSDBA =                 2
#OCI_SESSION_SYSOPER =                4
#OCI_SESSION_PRELIM_AUTH =            8
;}
;
;
If OCI_Initialize(@OCI_ErrorHandler(), #Null, #OCI_ENV_DEFAULT)
  ;
  hConnection = OCI_ConnectionCreate("x.x.x.x", "user", "pass", #OCI_SESSION_DEFAULT)
  If hConnection
    ;
    ;
    hStatement = OCI_StatementCreate(hConnection) ; Create statement
    ;
    ;
    TexteSQL$ = "Select count(*) FROM foo_table"
    ;
    If OCI_ExecuteStmt(hStatement, TexteSQL$)
      ;
      hResultSet = OCI_GetResultset(hStatement)
      ;
      If hResultSet
        ;
        NbColumns = OCI_GetColumnCount(hResultSet)
        ;
        While (OCI_FetchNext(hResultSet))
          ;
          Result$ = ""
          For Index = 1 To NbColumns
            Result$ + OCI_GetString(hResultSet, Index) + ":"
          Next
          Debug Result$
          ;
        Wend
      ;
      EndIf
      ;
    Else
      ;
      MessageRequester("ERROR", "SQL error !" + Chr(10) + Chr(10) + "ERROR " + Str(OCI_ErrorNumber) + " (" + OCI_ErrorString + ")", #MB_ICONERROR)
      ;
    EndIf
    ;
    ;
    OCI_StatementFree(hStatement) ; Free statement
    ;
    ;
  Else
    ;
    MessageRequester("ERROR", "Could not connect to database !" + Chr(10) + Chr(10) + "ERROR " + Str(OCI_ErrorNumber) + " (" + OCI_ErrorString + ")", #MB_ICONERROR)
    ;
  EndIf
  ;
  ;
  OCI_Cleanup()
  ;
  ;
Else
  ;
  MessageRequester("ERROR", "Could not initialize OCILIB !", #MB_ICONERROR)
  ;
EndIf

Re: OCILIB Help requested!

Posted: Wed Jun 03, 2015 1:41 am
by Michael42
Was it ever optimally answered, i.e. how to import ocilib etc.?

If not can you point me in the right direction to the steps to use ocilib with PB?

Thanks.

Re: OCILIB Help requested!

Posted: Fri Jun 05, 2015 1:21 pm
by Michael42
Bueller?