iOS Question ser_objecttobytes issue

enrfortin

Member
Licensed User
i have a problen with DBRequestManager (i think)
when i use ExecuteBatch i got this message ( and the insert dont work)
Event target instance was released: ser_objecttobytes::
some times works at the first other times works at the third sometimes dont work
(same code in b4a works great)
any help is welcome, thanks.
my code:

code:
    If IsFound = 1 Then
        Log("found")
        tokenpw=RandomString2(6)
        Log(tokenpw)
        Dim cmdc As DBCommand = CreateCommand("UP_PhoneNumber", Array(EditText3.Text,tokenpw))
        Dim j As HttpJob = CreateRequest.ExecuteBatch(Array(cmdc), Null)
        'here start the problem'
        Wait For(j) JobDone(j As HttpJob)
        'here ends the problems'
        If j.Success Then
            Log("sucees up phonenumer")
            numero_cliente=EditText3.Text
            cpnl.Visible=True             
            Timer1.Initialize("timer1",1000)
            Timer1.Enabled=True             
            btnsms.Enabled=False
            lbltime.Visible=True
            lblwatch.Visible=True
            lblnocode.Visible=True
            lblreen.Visible=True
            'btnsms.SetColorAndBorder(Colors.Gray,2dip,Colors.Gray,25dip)
            SetButtonGradient(btnsms,Colors.Gray,Colors.Gray)                 
            SendTwilioSMS("504"&numero_cliente,"Palominos: Su codigo de seguridad es: " & tokenpw &". Vence en 10 minutos. No comparta este codigo con nadie.")
        End If
        j.Release
    Else
        clsToast.show("No sé a encontrado una cuenta registrada a este número")
    End If

DBRequesManager:
'Requires support for resumable subs
'Class module

Sub Class_Globals
    Private mTarget As Object
    Private link As String
    Private VERSION As Float = 2
    Dim ser11 As B4XSerializator
  
    Dim Job11 As HttpJob
    Dim Tag11 As Object
End Sub

'Target - The module that handles JobDone (usually Me).
'ConnectorLink - URL of the Java server.
Public Sub Initialize (Target As Object, ConnectorLink As String)
    mTarget = Target
    link = ConnectorLink
End Sub

'Sends a query request.
'Command - Query name and parameters.
'Limit - Maximum rows to return or 0 for no limit.
'Tag - An object that will be returned in the result.
Public Sub ExecuteQuery(Command As DBCommand, Limit As Int, Tag As Object) As HttpJob
    Dim ser As B4XSerializator
    Dim data() As Byte = ser.ConvertObjectToBytes(CreateMap("command": Command, "limit": Limit,  "version": VERSION))
    Return SendJob(CreateJob, data, Tag, "query2")
End Sub

Private Sub SendJob(j As HttpJob, Data() As Byte, Tag As Object, Method As String) As HttpJob
    j.Tag = Tag
    j.PostBytes(link & "?method=" & Method , Data)
    Return j
End Sub

Private Sub CreateJob As HttpJob
    Dim j As HttpJob
    j.Initialize("DBRequest", mTarget)
    Return j
End Sub

'Executes a batch of (non-select) commands.
'ListOfCommands - List of the commands that will be executes.
'Tag - An object that will be returned in the result.
Public Sub ExecuteBatch(ListOfCommands As List, Tag As Object) As HttpJob
    Dim j As HttpJob = CreateJob
    Job11 = j
    Tag11 = Tag
    ExecuteBatchImpl(ListOfCommands)
    Return j
End Sub

Sub ser_ObjectToBytes (Success As Boolean, Bytes() As Byte) 
    SendJob(Job11, Bytes, Tag11, "batch2") 
End Sub


Private Sub ExecuteBatchImpl(ListOfCommands As List)

    ser11.ConvertObjectToBytesAsync(CreateMap("commands": ListOfCommands,  "version": VERSION), "ser")

End Sub


'Similar to ExecuteBatch. Sends a single command.
Public Sub ExecuteCommand(Command As DBCommand, Tag As Object) As HttpJob

    Return ExecuteBatch(Array As DBCommand(Command), Tag)
End Sub

'Handles the Job result and returns a DBResult.
'It is recommended to use HandleJobAsync instead.
Public Sub HandleJob(Job As HttpJob) As DBResult
    Dim ser As B4XSerializator
    Dim data() As Byte = Bit.InputStreamToBytes(Job.GetInputStream)
    Dim res As DBResult = ser.ConvertBytesToObject(data)
    res.Tag = Job.Tag
    Return res
