In lua, using the sqlite3 stuff, you can do something like this
This makes it easy to write a for loop to insert a lua table into a sql table without having to rebuild the insert string for each new item. I know the database API for MUSHclient includes a prepare, step, reset, and finalize. Is there an equivalent way to bind_names in the API or could it be added?
Thanks,
Bast
db = assert(sqlite3.open("somedb.db"))
db:exec([[CREATE TABLE mobs(
mob_id INTEGER NOT NULL PRIMARY KEY autoincrement,
mobname TEXT,
mobarea TEXT
)]])
t = {
{name = "Some mob", room = "Some room"},
{name = "Another mob", room = "Another room"},
}
stmt = db:prepare("INSERT INTO mobs VALUES (NULL, :name, :room)")
for i,v in ipairs(t) do
stmt:bind_names(v)
stmt:step()
stmt:reset()
end
stmt:finalize()
This makes it easy to write a for loop to insert a lua table into a sql table without having to rebuild the insert string for each new item. I know the database API for MUSHclient includes a prepare, step, reset, and finalize. Is there an equivalent way to bind_names in the API or could it be added?
Thanks,
Bast