Page 1 of 1

parse a record set

Posted: Wed Feb 17, 2010 1:49 am
by egn
Hello. New to RunRev and wanting to implement the following:

I have connected to a MySQL db/table and made a query. I need to loop through the result continuously displaying one field in a text field in stack one. The data displays on the same field at great speed until the user clicks on a button that makes it stop. The start and stop part I have solved. What I need is the DB part to loop though the query result. Can anyone point me to an example that does just that? Not data grids or lists because that moves differently. Thanks in advance.

Re: parse a record set

Posted: Wed Feb 17, 2010 10:06 am
by bangkok
egn wrote:Hello. New to RunRev and wanting to implement the following:

I have connected to a MySQL db/table and made a query. I need to loop through the result continuously displaying one field in a text field in stack one. The data displays on the same field at great speed until the user clicks on a button that makes it stop. The start and stop part I have solved. What I need is the DB part to loop though the query result. Can anyone point me to an example that does just that? Not data grids or lists because that moves differently. Thanks in advance.
Are you sure you need a "record set" ?

For large number of lines, I would rather use the revDataFromQuery command.

Doc : Gets records from a database according to a SQL query and places the resulting data in a variable, without creating a record set (database cursor).

put revDataFromQuery(,,dbID,dbSQL) into toParse

You receive all the lines given by your query. And then after you're free to to do whatever you want (loop to display each line in a field, until the mouse is clicked or whatever else).

Re: parse a record set

Posted: Wed Feb 17, 2010 4:29 pm
by egn
Thanks for the info.

I have not been able to implement this. It returns what seems to me like a big variable with all values in it. What I need is an array and some way to step through it one by one and if I reach the end then it will loop back to the first item in the array.

I've looked at the User's Guide but that just lists the commands available for DB access and no examples. The Dictionary has a few lines on the syntax but no complete examples. I'm afraid I'm stuck at this point and betting the solution is very simple!

Any example or webpage that has one would be of great help.

Tks.

Re: parse a record set

Posted: Wed Feb 17, 2010 5:02 pm
by bangkok
egn wrote:Thanks for the info.

I have not been able to implement this. It returns what seems to me like a big variable with all values in it. What I need is an array and some way to step through it one by one and if I reach the end then it will loop back to the first item in the array.

I've looked at the User's Guide but that just lists the commands available for DB access and no examples. The Dictionary has a few lines on the syntax but no complete examples. I'm afraid I'm stuck at this point and betting the solution is very simple!

Any example or webpage that has one would be of great help.

Tks.
Okay. With the script :
put "SELECT customerID, countryName FROM mytable WHERE countryname='germany' " into dbSQL
put revDataFromQuery(,,dbID,dbSQL) into toParse
You'll get :
1 line per record
each column being separated by tabulation

After, it's rather easy to parse :

Code: Select all

set itemdelimiter to tab
repeat with i = 1 to the number of lines of toParse
put item 1 of line i of toParse into field "myfield" -- or do something else, or put into an array
end repeat
Now let's imagine you have a "On / Off" button (that will start or stop the display in one field of each record).

Code: Select all

on mouseStillDown
   global theRecord,toParse
   
   if theRecord = the number of lines of toParse then put 1 into theRecord --we go back at first record
   put line theRecord of toParse into field "myfield"
   add 1 to theRecord

end mouseStillDown
Don't forget to put the value 1 into theRecord, with a global var (in opencard or openstack script for instance).

Each of the records will be displayed into the field "myfield" while the mouse button is down.

It's dirty code, it's not array, but I think you'll get the point.

(download the little stack with the example)

Re: parse a record set

Posted: Wed Feb 17, 2010 5:41 pm
by egn
Thanks! What did it was the "put item 1 of" .....

In my query I select 2 fields and the repeat I had was showing both values at the same time.

I am now using the item number to get every field of each record that I want to display and when the repeat stops I can have it put item 2 into another field to show the second data item from the table. I just did not know how to pick one specific field! I find I'm having to relearn ways of doing things in RunRev!

Again, thanks a million for your help.

Re: parse a record set

Posted: Wed Feb 17, 2010 5:44 pm
by trevordevore
FYI - there is an example of converting a database cursor to an array in the Data Grid manual in case you want to see another approach.

http://lessons.runrev.com/spaces/lesson ... Grid-Array