Assistance with database issues

Post Reply
Skylark
Posts: 46
Joined: Mon Feb 22, 2010 12:38 am

Assistance with database issues

Post by Skylark »

Hey all, thanks in advance for the help. I'm trying to use a database to track forged items in Achaea. I've already done something similar to track characters, but I'm running into a host of errors trying to make this latest database work.

I delete the database file and restart mudlet between each test.
Code: [show] | [select all] lua
db:create("forging", {items={name="", totalforged=0, avgdamage=0, avgtohit=0, avgspeed=0, avgblunt=0, avgcutting=0, avgTotal=0, topdamage=0, toptohit=0, topspeed=0, toptotal=0, _unique= {"name" }, _violations="IGNORE" }})
When I run the following (in an alias) I get an error message.
Code: [show] | [select all] lua
forging.item="rapier"

local mydb = db:get_database("forging")
db:add(mydb.items, {name= forging.item})
local items = db:fetch(mydb.items, db:eq(mydb.items.name, "rapier"))[1]
<mudlet-lua\lua\DB.lua:1486: Attempt to access field avgtotal in sheet items in database
forging that does not exist.>
I've tried a few variations, such as creating the database without defining default values for the fields in the items sheet. In that case I get
<mudlet-lua\lua\DB.lua:627: Failed to add item: this is probably a violation of a UNIQUE
index or other constraint.>
...regardless of whether or not there's a unique constraint when I create the database.

Any help would be greatly appreciated; I tried to keep everything as close as possible to the previous database I created/use, but obviously I messed it up somewhere. Thanks.

User avatar
Rakon
Posts: 350
Joined: Tue Feb 16, 2010 7:41 pm
Contact:

Re: Assistance with database issues

Post by Rakon »

Honestly, I would recommend utilizing the database functions found here : http://forums.mudlet.org/viewtopic.php?f=6&t=1553 instead of the Mudlet built in defaults for database manipulation. It seems the implementation of the database functions in Mudlet produces more errors than just getting 'simple' with it.

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

Re: Assistance with database issues

Post by tsuujin »

As I understand it, the db container shipped with mudlet is kind of "in the works." I haven't ever really used it myself, but I've seen a lot of minor issues with it on the forums from time to time.

Rakon just dropped a link to my simplified container which I've been using for a long time now without error, but it does require that you have existing knowledge of SQL and database structure. It works very well for what it does, but it won't really build your databases for you.

One of these days I may expand on it with a more full-featured version, but probably not.

Thanks for pointing out my script, though! It's always nice to see my scripts getting some love.

Skylark
Posts: 46
Joined: Mon Feb 22, 2010 12:38 am

Re: Assistance with database issues

Post by Skylark »

Thanks, I'll look into picking that up.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Assistance with database issues

Post by Vadi »

The issue is that db: lowercases column names for you, so 'avgTotal' actually became 'avgtotal'.

Next Mudlet update db won't be forcing this on you, but for now try 'avgtotal'.

Post Reply