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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
eupher
Apprentice


Joined: 18 Jan 2001
Posts: 116
Location: USA

PostPosted: Mon Apr 25, 2011 4:46 pm   

sqlite field not updating using $row.Item("fieldname") = <new value>
 
CMUD 3.34

I have the following code in an event:

Code:
$query = %concat("SELECT * FROM Items WHERE name LIKE '%",%replace($name,"'","''"),"'")
$row = %sql(mydb, $query)
#IF ($row.RecordCount() = 1) {
  $itemID = $row.Item("itemID")
  $query = %concat("SELECT * from ItemShops WHERE itemID = '",$itemID,
            "' AND shop = '",@location,"'")
  $row = %sql(mydb,$query)
  #IF ($row.RecordCount() = 0) {
    #CALL $row.Insert()
    $row.Item("itemID") = $itemID
    $row.Item("shop") = @location
    $row.Item("lowPrice") = $price
    $row.Item("highPrice") = $price
    #CALL $row.Post()
    } {
    #IF ($row.Item("lowPrice") > $price) {
      #MESSAGE 30 %concat("New mark-down from ",$row.Item("lowPrice")," to ",$price,"!")
      $row.Item("lowPrice") = $price
      #MESSAGE 30 %concat("New price: ",$row.Item("lowPrice"))
      }
    #IF ($row.Item("highPrice") < $price) {
      $row.Item("highPrice") = $price
      }
    }
  }


The insert branch works fine. However, if the record already exists, the update branch does not update the value in the database even though the #MESSAGEs say exactly what you would expect.
For example:
Quote:
New mark-down from 170 to 100!
New price: 100


It's probably just another stupid mistake I'm making... but if anyone sees what the problem might be... I'd appreciate the help. Smile
Reply with quote
eupher
Apprentice


Joined: 18 Jan 2001
Posts: 116
Location: USA

PostPosted: Mon Apr 25, 2011 4:53 pm   
 
I just changed

Code:
$row.Item("lowPrice") = $price

to

Code:
#CALL $row.Edit()
$row.Item("lowPrice") = $price
#CALL $row.Post()

and now it works. I haven't needed to do this in other cases... not sure what the difference is here. I thought the calls to Edit() and Post() where done automatically when using this syntax?
Reply with quote
eupher
Apprentice


Joined: 18 Jan 2001
Posts: 116
Location: USA

PostPosted: Mon Apr 25, 2011 8:14 pm   
 
Well.. it sort of works. Most of the time it is fine... but from time to time I now get this message in a pop-up "OK" box:

Quote:
2 record(s) updated. Only one record should have been updated

Ideas?
Reply with quote
Zugg
MASTER


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

PostPosted: Tue Apr 26, 2011 4:51 pm   
 
I haven't seen this problem before. Since you are already checking the RecordCount, I'm not sure how this could ever happen. You might need to run the Script Debugger to see exactly which trigger/script is running when you get that message. Maybe you have another script that is also using the database, or maybe your script shown above is getting executed more than once at the same time.

For example, if you have multiple threads then maybe the event above is running more than once?
Reply with quote
eupher
Apprentice


Joined: 18 Jan 2001
Posts: 116
Location: USA

PostPosted: Wed Apr 27, 2011 3:44 am   
 
I'll try the script debugger, but it doesn't happen that often. And I'm not accessing the db from outside of CMUD... and am not (intentionally) using threads. Is it possible for things to get "executed more than once at the same time" without intentionally creating separate threads?

I still wonder if it's tied to my original problem. Shouldn't the {$row.Item("lowPrice") = $price} command have taken care of edit() and post()? It just wasn't updating the database. Now I wonder if it *was* but only rarely, and now those rare occasions are what's causing the "2 records" error since I've wrapped the command in calls to edit() and post(). Or maybe that makes no sense. Smile


Thanks again.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Wed Apr 27, 2011 4:03 am   
 
Quote:

Is it possible for things to get "executed more than once at the same time" without intentionally creating separate threads?


Yes. CMud is a threading-capable application, so in addition to user commands like #WAIT and #WAITFOR that specifically and explicitly call for the creation of new threads there are also various things that CMud will automatically create new threads for even if you are not particularly using or expecting to use threads (user-defined functions seem to be one such case).
_________________
EDIT: I didn't like my old signature
Reply with quote
eupher
Apprentice


