I've got search query "aa bb" and also there is "aa bb cc" row in table. So my sql query should return that row. This is how I do:
select * from company
where
(ASCII_NAME like %'aa'%
and ASCII_NAME like %'bb'%)
and CITY_ID=0 and parent=-1;
But my log says:
android.database.sqlite.SQLiteException: near "%": syntax error (code
1): , while compiling: select * from company where (ASCII_NAME like
%'aa'% and ASCII_NAME like %'bb'%) and
CITY_ID=0 and parent=-1
What is wrong?
Your syntax is wrong
select * from company
where
(ASCII_NAME like '%aa%'
and ASCII_NAME like '%bb%')
and CITY_ID=0 and parent=-1;
Include % sign in single quotes.
Like:
select emp_name from employee where emp_name like '%s%';
Related
I am trying to create a static list of timestamps so that i can join them agains another table to create chart data. So far I have a query in this format SELECT * FROM (VALUES('a'),('b'),('c'),('d')) AS tbl ,which is working in sqlitestudio but not in android 4.4. When I run the query in the phone I get the error
android.database.sqlite.SQLiteException: near "VALUES": syntax error (code 1): , while compiling: SELECT * ...
I have also tried wrapping the values term inside another select like this SELECT * FROM (SELECT * FROM (VALUES('a'),('b'),('c'),('d'))) AS tbl but I still get the same error.
The full query now looks like this
SELECT * FROM (select * from ( VALUES (1458111312025),
(1455667200000),
(1455753600000),
(1455840000000),
(1455926400000),
(1456012800000),
(1456099200000),
(1456185600000),
(1456272000000),
(1456358400000),
(1456444800000),
(1456531200000),
(1456617600000),
(1456704000000),
(1456790400000),
(1456876800000),
(1456963200000),
(1457049600000),
(1457136000000),
(1457222400000),
(1457308800000),
(1457395200000),
(1457481600000),
(1457568000000),
(1457654400000),
(1457740800000),
(1457827200000),
(1457913600000),
(1458000000000),
(1458086400000))) i LEFT JOIN (
SELECT (osysdate- (osysdate % 86400000) ) interval, SUM(field004) totalval FROM onlineactivities WHERE field003 !=300000 and osysdate> 1455605711999 GROUP BY interval )
onl ON i.'' = onl.interval;;
Note that this works in sqlitestudio with sqlite version 3.8.10 but not in android kitkat (not sure about the sqlite version in it) What could be the problem?
Also please check out this question which is what I am trying to do but with sqlite and this answer
The VALUES syntax is available since SQLite 3.8.3, which is not available in every Android version.
To be compatible with earlier SQLite versions, you have to use a compound query:
SELECT 1458111312025 UNION ALL
SELECT 1455667200000 UNION ALL
...
Alternatively, put all the values into a temporary table.
I'm trying to write a simple query that fetches all the columns of a specific table, but also adds a count of rows from a related table.
Here is the query:
SELECT
todos.*,
(SELECT COUNT(assets.*) FROM assets WHERE assets.parent_id = todos._id) AS asset_count
FROM todos
Here is the error:
Caused by: android.database.sqlite.SQLiteException: near "*": syntax error (code 1): , while compiling: SELECT todos.*, (SELECT COUNT(assets.*) FROM assets WHERE assets.parent_id = todos._id) AS asset_count FROM todos
try replace COUNT(assets.*) for COUNT(*) or COUNT(assets._id)
my second suggestion, try running the inside select like a single one
SELECT COUNT(*) FROM assets WHERE assets.parent_id = 1 <-- any _id you have
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
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
all.
I've found in bugsense for Android application this exeception:
android.database.sqlite.SQLiteException: no such column: ۱۵۳۶۱۹۸۶۸۴۰۰۸۵۴۲۵۴۱ (code 1): , while compiling:
SELECT * FROM by_istin_android_xcore_source_DataSourceRequestEntity WHERE (_id = -۱۵۳۶۱۹۸۶۸۴۰۰
Seems like try to select with filter by arabic number.
Someone see it before?
If _id is a numeric column, you must change your code to generate numbers with ASCII digits.
If _id contains strings, you must change your code to 'quote' the string.