Page 1 of 2

[Implemented] REALBasic, SQLite and PB

Posted: Wed Jun 01, 2005 3:15 pm
by USCode
To me RealBasic is PB's most natural competitor. They both support native compilation among Windows, Linux and Mac OS X. Each has their strengths and weaknesses. http://www.realbasic.com

For the newest version of RealBasic, due out soon, they're adding direct SQLite support with a SQLite plugin, which will eventually replace their own homegrown SQL database. http://www.sqlite.org

:idea: Given the almost wide-open license of SQLite, I think an SQLite library would be an excellent addition to the list of standard libraries delivered with PB. A local SQL database can be VERY handy. Lots of fine work has already been done by El_Choni. With some magic by Fred the whole library could probably be worked so it could be completely linked into our executables like all the other PB libraries can be.

Yes, I've made this suggestion before: viewtopic.php?t=11516&highlight=sqlite
but now that RealBasic is actually doing it, I think now might be an opportune time for PB to do the same thing.

Just a suggestion.
Thanks

Posted: Wed Jun 01, 2005 6:14 pm
by aszid
I second the notion, databases are just so insanely usefull that anything to make them easier to impliment would be awesome. :)

Posted: Wed Jun 01, 2005 9:49 pm
by dell_jockey
same opinion here...

Posted: Thu Jun 02, 2005 7:51 am
by gnozal
I agree.

Posted: Thu Jun 02, 2005 8:13 am
by BinoX
I think native database access without use for ODBC would be good too :D

Posted: Thu Jun 02, 2005 11:52 am
by ColBoy
I'd definately love this feature added too.

Posted: Thu Jun 02, 2005 12:16 pm
by Fred
Ok, ok, i will take a closer look to it. BTW, El Choni did a wrapper for it no ?

Posted: Thu Jun 02, 2005 12:24 pm
by gnozal
Fred wrote:Ok, ok, i will take a closer look to it. BTW, El Choni did a wrapper for it no ?
Yes, he did : viewtopic.php?t=10724&highlight=sqlite

Posted: Thu Jun 02, 2005 12:45 pm
by Num3
I already stated several times, there should be an internal native database to Purebasic, has a complement to the ODBC ones.

And Sqlite seems very good, has it supports Win/Lin/Mac...
Fred wrote:Ok, ok, i will take a closer look to it. BTW, El Choni did a wrapper for it no ?
Yes, El choni wrapped it...

But i have unwrapped functions for version 3, that work both on windows and linux!

I'll paste them here tonight...

Posted: Thu Jun 02, 2005 1:15 pm
by dell_jockey
Fred wrote:Ok, ok, i will take a closer look to it. BTW, El Choni did a wrapper for it no ?
Si, qui, ja, yes.... he did. ;)

SQLite, link that baby in!

Posted: Thu Jun 02, 2005 6:37 pm
by USCode
Ok, ok, i will take a closer look to it. BTW, El Choni did a wrapper for it no ?
Thanks Fred! :D Yep, El Choni has created a wrapper but for me the key feature would be able to *link* everything into my executable *without an external library dependency*.

Posted: Thu Jun 02, 2005 7:00 pm
by Num3
Has promissed for Sqlite 320...
Not entirely my code !!!!

Code: Select all

#SQLITE3_OK          =   0   ; Successful Result
#SQLITE3_ERROR       =   1   ; SQL error Or missing database
#SQLITE3_INTERNAL    =   2   ; An internal logic error in SQLite
#SQLITE3_PERM        =   3   ; Access permission denied
#SQLITE3_ABORT       =   4   ; Callback routine requested An abort
#SQLITE3_BUSY        =   5   ; The database file is locked
#SQLITE3_LOCKED      =   6   ; A table in The database is locked
#SQLITE3_NOMEM       =   7   ; A malloc() failed
#SQLITE3_READONLY    =   8   ; Attempt To write A readonly database
#SQLITE3_INTERRUPT   =   9   ; Operation terminated by SQLite_Interrupt()
#SQLITE3_IOERR       =  10   ; Some kind of disk I/O error occurred
#SQLITE3_CORRUPT     =  11   ; The database disk image is malformed
#SQLITE3_NOTFOUND    =  12   ; (internal Only) table Or record not found
#SQLITE3_FULL        =  13   ; Insertion failed because database is full
#SQLITE3_CANTOPEN    =  14   ; Unable To open The database file
#SQLITE3_PROTOCOL    =  15   ; database lock protocol error
#SQLITE3_EMPTY       =  16   ; (internal Only) database table is empty
#SQLITE3_SCHEMA      =  17   ; The database schema changed
#SQLITE3_TOOBIG      =  18   ; Too much Data For one Row of A table
#SQLITE3_CONSTRAINT  =  19   ; abort due To contraint violation
#SQLITE3_MISMATCH    =  20   ; Data type mismatch
#SQLITE3_MISUSE      =  21   ; Library used incorrectly
#SQLITE3_NOLFS       =  22   ; Uses OS features not supported on host
#SQLITE3_AUTH        =  23   ; Authorization denied
#SQLITE3_ROW         = 100   ; sqlite_step() has another Row ready
#SQLITE3_DONE        = 101   ; sqlite_step() has finished executing