Joined: 18 Jan 2001
Posts: 116
Location: USA

PostPosted: Wed Apr 27, 2011 12:23 pm   
 
Ok, I captured what was going on in the script debugger at the point in time when I got the "2 record(s) updated" error. I'm probably missing something, but it looks right to me. This happens when I check a shop's inventory. I have triggers to check if each item is in my sqlite3 db. For each item that is in the db, I update the item's highPrice or lowPrice fields if the current sale price is higher or lower than the existing values.

Here's the debugger output:

Quote:
0.0013 | a TheFores |Item Price Weight Level Number Condition
0.0016 | a TheFores |---- ----- ------ ----- ------ ---------
0.0013 | f TheFores | Pattern: ^Item Price Weight Level ...
0.0012 | c TheFores | exec : Pattern "FINDMISSINGPURCHASE" : #TEMP {$} {#T- FINDMISSIN...
0.0006 | n TheFores | Exec Trigger "FINDMISSINGPURCHASE"
0.0064 | a TheFores |an enchanted scroll of identify 2181 0.30 1 8 perfect
0.0018 | f TheFores | Pattern: ^([^\d]+)\s+(\d+)\s+\d+\.\d{2}\s+[\d\*]+\s+\d+\s : (%1="an enchanted scroll of identify ", %2=2181)
0.0011 | c TheFores | exec : Pattern "FINDMISSINGPURCHASESHORT" : $name = @stripCondit...
0.0005 | n TheFores | Exec Trigger "FINDMISSINGPURCHASESHORT"
0.0006 | n TheFores | Exec Func "stripConditions"
0.0010 | n TheFores | Exec Func "itemExists"
0.0080 | m TheFores | Event "onShopInventory" raised : (%1="scroll of identify", %2=2181)
0.0006 | c TheFores | exec : Event "onShopInventory" : $query = %concat("SELECT * FROM...
0.0006 | n TheFores | Exec Event "onShopInventory"
0.0093 | a TheFores |An enchanted scroll of detect good
0.0011 | f TheFores | Pattern: ^([^\d]+)$ : (%1="An enchanted scroll of detect good")
0.0010 | c TheFores | exec : Pattern "FINDMISSINGPURCHASELONG" : $name = @stripConditi...
0.0007 | n TheFores | Exec Trigger "FINDMISSINGPURCHASELONG"
0.0003 | n TheFores | Exec Func "stripConditions"
0.0005 | n TheFores | Exec Func "itemExists"
0.0039 | k TheFores | Var "current_item" changed from "pair of studded leather sleeves" to "scroll of detect good"
0.0065 | a TheFores | 857 0.10 1 4 perfect
0.0007 | f TheFores | Pattern: ^([^\d]+)\s+(\d+)\s+\d+\.\d{2}\s+[\d\*]+\s+\d+\s : (%1=" ", %2=857)
0.0006 | c TheFores | exec : Pattern "FINDMISSINGPURCHASESHORT" : $name = @stripCondit...
0.0003 | n TheFores | Exec Trigger "FINDMISSINGPURCHASESHORT"
0.0003 | n TheFores | Exec Func "stripConditions"
0.0005 | n TheFores | Exec Func "itemExists"
0.0302 | m TheFores | Event "onShopInventory" raised : (%1="", %2=857)
0.0003 | c TheFores | exec : Event "onShopInventory" : $query = %concat("SELECT * FROM...
0.0003 | n TheFores | Exec Event "onShopInventory"
0.0301 | f TheFores | Pattern: ^\s+(\d+)\s+\d+\.\d{2}\s+[\d\*]+\s+\d+\s : (%1=857)
0.0006 | c TheFores | exec : Pattern "^\s+(\d+)\s+\d+\.\d{2}\s+[\d\*]+\s+\d+\s" : #RAI...
0.0003 | n TheFores | Exec Trigger "^\s+(\d+)\s+\d+\.\d{2}\s+[\d\*]+\s+\d+\s"
0.0003 | m TheFores | Event "onShopInventory" raised : (%1="scroll of detect good", %2=857)
0.0003 | c TheFores | exec : Event "onShopInventory" : $query = %concat("SELECT * FROM...
0.0003 | n TheFores | Exec Event "onShopInventory"
0.0048 | a TheFores |An enchanted scroll of magic missile
0.0006 | f TheFores | Pattern: ^([^\d]+)$ : (%1="An enchanted scroll of magic missile")
0.0005 | c TheFores | exec : Pattern "FINDMISSINGPURCHASELONG" : $name = @stripConditi...
0.0003 | n TheFores | Exec Trigger "FINDMISSINGPURCHASELONG"
0.0003 | n TheFores | Exec Func "stripConditions"
0.0005 | n TheFores | Exec Func "itemExists"
0.0039 | k TheFores | Var "current_item" changed from "scroll of detect good" to "scroll of magic missile"
0.0005 | a TheFores | 133 0.20 5 6 perfect
0.0007 | f TheFores | Pattern: ^([^\d]+)\s+(\d+)\s+\d+\.\d{2}\s+[\d\*]+\s+\d+\s : (%1=" ", %2=133)
0.0005 | c TheFores | exec : Pattern "FINDMISSINGPURCHASESHORT" : $name = @stripCondit...
0.0003 | n TheFores | Exec Trigger "FINDMISSINGPURCHASESHORT"
0.0003 | n TheFores | Exec Func "stripConditions"
0.0005 | n TheFores | Exec Func "itemExists"
0.0301 | m TheFores | Event "onShopInventory" raised : (%1="", %2=133)
0.0003 | c TheFores | exec : Event "onShopInventory" : $query = %concat("SELECT * FROM...
0.0003 | n TheFores | Exec Event "onShopInventory"
0.0300 | f TheFores | Pattern: ^\s+(\d+)\s+\d+\.\d{2}\s+[\d\*]+\s+\d+\s : (%1=133)
0.0006 | c TheFores | exec : Pattern "^\s+(\d+)\s+\d+\.\d{2}\s+[\d\*]+\s+\d+\s" : #RAI...
0.0003 | n TheFores | Exec Trigger "^\s+(\d+)\s+\d+\.\d{2}\s+[\d\*]+\s+\d+\s"
0.0003 | m TheFores | Event "onShopInventory" raised : (%1="scroll of magic missile", %2=133)
0.0003 | c TheFores | exec : Event "onShopInventory" : $query = %concat("SELECT * FROM...
0.0003 | n TheFores | Exec Event "onShopInventory"
0.0048 | a TheFores |an enchanted scroll of amnesia 17142 0.20 1 4 perfect
0.0008 | f TheFores | Pattern: ^([^\d]+)\s+(\d+)\s+\d+\.\d{2}\s+[\d\*]+\s+\d+\s : (%1="an enchanted scroll of amnesia ", %2=17142)
0.0005 | c TheFores | exec : Pattern "FINDMISSINGPURCHASESHORT" : $name = @stripCondit...
0.0002 | n TheFores | Exec Trigger "FINDMISSINGPURCHASESHORT"
0.0003 | n TheFores | Exec Func "stripConditions"
0.0005 | n TheFores | Exec Func "itemExists"
0.0039 | m TheFores | Event "onShopInventory" raised : (%1="scroll of amnesia", %2=17142)
0.0003 | c TheFores | exec : Event "onShopInventory" : $query = %concat("SELECT * FROM...
0.0003 | n TheFores | Exec Event "onShopInventory"
7.8688 | a TheFores |An enchanted scroll of detect evil
0.0013 | f TheFores | Pattern: ^([^\d]+)$ : (%1="An enchanted scroll of detect evil")
0.0010 | c TheFores | exec : Pattern "FINDMISSINGPURCHASELONG" : $name = @stripConditi...
0.0006 | n TheFores | Exec Trigger "FINDMISSINGPURCHASELONG"
0.0006 | n TheFores | Exec Func "stripConditions"
0.0010 | n TheFores | Exec Func "itemExists"
0.0078 | k TheFores | Var "current_item" changed from "scroll of magic missile" to "scroll of detect evil"
0.0009 | a TheFores | 857 0.10 1 4 perfect
0.0014 | f TheFores | Pattern: ^([^\d]+)\s+(\d+)\s+\d+\.\d{2}\s+[\d\*]+\s+\d+\s : (%1=" ", %2=857)
0.0011 | c TheFores | exec : Pattern "FINDMISSINGPURCHASESHORT" : $name = @stripCondit...
0.0005 | n TheFores | Exec Trigger "FINDMISSINGPURCHASESHORT"
0.0006 | n TheFores | Exec Func "stripConditions"
0.0010 | n TheFores | Exec Func "itemExists"
0.0350 | m TheFores | Event "onShopInventory" raised : (%1="", %2=857)
0.0003 | c TheFores | exec : Event "onShopInventory" : $query = %concat("SELECT * FROM...
0.0003 | n TheFores | Exec Event "onShopInventory"
0.0299 | f TheFores | Pattern: ^\s+(\d+)\s+\d+\.\d{2}\s+[\d\*]+\s+\d+\s : (%1=857)
0.0006 | c TheFores | exec : Pattern "^\s+(\d+)\s+\d+\.\d{2}\s+[\d\*]+\s+\d+\s" : #RAI...
0.0003 | n TheFores | Exec Trigger "^\s+(\d+)\s+\d+\.\d{2}\s+[\d\*]+\s+\d+\s"
0.0003 | m TheFores | Event "onShopInventory" raised : (%1="scroll of detect evil", %2=857)
0.0003 | c TheFores | exec : Event "onShopInventory" : $query = %concat("SELECT * FROM...
0.0003 | n TheFores | Exec Event "onShopInventory"
0.0105 | a TheFores |
0.0005 | f TheFores | Pattern: $
0.0006 | c TheFores | exec : Pattern "$" : #T- FINDMISSINGPURCHASESHORT;#T- FINDMISSIN...
0.0003 | n TheFores | Exec Trigger "$"
0.0031 | a TheFores |<SB 622/622h 1002/1002m 187/197v (-v) |Ns| Group: 187v 622h L:622/622h | ->


I'll put the associated script settings in the next post...
Reply with quote
eupher
Apprentice


Joined: 18 Jan 2001
Posts: 116
Location: USA

PostPosted: Wed Apr 27, 2011 12:29 pm   
 
Code:
<trigger name="FINDMISSINGPURCHASE" priority="28230" case="true" stop="true" id="19">
  <pattern>^Item                               Price  Weight  Level  Number  Condition$----                               -----  ------  -----  ------  ---------$</pattern>
  <value>#TEMP {$} {#T- FINDMISSINGPURCHASESHORT;#T- FINDMISSINGPURCHASELONG}
#T+ FINDMISSINGPURCHASESHORT
#T+ FINDMISSINGPURCHASELONG</value>
</trigger>


Code:
<trigger name="FINDMISSINGPURCHASELONG" priority="28250" case="true" regex="true" enabled="false" id="21">
  <pattern>^([^\d]+)$</pattern>
  <value>$name = @stripConditions(%1)
#IF (! @itemExists($name,1,0)) {#PCOL yellow %x1}
current_item = $name</value>
  <trigger param="1" case="true" regex="true">
    <pattern>^\s+(\d+)\s+\d+\.\d{2}\s+[\d\*]+\s+\d+\s</pattern>
    <value>#RAISE onShopInventory @current_item %1</value>
  </trigger>
</trigger>


Code:
<trigger name="FINDMISSINGPURCHASESHORT" priority="28240" case="true" regex="true" enabled="false" id="20">
  <pattern>^([^\d]+)\s+(\d+)\s+\d+\.\d{2}\s+[\d\*]+\s+\d+\s</pattern>
  <value>$name = @stripConditions(%1)
#IF (! @itemExists($name,1,0)) {#PCOL yellow %x1}
#RAISE onShopInventory $name %2
</value>
</trigger>


Code:
<func name="itemExists" id="6">
  <value>#IF %regex($name,"^\d") {#RETURN 1}
#IF %regex($name,"\bwaterskin\b") {#RETURN 1}
#IF %regex($name,"\bpure white rose\b") {#RETURN 1}
#IF %regex($name,"\b(red|indigo|green|white|purple) ball of light\b") {#RETURN 1}
#IF %regex($name,"\bring of vine vanquishing\b") {#RETURN 1}
$query = %concat( "SELECT * FROM Items WHERE name LIKE '",
          %if($openLeft,"%"), %replace( $name, "'", "''"),
          %if($openRight,"%"),"'")
$row = %sql( tfe_items, $query)
#IF ($row.RecordCount()) {
  #RETURN $row.RecordCount()
  } {
  $query = %concat( "SELECT * FROM Items WHERE alias LIKE '",
          %if($openLeft,"%"), %replace( $name, "'", "''"),
          %if($openRight,"%"),"'")
  $row = %sql( tfe_items, $query)
  #RETURN $row.RecordCount()
  }</value>
  <arglist>$name, $openLeft, $openRight</arglist>
</func>


Code:
<func name="stripConditions" id="25">
  <value>$name = %trim($name)
$name = %subregex($name," labeled .+$","")
#IF (%regex($name,"\bpoet shirts? ")) {#RETURN "poet shirt"}
$name = %subregex($name," [\-\+]\d+$","")
$proper_name = ""
#IF (%regex($name,"^\d+ ","")) {
  $name = %subregex($name,"^\d+ ","")
  $name = %subregex($name,"^(.+ of .+) of (.+)$","\1 2ndof \2")
  $name=%subregex($name," staves\b"," staff")
  $name=%subregex($name," mitres"," mitre")
  $name=%subregex($name,"\bteeth\b","tooth")
  $name=%subregex($name,"s\' ","'s ")
  #IF (%regex($name," \'.+\'$")) {
    $proper_name=%subregex($name,"^.+ (\'.+\')$","\1")
    $name=%subregex($name,"^(.+) \'.+\'$","\1")
    }
  #SWITCH (%regex($name,"rses (of|with) ")) {$name=%subregex($name,"rses (of|with) ","rse \1")}
    (%regex($name,"\bpair of ")) {}
    (%regex($name,"[^aeiou]{2}es (of|with) ")) {$name=%subregex($name,"([^aeiou]{2})es (of|with) ","\1 \2 ")}
    (%regex($name,"s (of|with) ")) {$name=%subregex($name,"s (of|with) "," \1 ")}
    (%regex($name,"\bknives\b")) {$name=%subregex($name,"\bknives\b","knife")}
    (%regex($name,"\bfeet\b")) {$name=%subregex($name,"\bfeet\b","foot")}
    (%regex($name,"rses\b")) {$name=%subregex($name,"rses\b","rse")}
    (%regex($name,"[^aeiou]{2}es$")) {$name=%subregex($name,"([^aeiou]{2})es$","\1")}
    (%regex($name,"s$")) {$name=%subregex($name,"s$","")}
  $name = %subregex($name," 2ndof "," of ")
  #IF ($proper_name) {
    $name = %concat($name," ",$proper_name)
  }
}
$name = %subregex($name,"^(\+evil\+|\+good\+) ","")
$name = %subregex($name,"^(a|A|an|An) ","")
$name = %subregex($name,"enchanted\,? ","")
$name = %subregex($name,"empty ","")
$name = %subregex($name,"\b(slightly scratched|scratched|very scratched|slightly rusty|rusty|very rusty|slightly tarnished|tarnished|very tarnished),? ","")
$name = %subregex($name," \(x\d+\)$","")
#RETURN $name</value>
  <arglist>$name</arglist>
</func>


Code:
<event event="onShopInventory" priority="28360" id="2836">
  <value>$query = %concat("SELECT * FROM Items WHERE name LIKE '%",%replace($name,"'","''"),"'")
$row = %sql(tfe_items, $query)
#IF ($row.RecordCount() = 1) {
  $itemID = $row.Item("itemID")
  $query = %concat("SELECT * from ItemShops WHERE itemID = '",$itemID,
            "' AND shop = '",%replace(@location,"'","''"),"'")
  $row = %sql(tfe_items,$query)
  #IF ($row.RecordCount() = 0) {
    #CALL $row.Insert()
    $row.Item("itemID") = $itemID
    $row.Item("shop") = @location
    $row.Item("lowPrice") = $price
    $row.Item("highPrice") = $price
    #CALL $row.Post()
    } {
    #IF ($row.Item("lowPrice") > $price) {
      #CALL $row.Edit()
      $row.Item("lowPrice") = $price
      #CALL $row.Post()
      }
    #IF ($row.Item("highPrice") < $price) {
      #CALL $row.Edit()
      $row.Item("highPrice") = $price
      #CALL $row.Post()
      }
    }
  }</value>
  <arglist>$name, $price</arglist>
