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
Dharkael Posted: Thu Apr 03, 2008 10:09 am
Python Sqlite COM Component for ZMUD/CMUD
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Thu May 08, 2008 3:00 am   
 
Yes, it makes sense and I should have known since that is the way I fetch values when I use functions, though I don't enclose the key name in quotes in that situation. It concerns me, though, that this seems inconsistent because the query against the underlying table returns an unqualified column value. That means that the processing script has to be aware that the data came from a view and not a real table.

NOTE: I did include the query against both the view and the table in my post.
_________________
Sic itur ad astra.
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Thu May 08, 2008 3:32 am   
 
Anaristos wrote:
NOTE: I did include the query against both the view and the table in my post.

So you did... here you go
Code:
$rec = @comsql.Execute("SELECT [Enabled Portals Anaristos].Entrypoint AS [Entrypoint], [Enabled Portals Anaristos].KeyWord AS [KeyWord] FROM [Enabled Portals Anaristos], Areas WHERE [Enabled Portals Anaristos].ZoneID = Areas.ZoneID AND Areas.Area LIKE ? ", %concat("%", "talsa", "%"))


Strictly speaking the AS and the square brackets[] aren't necessary here for the new column names.
I think it's a good idea to always include the AS because it makes it clear you're renaming the column.
In this case the new column names aren't reserved words and contain no characters that require the brackets or double quotes,
but sometime they might, and this is how you get around that.
Now that I think about it you could also recreate the view and rename the columns there, since [Portals Anaristos] is the original table name and not that of the view.
You would have to get rid of the [Portals Anaristos].* and explicitly request each column renaming where necessary (ie if the same column name exist in both [Portals Anaristos] and CharacterData).
_________________
-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: Thu May 08, 2008 3:39 am   
 
I understand your idea and I will use it. There is no confict between those two tables. The qualification in the WHERE clause is due to a collision between Portals Anaristos and Areas. Thanks for your help. I am still learning SQL.
_________________
Sic itur ad astra.
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Fri May 09, 2008 8:08 am   
 
I installed CMUD 2.25, one problem I have run into is that the COM variable that I use keeps getting stale. For one thing, under 2.18 I was using the OnLoad event to create the object, and that would last me the entire session unless there was a catastrophic error on the Python side, in which case Phtyon would close the connection. But under 2.25, I have to continuously keep issuing %comcreate.
_________________
Sic itur ad astra.
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Fri May 09, 2008 11:34 am   
 
We keep revisiting old issues.
about 3 weeks ago you said you were having the same issue, then you said nothing at all.
COM objects don't go stale they remain fresh as the day they were bakedRazz .

You say you have to keep using %comcreate, what gives you that ideaQuestion
Do some troubleshooting isolate when and how it stops working and If you can't resolve the issue
then create a test case in an empty session, if you can demonstrate with that, then paste the code you're using
without modification and I'll see if I can spot the problem.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Fri May 09, 2008 8:58 pm   
 
I manually created a connection and filled it with data from the Testwarrior script you previously gave.
Left it all day then came back and ran the alias again without creating another connection, no problems.
_________________
-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: Fri May 09, 2008 10:53 pm   
 
OK, let me qualify my statement about the COM object. It is not stale in the sense that it is not representing a connection. When I do
Code:
#ECHO @comsql.IsOpen()
it returns True.
The problem is that scripts that access the database, stop getting/putting data. When I re-create the object and re-open the database file, everything starts working again. You are right, this was happening about 3 weeks ago and then it basically went away. Though, during that period I had to change a memory table to a database table, because of this problem recurring intermittently with the :memory: database. I use the OnLoad event to establish the connection so that the tables are available even if I am working offline. Under 2.25 I have been getting some OLE errors and this could very well be what is breaking the connection and CMUD would not know that Python has stopped listening. There are times when Python won't complain if it finds an error, so not getting an error box is not a guarantee that everything is fine.
_________________
Sic itur ad astra.
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Fri May 09, 2008 11:02 pm   
 
What are the OLE errors? when do you get them?
Do you have a procedure to demonstrate?
Without these things I can't be of any assistance
_________________
-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 11, 2008 9:02 am   
 
Ive been running smoothly for a few days it seems now. :)

I started to convert what I've written from cmud back over to zmud for some friends.

Dharkael the code snippet you wrote for me works wonderfully in cmud but I dont understand what i should change for zmud:

#if ((@mobdb.Execute("SELECT COUNT(roomdesc) AS Count FROM mobdb WHERE roomdesc=?",%1).Count) < 1) {#show "its true so do something"}

the output i get from this in cmud is an integer and in my case either a 0 or 1, so it works

