Iterating a RowSet provides references to elements of DatabaseRow type.
What I am looking for is a way to assign a DatabaseRow type outside an iterator ?
Examples below simplified for clarity.
//this works
Var rs As RowSet = db.SelectSQL(myQuery)
For Each record As DatabaseRow In rs
DoSomethingWith(record)
Next
Sub DoSomethingWith(record as DatabaseRow)
Var name As String
name = record.Column("name").StringValue
End Sub
//but how to do this?
Var record As DatabaseRow, name As String
Var rs As RowSet = db.SelectSQL(myQuery)
rs.MoveToFirstRecord
record = ???? //what to assign to record?
name = record.Column("name").StringValue
Odd that an iterator can assign a DatabaseRow but I can’t find a way to do it directly.
The use case is a query that should only return a single record and wanting to pass the record to a function. I guess I can work around with a For…Each…Next it just seems a little redundant.
Var name As String
Var rs As RowSet = db.SelectSQL(myQuery)
rs.MoveToFirstRecord
name = rs.Column("name").StringValue
Using the iterator, even if only 1 record, should be clear to read. I prefer code that works the same for all situations that create code for special cases.
Maybe I don’t understand the ‘problem’. If using ‘for each … as … in …’ works, why change it if you know that you only have 1 record? And I read that .MoveToFirstRecords is not an option for all databases. I prefer coding in a ‘standard’ way that can be easily ported between db.
I would say it’s personal preference. A loop implies there may be more than one. I also naturally expect types to behave the same whether they are function parameters or any other declaration.
Not losing sleep over this one. Just a case of did I miss something and the answer apparently being no it can’t be done.