PDA

View Full Version : Sqlite?



BjornF
29-06-2017, 16:50
Dear All,

I have just discovered ThinBasic, very impressive! :D

I tried finding out if it supports SQLITE but could only find a couple of old (pre 2012) posts. Has there been any further development on this?

All the best, Björn

ErosOlmi
29-06-2017, 17:12
Ciao Björn

no, there is nothing native in thinBasic working on Sqlite.
It is on my personal list but so far no time to develop a module for it.

In few days there will be a new thinBasic version that will have a quite complete module working on ADODB (connections and recordset for all of the most important DB engines) but of course it is something different.

Will see if I will be able to add something for Sqlite in successive versions.
If you have any priority on which functionalities of Sqlite you would like to have first, le me know.

Ciao
Eros

BjornF
30-06-2017, 14:09
Dear Eros,

thank you for a rapid answer!

Just very basic ones: create database, create table, query, create, update and delete record

I'm not sure if it helps but I am working a little bit with RFO-Basic for Android (http://rfo-basic.com/manual/#_Toc477209093). There are two commands:
Sql.exec <DB_pointer_nvar>, <command_sexp>
Execute ANY non-query SQL command string ("CREATE TABLE", "DELETE", "INSERT", etc.) using a previously opened database.

Sql.raw_query <cursor_nvar>, <DB_pointer_nvar>, <query_sexp>
Execute ANY SQL Query command using a previously opened database and return a Cursor for the results.

that seem to communicate directly with the sqlite databases (there are also a number of others that makes life simpler for us newbie programmers). (The code for RFO Basic is freely available)

All the best, Björn

ErosOlmi
30-06-2017, 21:24
I think I will be able to have something in few weeks, maybe days.
I've already some code to adapt to thinBasic

Stay tuned.

BjornF
30-06-2017, 22:26
Excellent news. Thank you.

Björn

ErosOlmi
01-08-2017, 22:30
Quite ready to publish a new thinBasic version with a "basic" SQLite module inside

Example:

uses "Console"
uses "SQLIte"


'---Quick and dirty
sqlite_Open app_sourcepath & "SQLIte_Test.SQLITE", "C"
sqlite_Exe "Drop Table If Exists T1"
sqlite_Exe "Create Table If Not Exists T1 (F1, F2, F3, F4)"
sqlite_Close



dim lStart as Double
dim lEnd as Double
dim NumRecs as Long

'---Save starting time
lStart = Timer
'---Open sample database
sqlite_Open app_sourcepath & "chinook.sqlite"


'---Count records
sqlite_Select "Select count(1) as nRec from Customers"
sqlite_GetRow
printl "Number of records expected:", SQLite_FieldValue("nRec")
printl


'---Select record set
sqlite_Select "Select * from Customers order by CustomerId"


'---Process records
NumRecs = 0
Do While sqlite_GetRow
Incr NumRecs
'---Print something
printl strformat$("Rec: {1}, {2}, {3}, {4}", NumRecs, SQLite_FieldValue("FirstName"), SQLite_FieldValue("LastName"), SQLite_FieldValue("Company"))'SQLite_FieldValue(1), SQLite_FieldValue(2), SQLite_FieldValue("Address")
Loop


sqlite_Close


'---Save the time it took to run this test so we can display it later.
lEnd = Timer - lStart


'---Display results
printl "Test 1: Retrieve " & NumRecs & " rows." & " Time: " & Format$(lEnd, "##.0000") & " seconds."


WaitKey

BjornF
02-08-2017, 10:26
Very nice Eros, thank you!!

Björn

ErosOlmi
02-08-2017, 11:33
It's online with version 1.10.2
http://www.thinbasic.com/community/showthread.php?12778-thinBasic-1-10-x