lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi
 
I am writing a small Application utility in Lua using the lsqlite3 Lua binding, its a great very powerful binding, but it could definitely benefit from some better documentation and more extensive code examples. I am trying to do something fairly simple but couldnt figure out the correct syntax, I am hoping there are some Lua/Sqlite experts here that could assist me please.
 
I made a simplified example to post here, I am trying to add rows to a table that contains 2 string columns and a blob column. The difficulty was binding the 2 strings and the 1 blob colum all on the one row.  I eventually figured out the following code which does seem to work, but doesnt really look the correct way of doing it to me ?
 
require("lsqlite3")
 
local blobStr
local stmt
local db = sqlite3.open([[c:\test.db]])

 
db:exec([[CREATE TABLE IF NOT EXISTS tblApplications (AppFileName VARCHAR , AppBlob BLOB, GeneralNotes VARCHAR)]])
 
for i=1, 5 do
   local blobStr = tostring(i)
   local someAppName = "Some Appname " .. tostring(i)
   local someGenNotes = "Some GenNotes " .. tostring(i)

   
   stmt = db:prepare[[ INSERT INTO tblApplications (AppFileName, AppBlob, GeneralNotes) VALUES( ?, ?, ?)]];
   stmt:bind_values( someAppName, NULL, someGenNotes)
   stmt:bind_blob(2, blobStr)

   
   stmt:step()
   stmt:reset()

 
end
db:close()
 
what I dont like is the fact that I have to add the blob as a NULL using the initial bind_values line, which then gets corrected with the next bind_blob line. I am sure there is a more correct way of doing this ?
 
Thanks for any assistance
 
Geoff