End Sub
'Handles the Job result and raises the Result event when the data is ready.

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")
    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




'Reads a file and returns the file as a bytes array.
Public Sub FileToBytes(Dir As String, FileName As String) As Byte()
    Dim out As OutputStream
    out.InitializeToBytesArray(0)
    Dim In As InputStream = File.OpenInput(Dir, FileName)
    File.Copy2(In, out)
    out.Close
    Return out.ToBytesArray
End Sub
#if Not(B4J)
'Converts an image to a bytes array (for BLOB fields).
Public Sub ImageToBytes(Image As Bitmap) As Byte()
    Dim out As OutputStream
    out.InitializeToBytesArray(0)
    Image.WriteToStream(out, 100, "JPEG")
    out.Close
    Return out.ToBytesArray
End Sub
'Converts a bytes array to an image (for BLOB fields).
Public Sub BytesToImage(bytes() As Byte) As Bitmap
    Dim In As InputStream
    In.InitializeFromBytesArray(bytes, 0, bytes.Length)
    Dim bmp As Bitmap
    bmp.Initialize2(In)
    In.Close
    Return bmp
End Sub
#End If

'Prints the table to the logs.
Public Sub PrintTable(Table As DBResult)
    Log("Tag: " & Table.Tag & ", Columns: " & Table.Columns.Size & ", Rows: " & Table.Rows.Size)
    Dim sb As StringBuilder
    sb.Initialize
    For Each col In Table.Columns.Keys
        sb.Append(col).Append(TAB)
    Next
    Log(sb.ToString)
    For Each row() As Object In Table.Rows
        Dim sb As StringBuilder
        sb.Initialize
        For Each record As Object In row
            sb.Append(record).Append(TAB)
        Next
        Log(sb.ToString)
    Next
End Sub
 
