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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » Finished MUD Scripts Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next
Dharkael Posted: Thu Apr 03, 2008 10:09 am
Python Sqlite COM Component for ZMUD/CMUD
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: Sun May 04, 2008 5:28 pm   
 
Dharkael here is a workable in memory alias that you can run... the returns are not in my data, however I tried the trim just to be sure but it still does it.

Code:
#var stuff %comcreate("Sqlite.ZMUD.WSC")
#call @stuff.Open(":memory:")
#call @stuff.Execute("create table myeq (name,wear,level)")
#call @stuff.Execute("insert into myeq values('<*><|Sash of Jord|><*>','waist','41')")
#call @stuff.Execute("insert into myeq values('fine sash','waist','1')")
#call @stuff.Execute("insert into myeq values('cord of justice','waist','21')")
#call @stuff.Execute("insert into myeq values('a rope belt','waist','31')")
#call @stuff.Execute("insert into myeq values('\|/ Ogham Bark \|/','torso','1')")
#call @stuff.Execute("insert into myeq values('=|EarthSword>','wield','11')")
#call @stuff.Execute("insert into myeq values('Skull Basher','wield','2')")
#call @stuff.Execute("insert into myeq values('Bastard Sword','wield','25')")
#call @stuff.Execute("insert into myeq values('[|Pencil|>','wield','111')")
#show %ansi(high,magenta,under)"Clan Equip                   "%ansi(high,blue,under)"Wear"%ansi(high,magenta,under)" Lvl"
#for  @stuff.Execute("SELECT * FROM myeq") {
#showp %ansi(white)%format( "&-29s", %left(%trim(%db(%i,"name")),28))
#showp %ansi(high,blue)%format( "&4s", %left(%db(%i,"wear"),4))
#showp %ansi(high,magenta)%format( "&4s", %left(%db(%i,"level"),4))
#show ""
}


This is what the output looks like when I run the above alias:
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Sun May 04, 2008 5:46 pm   
 
Hey Xekon, I tried your in memory example and I can't reproduce the problems you're having.

This is what's displayed on my screen


Have you tried running your example alias in an empty session?
Maybe some other trigger or something is modifying the display.
I noticed that in the picture you showed the problem appears only after items who's name ends in a / or a >
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: Sun May 04, 2008 5:52 pm   
 
Yes, I just tried it in an empty session, that did not work, then something Dawned on me, it happens when in your com object

_CMUDFormat = True

when thats set to true, i set it to true because i do use cmud, however if i set it to false then it works the way it should.... maybe i should just leave it to false then? what exactely does this variable do?

Also I will note that its the updown bar the pipe that causes it | or lots of quotes being in the name

Code:
<*><|Sash of Jord|><*>
<*><|Fenris Fangs|><*>
<*><|Modi's Courage|><*>
<*><|Asgardian Greaves|><*>
<*><|Brisings' Necklace|><*>
<*><|Strength of Magni|><*>
\|/ Ogham Bark \|/
\|/ The Yellow Book of Lechan \|/
=|EarthSword>
||A Book of Troll Poetry||
[|Pencil|>
|white toga|
|=|=|Footsteps of Evil|=|=|
/-|Strength Of Perseverance|-\

"blade named ""Stormbringer"""
"black hilted sword called, ""Dwarf Slayer"""
"Holy Avenger ""Faith Restorer"""
"Holy Avenger ""Faith Restorer"""
Reply with quote
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: Sun May 04, 2008 6:03 pm   
 
DOH! Cmudformat is what fixed this issue

Code:
golem's ear                   
-*                           


here is what should have been returned:

Code:
golem's ear
-*)Fu-leng's Legacy(*-
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Sun May 04, 2008 6:36 pm   
 
Yeah there was an issue was in how I was formating the data returned when using the CMUDFormat.
For the curious I was calling the Utility function CMUD_LIE once and passing the key separator and value as one argument.
What I should have been doing was encoding each seperately, Which I've now corrected.

Xekon, in the future I'd recommend you not modify the source if you're going to seek help from me or someone else using the component.
If we're not using the same component, then any problems reported, troubleshooting steps tried and resolved may not be relevant.
If you want to change the CMUDFormat then do something like stuff.CMUDFormat=1 to set it Smile
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: Sun May 04, 2008 6:40 pm   
 
Quote:
stuff.CMUDFormat=1


