Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to query the call log details from phone, my query is like below

Cursor groupCur = mcontext.getContentResolver().query(Calls.CONTENT_URI,
CallLogAdapter.PROJECTION, Calls.NUMBER + " = " + number, null,Calls.DEFAULT_SORT_ORDER);

CallLogAdapter.PROJECTION contain some fields(columns) of call log.

It works fine, but in below condition it will give force close.

Condition:-If dial number starting with * or # (ex: *1234567 or #123457) and number end with * (ex: 1234567*)

**ERROR LOG:**

10-14 14:54:50.425: INFO/Database(26307): sqlite returned: error code = 1, msg = near syntax error 10-14 14:54:50.429: ERROR/DatabaseUtils(26307): Writing exception to parcel 10-14 14:54:50.429: ERROR/DatabaseUtils(26307): android.database.sqlite.SQLiteException: near "*": syntax error: , while compiling: SELECT _id, number, name, date, duration, new, type FROM calls WHERE (number = *674088888) ORDER BY date DESC 10-14 14:54:50.429: ERROR/DatabaseUtils(26307): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method) 10-14 14:54:50.429: ERROR/DatabaseUtils(26307): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92) 10-14 14:54:50.429: ERROR/DatabaseUtils(26307): at android.database.sqlite.SQLiteCompiledSql.(SQLiteCompiledSql.java:65) 10-14 14:54:50.429: ERROR/DatabaseUtils(26307): at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:83) 10-14 14:54:50.429: ERROR/DatabaseUtils(26307): at android.database.sqlite.SQLiteQuery.(SQLiteQuery.java:49) 10-14 14:54:50.429: ERROR/DatabaseUtils(26307): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42) 10-14 14:54:50.429: ERROR/DatabaseUtils(26307): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356) 10-14 14:54:50.429: ERROR/DatabaseUtils(26307): at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:330) 10-14 14:54:50.429: ERROR/DatabaseUtils(26307): at com.android.providers.contacts.CallLogProvider.query(CallLogProvider.java:129) 10-14 14:54:50.429: ERROR/DatabaseUtils(26307): at android.content.ContentProvider$Transport.bulkQuery(ContentProvider.java:174) 10-14 14:54:50.429: ERROR/DatabaseUtils(26307): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:111) 10-14 14:54:50.429: ERROR/DatabaseUtils(26307): at android.os.Binder.execTransact(Binder.java:320) 10-14 14:54:50.429: ERROR/DatabaseUtils(26307): at dalvik.system.NativeStart.run(Native Method) 10-14 14:54:50.429: DEBUG/AndroidRuntime(27470): Shutting down VM 10-14 14:54:50.429: WARN/dalvikvm(27470): threadid=1: thread exiting with uncaught exception (group=0x40015560) 10-14 14:54:50.433: ERROR/AndroidRuntime(27470): FATAL EXCEPTION: main 10-14 14:54:50.433: ERROR/AndroidRuntime(27470): android.database.sqlite.SQLiteException: near "*": syntax error: , while compiling: SELECT _id, number, name, date, duration, new, type FROM calls WHERE (number = *674088888) ORDER BY date DESC 10-14 14:54:50.433: ERROR/AndroidRuntime(27470): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:158) 10-14 14:54:50.433: ERROR/AndroidRuntime(27470): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114) 10-14 14:54:50.433: ERROR/AndroidRuntime(27470): at android.content.ContentProviderProxy.bulkQueryInternal(ContentProviderNative.java:330) 10-14 14:54:50.433: ERROR/AndroidRuntime(27470): at android.content.ContentProviderProxy.query(ContentProviderNative.java:366) 10-14 14:54:50.433: ERROR/AndroidRuntime(27470): at android.content.ContentResolver.query(ContentResolver.java:262)

Can anyone help me.

share|improve this question

1 Answer 1

up vote 6 down vote accepted

Try using it like:

Cursor groupCur = mcontext.getContentResolver().query(Calls.CONTENT_URI,
CallLogAdapter.PROJECTION, Calls.NUMBER + " ='" + number+"'", null,Calls.DEFAULT_SORT_ORDER);
share|improve this answer
    
Thanks for your quick response and its works fine. thank you Hiral :) –  VKJ Oct 14 '11 at 9:54
    
Glad to know this.BTW,You should accept the answer if it is useful to you. –  Hiral Oct 14 '11 at 9:55
    
+1 Working like charm..Thanks @Hiral –  Venky Feb 29 '12 at 14:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.