</event>
Reply with quote
eupher
Apprentice


Joined: 18 Jan 2001
Posts: 116
Location: USA

PostPosted: Wed Apr 27, 2011 12:34 pm   
 
The error occurs during the onShopInventory event handler. In the case of the shop inventory I viewed for this particular debug log, mud output stopped right after displaying the line

Quote:

An enchanted scroll of detect good


and displayed the error pop-up. Mud scrolling resumed once I clicked 'OK'.

I don't use #WAIT, #WAITFOR, #WAITTHREAD, #WAITSIGNAL, or #SUSPEND anywhere in any of my settings. I do use user-defined functions, and they are being used in this case. If that's the problem... how do I work around it?

Thanks again!
Reply with quote
eupher
Apprentice


Joined: 18 Jan 2001
Posts: 116
Location: USA

PostPosted: Wed Apr 27, 2011 12:41 pm   
 
and here's the raw mud output that I'm processing with this script:

Quote:
Item Price Weight Level Number Condition
---- ----- ------ ----- ------ ---------
an enchanted scroll of identify 2181 0.30 1 8 perfect
An enchanted scroll of detect good
857 0.10 1 4 perfect
An enchanted scroll of magic missile
133 0.20 5 6 perfect
an enchanted scroll of amnesia 17142 0.20 1 4 perfect
An enchanted scroll of detect evil
857 0.10 1 4 perfect
an enchanted scroll of confuse 4500 0.30 5 1 perfect


