/
sqlite3_test.bas
90 lines (68 loc) · 1.55 KB
/
sqlite3_test.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
''
'' SQLite test, translated by Nex/marzec
''
#include once "sqlite3.bi"
const DEFAULT_DATABASE = "sqlite3_test.db"
const DEFAULT_QUERY = "select * from features"
declare sub showusage( )
declare function callback cdecl _
( _
byval NotUsed as any ptr, _
byval argc as long, _
byval argv as zstring ptr ptr, _
byval colName as zstring ptr ptr _
) as long
dim as sqlite3 ptr db
dim as zstring ptr errMsg
dim as string database_name, query
if( __FB_ARGC__ > 3 ) then
showusage
end 1
end if
if( __FB_ARGC__ = 2 ) then
database_name = command( 1 )
else
database_name = DEFAULT_DATABASE
end if
if( __FB_ARGC__ = 3 ) then
query = command( 2 )
else
query = DEFAULT_QUERY
end if
if sqlite3_open( database_name, @db ) then
print "Can't open database: "; *sqlite3_errmsg( db )
sqlite3_close( db )
end 1
end if
print "Using database: "; database_name
print
if sqlite3_exec( db, query, @callback, 0, @errMsg ) <> SQLITE_OK then
print "SQL error: "; *errMsg
end if
sqlite3_close(db)
'':::::
function callback cdecl _
( _
byval NotUsed as any ptr, _
byval argc as long, _
byval argv as zstring ptr ptr, _
byval colName as zstring ptr ptr _
) as long
dim as integer i
dim as string text
for i = 0 to argc - 1
text = "NULL"
if( argv[i] <> 0 ) then
if *argv[i] <> 0 then
text = *argv[i]
end if
end if
print *colName[i], " = '"; text; "'"
next
print
function = 0
end function
'':::::
sub showusage( )
print "Usage: "; command( 0 ); " database ""query"""
end sub