iOS Question DBRequestmanager error Object was not initialized (NSMutableURLRequest)

lucas555

Member
Licensed User
Longtime User
Hi,
Im triing to move my code from b4A TO B4I

But when i use most of the same code when i use the DBRequestmanager that i use from my ba4 with work well for many many years :)
when i try to make a connection i get Object was not initialized (NSMutableURLRequest)

I look the forum but no luck ?

thks in advances
 

lucas555

Member
Licensed User
Longtime User
The
error message:
Error occurred on line: 288 (HttpJob)
Object was not initialized (NSMutableURLRequest)
Stack Trace: (
  CoreFoundation       <redacted> + 150
  libobjc.A.dylib      objc_exception_throw + 38
  CoreFoundation       <redacted> + 0
  Pos3 Eat-TO          -[B4IObjectWrapper object] + 188
  Pos3 Eat-TO          -[B4IHttpRequest setTimeout:] + 40
  Pos3 Eat-TO          -[b4i_dbrequestmanagerb _sendjob:::::] + 1030
  Pos3 Eat-TO          -[b4i_dbrequestmanagerb _executequery::::] + 1590
  Pos3 Eat-TO          -[ResumableSub_b4xmainpage_GETBEGINUPDATE resume::] + 4090
  Pos3 Eat-TO          -[b4i_b4xmainpage _getbeginupdate:] + 442
  Pos3 Eat-TO          -[b4i_b4xmainpage _wobblemenu1_tab1click:] + 1144
 CoreFoundation       <redacted> + 68
 CoreFoundation       <redacted> + 292
 Pos3 Eat-TO          +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1790
 Pos3 Eat-TO          -[B4IShell runMethod:] + 588
 Pos3 Eat-TO          -[B4IShell raiseEventImpl:method:args::] + 2192
 Pos3 Eat-TO          -[B4IShellBI raiseEvent:event:params:] + 1328
 Pos3 Eat-TO          -[B4ICommon CallSub4::::] + 326
 Pos3 Eat-TO          -[B4ICommon CallSub:::] + 116
 Pos3 Eat-TO          -[b4i_wobblemenu _triggertabclickevent::] + 3412
 Pos3 Eat-TO          -[b4i_wobblemenu _icontab_click:] + 718
 CoreFoundation       <redacted> + 68
 CoreFoundation       <redacted> + 292
 Pos3 Eat-TO          +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1790
 Pos3 Eat-TO          -[B4IShell runMethod:] + 588
 Pos3 Eat-TO          -[B4IShell raiseEventImpl:method:args::] + 2192
 Pos3 Eat-TO          -[B4IShellBI raiseEvent:event:params:] + 1328
 Pos3 Eat-TO          __33-[B4I raiseUIEvent:event:params:]_block_invoke + 74
 libdispatch.dylib    <redacted> + 10
 libdispatch.dylib    <redacted> + 22
 libdispatch.dylib    <redacted> + 1524
 CoreFoundation       <redacted> + 8
 CoreFoundation       <redacted> + 1574
 CoreFoundation       CFRunLoopRunSpecific + 520
 CoreFoundation       CFRunLoopRunInMode + 108
 GraphicsServices     GSEventRunModal + 160
 UIKit                UIApplicationMain + 144
 Pos3 Eat-TO          main + 106
 libdyld.dylib        <redacted> + 2
)
ode is the same
DBRequestManager:
Sub Class_Globals
    Private mTarget As Object
    Private link As String
    Private VERSION As Float = 2
   
End Sub

'Target - The module that handles JobDone (usually Me).
'ConnectorLink - URL of the Java server.

'Sub CreateMutableUrlRequest (url As String) As Object
'    Dim u As NativeObject
'    u = u.Initialize("NSURL").RunMethod("URLWithString:", Array(url))
'    Dim request As NativeObject
'    request = request.Initialize("NSMutableURLRequest").RunMethod("requestWithURL:", Array(u))
'    Return request
'End Sub

Public Sub Initialize (Target As Object, ConnectorLink As String)
    mTarget = Target
    link = ConnectorLink&"/rdc"
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(Tag), 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.GetRequest.Timeout=5000
    j.PostBytes(link & "?method=" & Method , Data)
    Return j
End Sub

Private Sub CreateJob(TAg As String) As HttpJob
    Dim j As HttpJob
    j.Initialize( TAg& "=", 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(Tag)
    ExecuteBatchImpl(j, ListOfCommands, Tag)
    Return j
End Sub

Private Sub ExecuteBatchImpl(Job As HttpJob, ListOfCommands As List, Tag As Object)
    Dim ser As B4XSerializator
    ser.ConvertObjectToBytesAsync(CreateMap("commands": ListOfCommands,  "version": VERSION), "ser")
    Wait For (ser) ser_ObjectToBytes (Success As Boolean, Bytes() As Byte)
    If Success = False Then
        Log("Error building command: " & LastException)
        Return
    End If
    Dim ser As B4XSerializator = Sender
    SendJob(Job, Bytes, Tag, "batch2")
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)
    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



'Prints the table to the logs.
Public Sub GetTable(Table As DBResult) As List
    Dim li As List
    Dim  CLEUNIQUE As Int
    Dim ii As Int
   
    li.Initialize
'        Log("Tag: " & Table.Tag & ", Columns: " & Table.Columns.Size & ", Rows: " & Table.Rows.Size)
    Dim sb As StringBuilder
    Dim sf As List

    sf.Initialize
    CLEUNIQUE=-1
    ii=0
    For Each col In Table.Columns.Keys
        If col<>"cleunique" Then
            sf.Add(col)
        Else
            '        Msgbox("cleunique","cleunique")
            CLEUNIQUE=ii
        End If
        ii=ii+1
    Next
    li.Add(sf)

    For Each row() As Object In Table.Rows
        Dim sb As StringBuilder
        sb.Initialize
        Dim lit As List
        lit.Initialize
        ii=0
   
        For Each record As Object In row
            If CLEUNIQUE<>ii Then
                lit.Add(record)
                sb.Append(record).Append(CRLF)
            End If
            ii=ii+1
        Next

        li.Add(lit)
       
       

   
    Next
    Return li

End Sub
CreateRequest:
Dim req As DBRequestManagerB = module1.CreateRequest(Me)
Dim CMD2 As DBCommand = module1.CreateCommand("getwebupdate", Array As Object())
Wait For (req.ExecuteQuery(CMD2, 0,  "GETDATABASES"    ) )  JobDone(j As HttpJob)

If j.Success=True Then
''''
end if
CreateRequest:
Sub CreateRequest(target As Object) As DBRequestManagerB
   Dim req As DBRequestManagerB
'    Log("module1 create request serveur ip:"&ServerIP)
   req.Initialize(target, "http://"&StoreIP&":17178")
 
   Return req
End Sub


Sub CreateCommand(Name As String, Parameters() As Object) As DBCommand
   Dim CMD2 As DBCommand
   CMD2.Initialize
   CMD2.Name = Name
   CMD2.Parameters = Parameters
'        Log("CREATE COMMAND: "&Name)

    If Name<>"cbupboisson" And Name<>"cbgetboisson" Then
'        Log("CREATE COMMAND: "&Name)
       End If
   Return CMD2

End Sub
 
Last edited:
Upvote 0

lucas555

Member
Licensed User
Longtime User
DBREquestManagerB is the same as yours but i add gettable in it

Update : It is Fixe Now :) -> i use your DBREquestManager and added my GetTable Sub

Thank you Erel
 
Upvote 0
Top