I'm not sure how to get the board to display the extra spaces, but in the output all the columns line up.
Reply with quote
Zugg
MASTER


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

PostPosted: Wed Apr 27, 2011 5:01 pm   
 
It looks good to me too. Try adding some #SHOW commands in your onShopInventory script before and after various lines, like your Edit and Post lines, etc. Also add a #show command near the top to actually display the RecordCount. See if you can determine which line of the script is actually causing the popup error message.
Reply with quote
eupher
Apprentice


Joined: 18 Jan 2001
Posts: 116
Location: USA

PostPosted: Wed Apr 27, 2011 7:37 pm   
 
All kinds of weirdness going on.

I added echoes in the following places:

state 0 of FINDMISSINGPURCHASELONG -> #ECHO FINDMISSINGPURCHASELONG name = @current_item
state 1 of FINDMISSINGPURCHASELONG -> #ECHO RAISE onShopInventory @current_item %1 (***BEFORE*** I #RAISE onShopInventory)
inside my onShopInventory event -> #ECHO Executed onShopInventory with arguments $name $price

Output from a shop listing is:

Code:
Item                               Price  Weight  Level  Number  Condition
----                               -----  ------  -----  ------  ---------
an enchanted scroll of identify     2181    0.30      1       8  perfect
Executed onShopInventory with arguments scroll of identify 2181
An enchanted scroll of magic missile
FINDMISSINGPURCHASELONG name = scroll of magic missile
                                     150    0.20      5       5  perfect
