B4J Question Is there any solution for the problem with B4xSerialize with bigint data?

Jorge Bini

New Member
Hi!

I'm using jDRC2 and I want to transfer data from Mariadb Bigint ID columns.

When I use B4xserialize library in DBRequestManager

it generates an error: java.lang.RuntimeException: java.io.EOFException.

I know that if I use INT instead BIGINT works fine but I need the bigint type.

Thank you!

B4X:
Public Sub HandleJobAsync(Job As HttpJob, EventName As String)
    Dim ser As B4XSerializator
    Dim data() As Byte = Bit.InputStreamToBytes(Job.GetInputStream)
    ser.ConvertBytesToObjectAsync(data, "ser")
    
    'Here generates the error

    Wait For (ser) ser_BytesToObject (Success As Boolean, NewObject As Object)
    If Success = False Then
        Log("Error reading response: " & LastException)
        Return
    End If
    Dim res As DBResult = NewObject
    res.Tag = Job.Tag
    CallSubDelayed2(mTarget, EventName & "_result", res)
End Sub
 

Jorge Bini

New Member
Thanks Erel!

But finally I found the solution, the problem was when creates the res (DBresult) from rsmd JavaObject.
jrs.RunMethod("getObject" doesn't recognize BigInt value so it may be forced with jrs.RunMethod("getLong"
Must modify some lines in the sub ExecuteQuery2, proyect JRDC (jRDC2), module RDCHandler, adding a case for ColumnType -5 (BigInt)

B4X:
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

With this changes works fine.
 

Attachments

  • jRDC2.zip
    5.8 KB · Views: 42
Upvote 0
Top