Query Error in ORMLite Update Raw - android

String sql3 = "INSERT INTO temp_d_takingOrder(
HeaderId,
ItemCode,
Qty1,
Qty2,
Qty3,
RegDisc,
ExtraDisc,
OthersDisc,
RegPerc,
ExtraPerc,
OthersPerc)
SELECT
t._id,
m.itemCode,0 AS Qty1,
0 AS Qty2,
0 AS Qty3,
0 AS RegDisc,
0 AS ExtraDisc,
0 AS OthersDisc,
0 AS RegPerc,
0 AS ExtraPerc,
0 AS OthersPerc
FROM m_Route AS m
JOIN t_TakingOrder AS t ON
m.CustId = t.CustId **WHERE t.CustId=?"**;
dataTemp_d_TakingOrder.updateRaw(sql3);
When I used WHERE t.CustId=?, the query is not working. But if I delete that statements, the query is working.. can u help me?

You add a where clause and call updateRaw without providing any value.

Related

Select elements with between between not work in SQLite

Following table contains my SQLite-Database on Android:
>>>>> Dumping cursor android.database.sqlite.SQLiteCursor#9f3d273
0 {
id=1543948972569
relationItemID=-1
degree=-1
}
1 {
id=-1
relationItemID=1543948972569
degree=1
}
2 {
id=1543948972569
relationItemID=1543948978808
degree=1
}
3 {
id=1543948978808
relationItemID=1543948972569
degree=-1
}
<<<<<
The SQLite-Query
SELECT id FROM itemsHierarchy
WHERE id = 1543948972569 AND degree BETWEEN 0 AND -128
Returns an empty cursor even though it should find id of first entry.
But if I use '<' instead of 'BETWEEN 0 AND -128' like below, it works.
SELECT id FROM itemsHierarchy WHERE id = 1543948972569 AND degree < 0;
Did I do something wrong or is it a problem of SQLite?
It should be -
SELECT id
FROM itemsHierarchy
WHERE id = 1543948972569
AND degree BETWEEN -128 AND 0

Why is this query not returning anything in android SQLite

SELECT * FROM EVENT_total_time
WHERE USER_ID = 2
AND LEVEL_SEQUENCE_NUMBER = 1
AND DATETIME( TIMESTAMP ) BETWEEN DATETIME('now','-7 days') AND DATETIME('now')
ORDER BY datetime( TIMESTAMP ) ASC
and the DB has
PRINTING TABLE EVENT_total_time
0 {
_id=56
USER_ID=2
TIMESTAMP=2016-02-15 21:29:29
EPOCH_TIME=1455571769621
NEW_VALUE=3.034
LEVEL_ID=7
LEVEL_SEQUENCE_NUMBER=1
EXTRAS={"old_value":0}
}
1 {
_id=57
USER_ID=2
TIMESTAMP=2016-02-15 21:29:29
EPOCH_TIME=1455571769822
NEW_VALUE=3.219
LEVEL_ID=7
LEVEL_SEQUENCE_NUMBER=1
EXTRAS={"old_value":3.034}
}
this query was ran 30sec ago so ... datetime('now') should be 15.02.2016 21:32:00 ....
I ran this query and it produced an empty result. Can someone spot why?

How to make... SQLite select DISTINCT -> query(true, ...)

My query is:
String _query = "select DISTINCT Y.CATE_CODE4 CATE_CODE, Y.CATE_NAME4 CATE_NAME,
0 IS_PRESET from G_MASTER X INNER JOIN CATEGORY_VIEW Y ON X.CATE_4 = Y.CATE_CODE4
where X.IS_SALE = 1 AND Y.IS_LOCKED4 = 0 AND Y.CATE_NAME2 not in ('XXXX')";
How does Android SQLite make db.query()?
First of all you should read SQLiteDatabase reference.
You could use a rawQuery(), here's an example of it :
rawQuery - db.rawQuery("select DISTINCT Y.CATE_CODE4 CATE_CODE, Y.CATE_NAME4 CATE_NAME,
0 IS_PRESETG_MASTER X INNER JOIN CATEGORY_VIEW Y ON X.CATE_4 = Y.CATE_CODE4 from table where X.IS_SALE = 1 AND Y.IS_LOCKED4 = 0 AND Y.CATE_NAME2 not in ('XXXX')"",new String[]{"data"});
It's just an example, you have to adapt your code to this.

