It describes how to add tables to a database, yes. However, that's not really what I'm asking, I should have explained myself. Like tsuujin, I take in a large number of names separated by commas as a string. I then use the split function to create a table with all the names in it. It's then easy to modify this table so that each entry is of the name="person" form, so the end result is
persontable={name="Abby", name="Bob", name="Carlos", name="Dylan"}
I could then do a db:add with persontable[1], persontable[2], etc. The problem is that the number of names I capture will vary, and so I don't know how to write a script that will db:add only the number of times that there are entries in persontable.
Edit: This is easy to do with multiple db:adds, but that's exactly what I'm trying to avoid due to speed issues
luasql in mudlet
Re: luasql in mudlet
db:add(mydb, persontable) doesn't work? As the example shows, you can pass it multiple rows to be added at once, not just per-row.
Re: luasql in mudlet
If I do that then only the last name is added to the database- or at least it's the only one I can find when I query it. Perhaps the others are being overwritten?
Re: luasql in mudlet
Possible, but impossible for us to know without knowing the DB structure and the exact commands you're sending.Skylark wrote:If I do that then only the last name is added to the database- or at least it's the only one I can find when I query it. Perhaps the others are being overwritten?
Re: luasql in mudlet
I've been using an alias to test Vadi's suggestion out:
Then to see if it worked, I use another alias:
^find (\w+)$
The find alias is working fine, or at least it has been in the past. However, if I attempt to find Abby or Bob after running the first alias to input the data, they don't appear to exist. Carlos appears normally. Anytime I try something of this form only the last name is added to the database.
Code: Select all
local mydb = db:get_database("people")
local persontable= {name="Abby", name="Bob", name="Carlos"}
db:add(mydb.folks, persontable)
^find (\w+)$
Code: Select all
local mydb = db:get_database("people")
local searching = capitalize(matches[2])
local results= db:fetch(mydb.folks, db:eq(mydb.folks.name, searching))
display(results)
Re: luasql in mudlet
what's the database structure? Got uniques, or primary keys?
Re: luasql in mudlet
db:create("people", {folks={name="", city="", enemied=0, infamous=0, mark=0, watching=0, class="", _unique= {"name" }, _violations="IGNORE" }})
Re: luasql in mudlet
Might have to do with the DB wrapper then. I honestly don't use it, so I'm not familiar with it's issues. If the code is supposed to look the way you have it written, I don't see a problem with the structure.
Re: luasql in mudlet
Code: Select all
local persontable= {name="Abby", name="Bob", name="Carlos"}
As per the example of:
Use
Code: Select all
local persontable= {{name="Abby"}, {name="Bob"}, {name="Carlos"}}
Re: luasql in mudlet
Thanks for the pointers, that was incredibly silly of me.
Unfortunately, attempting to add that table as suggested earler,
..results in this error:
Failed to add item: this is probably a violation of a UNIQUE index or other constraint.
Unfortunately, attempting to add that table as suggested earler,
Code: Select all
local mydb = db:get_database("people")
local persontable= {{name="Abby"}, {name="Bob"}, {name="Carlos"}}
db:add(mydb.folks, persontable)
Failed to add item: this is probably a violation of a UNIQUE index or other constraint.