So, apparently my problem was saving in the middle of writing the DB constructor, and getting things wrong that I then later fixed. I had both _index and _unique equal to {"name"} at one point, and changing it didn't do anything until I deleted the database and restarted Mudlet (because it wouldn't recreate it after it was deleted while it was running). I also apparently can't add fields even through restarts so long as the database is the same (at least not with the db:create function).
However, the timestamp still creates problems. Update worked fine without a timestamp in the database, but when I put it back in, the error came back.
Mudlet 2.1 Database Problem
Re: Mudlet 2.1 Database Problem
Specifically, I modified the db:create line to add in an extra field, I called it "testing". I then restarted Mudlet, and created a new row, with a new unique identifier, in the mydb.people sheet, fetched it, and displayed it... the new field "testing" was not present.
Re: Mudlet 2.1 Database Problem
I get this when I run your code:Jor'Mox wrote:So, I think I grabbed the most recent version of DB.lua and replaced the old one. Then I started experimenting with a database to see how to make it work. This is the example script I made just to test things out. It seems to me that the unique setting is not being used at all. Am I doing something wrong? Also, the way I had to put the fields in the db:fetch call for sorting was really weird.
Which looks correct?"George : dwarf : thief : 10 : george"
"bob : human : warrior : 15 : bob"
"Frank : ogre : cleric : 31 : frank"
Re: Mudlet 2.1 Database Problem
Yeah, it is. Like I said, the issue was that the database had originally been constructed with both _index and _unique equal to the same column. Changing the values later didn't actually change the structure of the database, so it didn't work correctly. Once I deleted the database and restarted so that it was recreated, it worked just fine.
So, looking at my overall results, it seems that there is an issue with updating a database sheet after it has been created.
If you delete the old database, and change the db:create call to this, you will have the problem I was experiencing:
After I sorted that out, I did this:
So, looking at my overall results, it seems that there is an issue with updating a database sheet after it has been created.
If you delete the old database, and change the db:create call to this, you will have the problem I was experiencing:
Even after I fixed the mistake, and changed _unique back to "keyword" as originally intended, it continued to behave as if it hadn't changed.
After I sorted that out, I did this:
Not only did the previously entered rows not have the new field "testing", newly created rows didn't have it either.
Re: Mudlet 2.1 Database Problem
The docs say you should provide the fields to sort by, so not {"level", "name"} but {mydb.people.level, mydb.people.name}.Jor'Mox wrote:Also, the way I had to put the fields in the db:fetch call for sorting was really weird.
sorting {"level","name"} didn't work
There is a sorting problem however that I can into, trying to get SQLite to sort it in descending order (levels first then names in descending) flips the results, so both levels and names are sorted right... but in ascending order. This is the raw SQL data you can run in an sqlite3 console: http://pastebin.com/7rx2BgFN and the results that follow are:
Code: Select all
194 warrior bob elf bob 2013-06-28 00:04:31 1
195 thief george dwarf George 2013-06-28 00:04:31 15
200 warrior Bobc human Bobc 2013-06-28 00:04:31 15
199 warrior Bobb human Bobb 2013-06-28 00:04:31 15
198 warrior Boba human Boba 2013-06-28 00:04:31 15
197 warrior Bob human Bob 2013-06-28 00:04:31 15
201 cleric Frank ogre Frank 2013-06-28 00:04:31 31
Re: Mudlet 2.1 Database Problem
Using db:create to add new fields to a database (changing them was never supported) doesn't work, due to a bug in Lua-SQL (the Lua SQL bindings we're using) not being updated for an SQLite API change, and thus the table_info pragma not working. This means that db: can't ask sqlite for which tables currently exist and add new ones appropriately.
Re: Mudlet 2.1 Database Problem
I should have read the updates you posted before posting!
Yeah, adding new columns right now is broken, due to the aforementioned Lua-SQL bug (http://lua-users.org/lists/lua-l/2013-02/msg00252.html). We'll be able to patch Lua-SQL in Windows and Mac for the next releases, I think.
Yeah, adding new columns right now is broken, due to the aforementioned Lua-SQL bug (http://lua-users.org/lists/lua-l/2013-02/msg00252.html). We'll be able to patch Lua-SQL in Windows and Mac for the next releases, I think.
Re: Mudlet 2.1 Database Problem
Okay, solved it, you're supposed to pass the sorting flag for each field. That's a more flexible mechanism as well.Vadi wrote:I'm still trying to work out what is going wrong here.
I'll fix db:fetch to apply the flag to all fields properly, and later on adjust the syntax to allow specifying the sorting parameter on each field.
Re: Mudlet 2.1 Database Problem
You may well be right about how you are supposed to provide fields for sorting, but the examples and explanation in the wiki is what I was using for guidance, and it pretty clearly spelled out sorting using {"level","name"} as the method to use. Also, since the code that is used for determining sorting is this:
Well, apparently giving it a bogus column name just means it doesn't sort by that column. So, no real issues with a non-existent column.
It should be able to be changed fairly easily to this to allow for either option:
You obviously may want some sort of check to be sure that the field exists, but I would think that SQL will just spit out an error if there is a problem on that end, so it isn't catastrophic if you can't.
Well, apparently giving it a bogus column name just means it doesn't sort by that column. So, no real issues with a non-existent column.
Re: Mudlet 2.1 Database Problem
Which examples? http://wiki.mudlet.org/w/Manual:Scripting#Querying has no mention of this. They need to be fixed if so.
Bogus names aren't catastrophic, but silent errors are I'd prefer that it throw the error.
I've worked out the sorting problem, the latest DB.lua (please don't forget to remove this file when you update Mudlet) sorts this code properly:
Bogus names aren't catastrophic, but silent errors are I'd prefer that it throw the error.
I've worked out the sorting problem, the latest DB.lua (please don't forget to remove this file when you update Mudlet) sorts this code properly: