Confused about SQLite...
Confused about SQLite...
Hi guys,
I have PB 4.2 and I am aware that I can use SQLite database without any other library. I have been creating my application ok but I noticed that the functions available in PB for SQLite are not complete. For example, I want to know how many rows my Select has returned. At moment I have to use NextDatabaseRow() to count the rows one by one. Is there another way to get that ? Also I defined a INTEGER AUTO INCREMENT field but I am lost in the syntax of the INSERT statement in this case. The first field is the ID field which has the AUTO INCREMENT. If I ignore that field, I get a error message saying that is missing a value for a field. If I put a number, it does not increase automatically. What I am doing wrong ? Is it better download the SLQlite library from SQLlite site and use that library ? Is there a conflict with the SQLite already in PB ? Thanks for any light on this.
I have PB 4.2 and I am aware that I can use SQLite database without any other library. I have been creating my application ok but I noticed that the functions available in PB for SQLite are not complete. For example, I want to know how many rows my Select has returned. At moment I have to use NextDatabaseRow() to count the rows one by one. Is there another way to get that ? Also I defined a INTEGER AUTO INCREMENT field but I am lost in the syntax of the INSERT statement in this case. The first field is the ID field which has the AUTO INCREMENT. If I ignore that field, I get a error message saying that is missing a value for a field. If I put a number, it does not increase automatically. What I am doing wrong ? Is it better download the SLQlite library from SQLlite site and use that library ? Is there a conflict with the SQLite already in PB ? Thanks for any light on this.
You can use the static lib from pb directly with API, but in the moment, you
can't mix this. See here:
http://www.purebasic.fr/english/viewtop ... 853#240853
Greetings
Thomas
can't mix this. See here:
http://www.purebasic.fr/english/viewtop ... 853#240853
Greetings
Thomas
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: Confused about SQLite...
You answered your own questionjmauver wrote:... but I noticed that the functions available in PB for SQLite are not complete.