however in zmud instead of a 0 or 1 im getting (Count1)
Reply with quote
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: Sun May 11, 2008 9:04 am   
 
Let me know if what I need to change is not obvious, and I will post a workable example for zmud.
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

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



In ZMUD you have to use %item on the result to select the first item explicitly, also instead of using (result).Key you have to do %db(result,Key)
All together %db(%item(result,1),Key)
_________________
-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: Sun May 11, 2008 7:52 pm   
 
OK, Dharkael, now that we know why my COM object stopped working, I can get to mention the problem that gets me the Python/OLE error. This one is no big deal but after I saw your code snippet above, it makes me wonder.
You used:
Code:

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

In this code you have the SELECT statement embedded in a CMUD function, so obviously this works for you. It has never worked for me. I ran a test so that I could get the specific Python error and here is the code and the error:
Code:

#IF (%bitand( %db( @comsql.Execute("Select Flags FROM CharacterData WHERE Name = ?", @Username), Flags), 1)) {#ECHO User is Active.} {#ECHO Yo, Fool. You blew it!}


Python says to this: Traceback (most recent call last): TypeError: Execute() takes at least 1 argument (0 given)
Followed by the OLE error 80020101.

I don't know what I am doing wrong, I spent a while trying to figure it out and finally gave up and loaded a variable with the SELECT output instead, which works, but I a am a nut for minimalism, so I would really like to get this to work.

Just so you understand that the level of embedding is not the problem, I re-ran the above like this:
Code:

#IF ( %db( @comsql.Execute("Select Flags FROM CharacterData WHERE Name = ?", @Username), Flags)) {#ECHO User is Active.} {#ECHO Yo, Fool. You blew it!}

with the same result.
_________________
Sic itur ad astra.
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Sun May 11, 2008 8:48 pm   
 
Anaristos wrote:
In this code you have the SELECT statement embedded in a CMUD function

For clarity's sake, I'll just say that that's not a CMUD function he's calling there, it's a method of the COM object. They're different things.
_________________
Rorso's syntax colouriser.

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


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Sun May 11, 2008 8:53 pm   
 
I know what you mean Anaristos thats a CMUD problem.
The script I gave to Xekon was meant for ZMUD.

It's not something specific to my COM object either, In CMUD 2.18 It just gave an error that you could recover from if I remember correctly(I foolishly did not save a copy of 2.18),
now in CMUD 2.25 it locks up and I have to Force Quit the CMUD process.
Here's an example using another COM object
Code:
#var dict %comcreate( "Scripting.Dictionary")
#call @dict.Add("A","Count=1")
#echo 1 @dict.Item("A")
#echo 2 %item( @dict.Item("A"), 1)


That will run correctly in ZMUD.
In CMUD if you don't comment out the last line, it will lock up.
COM is definitely a little messed up in CMUD


EDIT:
I apparently did have a copy of CMUD 2.18 in my temp folders and I just tested and confirmed
In 2.18 the script above would return an invalid number of parameters error (Which is still a CMUD bug)
However it did not cause a lockup.
Which is equiv to the error
" TypeError: Execute() takes at least 1 argument (0 given) Followed by the OLE error 80020101. "


P.P.S.
Fang's right of course but I understood what he was trying to say: the function is being called from CMUD rather than embedded in the SQLite Engine
_________________
-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: Sun May 11, 2008 9:19 pm   
 
OK, thanks Dharkael. I guess I am not going crazy after all.
If you have time, would you consider adding a SetPath() function to the API? This would set up an implicit path if none were given. I suppose that calling the method without a parameter would just return the current default path. Just an idea.

EDIT:
That's a tough technicality, Fang. Semantically, object methods are as functions since they are forced to return something even if it's a Void. Black-hole methods are not OOP-sanctioned, though I am sure there is a truckload of them out there. Of course when I said SELECT, I referred to the object of the method, and not the method itself, because I felt this was an unambiguous nuance. Wink
_________________
Sic itur ad astra.
Reply with quote
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: Fri May 16, 2008 10:57 am   
 
