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
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
@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!
[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.