BASIC Developer & Support Resources > Scripting Languages

iCALL

<< < (12/12)

JRS:
I found the problem. I had a typo in my sqlite3_step definition and forgot the number of arguments parameter.


--- Code: ---' SQLite3 Test Script

DECLARE SUB DLL ALIAS "_gtk" LIB "gtk-server"
DECLARE SUB VARPTR ALIAS "varptr" LIB "gtk-server"

CONST SQLITE_ROW = 100

DLL("gtk_server_cfg -cfg=sqlite3.cfg")

db = 0
db_addr = VARPTR(db)
result = DLL("sqlite3_open \"testsql\" " & db_addr)
dberr = 0
dberr_addr = VARPTR(dberr)
result = DLL("sqlite3_exec " & db & " \"CREATE TABLE demo(someval INTEGER,  sometxt TEXT);\" 0 0 " & dberr_addr)
PRINT result,"\n"
result = DLL("sqlite3_exec " & db & " \"INSERT INTO demo VALUES (123, 'Hello');\" 0 0 " & dberr_addr)
PRINT result,"\n"
result = DLL("sqlite3_exec " & db & " \"INSERT INTO demo VALUES (234, 'cruel');\" 0 0 " & dberr_addr)
PRINT result,"\n"
result = DLL("sqlite3_exec " & db & " \"INSERT INTO demo VALUES (345, 'world');\" 0 0 " & dberr_addr)
PRINT result,"\n"
stmt = 0
stmt_addr = VARPTR(stmt)
result = DLL("sqlite3_prepare_v2 " & db & " \"SELECT * FROM demo;\" -1 " & stmt_addr & " 0")
SPLIT result BY " " TO ok, stmt

WHILE DLL("sqlite3_step " & stmt) = SQLITE_ROW
  PRINT DLL("sqlite3_column_text " & stmt & " " & 0) & " - " & DLL("sqlite3_column_text " & stmt & " " & 1),"\n"
WEND

--- End code ---

jrs@Laptop:~/SB/test$ scriba sql3-1.sb
0 (null)
0 (null)
0 (null)
0 (null)
123 - Hello
234 - cruel
345 - world
jrs@Laptop:~/SB/test$

AIR:
Cool.

Is that SPLIT statement needed?  I ask because the return value from the function is a single int, so I would think that SPLIT has no effect.

JRS:

--- Quote ---Is that SPLIT statement needed?
--- End quote ---

GTK-Server returns a S-LANG format response if you use PTR_ reference on an argument. SPLIT just separates the string response into variables.

Here is the final ScriptBasic SQLite3 example based on Peter's BaCon demo.


--- Code: ---' SQLite3 Demo Script

DECLARE SUB DLL ALIAS "_gtk" LIB "gtk-server"
DECLARE SUB VARPTR ALIAS "varptr" LIB "gtk-server"

DLL("gtk_server_require libsqlite3.so")

DLL("gtk_server_define sqlite3_open NONE INT 2 STRING LONG")
DLL("gtk_server_define sqlite3_exec NONE INT 5 LONG STRING INT NULL PTR_STRING")
DLL("gtk_server_define sqlite3_prepare_v2 NONE INT 5 LONG STRING INT PTR_LONG NULL")
DLL("gtk_server_define sqlite3_step NONE INT 1 LONG")
DLL("gtk_server_define sqlite3_column_text NONE STRING 2 LONG INT")
DLL("gtk_server_define sqlite3_close NONE INT 1 LONG")

CONST SQLITE_ROW = 100
db = 0
dberr = 0
stmt = 0

DLL("sqlite3_open \"testsql\" " & VARPTR(db))
DLL("sqlite3_exec " & db & " \"CREATE TABLE demo(someval INTEGER,  sometxt TEXT);\" 0 0 " & VARPTR(dberr))
DLL("sqlite3_exec " & db & " \"INSERT INTO demo VALUES (123, 'Hello');\" 0 0 " & VARPTR(dberr))
DLL("sqlite3_exec " & db & " \"INSERT INTO demo VALUES (234, 'cruel');\" 0 0 " & VARPTR(dberr))
DLL("sqlite3_exec " & db & " \"INSERT INTO demo VALUES (345, 'world');\" 0 0 " & VARPTR(dberr))
result = DLL("sqlite3_prepare_v2 " & db & " \"SELECT * FROM demo;\" -1 " & VARPTR(stmt) & " 0")
SPLIT result BY " " TO ok, stmt

WHILE DLL("sqlite3_step " & stmt) = SQLITE_ROW
  PRINT DLL("sqlite3_column_text " & stmt & " " & 0) & " - " & DLL("sqlite3_column_text " & stmt & " " & 1),"\n"
WEND

DLL("sqlite3_close " & db)

--- End code ---

jrs@Laptop:~/SB/test$ scriba sqlite3.sb
123 - Hello
234 - cruel
345 - world
jrs@Laptop:~/SB/test$

AIR:
Ok, I'm glad you finally got this going!

You should probably close the db when done as well.  That's the only thing missing, I think.

JRS:
@Armado
Thanks for all your help, code  and encouragement to complete this interface.

I added the sqlite3_close() and changed the WIDGET's to LONG's in the GTK-Server definitions.


@All
I will try and get a new gtk-server.dll compiled for Windows that has the SB VARPTR() function by AIR.  The second parameter of the GTK-Sever definition is a CallBack tag/function label. I wonder if the GTK-Server's event loop would also work with the Windows message pump? I have lost interest in Windows and will only do client work with the OS. It would be great if what is going with the Linux version of SB could also be maintained on the Windows side. I don't own a Mac so it's a gift if Armando contributes his time to SB on that OS.

Navigation

[0] Message Index

[*] Previous page

Go to full version