sqliteconnect #users, "test.db"
call execAndPrint "select * from users"
call execAndPrint "select count(*) from users"
#users disconnect()
end
sub execAndPrint query$
#users execute(query$)
while #users hasanswer()
result$ = #users nextrow$(",")
print result$
wend
end sub
SQLite is a popular database engine provided as a library and is supported for Windows, Mac and Linux. The source code is available and is in the public domain so it is completely free. We will support the parts of Run BASIC that integrate with SQLite, but as for the specific level of conformance to the SQL standard and other technical details, see http://www.sqlite.org/
The SQLITECONNECT #obj, "databasefile.db" statement connects to a database and sets the #obj variable to be a connection object. The connection object understands EXECUTE(), HASANSWER(), NEXTROW$() and DISCONNECT(). I'm sure there will be more commands.
Notice the NEXTROW$() method. It returns each query result row as a string, with each item delimited by the specified string ("," in the example but it could be CHR$(9) or something else). It is trivial then to use the WORD$() function to extract the information. We will certainly also add the ability to get items by name.
2 comments:
That's exciting news Carl! With all of the other features of Run BASIC, the addition of DB capabilities (and SQLite in particular)should be the finishing touches for high quality web applications. Good Stuff!
Excellent blog. Easy to follow step by step instructions which seem to be absent from every other site dealing with SQLite and Run Basic. In our project we are plaPrashanting to use SQLite.
http://www.sharpprogrammer.com
Advanced Programming Tips Tricks
Post a Comment