Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
DanteX
Apprentice


Joined: 13 Aug 2007
Posts: 166

PostPosted: Tue Nov 17, 2009 7:09 pm   

Creating, opening and accessing a database
 
Hi all

I'm trying to create a database. I have the following in an alias.

Code:
DB_name="Aardwolf_database.db"
#SQLDB @DB_name
#SQLCLOSE @DB_name


The first time I run the alias, a databse file is created. Empty of course.

The second time I run it, I get an error / crash saying that the file I'm accessing "is not a valid SQLite database file."

What is wrong?

D
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Tue Nov 17, 2009 8:14 pm   
 
You probably need to create some Tables in the database. I think SQLite gives an error when you try to open an empty file.
Reply with quote
DanteX
Apprentice


Joined: 13 Aug 2007
Posts: 166

PostPosted: Wed Nov 18, 2009 8:45 am   
 
Ok, I had problems creating a new dabase file that worked. I got all sorts of errors... so I used the muds.db file, renamed it etc and now I got a working file.

What I've done is to create a new table inside that file, and I got 1 record inside, just to learn to handle this stuff.
I've made the following code to check the content:


Code:
#SQLDB Aardwolf_MobList.db
row = %sql(Aardwolf_MobList, "SELECT * FROM MobList")
#LOOP 10 {
  #SHOW "MobName: " @row.Item("MobName")
  #CALL @row.Next
}



When I run that code from the command line, it does show the content.

When I put it inside an alias, it doesn't work. It shows this 10 times:

MobName: <COMObject>.Item

I have also tried:

Code:

DB_name="C:\full_path_to_the_file\Aardwolf_MobList.db"
#SQLDB @DB_name


and that also results in

MobName: <COMObject>.Item

How can I make it access the file I want from an alias?

D
Reply with quote
DanteX
Apprentice


Joined: 13 Aug 2007
Posts: 166

PostPosted: Wed Nov 18, 2009 9:18 am   
 
Also, I cannot seem to close databse connections. Whenever I run that alias, a new connection seems to become established according to #SQLDB.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Wed Nov 18, 2009 4:57 pm   
 
The #SQLDB command should only be used once at the start of your session. It defines a Named database connection and then opens the database. I will try to modify the #SQLDB command in the future so that it will reuse an existing database connection with the same name if it already exists. But for now, take the #SQLDB command out of the alias and just run that once.

However, I just renamed the muds.db database to a new name and used it in your script example above and it worked fine for me here within an alias. So maybe it has to do with only having a single row in the database or something?

Try to give the full example of how you created the database, the tables, and the data itself (show your various SQL commands) so that other people can try to help reproduce this issue since I can't get it to fail.
Reply with quote
DanteX
Apprentice


Joined: 13 Aug 2007
Posts: 166

PostPosted: Wed Nov 18, 2009 5:16 pm   
 
Ok Zugg.

I will do that, but like I said, when I run the code from the command line, it does show me the content of the table. The table only has 1 entry.

It's when I run that code from an alias (that is attached to the main package for my main window) that it shows nothing....
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Wed Nov 18, 2009 5:45 pm   
 
I know that is what you said. But I don't get any problems either from the command line or from an alias. But this problem was reported by somebody else in the past, so I need your help to debug it.

It would also help if you tried it in a blank session (close the Sessions window) to be sure it's not related to something else in your scripts. The last time someone had problems with this, they were accessing their @row variable in other scripts and that was interfering with it.
Reply with quote
DanteX
Apprentice


Joined: 13 Aug 2007
Posts: 166

PostPosted: Thu Nov 19, 2009 12:00 am   
 
Ok Zugg.

I've tried this now, I have the following behaviour in a blank session:

I paste the code, with the full path to the file stored inside a variable, then accessing through the var... inside the command line. It works perfectly

I create an alias with the identical code. Placed directly inside the "untitled" window. I run the alias - it works perfectly.

I create a folder and move that alias into te folder (dragging it)... it doesn' work, returns 10 x
MobName: <COMObject>.Item

I go back to my working session...

I move my alias from the folder, into the main window. I run it, and works perfectly.

