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: Sat Dec 05, 2009 9:04 am   

[3.12] Endless loop when using #WHILE (!@row.Eof()) and calling an SQLite db
 
I have a database with 2 records, for testing.

Code:

#VAR row %sql(@DB_name, "SELECT * FROM MobList")
#LOOP 5 {
  #SHOW "MobName: " @row.Item("MobName"), Position: @row.Position
  #CALL @row.Next
}

displays:

MobName: A Living Rock, Position: 1
MobName: Some Reeds, Position: 2
MobName: Some Reeds, Position: 2
MobName: Some Reeds, Position: 2
MobName: Some Reeds, Position: 2

But the following code gets stuck in an endless loop:
Code:

#VAR row %sql(@DB_name, "SELECT * FROM MobList")
#WHILE (!@row.Eof()) {
  #SHOW "MobName: " @row.Item("MobName"), Position: @row.Position
  #CALL @row.Next
}


It's like the .Eof() flag won't work. The same endless loop occurs when I use this alias below and search for "Some Reeds" e.g.
Code:

#IF (%0) {
  #VAR db_search_string %0
  #VAR row %sql( @DB_name, "SELECT * FROM MobList WHERE MobName LIKE" '@db_search_string')
  #MXP %ansi( Red, high)Results for mob: %ansi( White, high)'@db_search_string'
  #WHILE (!@row.Eof()) {
    #SHOW "MobName: " @row.Item("MobName"), Position: @row.Position
    #CALL @row.Next
    }
  }


The resulting output from that operation is, and I have to hit ESC to abort the loop:
Results for mob: 'Some Reeds'
MobName: Some Reeds, Position: 1
MobName: Some Reeds, Position: 1
MobName: Some Reeds, Position: 1
MobName: Some Reeds, Position: 1
MobName: Some Reeds, Position: 1

When I use the muds.db file to test, I use the following code, and the result is displayed below the code (only the end of the spam).

Code:

#VAR row %sql(muds, "SELECT * FROM MudList")
#WHILE (!@row.Eof()) {
  #SHOW "Title: " @row.Item("Title")
  #CALL @row.Next
}


Title: DragonBall A New Dimension
Title: Reality Dysfunction
Title: Creeping Death II
Title: Realms of Talos
Title: Cory Mud
Title: Celestial Knights
Title: Asgardian Nightmare: Chaos Theory
Title: Asgardian Nightmare: Chaos Theory
Title: Asgardian Nightmare: Chaos Theory
Title: Asgardian Nightmare: Chaos Theory
Title: Asgardian Nightmare: Chaos Theory
Title: Asgardian Nightmare: Chaos Theory

(ESC had to be hit to stop the loop)

Bug in .Eof?

//DanteX
Reply with quote
Zugg
MASTER


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

PostPosted: Mon Dec 07, 2009 9:21 pm   
 
Confirmed and added to bug list. The EOF function is part of the SQLite driver, so I have no idea why it's not returning the correct value, but I'll look into it. It certainly needs to be fixed to make looping through databases useful. And I don't remember seeing any problem like this in zApp. Maybe it's an SQLite v3 issue? (zApp only used SQLite v2)
Reply with quote
Zugg
MASTER


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

PostPosted: Wed Jan 27, 2010 10:53 pm   
 
Well, I found this bug, and it's really an annoying and stupid one.

The "@row.Next" method actually calls the ZeosLib "MoveNext" method, which supports moving through a filtered dataset rather than just the raw records. And while MoveNext returns true or false depending upon it it's successful, it does NOT set the EOF flag at the end. Grrr...

I guess they thought that since EOF means "End of File" and with a filtered dataset you are just at the last record in the filter and not necessarily at the last record in the entire database file.

The problem with this is that the Delphi EOF method for generic DataSet objects is a READONLY property. So I have no way to set this property myself when MoveNext returns false. Looks like I need to completely override the Delphi EOF property with my own and then handle this all myself. What a pain.
Reply with quote
chris-74269
Magician


Joined: 23 Nov 2004
Posts: 364

PostPosted: Wed Jan 27, 2010 11:56 pm   
 
For the time being, you could check the record index with %item(@row.List,1) and if it matches the previous one, stop there.
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Thu Jan 28, 2010 2:55 pm   
 
Does @row.Next return a TRUE/FALSE value? If so, testing for a FALSE would be another workaround.
Reply with quote
Zugg
MASTER


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

PostPosted: Thu Jan 28, 2010 5:20 pm   
 
Yes, @row.Next returns false when you get to the end of the database, but I still wanted to fix @row.Eof also. I got this all fixed yesterday for the next version, so it's no longer an issue.
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