Private Sub ExecuteQuery2 (con As SQL, in As InputStream, resp As ServletResponse) As String
Dim ser As B4XSerializator
Dim m As Map = ser.ConvertBytesToObject(Bit.InputStreamToBytes(in))
Dim cmd As DBCommand = m.Get("command")
'Log(Main.rdcConnector1.GetCommand(cmd.Name))
Dim limit As Int = m.Get("limit")
Dim rs As ResultSet = con.ExecQuery2(Main.rdcConnector1.GetCommand(cmd.Name), cmd.Parameters)
If limit <= 0 Then limit = 0x7fffffff 'max int
Dim jrs As JavaObject = rs
Dim rsmd As JavaObject = jrs.RunMethod("getMetaData", Null)
Dim cols As Int = rs.ColumnCount
Dim res As DBResult
res.Initialize
res.columns.Initialize
res.Tag = Null 'Sin esto el Tag no será serializable de manera correcta.
For i = 0 To cols - 1
res.columns.Put(rs.GetColumnName(i), i)
Next
res.Rows.Initialize
Do While rs.NextRow And limit > 0
Dim row(cols) As Object
For i = 0 To cols - 1
Dim ct As Int = rsmd.RunMethod("getColumnType", Array(i + 1))
'ct bigint = -5
'ct int = 4
'ct string = 12
'check whether it is a blob field
Select Case True
Case ct = -2 Or ct = 2004 Or ct = -3 Or ct = -4
row(i) = rs.GetBlob2(i)
Case ct = 2 Or ct = 3
row(i) = rs.GetDouble2(i)
Case DateTimeMethods.ContainsKey(ct)
Dim SQLTime As JavaObject = jrs.RunMethodJO(DateTimeMethods.Get(ct), Array(i + 1))
If SQLTime.IsInitialized Then
row(i) = SQLTime.RunMethod("getTime", Null)
Else
row(i) = Null
End If
Case ct = -5 'bigint
row(i) = jrs.RunMethod("getLong", Array(i + 1))
Case Else
row(i) = jrs.RunMethod("getObject", Array(i + 1))
End Select
Next
res.Rows.Add(row)
Loop
rs.Close
Dim data() As Byte = ser.ConvertObjectToBytes(res)
resp.OutputStream.WriteBytes(data, 0, data.Length)
Return "query: " & cmd.Name
End Sub