Wish SQlite json_object

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
B4X:
SELECT json_group_array(json_object('col1', col1, 'col2', col2,'col3', col3, 'col4', col4)) AS json_result FROM (SELECT * FROM tablename);
'It throughs error: android.database.sqlite.SQLiteException: no such function: json_object (code 1 SQLITE_ERROR[1]): , while compiling: ......
 

alwaysbusy

Expert
Licensed User
Longtime User
For me it works. What version of the sqlite-jdbc jar do you use? I use sqlite-jdbc-3.36.0.3.jar (https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc/3.36.0.3)

B4X:
#AdditionalJar: sqlite-jdbc-3.36.0.3
...
Dim results As ResultSet = SQL.execquery("Select json_group_array(json_object('id',id, 'deviceid', deviceid)) AS json_result FROM users;")
If results.NextRow Then
        Log(results.GetString("json_result"))
End If

Result:
B4X:
[{"id":1,"deviceid":"b8cdaaf4-1f38-4b51-9fd7-e8c0ad8286b5"},{"id":2,"deviceid":"1d66f64c-c770-49dc-a747-1dbe12160de5"},{"id":3,"deviceid":"e4da9483-dad0-4209-adec-40f15f164474"},{"id":4,"deviceid":"2e17a510-6c47-4302-a59b-c968d0780db4"},{"id":5,"deviceid":"8cf0014f-a86a-4f90-88ae-db753e5aa9a1"},{"id":6,"deviceid":"50ddccfc-2d3d-4593-bde8-b24408a1bcc6"},{"id":7,"deviceid":"b4bb9b04-d78f-413e-88cf-dd0182182bd2"},{"id":8,"deviceid":"1cf07fb0-ff3a-4e00-901e-3cceecf9b672"},{"id":9,"deviceid":"4a68a6df-181d-41d2-8f2a-c7026b531777"},{"id":10,"deviceid":"e091d8f8-302b-434e-ad9f-2a89ba072a2b"},{"id":11,"deviceid":"22360eeb-c8a0-47d5-b394-f932e603a17e"},{"id":12,"deviceid":"6c97e264-f850-4749-a4ce-5ba239be97dc"},{"id":13,"deviceid":"865ac405-f332-4cdf-812f-8bbb7815db77"},{"id":14,"deviceid":"d7298f89-8d45-4f22-9b68-68f68461ba09"},{"id":15,"deviceid":"cd2df98b-30a3-43e2-8766-ceaf13acaca9"},{"id":16,"deviceid":"20925ff0-07a0-4105-978a-9c84a138d18a"},{"id":17,"deviceid":"38e9f5b8-713b-4341-a9aa-fb3e97174a15"},{"id":18,"deviceid":"d2b88be2-5bf5-4bcf-a83b-a40fb2a42f30"},{"id":19,"deviceid":"fe3c4647-c363-40ac-87eb-0923816f1888"},{"id":20,"deviceid":"489447da-717d-4715-ae5d-d5e2fdc18479"},{"id":21,"deviceid":"cb2f34c5-44ca-465e-959f-625dca52492a"}]

Alwaysbusy
 
Top