There's quite a bit missing. I'm not sure if this is something they intend to build on in future version and expand the command set in the PB DB or not though ( I hope they do). I would say if you have more than basic database needs, use the dll with an include file.
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Thank you !
Thanks guys. I am really a beginner here so would you tell me which library and include files I should download and where to place them ? Once placed, is it just a matter of calling the functions as I would do normally in PB ? Sorry for my ignorance on this. I just do not want to mess up with my PB installation.
Thanks again!
Thanks again!
Follow TS_Softs link for an include file, the latest sqlite dll can be downloaded at www.sqlite.org or I think it can use the lib file that PB bundle, not sure though.
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
its me again...:(
Hi pdwyer,
Thanks for the explanation. Would it be possible you show me a very simple code as kick start for me ? I get a error message when using "SQLiteInit()".
Thanks !
Thanks for the explanation. Would it be possible you show me a very simple code as kick start for me ? I get a error message when using "SQLiteInit()".

Actually I don't use that include file, I have my own (simpler one), but it uses the DLL.
Perhaps if you posted an error?

Perhaps if you posted an error?
Paul Dwyer
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
This code here does not work...pdwyer wrote:Actually I don't use that include file, I have my own (simpler one), but it uses the DLL.![]()
Perhaps if you posted an error?

Code: Select all
If SQLiteInit()
hDB = SQLiteOpen("c:\MyDB.db", #True)
; reading
SQLiteClose(hDB.l)
hDB = SQLiteOpen("c:\MyDB.db", #False)
;writing
SQLiteClose(hDB.l)
EndIf
- Fangbeast
- PureBasic Protozoa
- Posts: 4789
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Save TS-Soft's include file as a .PB or .PBI file (in keeping with pb naming conventions) and then XINCLUDEFILE that file at state start of any program using those functions.
The below is an excerp of my document manager
The below is an excerp of my document manager
Code: Select all
; Any specific modules that have to load first
XIncludeFile "\Development\Resources\Modules\_SqLite3Base.pbi" ; TS-Soft's SqLite functions for PB4.2
; Try to open the system database and create missing tables
Global dbHandle.l = SQLiteOpen("MyDatabase.db") ; Make handle global for other functions to use
If Program\dbHandle
Query.s = "CREATE TABLE IF NOT EXISTS documents("
Query.s + "added TEXT, lastrun TEXT, docnum TEXT, title TEXT, owner TEXT, active TEXT, note TEXT, filename TEXT, "
Query.s + "directory TEXT, filesize TEXT, md5 TEXT CONSTRAINT md5 UNIQUE, created TEXT, accessed TEXT, modified TEXT, "
Query.s + "readonly TEXT, archive TEXT, system TEXT, hidden TEXT, normal TEXT, backedup TEXT, compressed TEXT, "
Query.s + "lastbackedup TEXT, category TEXT, subcategory TEXT, deleted TEXT, "
Query.s + "record INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT)"
If SQliteExecute(dbHandle, Query.s) = #False
Debug SQLiteErrorMsg(dbHandle)
Else
Debug " Opened and ready to work"
EndIf
Else
Debug SQLiteErrorMsg(dbHandle)
EndIf
; This creates and/or opens the database and tables. Now do your reading, writing and close at program end
I had the same problem a while ago, when switching from DLL to static.
The macro SQLiteInit never returned "TRUE", AFAIR.
(And I must confess, I don't understand, why
)
After replacingbyeverything worked again:
hth...
The macro SQLiteInit never returned "TRUE", AFAIR.
(And I must confess, I don't understand, why

After replacing
Code: Select all
Macro SQLiteInit(a="")
EndMacro
Code: Select all
Procedure SQLiteInit()
ProcedureReturn #True
EndProcedure;
Code: Select all
XIncludeFile "sqlite_static_420.pbi"
If SQLiteInit()
hDB = SQLiteOpen("MyDB.db")
; reading
SQLiteClose(hDB.l)
hDB = SQLiteOpen("MyDB.db")
;writing
SQLiteClose(hDB.l)
EndIf
Sorry 4 my poor English, it's the only one I learned 40 years ago...
since 17.12.08: XPHome(SP3) + PB 4.30
since 17.12.08: XPHome(SP3) + PB 4.30
SQLiteInit is useless in this version and removed.
This Code make this automatic for you:
This Code make this automatic for you:
Code: Select all
UseSQLiteDatabase()
ImportC ""
sqlite3_close (hDB.l)
sqlite3_errcode (hDB.l)
sqlite3_errmsg (hDB.l) ; ...
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Thanks Fangbeast !Fangbeast wrote:Save TS-Soft's include file as a .PB or .PBI file (in keeping with pb naming conventions) and then XINCLUDEFILE that file at state start of any program using those functions.
The below is an excerp of my document manager
Code: Select all
; Any specific modules that have to load first XIncludeFile "\Development\Resources\Modules\_SqLite3Base.pbi" ; TS-Soft's SqLite functions for PB4.2 ; Try to open the system database and create missing tables Global dbHandle.l = SQLiteOpen("MyDatabase.db") ; Make handle global for other functions to use If Program\dbHandle Query.s = "CREATE TABLE IF NOT EXISTS documents(" Query.s + "added TEXT, lastrun TEXT, docnum TEXT, title TEXT, owner TEXT, active TEXT, note TEXT, filename TEXT, " Query.s + "directory TEXT, filesize TEXT, md5 TEXT CONSTRAINT md5 UNIQUE, created TEXT, accessed TEXT, modified TEXT, " Query.s + "readonly TEXT, archive TEXT, system TEXT, hidden TEXT, normal TEXT, backedup TEXT, compressed TEXT, " Query.s + "lastbackedup TEXT, category TEXT, subcategory TEXT, deleted TEXT, " Query.s + "record INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT)" If SQliteExecute(dbHandle, Query.s) = #False Debug SQLiteErrorMsg(dbHandle) Else Debug " Opened and ready to work" EndIf Else Debug SQLiteErrorMsg(dbHandle) EndIf ; This creates and/or opens the database and tables. Now do your reading, writing and close at program end
I got it working ! I saved TS-Soft static lib. I saved it in the PureLibraries/UserLibries, not sure if it is the right place. But it worked. I changed your code a little bit as it was giving an error for the structure. This the code that worked:
Code: Select all
XIncludeFile "C:\Program Files\PureBasic\PureLibraries\UserLibraries\sqlite3.pbi"
Global dbHandle.l = SQLiteOpen("c:\MyDatabase.db") ; Make handle global for other functions to use
Query.s = "CREATE TABLE IF NOT EXISTS documents("
Query.s + "added TEXT, lastrun TEXT, docnum TEXT, title TEXT, owner TEXT, active TEXT, note TEXT, filename TEXT, "
Query.s + "directory TEXT, filesize TEXT, md5 TEXT CONSTRAINT md5 UNIQUE, created TEXT, accessed TEXT, modified TEXT, "
Query.s + "readonly TEXT, archive TEXT, system TEXT, hidden TEXT, normal TEXT, backedup TEXT, compressed TEXT, "
Query.s + "lastbackedup TEXT, category TEXT, subcategory TEXT, deleted TEXT, "
Query.s + "record INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT)"
If SQliteExecute(dbHandle, Query.s) = #False
Debug SQLiteErrorMsg(dbHandle)
Else
Debug " Opened and ready to work"
EndIf
Again, thanks all for all replies.
