0

I write the selection query like this:

'String selection3 = TriplePayProviderMetaData.ProgramTableMetaData.PROGRAM_LCN + " = '" + channelLcn + "'" + " AND " + TriplePayProviderMetaData.ProgramTableMetaData.PROGRAM_START_TIME + " > " + " '" + time + "'" + " LIMIT " + " '" + 3 + "'";'

But it says syntax error at limit:

'android.database.sqlite.SQLiteException: near "LIMIT": syntax error: , while compiling: SELECT title, lcn, _id, end_time, description, program_logo, start_time, rating, parent_guide FROM programs WHERE (lcn = '100' AND start_time > '1327026600000' LIMIT '3') ORDER BY start_time ASC E/AndroidRuntime(15912): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:158) E/AndroidRuntime(15912): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114) E/AndroidRuntime(15912): at android.content.ContentProviderProxy.bulkQueryInternal(ContentProviderNative.java:330) E/AndroidRuntime(15912): at android.content.ContentProviderProxy.query(ContentProviderNative.java:366) E/AndroidRuntime(15912): at android.content.ContentProviderClient.query(ContentProviderClient.java:49) E/AndroidRuntime(15912): at com.vovinet.miniepguru.MiniEpgActivity$1.onClick(MiniEpgActivity.java:150) E/AndroidRuntime(15912): at android.view.View.performClick(View.java:2485) E/AndroidRuntime(15912): at android.view.View.onKeyUp(View.java:4257) E/AndroidRuntime(15912):
at android.view.KeyEvent.dispatch(KeyEvent.java:1280) E/AndroidRuntime(15912): at android.view.View.dispatchKeyE W/ActivityManager( 1133): Force finishing activity com.vovinet.miniepguru/.MiniEpgActivity W/ActivityManager( 1133): Activity pause timeout for HistoryRecord{40630af0 com.vovinet.miniepguru/.MiniEpgActivity}'

2 Answers 2

2

You are passing limit as String. Limit is an integer value. So remove "'" tag from limit.

Also Limit has two parameters

LIMIT 0 , 10

1st value 0 show that start getting record form 0 position. 2nd value 10 show that get then record from starting position. So it will return 1st 10 records.

if you say 10 , 10. It will get 10-20 record form the cursor. As starting position is 10 and no of record is also 10.

You can also check this link http://www.sqlite.org/lang_select.html

Edited: Your query is

SELECT title, lcn, _id, end_time, description, program_logo, start_time, rating, parent_guide FROM programs WHERE (lcn = '100' AND start_time > '1327026600000' LIMIT 0 , 3) ORDER BY start_time ASC

Basically you are adding limit wrongly

LIMIT is used after ORDER BY cluse ( check the link http://www.sqlite.org/lang_select.html)

It should be

SELECT title, lcn, _id, end_time, description, program_logo, start_time, rating, parent_guide FROM programs WHERE (lcn = '100' AND start_time > '1327026600000') ORDER BY start_time ASC LIMIT 0 , 3

Sign up to request clarification or add additional context in comments.

2 Comments

hello arslan thanks for your quick response.if i am using like the above but it gives the same error` android.database.sqlite.SQLiteException: near "LIMIT": syntax error: , while compiling: SELECT title, lcn, _id, end_time, description, program_logo, start_time, rating, parent_guide FROM programs WHERE (lcn = '100' AND start_time > '1327026600000' LIMIT 0 , 3) ORDER BY start_time ASC`
THANKS FOR REPLY,by using the above select query how to write query to get the result SELECT title, lcn, _id, end_time, description, program_logo, start_time, rating, parent_guide FROM programs WHERE (lcn = '100' AND start_time > '1327026600000') ORDER BY start_time ASC LIMIT 0 , 3 like this.
0

In fact the SQLiteDatabase has a function to do this thing.

public Cursor query (String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit) Query the given table, returning a Cursor over the result set.

limit Limits the number of rows returned by the query, formatted as LIMIT clause. Passing null denotes no LIMIT clause.

Please look at here

1 Comment

hi hubert thanks for your response actually i am querying the data from database content provider.so if i query by the above arguements it gives the compilation error the method query in the tupe content providerclient is not applicable

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.