Android Question Send data from SQLite(Local) to MySQL(Remote)

dhernandez

Active Member
Licensed User
Longtime User
Good morning to all.
Again consult with you this difficulty I have.
My app collects data entered by the user and stored in the external memory in SQLite.
It has a submit button, you should do the following:
- Perform a SELECT from the SQLite database and sent to a
remote MySQL server
How do I do that?
I want that when you do the SELECT to local SQLite, Collect and send data to the remote server (MySQL).

I am using PHP and JSON to send data to MySQL, but when sending data, I add fields Null, without information.

thanks.

Sorry for my English
 

dhernandez

Active Member
Licensed User
Longtime User
Thanks for answering Erel.
Look, I used the PHP Connection because he could not properly configure the DRC.
In doing with PHP connecting and sending directly from my mobile phone to the remote server is successful.

But to make the extraction of information from the mobile database and send it to the remote (MySQL), it fails. sends blank data ...
I suspect the problem is in the extraction of data from mobile.

Here my Code.

B4X:
'Activity module
Sub Process_Globals
    Private MODELO_LISTA="modelo_lista", MODELO_EXISTENCIA="modelo_existencia" As String
    Dim SQL1 As SQL
    Dim cursor1 As Cursor
End Sub
Sub Globals
    'Objetos a utilizar
    Dim TxtID As EditText
    Dim TxtTipo As EditText
    Dim TxtModelo As EditText
    Dim TxtStock As EditText
    Dim TxtUsuario As EditText
    Dim Enviar As Button
    Dim Guardar As Button
   
    'Variables para almacenar momentaneamente Informacion de la base de datos Local
    Dim IDCARTUCHO, TIPOCARTUCHO,MODELOCARTUCHO, STOCKCARTUCHO, USUARIOCARTUCHO As Cursor
End Sub
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("AndroidPhp")
    Enviar.Text="Guardar"
        If File.Exists(File.DirDefaultExternal,"adb.db")=False Then
            File.Copy(File.DirAssets, "adb.db", File.DirDefaultExternal, "adb.db")
        End If
    If SQL1.IsInitialized=False Then
        SQL1.Initialize(File.DirDefaultExternal, "adb.db",False)
    End If
    End Sub
Sub EjecutarConsulta
    'ExecuteRemoteQuery("INSERT INTO cartuchos(ID_Cartucho, tipo_cartucho, modelo_cartucho, stock_cartucho, usuario_cartucho) VALUES('" & TxtID.Text & "', '" & TxtTipo.Text & "', '" & TxtModelo.Text & "', '" & TxtStock.Text & "', '" & TxtUsuario.Text & "')",MODELO_LISTA)
End Sub
Sub ExecuteRemoteQuery(Query As String, JobName As String)
    Dim job As HttpJob
    job.Initialize(JobName, Me)
    job.PostString("http://192.168.2.142/Info.php", Query)

End Sub

Sub JobDone(Job As HttpJob)
   
End Sub

Sub Activity_Resume

End Sub
Sub Activity_Pause (UserClosed As Boolean)

End Sub
'Declaro las variables Para que guarden las consultas en ellas.
Sub ForID
    IDCARTUCHO=SQL1.ExecQuery("SELECT id_cartucho FROM cartuchos")
        For i = 0 To IDCARTUCHO.RowCount -1
            IDCARTUCHO.Position = i
        Next
            IDCARTUCHO.Close
End Sub
Sub ForTipo
    TIPOCARTUCHO=SQL1.ExecQuery("SELECT tipo_cartucho FROM cartuchos")
        For i = 0 To TIPOCARTUCHO.RowCount -1
            TIPOCARTUCHO.Position = i
        Next
            TIPOCARTUCHO.Close
End Sub
Sub ForModelo
    SQL1.ExecQuery("SELECT modelo_cartucho FROM cartuchos")
        For i = 0 To MODELOCARTUCHO.RowCount -1
            MODELOCARTUCHO.Position = i
        Next
            MODELOCARTUCHO.Close
End Sub
Sub ForStock
    STOCKCARTUCHO=SQL1.ExecQuery("SELECT stock_cartucho from cartuchos")
        For i = 0 To STOCKCARTUCHO.RowCount -1
            STOCKCARTUCHO.Position = i
        Next
            STOCKCARTUCHO.Close
End Sub
Sub ForUsuario
    USUARIOCARTUCHO=SQL1.ExecQuery("SELECT usuario_cartucho FROM cartuchos")
        For i = 0 To USUARIOCARTUCHO.RowCount -1
            USUARIOCARTUCHO.Position = i
        Next
            USUARIOCARTUCHO.Close
End Sub
Sub Enviar_Click
    'Aqui Recojo los datos de las variables y las envío al servidor remoto...
        ExecuteRemoteQuery("INSERT INTO cartuchos(ID_Cartucho, tipo_cartucho, modelo_cartucho, stock_cartucho, usuario_cartucho) VALUES('" & ForID & "','" & ForTipo & "','" & ForModelo & "','" & ForStock & "','" & ForUsuario & "')",MODELO_LISTA)
        TxtID.Text=""
        TxtTipo.Text=""
        TxtStock.Text=""
        TxtModelo.Text=""
        TxtUsuario.Text=""
        TxtID.RequestFocus
End Sub

Make your query, but I think the performs poorly, because I inserted empty fields ..
and to verify data from the SQLite database of Mobile, there is the information.
 
Upvote 0

dhernandez

Active Member
Licensed User
Longtime User
I am very novice to understand that.
Where I can upload my file for you to see and guide me?
 
Upvote 0
Top