Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ General
➜ bind_names Database function
bind_names Database function
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Bast
(78 posts) Bio
|
Date
| Thu 25 Jun 2009 07:45 PM (UTC) Amended on Thu 25 Jun 2009 07:47 PM (UTC) by Bast
|
Message
| In lua, using the sqlite3 stuff, you can do something like this
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 |
Bast
Scripts: http://github.com/endavis | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Thu 25 Jun 2009 09:14 PM (UTC) |
Message
| There isn't, partly because it is available in Lua, and partly because I thought in other languages you could achieve the same effect by simply using the equivalent to Lua's string.format (to make up a statement at runtime), or just concatenating values together. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
10,037 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top