sqlite match operator - android

On Android i would like to use a query similar to this:
SELECT docid FROM docs WHERE docs MATCH '("sqlite database" OR "sqlite library") AND linux'
http://www.sqlite.org/fts3.html#section_3
The problem is that I got a "malformed match expression error". When I do more basic match query it works, and it seems the issue might be because of the parentheses.
When I use exactly the same statement (except the table the column name) the error is the same.
The complete error message:
sqlite returned: error code = 1, msg = statement aborts at 7: [SELECT * FROM namedays WHERE names MATCH '("sqlite database" OR "sqlite library") AND linux';] malformed MATCH expression: [("sqlite database" OR "sqlite library") AND linux], db=/data/data/org.xyz/databases/data
Any idea?

I believe you do not have SQLite compiled with the SQLITE_ENABLE_FTS3_PARENTHESIS option. As such, you can only use the Standard Query Syntax, not the Enhanced Query Syntax
You can easily verify this by executing the compile_options pragma. For example, we see that my sqlite3 doesn't have the enhanced syntax:
sqlite> PRAGMA compile_options;
DISABLE_DIRSYNC
ENABLE_COLUMN_METADATA
ENABLE_FTS3
ENABLE_RTREE
ENABLE_UNLOCK_NOTIFY
SECURE_DELETE
TEMP_STORE=1
THREADSAFE=1

Related

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.

Error with query in SQLite

My SQLLite query is not working properly. See below:
UUID i=UUID.randomUUID();
String Beregero ="INSERT INTO
contacts(id,uuid,name,phone,email,street,city,state,zip) " +
" VALUES(3,"+"'"+i.toString()+"'"+",'Patrice
Beregeron','978-555-1212','pBeregero#BostonBruins.com'," +
"'1 causeway street','Boston','Mass','01236');";
db.execSQL(Beregero);
I am receiving the following error in my log:
(table contacts has no column named uuid (code 1): , while
compiling: INSERT INTO contacts(id,uuid,name,phone,email,
street,city,state,zip) VALUES(3,'12ee5bbf-dabb-4d95-bfe7-6e6f14702add',
'Patrice Beregeron','978-555-1212','pBeregero#BostonBruins.com',
'1 causeway street','Boston','Mass','01236');)
#################################################################
The exception says it all, your table has no column name uuid created. So uninstall the app, then run it again. This error occurs only if the column is not generated.
The error message in you log clearly states the problem. The contacts table does not have a column uuid. You now could do the following:
Check if you have got right lower case vs. upper case. The column in question might be UUID instead of uuid (I don't know SQLite, but case matters in many database systems).
If the column really is not in the table yet, then add it (either by code or by hand). Read SQLite's documentation to learn how to that (I can't help you here because I don't know SQLite).
Uninstalling and re-installing the app would help only if the app would generate the database upon installing or during the first run. Since we don't know anything about the app, this might or might not be the case.
You have not added the column "uuid" in the create table "contacts" query like this :
String createTableContacts = "create table contacts ( ' uuid text ')";

Ormlite unknown ROWID

I have to find the physical location of a row by ROWID using Ormlite.
But when I tried to sort rows using ROWID it throws the exception.
java.lang.IllegalArgumentException: Unknown column name 'rowid' in table Deals
Code follows,
mDealsDao.queryBuilder().orderBy("rowid", true).query();
How can I overcome this worry ? Does any one have faced the Issue Prior... ?
Unknown column name 'rowid' in table Deals
In the future, you should show the entity in question. I suspect that your entity does not have rowid field. Rather, I guess that rowid is an internal database feature. If this is the case, you can deal with rowid in a raw sense but if you try to use it as a field, ORMLite is going to complain.
So you could use:
queryBuilder.orderByRaw("rowid") ("rowid DESC" for descending)
dao.queryRaw(...)
And other raw methods.

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.

SQLite delete syntax error

This line, mDatabase.execSQL(sql);, gives me the following error:
{ sqlite returned: error code = 1, msg = near "*": syntax error }
for Delete * from table_name Query
My SQL query is : DELETE * FROM table_name
How can I solve this?
DELETE * FROM table_name is a wrong sql command. Use DELETE from table_name
Syntax error means that basically your statement is spelled wrong and it can not be parsed. In this case error message states where exactly this error occurred - on "*" character. In such case you should go to database documentation and check proper syntax of the command you are trying to use. In case of SQLite it's here. You can find documentation about DELETE statement there, here is the link. It shows you the syntax in graphical way (called syntax diagrams or railroad diagrams) which should be quite easy to follow.
In this case, as mentioned earlier, you just can't specify "*" between DELETE and FROM. This is because you are always deleting whole rows and you can't delete individual selected columns.
If you need to delete the entire table can you use DROP TABLE IF EXISTS then recreate the table

Categories

Resources