B4J Question How to execute SQLite dump list ?

peacemaker

Expert
Licensed User
Longtime User
HI, All

Never tried, but if to update the db remotely, i think it's easy to prepare the DB dump text file, and execute after downloading.

BEGIN TRANSACTION;
CREATE TABLE [ref_sensors] ([id] INTEGER PRIMARY KEY, [subid] INTEGER, [type_ids] TEXT);
INSERT INTO ref_sensors VALUES(1,101,'101, 102');
INSERT INTO ref_sensors VALUES(2,201,201);

CREATE TABLE [sensor_commands] ([id] INTEGER PRIMARY KEY, [state_id] INTEGER, [name] TEXT, [command] TEXT);
CREATE TABLE [sensor_data] ([id] INTEGER PRIMARY KEY, [state_id] INTEGER, [val] TEXT, [time] TEXT, [stamp] TEXT);
CREATE TABLE [sensors] ([id] INTEGER PRIMARY KEY, [port] TEXT, [sensor_id] INTEGER, [type_id] INTEGER, [period] TEXT, [visible_interval] REAL, [line_color] TEXT, [point_color] TEXT, [line_size] INTEGER, [point_size] INTEGER, [active] TEXT, [linked] INTEGER, [time] TEXT, [miny] REAL, [maxy] REAL, [fixed_y] INTEGER);
COMMIT;

But how to execute it in B4J and B4A ?
 
Last edited:

aeric

Expert
Licensed User
Longtime User
I only can think to use the query batch run the commands one by one
B4X:
SQL.AddNonQueryToBatch(Query1, Null)
SQL.AddNonQueryToBatch(Query2, Null)
SQL.AddNonQueryToBatch(Query3, Null)
Dim sf As Object = SQL.ExecNonQueryBatch("SQL")
Wait For (sf) SQL_NonQueryComplete (Success As Boolean)
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Maybe this help.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Used some workaround:
B4X:
Sub Execute_DBDump(path As String, sql_object As SQL)
    If File.Exists("", path) = False Then Return
    Dim s() As String = Regex.Split(CRLF, File.ReadString("", path))
    For i = 0 To s.Length - 1
        sql_object.ExecNonQuery(s(i))
    Next   
End Sub
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I think it is less prone to errors to use a list:
B4X:
Sub Execute_DBDump(path As String, sql_object As SQL)
    If File.Exists("", path) = False Then Return
    Dim MyList As List= File.ReadList("", path)
    For Each s As String In MyList
        sql_object.ExecNonQuery(s)
    Next
End Sub
 
Upvote 0
Top