Very basic DB problems

Post Reply
vintermann
Posts: 2
Joined: Sun Nov 20, 2011 2:31 pm

Very basic DB problems

Post by vintermann »

I'm trying to do some very basic things with databases, just running the code from the manual, but I run into trouble:

I do this:
Code: [show] | [select all] lua
        db:create("people", {friends={"name", "city", "notes"}, enemies={"name", "city", "notes"}})
then this:
Code: [show] | [select all] lua
mydb = db:get_database("people")
then this:
Code: [show] | [select all] lua
        db:add(mydb.friends, {name="Ixokai", city="Magnagora"})
Then I get this in the errors log: </usr/share/games/mudlet/lua/DB.lua:627: Failed to add item: this is probably a violation of a UNIQUE index or other constraint.>

What's this? I'm on 64-bit Ubuntu, using the package mudlet_2.0-rc11-1ubuntu7_amd64.deb which I found a link to on this forum (I tried to install from the PPA, but what was there had issues such as segfaulting on all aliases.)

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

Re: Very basic DB problems

Post by Vadi »

Someone else ran into this, I showed them a solution that worked... should be somewhere on forums here.

vintermann
Posts: 2
Joined: Sun Nov 20, 2011 2:31 pm

Re: Very basic DB problems

Post by vintermann »

I did search the forums before posting, and I can't find it - or, at least not anything that appears to work for me. I tried declaring the schema with default initializers, but that didn't help.

Sure this isn't a regression, or something specific to this build?

I will try building from git tomorrow, to see what I can find of more information, but it's a lot of pain for getting code direct from the manual to work.

Jinresh
Posts: 2
Joined: Fri Nov 25, 2011 7:26 pm

Re: Very basic DB problems

Post by Jinresh »

I am new to mudlet and I was working through the manual as well, trying to learn how to use the databases in mudlet, and I have run into the same problem.
LUA: ERROR running script ^mudlettest (Alias130) ERROR:./mudlet-lua/lua/DB.lua:627: Failed to add
item: this is probably a violation of a UNIQUE index or other constraint.
I did search the forums and saw that Vadi posted about using db:merge_unique() in place of the db:add() function. Unfortunately this solution hasn't worked for me either. I receive a different error,
LUA: ERROR running script ^mudlettest (Alias130) ERROR:./mudlet-lua/lua/DB.lua:922: db:merge_unique
only works on a sheet with a unique index.
I looked at the database file using SQLite Sorcerer and the sheet in the database doesn't seem to have any fields aside from the standard "_rowid". I've tried different ways of initializing the database creation but I can't get it to actually create any fields (which is likely why db:add() and db:merge_unique() are not working).

So I am not quite sure how to go about actually using the databases in mudlet at this point. I am following the basic steps from the manual, posted at the beginning of this thread, and can't seem to get anything working regarding databases.

Any help would be greatly appreciated!

Lucky24
Posts: 52
Joined: Sun Sep 12, 2010 1:50 am

Re: Very basic DB problems

Post by Lucky24 »

I had issues with MERGE_UNIQUE simply not working. I ended up serializing my tables with table.load() and table.save(), instead of using the db stuff.

Also, check out the tsujin's generic luasql front-end, which you can use if you're familiar with SQL http://forums.mudlet.org/viewtopic.php? ... lit=luasql

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

Re: Very basic DB problems

Post by Vadi »

db: has been fixed and in a future Mudlet update, the example will work as expected.

Post Reply