This is the message from LogCat:
no such column: dkbdxfywpbkb (code 1): , while compiling: SELECT meetup_event_id FROM events WHERE meetup_event_id = dkbdxfywpbkb
Why is it trying to find a column called "dkbdxfywpbkb" when the selection argument is "....WHERE meetup_event_id = dkbdxfywpbkb"
I have checked that column "meetup_event_id" exists and is of type text.
Notes:
This query works fine except when the value(in this case "dkbdxfywpbkb") I am searching for is a piece of text rather than a number.
The value(in this case "dkbdxfywpbkb") I am searching for is from the Meetup API and not generated by my app.
I think you need single quotes. You want a string constant:
SELECT meetup_event_id
FROM events
WHERE meetup_event_id = 'dkbdxfywpbkb';
Without the quotes, SQLite thinks the string value is an identifier (numbers are treated differently from strings in this respect).
Related
In Android SQLite i got tabel like this
domainObjectId: String // like '9876543210'
name: String
description: String
I want to use FTS on this to search without worrying about diacritical marks, how ever i want to let user select also by typing part of object ID(ex. last 4 char)
I got select like
`SELECT * FROM tabel LEFT JOIN tabel_fts on tabel_fts.domainObjectId = tabel.domainObjectId WHERE tabel_fts MATCH '3210*' OR tabel.domainObjectId LIKE '%3210%'
But in return i get error
unable to use function MATCH in the requested context (code 1 SQLITE_ERROR);
Is this possible to add additional condition to select with MATCH?
Try to remove "MATCH" into separate "SELECT":
`SELECT * FROM tabel LEFT JOIN (select * from tabel_fts WHERE tabel_fts.domainObjectId MATCH '3210*') as tabel_fts WHERE tabel.domainObjectId LIKE '%3210%' OR table_fts.ID IS NOT NULL
By the way:
In your "WHERE tabel_fts" it seemed you've missed a column name
There is no "ON" condition in tables JOINm just "WHERE". That's OK? May be it would be better to use UNION?
I got a scenario where I have to find all rows in Android SQLite db, where a particular column field value lies in the input string. For example,
Input string:
I am not done yet, I can’t call it a day I need to work more for couple of hours.
Now my table in SQLite(Android) has a column called Title
I need to find all rows whose Title column field values lies in above input string. Basically I want following rows
where the full Title string is like one of below
call it a day
am not done yet
I want to know if it is possible using a single query in sqlite Android or not. What I know is LIKE query work on opposite manner.
Given that your table contains a column title which has titles that you want to match in the given string, you can do concatenation with % to use LIKE
select *
from your_table
where 'your input string here' like '%' || title || '%'
Having a weird issue here where a query executes just fine in Sqlite DB Browser on my desktop - results exactly as expected - but throws an exception when executing a Cursor in Android (4.4.2). I'm new to both Android and Sqlite so maybe there's a "gotcha" I haven't discovered yet.
Simple query:
select
max(_id) as '_id',
max(envid) as 'envid',
max(action) as 'action',
max(title) as 'title',
max(cast(version as INTEGER)) as 'version',
max(layout) as 'layout'
from template
where direction = 'return'
group by title
Exception:
E/AndroidRuntime(20731): Caused by:
android.database.sqlite.SQLiteException: aggregate functions are not
allowed in the GROUP BY clause (code 1): , while compiling: select
max(_id) as '_id', max(envid) as 'envid', max(action) as 'action',
max(title) as 'title', max(cast(version as INTEGER)) as 'version',
max(layout) as 'layout' from template where direction = 'return' group
by title
I'd expect to see that if I put an aggregate function in the group by clause...but I haven't.
This fixed it - which is all I really needed (see comment from Rohit5k2 above.)
select _id, envid, action, title, max(cast(version as INTEGER)) as 'version', layout from template where direction = 'return' group by title
SELECT * FROM <TableName> WHERE <attribute(id)> IN <ArrayList type>
but theres an error
04-24 21:18:41.748:
ERROR/Error(29495):
android.database.sqlite.SQLiteException:
no such table: 1: , while compiling:
SELECT * FROM Main WHERE id IN [1]
basically i want to select those rows with Attribute(id) which are present in an ArrayList...
but the format of the ArrayList is not the same as the one reqd for this type of query(i guess)
and i think this is the reason, its not workin correctly
if i query it with:
SELECT * FROM <TableName> WHERE <attribute(id)> IN <Integer>
it shows me the correct result... but obv it only selects that particular id's row...
note: ArrayList is replaced with Integer... (which is the data-type of my attribute(id))
Thanks in advance :)
There is no such thing as IN <ArrayList type>.
You need to compute the enumerating string yourself by using JAVA code.
SELECT * FROM <TableName> WHERE _id IN ('1','2','3','4','5')
Also please note that on Android the primary key is recommended to be _id with underscore.
When working with apps, I prefer to let the List I'm using to contain the elements it's holding like:
List<ElementType> = ...
By doing this, you can simply ask each element for their id's. Pentium10's solution will do the job, but I prefer doing this as it gives more flexibility.
I have code that gives me a number, and I have an Android SQLite table.
The first column has a lots of numbers and I need to compare the number that I got from the code to these numbers in the table and find the one that matches my number that I got from the code. Once I find it, I need to update the row.....
what is the best way to do it.....?
Your question lacks details, like the name of the column holding the number value and the column(s) being updated when the record is found, but you'll be using something that resembles:
UPDATE your_table
SET column_1 = ?,
column_2 = ?
WHERE number_column = number_from_code