B4J Question Fast Net For B4J

MJA_Hack

Member
Hi @Earl, I am currently working on building a cross-platform project for B4A and B4J. Previously, I had completed the same project fully for B4A and it had good results. When I decided to work on the project for Windows, I used B4X instead. The issue I am facing is with retrieving data from an online database, which accounts for almost 90% of my project. In B4A , I used the FastNet library which allowed me to quickly retrieve data from the database, even when there were over 1000 fields in a table. However, this library does not exist for B4J. Therefore, I was forced to use the jokhttputlis2 library, which has two fundamental issues for B4J. Firstly, it takes approximately half a second to retrieve and save data offline for each ID, and if the internet speed is slow, it could take longer. Secondly, while retrieving data online, no other thread can be performed, and the program becomes unresponsive until all data is retrieved. I was wondering if there is any way to use a library similar to FastNet within B4J, which allows for quick retrieval of all data from an online database.

Wait For:
jb_amar.PostString("http://example.com/upload_amar.php","")
        Wait For JobDone (job As HttpJob)
        If job.Success Then
            Upload(job)
        Else
            log("Not Success")
        End If

job done sub:
Sub Upload (job As HttpJob)
If job.GetString = Null Then
        log("Null")
    Else
        js_amar.Initialize(job.GetString)
        map_amar = js_amar.NextObject
        list_amar = map_amar.Get("result")
        For Each row As Map In list_amar
            If Deletecount = False Then
                sql_amar.InitializeSQLite(File.DirApp&"/data/", "db.db", True)
                sql_amar.ExecNonQuery("DELETE FROM tbl")
                sql_amar.Close
            End If
            Deletecount=True
            id = row.Get("id")
            user = row.Get("user")
            line = row.Get("line")
            working = row.Get("working")
            recovery = row.Get("recovery")
            If sql_amar1.IsInitialized = False Then
                sql_amar1.InitializeSQLite(File.DirApp&"/data/", "db.db", True)
            End If
            sql_amar1.ExecNonQuery("INSERT INTO tbl (id,user,line,working,recovery) VALUES ('"&id&"','"&user&"','"&line&"','"&working&"','"&recovery&"')")
            Log(id)
        Next
        sql_amar1.Close
        num = num + 0.4
        ProgressBar1.Progress = num
        Log("Frist Upload"&ProgressBar1.Progress)
        Deletecount=False
    End If
End Sub
 
Last edited:

MJA_Hack

Member
"Thank's @Erel for your response. Unfortunately, I was not able to understand the jRDC example codes. If possible, could you please send me the jRDC codes in a summary format for my PHP file?

Additionally, I have included the Fast Network library codes that I used in B4a for you below. Unfortunately, this library is private and I do not have permission to share the original library file."

my php file:
 <?php
  $databasehost = "";
  $databasename = "";
  $databaseusername = "";
  $databasepassword = "";

    $con = mysqli_connect($databasehost,$databaseusername,$databasepassword,$databasename);
    if ($con){
        mysqli_query($con,"SET CHARACTER SET utf8");
        $query1 = "SELECT * FROM tbl ORDER BY id ASC";
        $result = mysqli_query($con,$query1);
        $rows1 = array();
            while($row1=mysqli_fetch_array($result)){   
                $temp1["id"]=$row1['id'];
                $temp1["user"]=$row1['user'];
                $temp1["line"]=$row1['line'];
                $temp1["working"]=$row1['working'];
                $temp1["recovery"]=$row1['recovery'];
                $rows1[]=$temp1;
            }
      
    }else{
        print 'null';
    }   
     print json_encode(array("result"=>$rows1),JSON_UNESCAPED_SLASHES);
     mysqli_close($con);
?>

and My B4A PersianFastNetwork cods
PERSIANFASTNETWORK LIBRARY:
Dim pr As PersianFastNetwork
Dim post As PostRequest
pr.initialize("pr")
post = pr.BuildPostQuery("http://example.com/mysql_b4a/upload.php","pr")
post.executRequest

Sub pr_amar_onSucsess(Result As String  , Tag As Object)
    ProgressDialogHide
    If Result = Null Then
        toast.Initialize("null",toast.Duration_LONG,toast.Type_ERROR)
    Else
        Dim prjobj As PersianJSONOBject
            prjobj.initialaizJsonString(Result)
        Dim prjarray As PersianJSONArray=prjobj.getJsonArray("result")
        For i=0 To prjarray.size-1
            Dim prjobj1 As PersianJSONOBject=prjarray.getJsonObject(i)
                If Deletecount = False Then
                    cu =  Main.db.ExecQuery("DELETE FROM tbl")
                    cu.Position=0
                    cu.Close
                End If
                Deletecount=True
                idamar = prjobj1.getString("id")
                user = prjobj1.getString("user")
                line = prjobj1.getString("line")
                working = prjobj1.getString("working")
                recovery = prjobj1.getString("recovery")
                cu1 = Main.db.ExecQuery("INSERT INTO tbl (id,user,line,working,recovery) VALUES ('"&id&"','"&user&"','"&line&"','"&working&"','"&recovery&"')")
                cu1.Position=0
                cu1.Close
                Log(id)
        Next
    End If
End Sub


this library is very very fast post and get online data .
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Try to create a sample project from my template

 
Upvote 0
Top