Android Question RDC remote database INSERT

Declan

Well-Known Member
Licensed User
Longtime User
I am attempting to insert records from a local SQLite table to a remote MySQL database table.
I can insert single records (with multiple fields) with no problem.
What I now need to accomplish is sending multiple records from the SQLite table.
Is the following code correct, or is there a more efficient/correct method:
B4X:
    Dim Curs As Cursor
    Curs = Starter.SQL0.ExecQuery("SELECT * FROM bookstime")
    Curs.Position = 0
   
    For i = 0 To Curs.RowCount - 1
        Curs.Position = i
        username = Curs.GetString("username")
        booktitle = Curs.GetString("booktitle")
        userid = Curs.GetString("userid")
        isbn = Curs.GetString("isbn")
        date = Curs.GetString("date")
        booktime = Curs.GetString("booktime")
       
        Dim cmd As DBCommand
        cmd.Initialize
        cmd.Name = "insert_bookstime" 
        cmd.Parameters = Array As Object(Null, username, booktitle, userid, isbn, date, booktime )
        reqManager.ExecuteCommand(cmd, "insert_bookstime")
    Next
 

Declan

Well-Known Member
Licensed User
Longtime User
Ok, I have tried:
B4X:
            Dim CursorLog As Cursor
            Dim i As Int
            Dim commands As List
            commands.Initialize
'            CursorLog = Starter.SQL0.ExecQuery("Select col1,col2 from Table1")
            CursorLog = Starter.SQL0.ExecQuery("SELECT id,username,booktitle,userid,isbn,date,booktime FROM bookstime")
                Dim commands As List
                commands.Initialize
                For i = 0 To CursorLog.RowCount - 1
                 CursorLog.Position = i
                 Dim cmd As DBCommand
                 cmd.Initialize
                 cmd.Name = "insert_bookstime"
                 cmd.Parameters = Array(CursorLog.GetString("id"), CursorLog.GetString("username"), CursorLog.GetString("booktitle"), CursorLog.GetString("userid"), CursorLog.GetString("isbn"), CursorLog.GetString("date"), CursorLog.GetString("booktime"))
                 commands.Add(cmd)
                Next
                reqManager.ExecuteBatch(commands, "insert_bookstime")
My Server config file, I have this line:
B4X:
sql.insert_bookstime=INSERT INTO bookstime VALUES (?,?,?,?,?,?,?)
But I get an error:
B4X:
Error: Server Error
 
Upvote 0
Top