Use SQLite the easy way
Posted: Sun Feb 25, 2007 12:03 pm
This probably doesn't qualify as a trick, so let's call it a tip: You can make the freely-distributable ODBC driver for SQLite found at http://www.ch-werner.de/sqliteodbc/sqliteodbc.exe part of the install program for your app. Then, you can simply do this and your SQLite3 database is fully accessible with PureBasic's native database commands:
That's all there is to it, no dlls or wrappers to mess with at all.
Code: Select all
Declare AddConnection(Driver.s,ConnectString.s)
Declare RemoveConnection(Driver.s,DSN.s)
#ODBC_ADD_DSN = 1
#ODBC_CONFIG_DSN = 2
#ODBC_REMOVE_DSN = 3
;Replace File.s with a database that exists on your system!
File.s = "i:\_movies\sample.db"
Driver.s = "SQLite3 ODBC Driver"
Connectstring.s = "DSN=SessionDSN;Database="+File
Result=AddConnection(Driver,Connectstring)
If Result
InitDatabase()
db = OpenDatabase(0, "SessionDSN", "", "")
If db
Debug "Opened Successfully"
CloseDatabase(0)
If RemoveConnection(Driver,"SessionDSN")
Debug "Closed Successfully"
EndIf
EndIf
EndIf
Procedure AddConnection(Driver.s,ConnectString.s)
Result=SQLConfigDataSource_(0,#ODBC_ADD_DSN,Driver,ConnectString )
If Result
ProcedureReturn 1
EndIf
EndProcedure
Procedure RemoveConnection(Driver.s,DSN.s)
Result=SQLConfigDataSource_(0,#ODBC_REMOVE_DSN,Driver,"DSN="+DSN)
If Result
ProcedureReturn 1
EndIf
EndProcedure