I found a few things that needed corrections. The biggest issue is that you
needed to declare the callback function as a CFUNCTION.
Also, the returned arrays in the callback function are arrays of pointers so they
requires special attention to retrieve their string values.
See the attached file. I've changed it to call sqlite3 functions directly instead of using XstCall.
I can send you the .dec and .lib files if you want.
D.
dougla...@gmail.com wrote:
> Hello,
>
> I wrote a program to create, update and query a SQLite database. I am using XstCalls to SQLite3.dll.
>
> I got everything working except for my query callback function. It causes the program to crash.
>
> Can anyone see what I am doing wrong?
>
> Here is my program:
>
> PROGRAM "sqlite3_test"
> CONSOLE
>
> IMPORT "xst_s.lib"
> IMPORT "xsx_s.lib"
>
> DECLARE FUNCTION Main()
> DECLARE FUNCTION MyCallback (hwnd, cols, @lpdata$[], @colnames$[])
>
> FUNCTION Main()
>
> DIM args[0]
> args[0] = 0
> ret = XstCall ("sqlite3_libversion", "sqlite3.dll", @args[])
> PRINT "version: "; CSTRING$(ret)
>
> DIM args[1]
> db$ = "test.db"
> args[0] = &db$
> dbHandle = 0
> args[1] = &dbHandle
> ret = XstCall ("sqlite3_open", "sqlite3.dll", @args[])
> PRINT "open return code:"; ret
>
> DIM args[4]
> args[0] = dbHandle
> sql$ = "create table test (item varchar primary key, color text, price real);"
> args[1] = &sql$
> args[2] = 0
> args[3] = 0
> args[4] = 0
> ret = XstCall ("sqlite3_exec", "sqlite3.dll", @args[])
> PRINT "create table return code:"; ret
>
> DIM args[4]
> args[0] = dbHandle
> sql$ = "begin transaction;insert into test values ('apple1a','green',0.95);insert into test values ('apple2a','red',0.85);insert
> into test values ('apple3a','blue',0.85);insert into test values ('apple4a','red',0.85);insert into test values
> ('apple5a','green',0.85);insert into test values ('apple6a','red',0.85);insert into test values ('apple7a','blue',0.85);insert
> into test values ('apple8a','red',0.85);insert into test values ('apple9a','green',0.85);insert into test values
> ('tomato1a','green',0.65);insert into test values ('tomato2a','red',0.65);insert into test values ('tomato3a','red',0.65);insert
> into test values ('tomato4a','red',0.65);insert into test values ('tomato5a','red',0.65);insert into test values
> ('tomato6a','red',0.65);insert into test values ('tomato7a','red',0.65);insert into test values ('tomato8a','red',0.65);insert
> into test values ('tomato9a','red',0.65);insert into test values ('strawberry1a','red',0.15);insert into test values
> ('strawberry2a','red',0.25);insert into test values ('strawberry3a','red',0.35);insert into test values
> ('strawberry4a','red',0.45);insert into test values ('strawberry5a','red',0.55);insert into test values
> ('strawberry6a','red',0.65);insert into test values ('strawberry7a','red',0.75);insert into test values
> ('strawberry8a','red',0.85);insert into test values ('strawberry9a','red',0.95);insert into test values
> ('banana1a','yellow',1.15);insert into test values ('banana2a','yellow',1.25);insert into test values
> ('banana3a','yellow',1.35);insert into test values ('banana4a','yellow',1.45);insert into test values
> ('banana5a','yellow',1.55);insert into test values ('banana6a','yellow',1.65);insert into test values
> ('banana7a','yellow',1.75);insert into test values ('banana8a','yellow',1.85);insert into test values
> ('banana9a','yellow',1.95);insert into test values ('pineapple1','yellow',1.15);insert into test values
> ('pineapple2','yellow',1.25);insert into test values ('pineapple3','yellow',1.35);insert into test values
> ('pineapple4','yellow',1.45);insert into test values ('pineapple5','yellow',1.55);insert into test values
> ('pineapple6','yellow',1.65);insert into test values ('pineapple7','yellow',1.75);insert into test values
> ('pineapple8','yellow',1.85);insert into test values ('pineapple9','yellow',1.95);insert into test values
> ('beans1','green',0.35);insert into test values ('beans2','yellow',0.40);insert into test values ('beans3','red',2.00);insert into
> test values ('beans4','blue',1.40);insert into test values ('beans5','yellow',5.45);insert into test values
> ('beans6','yellow',0.40);insert into test values ('beans7','yellow',0.40);insert into test values ('beans8','yellow',0.40);insert
> into test values ('beans9','yellow',0.40);insert into test values ('dairy1','yellow',0.40);insert into test values
> ('dairy2','red',0.60);insert into test values ('dairy3','blue',0.80);insert into test values ('dairy4','green',0);commit;"
> args[1] = &sql$
> args[2] = 0
> args[3] = 0
> args[4] = 0
> ret = XstCall ("sqlite3_exec", "sqlite3.dll", @args[])
> PRINT "insert row return code:"; ret
>
> DIM args[4]
> args[0] = dbHandle
> sql$ = "select * from test where color = 'red';"
> args[1] = &sql$
> args[2] = &MyCallback()
> args[3] = 0
> args[4] = 0
> ret = XstCall ("sqlite3_exec", "sqlite3.dll", @args[])
> PRINT "select return code:"; ret
>
> DIM args[0]
> args[0] = dbHandle
> ret = XstCall ("sqlite3_close", "sqlite3.dll", @args[])
> PRINT "close return code:"; ret
>
> END FUNCTION
>
> FUNCTION MyCallback (hwnd, cols, @lpdata$[], @colnames$[])
> FOR i = 0 TO cols-1
> PRINT lpdata$[i];
> NEXT
> PRINT
> RETURN 0
> END FUNCTION
>
> END PROGRAM
>
> Thanks,
> -Doug
> --
> You received this message because you are subscribed to the Google Groups "xblite" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
xblite+un...@googlegroups.com.
> To post to this group, send email to
xbl...@googlegroups.com.
> Visit this group at
http://groups.google.com/group/xblite?hl=en.
> For more options, visit
https://groups.google.com/groups/opt_out.
>
>