Last edited:
Solution
First step is to change the code to:
B4X:
   Dim req As DBRequestManager = CreateRequest
   Dim cmdc As DBCommand = CreateCommand(...
   Wait For (req.ExecuteBatch(Array(cmdc), Null)) JobDone(j As HttpJob)

enrfortin

Member
Licensed User
What is the output of Log(j) after the wait for line?

Post the full logs.
Hi, thanks for you reply, if i try Log(j) after the wait for line, i dont receive results,
if i try Log(j) before i receive this result:

Application_Start
*** mainpage: B4XPage_Created
Application_Active
*** mainpage: B4XPage_Appear [mainpage]
*** mainpage: B4XPage_Resize [mainpage]
*** mainpage: B4XPage_Resize [mainpage]
*** paginalogin: B4XPage_Created [mainpage]
*** mainpage: B4XPage_Disappear [paginalogin]
*** paginalogin: B4XPage_Appear [paginalogin]
*** paginalogin: B4XPage_Resize [paginalogin]
*** recuperar_user: B4XPage_Created [paginalogin]
*** paginalogin: B4XPage_Disappear [paginalogin, recuperar_user]
*** recuperar_user: B4XPage_Appear [paginalogin, recuperar_user]
*** recuperar_user: B4XPage_Resize [paginalogin, recuperar_user]
Can't find keyplane that supports type 4 for keyboard iPhone-PortraitTruffle-NumberPad; using 27071_PortraitTruffle_iPhone-Simple-Pad_Default
*** recuperar_user: B4XPage_KeyboardStateChanged [paginalogin, recuperar_user]
enviado98780884
succes
result + 0
Enrique Humberto Fortin Betance
found
023506
aca=???
[_jobname=DBRequest, _success=0, _username=
, _password=, _errormessage=, _target=[_root=<B4XViewWrapper: <B4IPanelView: 0x7fd8c9a294e0; frame = (0 0; 428 926); layer = <CALayer: 0x60000111b0a0>>>, _xui=<B4IXUI: 0x600001345710>, _btnsms=<B4XViewWrapper: <UIButton: 0x7fd8c9b24f10; frame = (114 320; 200 45); clipsToBounds = YES; opaque = NO; gestureRecognizers = <NSArray: 0x600001f62220>; layer = <CALayer: 0x60000111f740>>>
, _edittext3=<B4XViewWrapper: <UITextField: 0x7fd8c907f600; frame = (90 2; 233 41); opaque = NO; gestureRecognizers = <NSArray: 0x600001f6cf30>; placeholder = Ingrese su número de teléfono; borderStyle = RoundedRect; background = <_UITextFieldSystemBackgroundProvider: 0x600001104140: backgroundView=<_UITextFieldRoundedRectBackgroundViewNeue: 0x7fd8c9b3dc90; frame = (0 0; 233 41); opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x6000011041a0>>, fillColor=UIExtendedSRGBColorSpace 0 0 0 0, textfield=<UITextField 0x7fd8c907f600>>; layer = <CALayer: 0x60000116f960>>>, _img=<B4XViewWrapper: <UIImageView: 0x7fd8c99200c0; frame = (176 147; 75 75); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x600001116d20>>>, _label1=<B4XViewWrapper: <UILabel: 0x7fd8c9b319e0; frame = (0 0; 40 45); text = ''; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x60000325fc00>>>
, _lblsup=<B4XViewWrapper: <UILabel: 0x7fd8c9935e10; frame = (172 406; 84 40); text = 'Ingresa'; gestureRecognizers = <NSArray: 0x600001f79680>; layer = <_UILabelLayer: 0x600003241f90>>>, _lbltitle=<B4XViewWrapper: <UILabel: 0x7fd8c9922bf0; frame = (88 225; 252 30); text = 'Recuperar Contraseña'; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x600003241d10>>>, _newuser=<B4XViewWrapper: <UILabel: 0x7fd8c99363c0; frame = (154 366; 120 40); text = '¿Ya tienes cuenta?'; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x6000032423f0>>>
, _panel1=<B4XViewWrapper: <B4IPanelView: 0x7fd8c9b36390; frame = (-286 -926; 1000 1110); clipsToBounds = YES; layer = <CALayer: 0x60000111f300>>>, _panel2=<B4XViewWrapper: <B4IPanelView: 0x7fd8c9b2a3b0; frame = (-286 557; 1000 1000); clipsToBounds = YES; layer = <CALayer: 0x60000111f520>>>, _panel3=<B4XViewWrapper: <B4IPanelView: 0x7fd8c9b2c980; frame = (50 260; 328 45); clipsToBounds = YES; layer = <CALayer: 0x60000111fb00>>>
, _clstoast=[_mactivity=<B4XViewWrapper: <B4IPanelView: 0x7fd8c9a294e0; frame = (0 0; 428 926); layer = <CALayer: 0x60000111b0a0>>>, _ptoast=<B4IPanelWrapper: <B4IPanelView: 0x7fd8c9937e00; frame = (0 1110; 1000 77.7); clipsToBounds = YES; hidden = YES; layer = <CALayer: 0x600001101900>>>, _lbltoast=<B4ILabelWrapper: <UILabel: 0x7fd8c9938020; frame = (50 0; 940 77.7); userInteractionEnabled = NO; layer = <_UILabelLayer: 0x6000032428f0>>>
, _main=<b4i_main: (null)>, _globalparameters=<b4i_globalparameters: (null)>, _b4xpages=<b4i_b4xpages: (null)>
, _b4xcollections=<b4i_b4xcollections: (null)>, _httputils2service=<b4i_httputils2service: (null)>], _tokenpw=023506, _numero_cliente=
, _cpnl=<B4IPanelWrapper: <B4IPanelView: 0x7fd8c9b33870; frame = (0 277.5; 1000 380); clipsToBounds = YES; hidden = YES; layer = <CALayer: 0x6000011044c0>>>, _a=180, _labeldibujo=<B4XViewWrapper: <UILabel: 0x7fd8c9925430; frame = (40 0; 50 45); text = '+504'; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x600003241db0>>>
, _lblcerrar=<B4ILabelWrapper: <UILabel: 0x7fd8c9a357b0; frame = (389 254; 116.145 34.8436); text = 'Cerrar'; clipsToBounds = YES; gestureRecognizers = <NSArray: 0x600001f6c5a0>; layer = <_UILabelLayer: 0x600003247700>>>, _lbltime=<B4XViewWrapper: <UILabel: 0x7fd8c9936b80; frame = (215 527; 50 40); text = '180'; hidden = YES; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x6000032424e0>>>, _timer1=<B4ITimer: 0x600001f77570>
, _lblwatch=<B4ILabelWrapper: <UILabel: 0x7fd8c9936fa0; frame = (169 527; 45 45); text = ''; hidden = YES; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x6000032425d0>>>, _lblnocode=<B4ILabelWrap (message truncated)...
Event target instance was released: ser_objecttobytes::
 
Upvote 0

enrfortin

Member
Licensed User
First step is to change the code to:
B4X:
   Dim req As DBRequestManager = CreateRequest
   Dim cmdc As DBCommand = CreateCommand(...
   Wait For (req.ExecuteBatch(Array(cmdc), Null)) JobDone(j As HttpJob)
apparently works fine with this change, thanks!
 
Upvote 0
Top