Executed onShopInventory with arguments  150
RAISE onShopInventory scroll of magic missile 150
Executed onShopInventory with arguments scroll of magic missile 150
An enchanted scroll of detect evil
FINDMISSINGPURCHASELONG name = scroll of detect evil
                                    1200    0.10      1       2  perfect
Executed onShopInventory with arguments  1200
RAISE onShopInventory scroll of detect evil 1200
Executed onShopInventory with arguments scroll of detect evil 1200
An enchanted scroll of detect good
FINDMISSINGPURCHASELONG name = scroll of detect good
                                    1500    0.10      1       1  perfect
Executed onShopInventory with arguments  1500
RAISE onShopInventory scroll of detect good 1500
Executed onShopInventory with arguments scroll of detect good 1500
an enchanted scroll of amnesia     30000    0.20      1       1  perfect
Executed onShopInventory with arguments scroll of amnesia 30000


So for the 2-line inventory items, onShopInventory is being raised before I raise it... if that makes any sense. It's also getting raised with a blank item name, although the price gets passed successfully.

Raising onShopInventory with a blank name causes my query to match every record. When I echoed RecordCount(), it showed what I expected... 1 if the name was passed, and 1331 if it wasn't. I'm still not sure how this gets us to the error I'm seeing, since all of my logic to do any edit/posting is wrapped inside a test to make sure RecordCount() =1.