Regex Trigger: mobs without auras...
Code:
^(.*)([.?!'a-z?])$


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


As you can see I have %replace for quotes, semicolons, and single quotes.... all of these replaces work great in cmud, but only the semicolon and single quote replace work in zmud... in zmud the quotes are getting still getting stripped before finding their way to the DB....

so instead of storing (works in cmud just not zmud):

A Whitecloak screams "DARKFRIEND!!!" and attacks!

it stores:

A Whitecloak screams DARKFRIEND!!! and attacks!
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Fri May 16, 2008 9:16 pm   
 
I think I need to see more to help Xekon
Because using the pattern and the code above in a trigger I had no problems inserting
A Whitecloak screams "DARKFRIEND!!!" and attacks!
Of course I can't see what you're doing in your addmobdb alias
Mine looks like this.

Code:

#ALIAS addmobdb {
  #call @comsql.Execute("INSERT INTO TBL VALUES(?)",%0) 
  }
_________________
-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 18, 2008 5:08 am   
 
Sometimes its the easy stuff that escapes us for whatever reason... I should have checked my code better, the problem was being so used to and comfortable with cmud.

I had:
Code:

addmob=%-1
#addkey mobitem roomdesc @addmob


should of had it with quotes:
Code:

addmob="%-1"
#addkey mobitem roomdesc @addmob
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Thu Jun 19, 2008 2:26 am   
 
Dharkael, I've noticed that code like this is not working and I was under the impression that it was fixed
Code:

....
#IF (@comsql.isOpen()) {do something}
....
#IF (!@comsql.isOpen()) {do something}
....
#IF (@comsql.LastError()) {do something}
....
#IF (!@comsql.LastError()) {do something}
...
_________________
Sic itur ad astra.
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Thu Jun 19, 2008 1:39 pm   
 
Those are properties.
Try calling them without the parens à la:

Code:
#IF (!@comsql.IsOpen) {do something}
....
#IF (@comsql.LastError) {do something}
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
frasten
Beginner


Joined: 06 Jan 2006
Posts: 24

PostPosted: Sun Dec 14, 2008 3:39 am   
 
I have some issues when I select some records whose data contain carriage returns: they are split into different records.
I need that, because I'm connecting to the mapper db.

I think that the problem is in the join process in GetData().
I'm using CMUD, and I set
Code:
dbmapper.cmudFormat=1
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Wed Feb 04, 2009 2:56 am   
 
It seems that when one uses an array to pass binding paramters to SQL, the array must be explicitly declared in the EXEC statement. It falis for me when I insert an array variable instead.
Code:

$sql = "SELECT * FROM [mob data] WHERE [name] = ? AND [zone] = ? AND [room] = ?"
;;
$rec = @commob.Execute($sql, %array( "Rammi", "Grand City of Aylor", 35))
;;
#IF (!%null( $rec)) {
  #ECHO %crlf
  #ECHO <color yellow>mob = %db( $rec, name) - zone = %db( $rec, zone) - room = %db( $rec, room)</color>
  } {#ECHO ERROR is @commob.LastError()}

Works just fine, but:
Code:

$sql = "SELECT * FROM [mob data] WHERE [name] = ? AND [zone] = ? AND [room] = ?"
;;
#VAR darray %array( "Rammi", "Grand City of Aylor", 35)
;;
$rec = @commob.Execute($sql, @darray)
;;
#IF (!%null( $rec)) {
  #ECHO %crlf
  #ECHO <color yellow>mob = %db( $rec, name) - zone = %db( $rec, zone) - room = %db( $rec, room)</color>
  } {#ECHO ERROR is @commob.LastError()}

returns the following error: Incorrect number of bindings supplied. The current statement uses 3, and there are 0 supplied.
;;
If this is not a bug, the IMO, the use of arrays for binding is rather more work than just plugging in the values such as:
Code:

....
....
$rec = @commob.Execute($sql, "Rammi", "Grand City of Aylor", 35)
....
....
_________________
Sic itur ad astra.
Reply with quote
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: Thu Apr 16, 2009 5:01 am   Not sure if anyone is still monitoring this, but I just installed Windows 7 help
 
Windows 7 and activepython, com object worked under xp with activepython 2.5.4.3

Under windows XP I installed activepython 2.5.4.3 and registered my com object (where you right click on the file and select register).

Since then I have decided to try out Windows 7 beta (build 7077), and I knew going in that there would be things to work out, remarkable all my driver and applications are working so far with the exception of this python com object. If anyone can give any help I would greatly appreciate it. I have included as much detail of the problem as I can think of
First I get a popup that says:

Code:
Unknown error:Python


then another error popup that says:

Code:
The module "C:\Windows\system32\scrobj.dll" was loaded but the call to dllInstall failed with error code 0x80020101.

For more information about this problem, search online using the error code as a search term.


Reply with quote
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: Fri Apr 17, 2009 8:29 am   actually dont worry about it
 
instead of trying to get the com object to work I stumbled across this post: http://forums.zuggsoft.com/forums/viewtopic.php?t=31518

and I am now in the process of rewriting my eqdb script with lua
Reply with quote
AlexanderTheGreat
Newbie


Joined: 28 Sep 2009
Posts: 2

PostPosted: Tue Sep 29, 2009 3:48 am   
 
I'm getting the same errors as Xekon and have tried everything to get the file to work. I have all the correct privileges, using vista.
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
Page 8 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