For various reasons I need the data types of the columns of a cursor produced by a SQLite query.
There doesn't seem an easy way to do this and the best I have come up with sofar is this:
Sofar this seems to work OK, but not fully tested yet.
Has anybody any better ideas or improvements?
RBS
There doesn't seem an easy way to do this and the best I have come up with sofar is this:
B4X:
Sub GetCursorDataTypes(Curs As Cursor) As String()
Dim c As Int
Dim p As Long
Dim r As Reflector 'needs Reflection library
Dim iColumns As Int
Dim lRows As Long
Dim iResult As Int
iColumns = Curs.ColumnCount
lRows = Curs.RowCount
r.Target = Curs
Dim arrDataTypes(iColumns) As String
For c = 0 To iColumns - 1
For p = 0 To lRows - 1
Curs.Position = p
iResult = r.RunMethod2("getType", c, "java.lang.int")
If iResult = 2 Then
arrDataTypes(c) = "R"
Exit 'exit row loop and move to next column
End If
If iResult = 4 Then
arrDataTypes(c) = "B"
Exit 'exit row loop and move to next column
End If
If iResult = 3 Then
arrDataTypes(c) = "T"
'no exit yet as may find a Real value?
End If
If iResult = 1 Then
arrDataTypes(c) = "I"
'no exit yet as may find a Real value?
End If
Next
If arrDataTypes(c) = 0 Then
arrDataTypes(c) = "T" 'or should we do a Null type?
End If
Next
Return arrDataTypes
End Sub
Sofar this seems to work OK, but not fully tested yet.
Has anybody any better ideas or improvements?
RBS