#SQLITE3_LIB  = 200

Global sqlite3_open.l
Global sqlite3_exec.l
Global sqlite3_close.l
Global sqlite3_errmsg.l
Global sqlite3_get_table.l
Global sqlite3_free_table.l
Global sqlite3_lasterror.s

Procedure.l SQLite3_Init()
  
  If OpenLibrary(#SQLITE3_LIB ,"sqlite3.dll")
    sqlite3_open       = IsFunction(#SQLITE3_LIB, "sqlite3_open")
    sqlite3_exec       = IsFunction(#SQLITE3_LIB, "sqlite3_exec")
    sqlite3_close      = IsFunction(#SQLITE3_LIB, "sqlite3_close")
    sqlite3_errmsg     = IsFunction(#SQLITE3_LIB, "sqlite3_errmsg")
    sqlite3_get_table  = IsFunction(#SQLITE3_LIB, "sqlite3_get_table")
    sqlite3_free_table = IsFunction(#SQLITE3_LIB, "sqlite3_free_table") 
    ProcedureReturn #True
  Else
    ProcedureReturn #False
  EndIf
  
EndProcedure

Procedure.l SQLite3_End()
  CloseLibrary(#SQLITE3_LIB)
EndProcedure

Procedure.l SQLite3_OpenDatabase(sDataBase.s)
  
  If CallCFunctionFast(sqlite3_open, sDataBase, @sqlite3_dbHandle) = #SQLITE3_OK
    ProcedureReturn sqlite3_dbHandle
  Else
    ProcedureReturn 0
  EndIf
  
EndProcedure

Procedure.l SQLite3_CloseDatabase(lDataBaseHandle.l)
  
  If CallCFunctionFast(sqlite3_close, lDataBaseHandle) = #SQLITE3_OK
    ProcedureReturn #True
  Else
    ProcedureReturn #False
  EndIf
  
EndProcedure

Procedure.s SQLite3_LastError()
  ProcedureReturn sqlite3_lasterror
EndProcedure

Procedure.l SQLite3_Execute(sSQLQuery.s, lDataBaseHandle.l)
  
  If CallCFunctionFast(sqlite3_exec, lDataBaseHandle, sSQLQuery, #Null, #Null, @ReturnValue) = #SQLITE3_OK
    ProcedureReturn #True
  Else
    CallCFunctionFast(sqlite3_errmsg, @ReturnValue)
    sqlite3_lasterror=PeekS(ReturnValue)
    ProcedureReturn #False
  EndIf
  
EndProcedure 

Procedure.l SQLite3_GetTable(sSQLQuery.s, *Rows, *Cols, lDataBaseHandle.l)
  
  
  If CallCFunctionFast(sqlite3_get_table, lDataBaseHandle, sSQLQuery, @LResultsPtr, @LRows, @LCols, @ReturnValue) = #SQLITE3_OK
    
    ; return number of rows/columns
    PokeL(*Rows, LRows)
    PokeL(*Cols, LCols)
    
    If LRows > -1 And LCols > 0
      
      ; redimension results array (clears data)
      Dim DBData.s(LRows, LCols - 1)
      
      ; copy data into array
      Address.l  = LResultsPtr
      AddrInc.l  = LCols * 4
      
      For Row.l  = 0 To LRows
        For Col.l  = 0 To LCols - 1
          DBData(Row, Col) = PeekS(PeekL(Address + Col  * 4))
        Next
        Address  + AddrInc
      Next
      
    EndIf
    
    ; free table memory
    CallCFunctionFast(sqlite3_free_table, LResultsPtr)
    
    ProcedureReturn #True
    
  Else
    CallCFunctionFast(sqlite3_errmsg, @ReturnValue)
    sqlite3_lasterror= PeekS(ReturnValue)
    ProcedureReturn #False
  EndIf
  
EndProcedure 

Posted: Thu Jun 02, 2005 7:04 pm
by Num3
My code was based on Kiffi's original code from the German forums!

So 90% of it is his coding!

Posted: Thu Jun 02, 2005 8:04 pm
by akee
US$99 for Realbasic. You save a few $$$ with PB. :wink:

Posted: Fri Jun 03, 2005 7:45 am
by Kiffi
> My code was based on Kiffi's original code from the German forums!

there is a new version of my SQLite3-Wrapper:

http://kiffi.ki.funpic.de/?Projekte:SQLite3 (and soon on PureArea)

The included help-file is unfortunately only in german but the demo-code is
easy to understand.

Greetings ... Kiffi