I am trying to create simple sqlite table to json and vice versa
Below code gives the json from sqlite table (here I use the strings.db of localizator as example). Ok here.
Below code I try to insert the above json to similar db "strings_empty.db
But not working. I think the "lstRoot2" is not correct format for InsertMaps.
Any idea how to solve it ?
BTW I got the above codes from below, thanks to @LucaMs
Below code gives the json from sqlite table (here I use the strings.db of localizator as example). Ok here.
B4X:
Dim JSONGen As JSONGenerator
JSONGen.Initialize(DBUtils.ExecuteJSON(sql, "SELECT key, lang, value FROM data", Null, 0, Array As String(DBUtils.DB_TEXT, DBUtils.DB_TEXT, DBUtils.DB_TEXT)))
Dim JSONString As String
JSONString = JSONGen.ToPrettyString(4)
Log(JSONString)
Below code I try to insert the above json to similar db "strings_empty.db
B4X:
Dim lstRecords2 As List
lstRecords2.Initialize
Dim parser2 As JSONParser
parser2.Initialize(JSONString)
Dim mapRoot2 As Map = parser2.NextObject
Dim lstRoot2 As List = mapRoot2.Get("root")
Log(lstRoot2)
Dim result2 As Boolean = DBUtils.InsertMaps(sql2, "data", lstRoot2)
Log(result2)
Log(LastException)
But not working. I think the "lstRoot2" is not correct format for InsertMaps.
Any idea how to solve it ?
BTW I got the above codes from below, thanks to @LucaMs
Exporting Sqlite data
Hi all, which could be the preferable way to export some data from an internal sqlite table? A bit of context. An app stores some data in one or more tables while the DB is initialized in DirInternal. A SELECT statement is needed to extract only some data. Columns are of different data types...
www.b4x.com