DOC Error?

This is the first of 3 code examples in the API 2 documentation:

Should this code:

//db is a valid connection to a SQLite database
Var rowsFound As RowSet
Try
rowsFound = db.SelectSQL(“SELECT * FROM CUSTOMERS WHERE POSTALCODE=” + PostalCode.Value)
If rs <> Nil Then
For Each row As DatabaseRow in rowsFound
ListBox1.AddRow(row.Column(“Name”).Value)
Next
rs.Close
End If
Catch error as DatabaseException
MessageBox("Error: " + error.Message)
End Try

Actually be this:

//db is a valid connection to a SQLite database
Var rowsFound As RowSet
Try
rowsFound = db.SelectSQL(“SELECT * FROM CUSTOMERS WHERE POSTALCODE=” + PostalCode.Value)
If rowsFound <> Nil Then
For Each row As DatabaseRow in rowsFound
ListBox1.AddRow(row.Column(“Name”).StringValue)
Next
rowsFound .Close
End If
Catch error as DatabaseException
MessageBox("Error: " + error.Message)
End Try

And ditto for the next 2 examples on that page?

What am I not getting?

If they used:

Var rowsFound As RowSet

then they can’t use rs, so yes, the code should say

If rowsFound <> Nil Then

about .Value or .StringValue, that is up to the user, here is the doc for Value (variant is used) and the one for StringValue (string is used)

Thank you for the confirmation and clarification, Alberto.

Just to be clear to others, the code is for Xojo 2019r2 and newer.

@Peter Greulich you can send an email to Xojo so they can fix the docs, create a Feedback case or contact @Paul Lefebvre

Will do.

Found another one on this page. In the first example:

If rs <> Nil Then
  While Not rs.AfterLastRow
    DataList.AddRow(data.ColumnAt(1).StringValue, data.ColumnAt(2).StringValue, _
      rs.ColumnAt(3).StringValue, data.ColumnAt(4).StringValue)
    
    rs.MoveToNextRow
  Wend
  rs.Close
End If

Should be:

DataList.AddRow(rs.ColumnAt(1).StringValue, rs.ColumnAt(2).StringValue, _
rs.ColumnAt(3).StringValue, rs.ColumnAt(4).StringValue)

Also note that ColumnAt is 0-based, so those index values probably need to be reduced by one.

DataList.AddRow(data.ColumnAt(0).StringValue, data.ColumnAt(1).StringValue, _ rs.ColumnAt(2).StringValue, data.ColumnAt(3).StringValue)

Thank you for this post…

@Paul Lefebvre The online documentation still hasn’t been updated. I think most of us know that “rs” should be “rowsFound” but newbies may be confused by this error. Hoping it’s fixed soon!

That sample is not wrong, the RowSet was named rs in this case:

Var rs As RowSet

but they should better show how to use an Iterator instead of the While loop to teach the recent best practices.

[quote=460524:@Peter Greulich]This is the first of 3 code examples in the API 2 documentation:

rowsFound = db.SelectSQL("SELECT * FROM CUSTOMERS WHERE POSTALCODE=" + PostalCode.Value) [/quote]
again here they should demonstrate the newer, safer syntax with automatic prepared statements and pass the postal code as an parameter. Reading this sample in context, I see, they are exactly trying to make that point here.

[quote=460787:@Tobias Bussmann]That sample is not wrong, the RowSet was named rs in this case:

Var rs As RowSet

but they should better show how to use an Iterator instead of the While loop to teach the recent best practices.[/quote]
Hi Tobias, the problem is not with ‘rs’ is with ‘data’ used instead of ‘rs’ here:

DataList.AddRow(data.ColumnAt(1).StringValue, data.ColumnAt(2).StringValue, _ rs.ColumnAt(3).StringValue, data.ColumnAt(4).StringValue)
all should say rs.ColumnAt, but as you can see only 1 say ‘rs.’ and the others say ‘data.’ and as Robin said, they are 0 based.

[quote=460790:@Alberto DePoo]Hi Tobias, the problem is not with ‘rs’ is with ‘data’ used instead of ‘rs’ here:

DataList.AddRow(data.ColumnAt(1).StringValue, data.ColumnAt(2).StringValue, _ rs.ColumnAt(3).StringValue, data.ColumnAt(4).StringValue)
I see, sorry - I got that wrong. Thanks for explaining. The renaming was obviously missed in this change while the Index should likely have been altered here.

This should be fixed now.