B4J Question AddNonQueryToBatch

johnB

Active Member
Licensed User
Longtime User
I would be grateful if somebody can tell me what is wrong with my code. I get Success = True but not records in the DB. The AddNonQueryToBatch seems to be correct

B4X:
    Main.SQL1.ExecNonQuery("DROP TABLE Test_Load")
    Main.SQL1.ExecNonQuery("CREATE TABLE IF NOT EXISTS Test_Load(Close INTEGER)")

    For i = 1 To 1000
        Main.SQL1.AddNonQueryToBatch("INSERT INTO Test_Load VALUES (?)", Array(i))
    Next
    Dim SenderFilter As Object = Main.SQl1.ExecQueryAsync("SQL", "SELECT * FROM Test_Load", Null)
    Wait For (SenderFilter) SQL_QueryComplete (Success As Boolean, rs As ResultSet)
    If Success Then
        Do While rs.NextRow
            Log(rs.GetInt2(0))
        Loop
        rs.Close
    Else
        Log(LastException)
    End If

I also tried

B4X:
Main.SQL1.ExecNonQuery("PRAGMA journal_mode = wal")

But I got an error message. I put it immediately after the Create statement

Thanks
 

DonManfred

Expert
Licensed User
Longtime User
Compare your code with Erels.... Xou are adding the queries to the Batch but you did not Execute the Batch.

For i = 1 To 1000
Main.SQL1.AddNonQueryToBatch("INSERT INTO Test_Load VALUES (?)", Array(i))
Next
Dim SenderFilter As Object = Main.SQl1.ExecQueryAsync("SQL", "SELECT * FROM Test_Load", Null)


B4X:
For i = 1 To 1000
   sql.AddNonQueryToBatch("INSERT INTO table1 VALUES (?)", Array(Rnd(0, 100000)))
Next
Dim SenderFilter As Object = sql.ExecNonQueryBatch("SQL")
 
Upvote 0

johnB

Active Member
Licensed User
Longtime User


Thanks Don

Don't know where I got that code from, thought that I copied it from somewhere
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…