oh neat! i didnt realize i could do that!
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Sun May 04, 2008 6:49 pm   
 
It's an exposed property, its been made both readable and writable.
All properties and methods that are accessible with the COM object are described in the first entry to this thread.
This includes anything new that I've added since the first post.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: Sun May 04, 2008 6:52 pm   
 
Well Dharkael, I owe you a huge thank you, with your last bug fix I now have a nearly finished equipment database script.... and its all in super awesome sqlite3...

All that is left for me to do is polish a couple of things.

I don't know what all you have cooked up or weather or not you even play Aardwolf, but let me know if you want a copy of what Ive done so far...

I know that your more than capable of doing any of this stuff yourself, but if what i have made could save you some time then that would be cool.

Also I am not sure if you use cmud or zmud primarily. This has been written in Cmud, but could probably be brought over to zmud fairly easily.

but again one big THANK YOU for sharing this and for you work on making it a polished finished product.
Reply with quote
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: Tue May 06, 2008 6:48 pm   
 
When I walk into rooms with this script enabled it checks to see if the mob is in my db, if it is not then it subs a clickable add button to the end of their name.
I was thinking this would be a very good time for me to use an index, also Im thinking I am probably not using the quickest sql statment and theres probably a better way of doing this.

Dharkael, was wondering if you could show me how to do this so that it is as fast as possible, I still have not created an index but was thinking I should on the roomdesc field... do index's have to be updated every so often, or do they update on their own after records are added to the table?

Code:
mobindb=0
$tempvar=%replace(%1,"'","''")
#for @mobdb.Execute("SELECT * FROM mobdb WHERE roomdesc=?",$tempvar) {mobindb=1}
#IF (@mobindb==0) {
#SUB {%ansi(brown)%1<send 'addmobdb $tempvar'>%ansi(high,red)"ADD"</send>}
}
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Tue May 06, 2008 7:16 pm   
 
I believe they're updated automatically. That means that indices cause adding data to be slower (because the index has to be updated) but makes lookups quicker.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Tue May 06, 2008 10:28 pm   
 
Fang is right on the money.
You can create indexes(or indices if you prefer) using (unsurprisingly) the CREATE INDEX command.
To create an index on the roomdesc column of the mobdb table using something like:
Code:
CREATE INDEX IF NOT EXISTS roomdesc_idx ON mobdb (roomdesc);

As for speed tips:
Its generally not a good idea to use * to specifiy the columns you're after because that retrieves all columns whether or not
you really need all the columns and that takes more time and memory than just specifying the column(s) you're really after.
If you're only interested in the roomdesc then SELECT roomdesc FROM......
is what you should specify.

In the code you posted what you're doing is counting the number of rows where the roomdesc matches
the current roomdesc. It would be much faster to let sqlite count them for you using the COUNT function A la:
Code:
#IF (@mobdb.Execute("SELECT COUNT(roomdesc) AS Count FROM mobdb  WHERE roomdesc=?",$tempvar).Count) {
#SUB {%ansi(brown)%1<send 'addmobdb $tempvar'>%ansi(high,red)"ADD"</send>}
}


Okay last thing.
I noticed in your code is that you're doubling single quotes manually while using qmark.
I presume you're trying to escape them, but as I've said before its not necessary since the qmark substitution automatically does it for you.
When using qmark if you double the quotes you're not escaping them you're doubling them and changing the data you're inserting
or querying with, surely as if you had decided that all A or E should be doubled changing BED to BEED and BAD to BAAD.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: Tue May 06, 2008 11:19 pm   
 
Thank you very much for the create index and better way of query the db using the count on only roomdesc, this is making it go much quicker!

You Sir are correct, I just checked all my data and it inserted double '' The reason I was escaping it before sending it is because if you do a "#sub <send alias var" and the var has single quotes that are not escaped then the output on the screen goes nuts... so this is probably the only time that its a good idea for me to use the "%format and the &s" OR I could after passing the variable to the alias with the sub send, do a reverse replace that replaces double '' with a single ' before insertion....
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Wed May 07, 2008 12:06 am   
 
Code:
#IF (@mobdb.Execute("SELECT COUNT(roomdesc) AS Count FROM mobdb  WHERE roomdesc=?",$tempvar).Count) {
#SUB {%ansi(brown)%1 <send 'addmobdb %replace($tempvar,"'","%char(39)")'>%ansi(high,red)"ADD"</send>}
}
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."

