Mudlet Databases

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

Re: Mudlet Databases

Post by Vadi »

try deleting your LuaGlobal in .config first

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Mudlet Databases

Post by Heiko »

Just delete LuaGlobal.lua in Mudlet home. LuaGlobal.lua will be restored automatically when you start Mudlet. It's compiled into the binary to shield against corruption in cases like yours. Make sure that ~/.config/mudlet has proper file permissions.

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

Re: Mudlet Databases

Post by Rakon »

Deleting LuaGlobal.lua was a lot better fix than trying to go back 30 or so saves, for the corruption.

As a note, I've found out that Mudlet will crash if attempting to highlight text with the mouse cursor, in the output window, if it's also trying to scroll. I'll try to post some form of an output error log when I am able.

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

Re: Mudlet Databases

Post by Rakon »

So I've been messing around with the database stuff, and trying to learn luasqlite implementation. (Seriously, is it too damn hard to have a tutorial explaining HOW to actually read/alter/commit data in a friggen function?)

Well, I've been 'reloading' the script a couple hundred times.... or at least, I thought I was reloading the script. HOWEVER, now I am getting errors of being unable to reload the script, and unable to save my profile because of ... 'too many open files'. How do I close an open file, so I can save the profile??

This is the error I get when trying to save the profile

Code: Select all

Failed to save Rakon to location /home/chris/.config/mudlet/profiles/Rakon/current/30-03-2010#23-07-55.xml because of the following error: Too many open files

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

Re: Mudlet Databases

Post by Rakon »

I got the settings restored, and able to reload the script file by closing out Mudlet.

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

Re: Mudlet Databases

Post by Rakon »

Alright...seriously.. is there NO GOOD luasql tutorial out there??

EVERY single one stupid example:

Code: Select all

cur = assert (con:execute"SELECT name, email from people")
-- print all rows, the rows will be indexed by field names
row = cur:fetch ({}, "a")
while row do
  print(string.format("Name: %s, E-mail: %s", row.name, row.email))
  -- reusing the table of results
  row = cur:fetch (row, "a")
end

Well, that's great when all you're doing is a select. Now, what about an update on preexisting fields?

I've been trying for way too damn long to get this lua implementation and sqlite3 commands down, to execute as simple update. SIMPLE @#~!@ update command!!

The following is the code I am using, to try and update a single field:
Code: [show] | [select all] lua
function rows (connection, sql_statement)
  rw_cursor = assert (connection:execute (sql_statement))
  return function ()
    return rw_cursor:fetch()
  end
end



function shop_sold(num)
 
 local env = assert(luasql.sqlite3())
 local conn = assert(env:connect(getMudletHomeDir() .. '/scripts/shop.db'))
 local num = strip(num)
 
 if num == '' then
   al_norm('You must enter an item and number: rapier1234, not 1234')
  return
 else
   for itemno, price, owner, inshop in rows(conn, string.format("select itemno,price,owner, inshop from items where itemno='%s'", num)) do
    conn:execute(string.format("update items set inshop='Y' where itemno='%s'",itemno))
    echo(string.format('\n-SOLD- %s owns: %s priced at %s gold', owner,itemno,price))
   end -- for
   
  rw_cursor:close()
  conn:commit()
  conn:close()
  env:close()
 end -- if
  
end -- function
Now, the echo is printing, because when I run this function I get the output to Mudlet window:

Code: Select all

-SOLD- Rakon owns: rapier1234 priced at 2000 gold
-SOLD- Rakon owns: rapier5678 priced at 2500 gold
This only prints out an error about an sql cursor, which I can't get id of :

Code: Select all

[ERROR:] object:<shop> function:<Trigger516>
         <[string "function Trigger516()..."]:25: LuaSQL: there are open cursors>
However, when I use the following function to to print out all items from the database that have the inshop status 'Y', I get nothing as a value:
Code: [show] | [select all] lua
 for itemno, price, owner, inshop in rows(conn, "select itemno,price,owner,inshop from items where inshop='Y'") do
     al_norm(string.format('-SOLD- %s owns: %s priced at %s gold', owner,itemno, price))
     conn:execute("delete from items where inshop='Y'")
    end -- for
Which prints out to screen... nothing. I take it this means that there are no items in the database, that meet my query.

So. Could anyone familiar with luasql explain to me why the update is not working, or show/link me to a better example than the one at http://www.keplerproject.org/luasql/examples.html ?

Thanks.

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

Re: Mudlet Databases

Post by Vadi »

Nope, nobody is familiar with it and you'd have to write to the authors of the thing.

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

Re: Mudlet Databases

Post by tsuujin »

To see what cursors you have open, you can use the "cur:getcolnames()" function. a cursor is returned from your attempt to execute a statement.

so
cur = conn:execute(some code)
would return your cursor, and
for i,k in pairs(cur) do
echo(k.."\n")
end
would, in theory, return your open cursors for debugging by column name.

keep in mind, this is a psudocode example to illustrate how it works.

I haven't used the sqlite system yet, but if it supports transactions then the reason it's not saving what you store might be that it's not commiting the data for some reason. Try asserting it with an error message?

Post Reply