lua-users home
lua-l archive

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


On Jun 25, 2010, at 5:36 AM, Luciano de Souza wrote:

> require('lsqlite3')
> 
> function initialize()
> 
> db = sqlite3.open('Ting.dbl')
> 
> cginsert = db:prepare [[insert into cathegories(entry, name, description) values(date('now'), :name, :description);]]
> 
> end
> 
> function finalize()
> 
> db:close()
> 
> end
> 
> function CathegoryInsert(name, description)
> 
> cginsert:bind(name, description)
> 
> cginsert:exec()
> 
> end
> 
> initialize()
> 
> CathegoryInsert('name1', 'description1')
> 
> finalize()
> 
> 'Bind" expect a number as the first argument? Probably is because the first implicit argument to be linked is 'id integer primary key'. But since I don't know what is the next valid integer, I prefer not to mention it in the SQL statement. How to fix this error?

stmt:bind(n[,value])
Binds value to statement parameter n. If the type of value is string or number, it is bound as text or double, respectively. If value is a boolean or nil or missing, any previous binding is removed.

stmt:bind_names(nametable)
Binds the values in nametable to statement parameters. If the statement parameters are named (i.e., of the form ":AAA" or "$AAA") then this function looks for appropriately named fields in nametable; if the statement parameters are not named, it looks for numerical fields 1 to the number of statement parameters.

stmt:bind_values(value1,value2,...,valueN)
Binds the given values to statement parameters.

e