Last edited by Dharkael on Wed May 07, 2008 12:12 am; edited 1 time in total
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Wed May 07, 2008 12:10 am   
 
You didn't close your %replace function, Dharkael. I assume you meant to have the closing bracket after (39)" and before '.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Wed May 07, 2008 12:12 am   
 
Thanks!
I actually fixed it in my test alias but forgot to do that in the the text file I was working from.

Good Eye! btw
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Wed May 07, 2008 12:52 am   
 
Here is an odd situation, Dharkael. I have created a table which is has exactly the same data as another table, that is I've made a duplicate by running the script that created the original table, just used another name. The reason for this is that I want to make so changes to the data and don't want to blow the original if something goes wrong, even though the original table has some errors, it is still usable. However, when I query the new table, it cannot find the data. Neither can the SQLite Expert program. It shows the table with all the data there but when I use WHERE on the name field (Name Text), it fails to locate the record, no matter where I place the field on the table. No such problem if I use any other column as the key. Using the name field works just fine on the original table
The first time I run the script, it always comes back with TABLE xxxx does not exist. It works the second time around, though. That is, it doesn't complain about it.
The only difference is that I am using the new COM object. I am going to back out the version and run the script again to see if it makes a difference. The other table was created with a much older object. I've also tried giving the column a different name and it didn't matter. I also checked to see that the data in the column was trimmed, and it was.

EDIT: OK, I've backed the COM object as far back as the object I created on 04/22/08. Still the same result. I've also found out that if I use WHERE Name LIKE 'xxxx%', it will find the row.

EDIT: OK, it is obviously my error. I re-ran the table create with a %trim() for the Name field and now the table queries work correctly.
It is peculiar, though, that length(Name) returns the correct length, that is it does not return the length including the offending blanks, though they are obviously there, else the query would not have failed.

EDIT: Another problem now. When I read the data
Code:

$rec = @comsql.Execute("SELECT * FROM [Data Master] WHERE Name = ?",%trim(%1))

If I do
Code:

$name = %db($rec,Name)

or
Code:

$name = $rec.Name

Name gets set to the entire record fetched. This is the case whether CMUDFormat is set to 0 or 1.

EDIT: Problem solved. I forced CMUDFormat to True in the object.
_________________
Sic itur ad astra.
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Wed May 07, 2008 2:06 am   
 
That is peculiar, I wonder if it's a bug in sqlite or known limitation?
Quote:
Problem solved. I forced CMUDFormat to True in the object.

That's not really a solution CMUDFormat works for me and nobody else has said it didn't work.
There's no reason why comsql.CMUDFormat = 1 or comsql.CMUDFormat= True should behave any differently than manually editing the COM object.
It's just a simple method that calls the Python function bool on whatever is assigned to it.
It really would be best if you left the source as is and tried to figure out why what you're doing isn't working, rather than just duct taping it over.
As I told Xekon, when you do that we're not using the same object anymore and I at least have no desire to troubleshoot an Object I don't have reliably info on.
If there's something really wrong with the object then thats something I should fix, if not then there's something wrong with the way you're using it and thats something you should fix

Segue:
I looked at the sqlite source and these are (some of?) the functions that I found are available.
most of them are pretty obvious the rest I'm sure can be googled.
Code:
min
max
typeof
length
substr
abs
round
upper
lower
coalesce
hex
ifnull
random
randomblob
nullif
sqlite_version
quote
last_insert_rowid
changes
total_changes
replace
ltrim
rtrim
trim
zeroblob
#These below are aggregates
min
max
sum
total
avg
count
group_concat


I also added REGEXP and STDDEV
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."

Last edited by Dharkael on Wed May 07, 2008 2:17 am; edited 1 time in total
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Wed May 07, 2008 2:16 am   
 
Well, I've found that using column names that are "reserved" as per the list you provided, and others, will cause the Create Table to fail. I notice that trim(), ltrim(), rtrim() are available functions. I Didn't see that in the documentation here. I've used max(length()) with success.
_________________
Sic itur ad astra.
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Wed May 07, 2008 2:20 am   
 
Well when in doubt go to the source but that's a good little resource.
In the case of "reserved" words use quotes "" or brackets [] as in create table sometable ([trim] text,[rtrim] integer)
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Wed May 07, 2008 2:26 am   
 
Quote:
There's no reason why comsql.CMUDFormat = 1 or comsql.CMUDFormat= True should behave any differently than manually editing the COM object.

