sqlite query runtime error - android

I was working with sqlite but I end up with this error.I'm not getting what is error here.
Below is my logcat.
android.database.sqlite.SQLiteException: near "/": syntax error: , while compiling:
SELECT start,end FROM crop_list WHERE name =/sdcard/Shri Ramachandra kripalu bhajamana.mp3

I think your problem is you forget to add the quotes marks (' ') like:
SELECT start,end FROM crop_list WHERE name ='/sdcard/Shri Ramachandra kripalu bhajamana.mp3'.

why do you not use class helper and Helper.dabase.query(.....) <- it is faster ;) around 2 segons faster that helper.dabase.rawquery ;)
SQLiteOpenHelper | Android Developers <-- best practice

Related

Android Database Sugar orm no such table

i'm working on a project in android ! And i use Sugar ORM for the interaction with my database.But i think sugar become crazy sometimes. I have an error No such Column while compiling.I dont understand ! Anywhere in the code I put it.
public List<Plats> getAllplatById(){
return Plats.find(Plats.class ,NamingHelper.toSQLNameDefault("id_menus")+"= ?" ,String.valueOf(id));
}
And i got this error :
Caused by: android.database.sqlite.SQLiteException: no such column: IDMENUS (code 1): , while compiling: SELECT * FROM PLATS WHERE IDMENUS=
Please Help me.
First option is that you should raise the value of your database version in the Manifest.xml:
<meta-data android:name="VERSION" android:value="2" />
That should be done every time you change something of the classes that you save in your database.
The other option is that you just pick the wrong column name.
I think you should try: "ID_MENUS" as column name and not use the NamingHelper. Because i've seen that kind of names more then IDMENUS ("example).

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.

ActiveAndroid migration not an error (code 0), syntax error

Does ActiveAndroid not support the "not in" syntax in migrations?
Does ActiveAndroid not support subqueries in migrations?
I've run into exceptions like these when running migrations:
java.lang.RuntimeException: Unable to create application com.example.app.YourApp: android.database.sqlite.SQLiteException: not an error (code 0)
Or
java.lang.RuntimeException: Unable to create application com.example.app.YourApp: android.database.sqlite.SQLiteException: near "in": syntax error (code 1): , while compiling: delete from Collections where _id not in
The answer is that ActiveAndroid doesn't support something else (at least not currently): each migration statement must be ONE line, ending in a semicolon.
If you separate a sql query into multiple lines, ActiveAndroid will take only the first line, and give you different exceptions (such as the above) depending on where your query got cut off.
Save yourself some time and kill some readability: ActiveAndroid migrations cannot contain newlines (especially likely to run into this if you were trying to make subqueries readable).

SQL Syntax Error Android

I am getting an SQL syntax error but I'm not quite sure why. This is the error code I am obtaining;
android.database.sqlite.SQLiteException: near "GCSE": syntax error (code 1): , while compiling: SELECT foreign_word,english_meaning,correct FROM vocab_words WHERE name = AQA GCSE Spanish Higher
Any suggestions to fix this - I don't know what the error is?
when the column's data type is string, its value should be wrapped with single quote.
SELECT foreign_word,english_meaning,correct
FROM vocab_words
WHERE name = 'AQA GCSE Spanish Higher'

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