Page 1 of 1

Read data from query a row at a time

Posted: Sat Jun 01, 2013 12:48 am
by asawyer13
I am wanting to read some rows from a mysql query and using the data for each row, I want to lookup a latitude and longitude and then update the record.
I want to loop thru the queried records one at a time.

Okay, I can open the database connection and issue my query, but the examples I have found put all the data in a listbox, etc.
I want retrieve the first row, do my lookup (which I know who to do) and then issue an update statement I guess to update the record.
Then go to the next record, etc, until all the records are done.

I'm sure it's simple, just can't quite figure it out.

Thanks in advance

Re: Read data from query a row at a time

Posted: Sat Jun 01, 2013 1:03 am
by sturgis
PUt the data into a property or variable, then you can use
So if you have the data saved in variable tData you can

Code: Select all

repeat for each line tLine in tData
   -- iterates through the lines that are in tData, placing the current working line into the variable tLine
   -- do your updates here using the data in tLine. each line should be tab delimited for column names. 
   -- so if you set the itemdelimiter to tab then you can address things by column
   -- you'll still need to parse things out so that you can construct your update.
end repeat

Re: Read data from query a row at a time

Posted: Sat Jun 01, 2013 1:06 am
by asawyer13
Thanks,
I kind of was heading down that road, but thinking that it really was reading all the rows into an array or something and then processing from the array.

I have a lot to learn, but I am here to stay.

Re: Read data from query a row at a time

Posted: Sat Jun 01, 2013 1:15 am
by sturgis
If you find it easier to work with arrays you might look at split and combine.

If you're planning on putting things into a datagrid, a numericly keyed array will help with that.

Also, you might look at dbLib, it makes lots of this stuff much easier, and if I remember right, query results are placed into an array. And I think that it has dual licenses now so you can use it with community, and then if you go commercial, get a license. (sqlyoga is pretty awesome too but its too complex for me and i'm not sure if its dual licensed yet)

Of course you could "repeat for each..." to create an array also, but if its just for updates, theres not much sense in creating an array then going through it again to do the update.

Re: Read data from query a row at a time

Posted: Sat Jun 01, 2013 1:18 am
by asawyer13
I believe I had looked at dblib before, so I may revisit that. I own a commercial LiveCode so we'll see how dblib is.
Thanks
Alan