AND and OR function in one query, not working? sqlite

i run a query with a WHERE
"COMPUTERCLASSROOM_SLOT1 = 0 OR COMPUTERCLASSROOM_SLOT2 = 0 AND COMPUTERCLASSROOM_DONE = 1"
though it return all the row that met a requirement..this is the table rows data
According to column presentation, here are the values of the rows
ROW 1 = 0 0 0
ROW 2 = 1 0 0
ROW 3 = 1 2 1
ROW 4 = 1 3 0
ROW 5 = 1 4 1
ROW 6 = 0 5 1
ROW 7 = 0 0 1
they all return..why is that? if i changed the OR with an AND, it would follow the query, returning ROW 7... its just weird..i need that OR and AND in one query, because my target is to return a row with at least 0 in either SLot1 or Slot2, and DONE = 1
it should be
WHERE (COMPUTERCLASSROOM_SLOT1 = 0 OR COMPUTERCLASSROOM_SLOT2 = 0) AND
COMPUTERCLASSROOM_DONE = 1
As #Jack already pointed out, the problem is because you are not using the parentheses. And hence your query is evaluated logically different from what you are expecting.
Try #JW.'s snippet and it would work perfectly.
WHERE (COMPUTERCLASSROOM_SLOT1 = 0 OR COMPUTERCLASSROOM_SLOT2 = 0) AND (COMPUTERCLASSROOM_DONE = 1)
Underlying cause
AND is evaluated as a multiplication; OR is evaluated as an addition. So according to arithmetic precedence rule (PEMDAS), AND is evaluated before evaluating OR.
Example: 1 OR 0 is 1 + 0 = 1; 1 AND 0 is 1 * 0 = 0;
So
X or X or X and X is grouped automatically as X or X or (X and X).
Use of parenthesis avoids the confusion, as well as makes code more readable.

select query with join is selecting data slowly from database in android

i have select query as follows
SELECT DISTINCT tt.firstname,
tt.lastname,
tc.caseid,
tt.courtcode AS courtid,
tcou.courtname,
(SELECT COUNT(*)
FROM tblcasetrafficticketlink
WHERE caseid = tc.caseid) AS ticketcount,
Max(tt.violationdate) AS violationdate,
( tt.address1
|| ','
|| tt.address2 ) AS address,
tt.city,
tt.state,
tt.zip,
tt.dob,
tt.sex
FROM tblcase tc
LEFT OUTER JOIN tblcasetrafficticketlink tcttl
ON tc.caseid = tcttl.caseid
LEFT OUTER JOIN tbltraffictickets tt
ON tcttl.courtid = tt.courtcode
AND tt.ticketnumber = tcttl.ticketnumber
AND ( tcttl.ticketextension = tt.ticketnumberex
OR tt.ticketnumberex IS NULL )
LEFT OUTER JOIN tblcourts tcou
ON tcou.courtid = tt.courtcode
WHERE tc.casetype = 'TRAFFIC'
AND tc.caseid<='"+recent_min_caseID+"'
GROUP BY tc.caseid,
tt.firstname,
tt.lastname,
tt.dob,
tt.sex,
tt.courtcode,
tcou.courtname,
tt.city,
tt.state,
tt.zip,
tc.casestatus,
tt.address1,
tt.address2
ORDER BY tc.caseid DESC
LIMIT 100;
this is taking much time to get data. can anybody help to improve performance.Here PRAGMA is useful? if so how? if not, tell me the way to fix this issue.
I've found that SQLite on Android seems to have some... unexpected quirks. In my case, it turned out that doing a straight query like select * from Foo where Bar is null was MUCH slower than selecting only the IDs and then fetching each row by ID individually. YMMV.

Categories

Resources