[Implemented] REALBasic, SQLite and PB

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
USCode
Addict
Addict
Posts: 923
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

[Implemented] REALBasic, SQLite and PB

Post 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
User avatar
aszid
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 01, 2003 8:38 pm
Location: California, USA
Contact:

Post by aszid »

I second the notion, databases are just so insanely usefull that anything to make them easier to impliment would be awesome. :)
--Aszid--

Making crazy people sane, starting tomorrow.
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

same opinion here...
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

I agree.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
BinoX
User
User
Posts: 46
Joined: Mon Jan 31, 2005 11:57 am

Post by BinoX »

I think native database access without use for ODBC would be good too :D
ColBoy
Enthusiast
Enthusiast
Posts: 143
Joined: Fri Feb 13, 2004 2:37 pm
Location: Ottawa, Canada
Contact:

Post by ColBoy »

I'd definately love this feature added too.
Colin
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Ok, ok, i will take a closer look to it. BTW, El Choni did a wrapper for it no ?
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post 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
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post 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...
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post 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. ;)
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
USCode
Addict
Addict
Posts: 923
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

SQLite, link that baby in!

Post 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*.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post 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 
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

My code was based on Kiffi's original code from the German forums!

So 90% of it is his coding!
akee
Enthusiast
Enthusiast
Posts: 496
Joined: Wed Aug 18, 2004 9:52 am
Location: Penang, Malaysia

Post by akee »

US$99 for Realbasic. You save a few $$$ with PB. :wink:
User avatar
Kiffi
Addict
Addict
Posts: 1491
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Post 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
Post Reply