Thanks again for your time.
Reply with quote
Zugg
MASTER


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

PostPosted: Thu Apr 28, 2011 4:29 pm   
 
I can see this in your original Script Debugger output too:
Code:
7.8688 | a TheFores |An enchanted scroll of detect evil
0.0013 | f TheFores | Pattern: ^([^\d]+)$ : (%1="An enchanted scroll of detect evil")
0.0010 | c TheFores | exec : Pattern "FINDMISSINGPURCHASELONG" : $name = @stripConditi...
0.0006 | n TheFores | Exec Trigger "FINDMISSINGPURCHASELONG"
0.0006 | n TheFores | Exec Func "stripConditions"
0.0010 | n TheFores | Exec Func "itemExists"
0.0078 | k TheFores | Var "current_item" changed from "scroll of magic missile" to "scroll of detect evil"
0.0009 | a TheFores | 857 0.10 1 4 perfect
0.0014 | f TheFores | Pattern: ^([^\d]+)\s+(\d+)\s+\d+\.\d{2}\s+[\d\*]+\s+\d+\s : (%1=" ", %2=857)
0.0011 | c TheFores | exec : Pattern "FINDMISSINGPURCHASESHORT" : $name = @stripCondit...
0.0005 | n TheFores | Exec Trigger "FINDMISSINGPURCHASESHORT"
0.0006 | n TheFores | Exec Func "stripConditions"
0.0010 | n TheFores | Exec Func "itemExists"
0.0350 | m TheFores | Event "onShopInventory" raised : (%1="", %2=857)
0.0003 | c TheFores | exec : Event "onShopInventory" : $query = %concat("SELECT * FROM...
0.0003 | n TheFores | Exec Event "onShopInventory"
0.0299 | f TheFores | Pattern: ^\s+(\d+)\s+\d+\.\d{2}\s+[\d\*]+\s+\d+\s : (%1=857)
0.0006 | c TheFores | exec : Pattern "^\s+(\d+)\s+\d+\.\d{2}\s+[\d\*]+\s+\d+\s" : #RAI...
0.0003 | n TheFores | Exec Trigger "^\s+(\d+)\s+\d+\.\d{2}\s+[\d\*]+\s+\d+\s"
0.0003 | m TheFores | Event "onShopInventory" raised : (%1="scroll of detect evil", %2=857)
0.0003 | c TheFores | exec : Event "onShopInventory" : $query = %concat("SELECT * FROM...
0.0003 | n TheFores | Exec Event "onShopInventory"

Notice onShopInventory is raised twice. The first time %1="" and the second time %1="scroll of detect evil". So *somewhere* in your script you are calling onShopInventory again. Try doing a global search of your scripts for this word (the Package Editor has a global search bar that lets you search the script contents).
Reply with quote
eupher
Apprentice


Joined: 18 Jan 2001
Posts: 116
Location: USA

PostPosted: Thu Apr 28, 2011 5:38 pm   
 
I just did the global search, and onShopInventory was found in only 3 places:

The named event handler.
That handler raised in FINDMISSINGPURCHASESHORT.
That handler raised in state 1 of FINDMISSINGPURCHASELONG (although the global search lists this match with a '2:' in front of it, like it was state 2)

As always seems to be the case.. the answer (or part of it anyway) was staring me in the face. The trigger pattern for FINDMISSINGPURCHASESHORT was matching the second line of 2-line items. I fixed that, and now onShopInventory only gets raised once per item.

I'm still a little confused. Even if I was raising the event twice, why was I getting errors about updating 2 records? The incorrect raising of the event was sending a blank item name, resulting in RecordCount() not being equal to 1. Since all the Edit()/Post() calls are wrapped inside a test to make sure RecordCount() IS 1, I'm not sure how this error occurred. Even if I had wanted to raise the event twice for the same line of output, shouldn't they happen one after the other based on trigger priority?

Anyway, thanks again for the help. It seems to all be working now, and I was even able to remove the calls to edit() and post() and rely on the direct assignments work.
Reply with quote
eupher
Apprentice


Joined: 18 Jan 2001
Posts: 116
Location: USA

PostPosted: Thu Apr 28, 2011 5:55 pm   
 
Whoops.. spoke too soon.
Code:
$row.Item("fieldname") = <new value>

is still not updating my database unless I wrap it inside
Code:
#CALL $row.Edit()
and
Code:
#CALL $row.Post()
Reply with quote
eupher
Apprentice


Joined: 18 Jan 2001
Posts: 116
Location: USA

PostPosted: Thu Apr 28, 2011 6:44 pm   
 
So I decided to try and start with a simple stand-alone alias to see if I can duplicate the problem. However, what should be simple is apparently not so simple for me. Sad

Here's the alias, which goes into an infinite loop. Mad

Code:
<alias name="testdb" id="39">
  <value>#SQLDB sqldbtest

$row = %sql(sqldbtest,"CREATE TEMPORARY TABLE People(name TEXT)")

$row = %sql(sqldbtest,"SELECT * from People")
#CALL $row.Insert()
$row.Item("name") = "Bob"
#CALL $row.Post()

#ECHO Initial Value:

$row = %sql(sqldbtest,"SELECT * FROM People")
#WHILE (!$row.Eof()) {
  #ECHO $row.Item("name")
  $row.Item("name") = "John"
  #CALL $row.Next()
}

#ECHO Final Value:

$row = %sql(sqldbtest,"SELECT * FROM People")
#WHILE (!$row.Eof()) {
  #ECHO $row.Item("name")
  #CALL $row.Next()
}

