SQLite Strange errors

Hello guys,

Does the latest Public XOJO have issues with SQLite databases ? as so far it seems that i get random results on this and it drives me nuts.

I have this code

Var rows As RowSet

Try
  rows = configDB.SelectSQL("SELECT * FROM settings")
  
  If rows <> Nil Then
    If rows.AfterLastRow Then
      Return False
    Else
      For Each row As DatabaseRow In rows

In XOJO i get

 If rows.AfterLastRow Then
      Return False

But in the database i have 4 records for that , can someone explain this ?

MacOS Sonoma 14.7
XOJO 2024 R2.1

Thanks

You are probably using a reserved name somewhere.

I don’t understand why check rows.AfterLastRow if your are going to do a For Each.
Do you expect ‘rows’ to point to the first row in rows?

Edit: I have only seen .AfterLastRow used on a While-Wend with .MoveToNext

it was just for debug purposes as i know i have 4 records but apparently it shows me like it has no records for that table, that will disappear from there , the purpose of that is to make sure that the rows is not empty , but apparently it is.

I looked into Beatrix cause as well, i changed the column names from name & value to pname and pvalue just for test and i get same result, so something does not work there.

Sorry, I don’t understand.

For me .AfterLastRow is only telling you that ‘rows’ is pointing past the records not that ‘rows’ is empty.

Try rows.MoveToFirstRow before your if rows.AfterLastRow or put a break before it and see if rows has records or not.

Create an entire test case that people can run and see. Probably doing so you can find the issue by yourself, if not we will see the same problem you see.

1 Like

Var db As New SQLiteDatabase

db.Connect

db.ExecuteSQL("CREATE TABLE settings (id INTEGER PRIMARY KEY, my_set TEXT);")

db.ExecuteSQL("INSERT INTO settings (my_set) VALUES ('aaa');")
db.ExecuteSQL("INSERT INTO settings (my_set) VALUES ('bbb');")
db.ExecuteSQL("INSERT INTO settings (my_set) VALUES ('ccc');")

Var rs As RowSet = db.SelectSQL("SELECT * FROM settings;")

Var isEOF As String = If(rs.AfterLastRow, "EOF", "Good to go!")

Break

Problem solved, thanks.

Apparently i had one more test code old one, that was creating the db in different location and it was writing in the good one but reading from the bad one which was empty.

Thank you all .

1 Like

that was a bug in past xojo version that empty records output a row in for each.

1 Like

The OP cuted the path and returned False if founding no settings to load, maybe he returns True if entering the ForEach path to load the settings.

Maybe just a case of the needs and the logic involved. :man_shrugging:t2:

1 Like

the reasion why i often print out useful things as example the path from database :slight_smile:
subclass this SQLiteDatabase class is also useful.

System.DebugLog(CurrentMethodName)
Var f As FolderItem=SpecialFolder.Documents
System.DebugLog(f.NativePath)

That’s the way to do it! - as Mr Punch said.

1 Like