Error in studio SQLiteException: json_each - android

I have json Array in my column and i want to extract json array as separate values I am using sqlite query
SELECT
json_extract(t2.value, '$.time') as time
FROM
json_each((SELECT column_name
FROM tbl_name)) AS t2
My column looks like this
[{"time":0,"value":0},{"time":2,"value":0},{"time":0,"value":0}]
It works fine in sqlite browser but I get an error in Android studio.
SQLiteException: no such table: json_each (code 1):
Update: I am using room database and it works fine for other queries

json_each and json_extract would need JSON1 extension. It's not available on Android. You need to do your json mapping in code.

Related

sql lite dynamic Query for sqllite-pcl xamarin forms

i have created dynamic tables in Xamarin forms by using SQLite queries
string cmdStr="CREATE TABLE Mytable ....";
i am able to create table using
SQLiteCommand command = new SQLiteCommand(sqlitConnection);
command.CommandText = cmdStr;
command.ExecuteNonQuery();
the above code is working fine ,i am able to save data to sql lite db
i am unable to get data from db using command.ExecuteQuery() using command string as "select * from Mytable". as seen in screenshot i am unable to fetch content from dynamic tables,please suggest any alternatives
enter image description here
The error message tells you exactly what is wrong - you are not specifying a Type argument T. The correct syntax is
List<T> results = command.ExecuteQuery<T>();
where T is the name of the class you are mapping the results to

Syntax Error using Vacuum Into on Android

I'm trying to make a backup of a database in an Android application, and I was pointed to the VACUUM INTO query. However, when I try to call it, I get a syntax error around "INTO":
Caused by: android.database.sqlite.SQLiteException: near "INTO": syntax error (code 1 SQLITE_ERROR): , while compiling: VACUUM INTO 'Test'
The String itself:
String query = "VACUUM INTO 'Test'";
I've tried using double quotes, single quotes, different path names, .db, no file type, including and excluding the database name - always the same error.
Is INTO not supported on Android's implementation of SQLite?

How to attach a database in Room?

I tried to attach database in Android Room like this: How to select from multiple databases in Android Room(How to attach databases) but i got error when building project:
error: There is a problem with the query: [SQLITE_ERROR] SQL error or missing database (no such table: database.table)
Error concerns
#Query("select t.id as tid from mydatabase.mytable t")
public List<MyPojo> getMyTableIds();
When I added #SkipQueryVerification, error changed on: error: Not sure how to convert a Cursor to this method's return type.
Error dissapears when I remove "mydatabase." from Query.
How to attach database in Android Room and make cross databases query?
You can attach your another database in onOpen callback. For details see the answer of another post here.

Why do I get syntax error when creating a view with column names?

Developing an Android app, but this is a SQLite question.... My SQL is much ropier than my Java.
This is the SQL (copied from a log file, in code it's constructed from various constants):
CREATE VIEW albums (_id, name , type ) AS SELECT rowno, name, subtype FROM metadata WHERE subtype = 'album'
but it throws:
android.database.sqlite.SQLiteException: near "(": syntax error (code 1): , while compiling:
Specifying column names in the view seems to me to be clearly permitted, if I understand the flow chart in the sqlite documentation here, and at this time of night I really can't see what's wrong. I have tried changing the name of the _id column in case it was something to do with the initial underscore, but to no avail and in any case I will need the _id column later for the CursorAdapter that will end up using this View.
At the bottom of the documentation page you linked it states:
Note that the column-name list syntax is only supported in SQLite
versions 3.9.0 and later.
Version 3.9.0 is not supported by Android. Lollipop has 3.7.11. Marshmallow has 3.8.10.2.

SQL error when using two tables in Android

I'm trying to get orders sorted by the customers delivery order.
This SQL statement works in my desktop database, but when I run it on the Android I get an error.
I tried using _id as well.
near "c": syntax error: , while compiling: SELECT * FROM Orders o,
Customer c WHERE o.Route='My Route' c.id=o.Customernum ORDER BY
c.StopNum
Your SQL statement is missing an AND:
SELECT * FROM Orders o, Customer c WHERE o.Route='My Route' AND
c.id=o.Customernum ORDER BY c.StopNum

Categories

Resources