#SQLCLOSE sqldbtest</value>
</alias>


Anyone see what I'm doing stupid this time? Smile
Reply with quote
Zugg
MASTER


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

PostPosted: Fri Apr 29, 2011 4:24 pm   
 
I'm not near my main computer to test this right now, but needing the Edit/Post was a separate issue from the popup error about the records. My guess with calling your event twice was that it was a threading issue. Raising an event doesn't necessarily block other triggers from running on the same line sometimes. So I think there were rare timing cases where the previous event wasn't finished when another call was raised.

I will test your new infinite loop issue next week, but hopefully somebody else can test it this weekend to see what might be wrong. At first glance your code seems ok to me.
Reply with quote
eupher
Apprentice


Joined: 18 Jan 2001
Posts: 116
Location: USA

PostPosted: Mon May 02, 2011 5:16 am   
 
Well I think I got my script working properly. Aside from the known stupid things I had wrong, it took two fixes that may or may not represent bugs...

1. I wrapped every occurrence of $row.Item("fieldname") assignments inside of calls to $row.Edit() and $row.Post()
The database just wasn't getting the updated values without this.

2. I replaced my onShopInventory event handler with an alias.
There apparently is some threading issues such that you can't rely on raised events running in the order they were raised and not stepping on each other. Since I've made the switch to an alias, I've had no more issues with the error: 2 record(s) updated. Only one record should have been updated. I did make this fix after the first one, so it may be possible this was related to the first issue.

Thanks again for the help. Smile
Reply with quote
Zugg
MASTER


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

PostPosted: Mon May 02, 2011 4:00 pm   
 
Glad you got it working. I have put the issue with Edit/Post on my bug list. The other issues does make some sense since #events are handled by Windows message events and there is definitely the possibility of getting them running at the same time in different threads. Your idea to use an alias instead is a good one since aliases do not create new threads.
Reply with quote
eupher
Apprentice


Joined: 18 Jan 2001
Posts: 116
Location: USA

PostPosted: Tue May 03, 2011 12:51 am   
 
Sorry to keep flip-flopping... but I was wrong (again). Changing the event to an alias did not solve the problem after all. Just wanted to let ya know. It's not a huge issue since it doesn't seem to be affecting anything other than I just have to hit <enter> to clear the dialog box when it pops up.
Reply with quote
Zugg
MASTER


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

PostPosted: Tue May 03, 2011 6:02 pm   
 
Hmm, thanks for letting me know. It makes me wonder if the database system itself is somehow delaying some operations or doing something in a multi-threaded way that might be causing this. If this was using ADO/COM then I'd be suspicious, but the SQLite database shouldn't be doing this kind of stuff, so I'm still rather perplexed.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion 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