BBC BASIC for Windows
Programming >> Database and Files >> Oracle Database Connection
http://bb4w.conforums.com/index.cgi?board=database&action=display&num=1324475178

Oracle Database Connection
Post by michael42 on Dec 21st, 2011, 12:46pm

Hello,

I am using the latest version of BBC BASIC for Windows. How can I connect to an Oracle database (10g/11g)?

If there are any code snippets that would be ideal.

EDIT: I did find and download the ODBC32.bbc but this only shows the initial CALL statement. A few standard SQL examples could go a long way. A SELECT to return a cursor\recordset and a standard DML statement (INSERT\UPDATE\DELETE).


Thanks,

Michael
Re: Oracle Database Connection
Post by admin on Dec 21st, 2011, 2:32pm

on Dec 21st, 2011, 12:46pm, michael42 wrote:
I am using the latest version of BBC BASIC for Windows. How can I connect to an Oracle database (10g/11g)?

One way would be to use the Microsoft ODBC driver (ODBC32.DLL) which you probably already have on your PC:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms713590.aspx

The ODBC API reference is here:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms714562.aspx

If you can find, say, some Visual BASIC code which does what you want it will probably be quite straightforward to translate it to BBC BASIC.

Richard.
Re: Oracle Database Connection
Post by admin on Dec 21st, 2011, 2:57pm

Here's a code snippet (untested) to get you started:

Code:
      SYS "LoadLibrary", "ODBC32.DLL" TO odbc%
      SYS "GetProcAddress", odbc%, "SQLAllocEnv" TO `SQLAllocEnv`
      SYS "GetProcAddress", odbc%, "SQLAllocConnect" TO `SQLAllocConnect`
      SYS "GetProcAddress", odbc%, "SQLDriverConnect" TO `SQLDriverConnect`
      
      SYS `SQLAllocEnv`, ^glEnv%
      IF glEnv% = 0 ERROR 100, "Unable to initialize ODBC API drivers"
      
      SYS `SQLAllocConnect`, glEnv%, ^glDbc%
      IF glDbc% = 0 ERROR 100, "Unable to allocate memory for connection handle"
      
      Connect$ = "DSN=" + DSN$ + ";UID=" + LoginID$ + ";PWD=" + Password$ + \
      \          ";APP=" + AppCode$ + ";DATABASE=" + Database$
      
      Result$ = STRING$(1024, CHR$0)
      
      SYS `SQLDriverConnect`, glDbc%, @hwnd%, Connect$, LEN(Connect$), \
      \                       Result$, LEN(Result$), ^size%, 0 TO res%
      IF res% ERROR 100, "Unable to connect to database"
      
      Result$ = LEFT$(Result$, size%) 

Richard.