I then move the row variable, into the class folder with my aliases (2 similiar ones), I run the other one, it doesn't work.

I move back my alias (always referred to earlier) into the folder. Run it, it doesn't work.

I change name of the row var inside that alias, to row2 everywhere.

I run the alias, and it works.

Hope it helps.

Also, how is the #SQLCLOSE command supposed to be used?

atm I've tried this, which doesn't close it for me:

[code]
DB_name="C:\full_path_to_the_file\Aardwolf_MobList"
#SQLCLOSE %concat(@DB_name,".db")
[\code]

and
#SQLDB %concat(@DB_name,".db")
is used to open the db.

Hope it helps.
Reply with quote
DanteX
Apprentice


Joined: 13 Aug 2007
Posts: 166

PostPosted: Thu Nov 26, 2009 11:37 am   
 
Sometimes it has also helped to

#UNVAR row

before

row = %sql(Aardwolf_MobList, "SELECT * FROM MobList")

But not always.
Reply with quote
DanteX
Apprentice


Joined: 13 Aug 2007
Posts: 166

PostPosted: Thu Nov 26, 2009 10:23 pm   
 
Further, I have moved this entier script into a separate module, just to see if it could affect the accessing somehow... and it didn't. Same problem
...
with

Code:

row = %sql(Aardwolf_MobList, "SELECT * FROM MobList")


it rarely worked, even with #UNVAR row before the row = line.
...
THEN
...
I changed the "row" variable assignment to

Code:

#VAR row %sql(Aardwolf_MobList, "SELECT * FROM MobList")


and now it always works!!

So please, Zugg, see if the "=" variable assignment can somehow screws up the reading / writing...
Reply with quote
DanteX
Apprentice


Joined: 13 Aug 2007
Posts: 166

PostPosted: Fri Dec 04, 2009 7:38 am   
 
Ok, here's the full process, on how to recreate this:

1. Open CMUD
2. Close the session window.
3. Open the settings window.
4. In the untitled window, create a new class, I named it "DBtestclass".
5. In that class, create a new variable, I named it DB_name, and put the following value: "C:\Documents and Settings\..path on my computer..\My Games\CMUD\muds"
6. In that class, create a new alias, I named it "dbinit", with the following code:
Code:

#SQLDB %concat(@DB_name,".db")

7. In that class, create a new alias, I named it "dbtest", with the following code:
Code:

#UNVAR row
row=%sql(@DB_name, "SELECT * FROM MudList")
#LOOP 10 {
  #SHOW "Title: " @row.Item("Title")
  #CALL @row.Next
}

8. In the command line, type "dbinit" and hit the enter button
9. In the command line, type "dbtest" and hit te enter button. For me, I got the following:
Code:

Title:  <COMObject>.Item
Title:  <COMObject>.Item
Title:  <COMObject>.Item
Title:  <COMObject>.Item
Title:  <COMObject>.Item
Title:  <COMObject>.Item
Title:  <COMObject>.Item
Title:  <COMObject>.Item
Title:  <COMObject>.Item
Title:  <COMObject>.Item

10. Go to the "dbtest" alias, and change it to
Code:

#UNVAR row
#VAR row %sql(@DB_name, "SELECT * FROM MudList")
#LOOP 10 {
  #SHOW "Title: " @row.Item("Title")
  #CALL @row.Next
}

11. repeat steps 8-9. Then I got the following:
Code:

Title:  The Original Leviathan
Title:  3-Kingdoms
Title:  Aaezure Odyssey
Title:  Fallout
Title:  Ring of Power
Title:  Buffy Mud
Title:  Aardwolf
Title:  Ancient Mists
Title:  Red Tide MUX
Title:  Darksun MUD

Last: repeat the steps 1-3 and 5-9 (don't create a folder but place everything right under the window where the folder was palced initially). Then I get the same result as displayed in step 11. In other words, the problem is not repeated when all aliases/variables are outside a folder.

//DanteX
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Fri Dec 04, 2009 5:21 pm   
 
Reproduced this and added it to the bug list. This sounds like a pretty serious problem with the "var=value" syntax for COM-based objects. So this bug probably effects more things than just the %sql database functions.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net