I don't doubt you, Dharkael. It just that never get it to work. So I edit the source. When I just reloaded the object, I tried setting the property the way you stated and the problem persisted. When I went into the source and forced the property to true, and again re-registered the object, the problem went away.
_________________
Sic itur ad astra.
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Wed May 07, 2008 2:37 am   
 
I'm sure thats quick and easy but thats ignoring the root cause and no solution at all for the reasons stated above.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: Wed May 07, 2008 7:53 am   
 
w00ts, this is working perfect for me:

Code:
#IF ((@mobdb.Execute("SELECT COUNT(roomdesc) AS Count FROM mobdb WHERE roomdesc=?",%1).Count) < 1) {
#SUB {%ansi(brown)%1 <send 'addmobdb %replace(%1,"'","%char(39)")'>%ansi(high,red)"ADD"</send>}
}


and yeah, I use (without any issues):

Code:
mobdb.CMUDFormat=1


One thing that I was uncertain of is weather or not Indexes were something I would have to use as in part of the SQL statement or not, I didnt realize that they simply need to be there to get the benefit from them.
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Wed May 07, 2008 8:16 am   
 
OK, I have fixed the problem. I was just setting the value improperly. I was treating it as a function and not as a value.
_________________
Sic itur ad astra.
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Thu May 08, 2008 1:32 am   
 
Here is something new I've discovered:
I created a view as follows:
Code:

CREATE VIEW [Enabled Portals Anaristos] AS SELECT [Portals Anaristos].* FROM [Portals Anaristos], CharacterData WHERE Enabled = 1 AND PortalLevel <= (10 * CurTier + CurLevel)

Now the view is created successfully. The problem is with the query. The query against both the view and the underlying table are successful, but the fetching of individual columns breaks down for the view. Not in Sqlite Expert, but in the CMUD code.
If I query the underlying table as follows:
Code:

$rec = @comsql.Execute("SELECT [Portals Anaristos].Entrypoint, [Portals Anaristos].KeyWord FROM [Portals Anaristos], Areas WHERE [Portals Anaristos].ZoneID = Areas.ZoneID AND Areas.Area LIKE ? AND [Portals Anaristos].Enabled = ?", %concat("%", "talsa", "%"),  1)

it returns
Code:

rec = EntryPointInside Toran RuinsKeyWordevil
rec = EntryPoinOpen FieldKeyWordirresistible

If I query the view in a similar fashion:
Code:

$rec = @comsql.Execute("SELECT [Enabled Portals Anaristos].Entrypoint, [Enabled Portals Anaristos].KeyWord FROM [Enabled Portals Anaristos], Areas WHERE [Enabled Portals Anaristos].ZoneID = Areas.ZoneID AND Areas.Area LIKE ? ", %concat("%", "talsa", "%"))

it returns
Code:

rec = Portals Anaristos.EntryPointInside Toran RuinsPortals Anaristos.KeyWordevil
rec = Portals Anaristos.EntryPointOpen FieldPortals Anaristos.KeyWordirresistible

Both outputs are identical except for the fact that the view output has the underlying table name prefixed to each column.
When I extract the key from the underlying table query as follows:
Code:

....
$kw = %db(%i, KeyWord)

$kw will contain evil and irresistible as expected. But doing the same thing for the view query returns null.

NOTE: The key/value separators are unprintable so I edited them out.

EDIT: I think the problem is that the prefix contains a blank. It should be encoded in such a way that the prefix is a single string.
_________________
Sic itur ad astra.
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Thu May 08, 2008 2:21 am   
 
I'm not sure what the issue is?

Anaristos wrote:
Both outputs are identical except for the fact that the view output has the underlying table name prefixed to each column.

So you're aware that the key is prefixed with the table name for the view output
so when
Code:
%db(%i, KeyWord)
is ran on the view output of course it finds nothing.
There is no KeyWord key,there is however a Portals Anaristos.KeyWord key.
Code:
%db(%i,"Portals Anaristos.KeyWord")

Is what you should be looking for.
If the sql statement you issue in SQLite Expert is EXACTLY the same as that issued in CMUD then if you check the column names of the returned data
you will see the same changes with regards to column names.
Since you don't show what query you use against the VIEW you'll have to work this out yourself, but you can always use SELECT ... AS ... to rename the columns returned
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » Finished MUD Scripts All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next
Page 7 of 8

 
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