luasql in mudlet

kkerwin1
Posts: 22
Joined: Tue Apr 20, 2010 7:37 am

Re: luasql in mudlet

Post by kkerwin1 »

ixokai wrote:First, can this thread *not* be a generic place where all questions related to the db frontend go? Its extremely hard to follow entirely separate conversations in a multi-page thread, especially when said conversations don't relate directly to the original topic(luasql, as opposed to the db frontend) :-)

One thread per issue is preferred, imho :)

First, display the full current contents of this table with:

display(db:fetch(mydb.tablename))

And copy/paste it to us? I can't use real values of mydb or tablename because there's been too many comments with output but not code, and it scrolled off of the forums view.

There may be a problem with your db:create() call (the error related to 'field does not exist') and that may even be a bug -- or there may be that you're trying to add duplicate data. And if you do that with multiple items in a db:add(), the -whole- thing cancels out, not just the duplicate.

As to the possibility of the first problem, try changing the table definition from {"name"} to {name=""}
My apologies for hijacking the thread.


display( db:fetch( mydb.folks)) returns:


table {}

Tried changing the code, as per a suggestion above:

init --

[syntax="lua"]
echo( "Initializing.\n")
db:create("all_people", {all_folks={"all_names"}})
local mydb = db:get_database("all_people")
personTable = {{all_names="Abby"},{all_names="Bob"},{all_names="Carlos"}}
db:add(mydb.all_folks, personTable)
[/syntax]

find --

[syntax="lua"]
echo("Querying " .. matches[2] .. ".\n")
local mydb = db:get_database("all_people")
--local searching = capitalize(matches[2])
local results= db:fetch(mydb.all_folks, db:eq(mydb.all_folks.all_names, matches[2]))
display(results)

[/syntax]

display --

[syntax="lua"]
local mydb = db:get_database( "all_people")
display(db:fetch( mydb.all_folks))
[/syntax]

Debug output --

Code: Select all

Alias name=^init$(^init$) matched.
Alias: capture group #1 = <init>
LUA: ERROR running script ^init$ (Alias1) ERROR:C:/Users/emily/.config/mudlet/db.lua:517: Failed to 
add item: this is probably a violation of a UNIQUE index or other constraint.Alias name=^find 
(\w+)(^find (\w+)) matched.
Alias: capture group #1 = <find Abby>
Alias: capture group #2 = <Abby>
LUA: ERROR running script ^find (\w+) (Alias2) ERROR:C:/Users/emily/.config/mudlet/db.lua:1017: 
Attempt to access field all_names in sheet all_folks in database allpeople that does not exist.
Alias name=^display$(^display$) matched.
Alias: capture group #1 = <display>
LUA OK script ^display$ (Alias3) ran without errors
So, it seems that the field names ("all_names" vs. "name") didn't make too much of a difference. Finally, the new display output, with the new variable names, also showed an empty table.

Thank you for your continued help.

ixokai
Posts: 63
Joined: Fri Dec 25, 2009 7:43 am

Re: luasql in mudlet

Post by ixokai »

You didn't actually make the change that I suggested. Change it as:

Code: Select all

db:create("all_people", {all_folks={all_names=""}}
Though I'm nto sure why the renaming is going on.

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: luasql in mudlet

Post by tsuujin »

ixokai wrote:You didn't actually make the change that I suggested. Change it as:

Code: Select all

db:create("all_people", {all_folks={all_names=""}}
Though I'm nto sure why the renaming is going on.
I asked him to change the names of his table and fields to eliminate the possibility of existing constraints

kkerwin1
Posts: 22
Joined: Tue Apr 20, 2010 7:37 am

Re: luasql in mudlet

Post by kkerwin1 »

ixokai wrote:You didn't actually make the change that I suggested. Change it as:

Code: Select all

db:create("all_people", {all_folks={all_names=""}}
Though I'm nto sure why the renaming is going on.
Ok. Changed as requested. Here was the output:

Code: Select all

 Alias name=^init$(^init$) matched.
Alias: capture group #1 = <init>
LUA: ERROR running script ^init$ (Alias1) ERROR:C:/Users/emily/.config/mudlet/db.lua:517: Failed to 
add item: this is probably a violation of a UNIQUE index or other constraint.Alias name=^find 
(\w+)(^find (\w+)) matched.
Alias: capture group #1 = <find Abby>
Alias: capture group #2 = <Abby>
LUA OK script ^find (\w+) (Alias2) ran without errors
Alias name=^display$(^display$) matched.
Alias: capture group #1 = <display>
LUA OK script ^display$ (Alias3) ran without errors

Both "find" and "display" returned empty tables, as no records were written to the database. I tried changing the variable names yet again, as tjuun requested, to make sure that there were no collisions. Still, having trouble adding records.

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: luasql in mudlet

Post by tsuujin »

Well, I can't save you from your current problem, but if you want to learn how to do it the hard way I can teach you.

kkerwin1
Posts: 22
Joined: Tue Apr 20, 2010 7:37 am

Re: luasql in mudlet

Post by kkerwin1 »

tsuujin wrote:Well, I can't save you from your current problem, but if you want to learn how to do it the hard way I can teach you.
Ok. Sure, let's do that. Would you care to start another thread?

Post Reply