Values in Global rowset getting set to Nil

I have a global rowset that is populated in my app correctly in one of the methods.I iterate through the rowset using a For Each - Next loop . Afterwards all the columns in the rowset get set to Nil?? Any ideas why this would be happening? Does iterating set them to Nil

gPicList = db.SelectSQL("SELECT * FROM Pictures " +_
"inner join locations on lid = Locid where detailid = " + gDetailID)

for each dr as databaserow in gpiclist

Next

You do not tested if it is Nil (get some records from Select)

gpiclist is populated from the shown select statement but after the iteration all the values are changed to nil

Figured it out, removed the iterator and just used gpiclist.MoveToNextRow and it works fine. the iterator must clear out the values after the iteration…

Can you provide a sample project that shows the problem?
You can zip the project and upload to the forum.

A simple test using Xojo’s SQLite Desktop example works correctly:
ForSharon.xojo_binary_project.zip (15.9 KB)

After you walked through all the databaserows in the rowset there is nothing more to see. It sounds like you’re asking “why are there no words after the last page of my book?”. Or am i misunderstanding something here?

As it should. If the values are still set after MoveToNextRow, that would be a bug.

I wasn’t expecting them to be removed after going through a For Next loop, but they were.

This sample you have does not iterate through a rowset, but rather through a list, If you save a rowset as a global and iterate through it, all the data is lost.

I expected the rowset to still be available to use and not all the data to be removed after iterating

It shouldn’t be.

1 Like

I’m sorry but I don’t understand what you are saying, the code is:

For Each row As DatabaseRow In data
  DataList.AddRow(row.Column("ID").StringValue, row.Column("Name").StringValue, _
  row.Column("Coach").StringValue, row.Column("City").StringValue)
  DataList.RowTagAt(DataList.LastAddedRowIndex) = row.Column("ID").IntegerValue
Next

and is iterating on the 3 records on the rowset adding the values to a listbox. Then iterate again and put another 3 records on the listbox.

Not sure what you mean for save a rowset as a global, maybe creating a module and adding a rowset property there? It works too:

ForSharon2.xojo_binary_project.zip (16.5 KB)

Could it be that you are closing your RowSet after the first Iterate? (making it Nil)

I commented out the data.close line so the RowSet is kept on the Global property.

Feel free to update the code to make it reproduce your problem.


Edit: a GIF on how to use the sample
2024-08-20_18-40-35

Hmm, interesting. I can’t seem to reproduce it in the sample file. and yes the global rowset I had was in a module with the rowset property. I didn’t close the rowset so it’s not that. I’ll have to go back and add the iterator to my project and see if I can make it happen again…

Thanks for your help

Ah made it fail. I have a check on another module that checks if there is an ID value in the global list. It doesn’t find any as all the values are nil
ForSharon.zip (16.7 KB)

If ‘fails’ because the first iterate moves the rowset until the end (no more rows).
To ‘fix’ your code add this line

glist.MoveToFirstRow

before your IF in ShowData1.

Hope this helps and makes sense.

1 Like

Thanks! got it :slight_smile:

1 Like