android.database.sqlite.SQLiteException:接近“*”:语法错误:,编译时:SELECT 调用._id

发布于 2024-12-09 13:34:29 字数 3294 浏览 0 评论 0原文

我想从电话查询通话记录详细信息,我的查询如下

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

CallLogAdapter.PROJECTION 包含通话记录的一些字段(列)。

它工作正常,但在以下条件下它会强制关闭。

条件:-如果拨打以 * 或 # 开头的号码(例如:*1234567 或 #123457)且号码以 * 结尾(例如:1234567*)

**ERROR LOG:**

10-14 14:54:50.425: INFO/Database(26307): sqlite 返回: 错误代码 = 1,msg = 接近语法错误 10-14 14:54:50.429:错误/DatabaseUtils(26307):写入包裹异常 10-14 14:54:50.429:错误/DatabaseUtils(26307):android.database.sqlite.SQLiteException:接近“*”:语法错误:,编译时:SELECT _id,数字,名称,日期,持续时间,新的,类型FROM 呼叫 WHERE(号码 = *674088888) ORDER BY 日期 DESC 10-14 14:54:50.429:错误/DatabaseUtils(26307):在android.database.sqlite.SQLiteCompiledSql.native_compile(本机方法) 10-14 14:54:50.429:错误/DatabaseUtils(26307):在 android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92) 10-14 14:54:50.429:错误/DatabaseUtils(26307):在android.database.sqlite.SQLiteCompiledSql。(SQLiteCompiledSql.java:65) 10-14 14:54:50.429: 错误/DatabaseUtils(26307): 在 android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:83) 10-14 14:54:50.429: 错误/DatabaseUtils(26307): 在 android.database.sqlite.SQLiteQuery.(SQLiteQuery.java:49) 10-14 14:54:50.429:错误/DatabaseUtils(26307):在 android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42) 10-14 14:54:50.429:错误/DatabaseUtils(26307):在 android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356) 10-14 14:54:50.429:错误/DatabaseUtils(26307):在 android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:330) 10-14 14:54:50.429:错误/DatabaseUtils(26307):在com.android.providers.contacts.CallLogProvider.query(CallLogProvider.java:129) 10-14 14:54:50.429:错误/DatabaseUtils(26307):在 android.content.ContentProvider$Transport.bulkQuery(ContentProvider.java:174) 10-14 14:54:50.429:错误/DatabaseUtils(26307):在android.content.ContentProviderNative.onTransact(ContentProviderNative.java:111) 10-14 14:54:50.429:错误/DatabaseUtils(26307):在android.os.Binder.execTransact(Binder.java:320) 10-14 14:54:50.429:错误/DatabaseUtils(26307):在dalvik.system.NativeStart.run(本机方法) 10-14 14:54:50.429:DEBUG/AndroidRuntime(27470):关闭虚拟机 10-14 14:54:50.429:WARN / dalvikvm(27470):threadid = 1:线程因未捕获的异常而退出(组= 0x40015560) 10-14 14:54:50.433:错误/AndroidRuntime(27470):致命异常:主要 10-14 14:54:50.433:错误/AndroidRuntime(27470):android.database.sqlite.SQLiteException:接近“*”:语法错误:,编译时:SELECT _id,数字,名称,日期,持续时间,新的,类型FROM 呼叫 WHERE(号码 = *674088888) ORDER BY 日期 DESC 10-14 14:54:50.433:错误/AndroidRuntime(27470):在android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:158) 10-14 14:54:50.433:错误/AndroidRuntime(27470):在android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114) 10-14 14:54:50.433:错误/AndroidRuntime(27470):在android.content.ContentProviderProxy.bulkQueryInternal(ContentProviderNative.java:330) 10-14 14:54:50.433:错误/AndroidRuntime(27470):在android.content.ContentProviderProxy.query(ContentProviderNative.java:366) 10-14 14:54:50.433: 错误/AndroidRuntime(27470): 在 android.content.ContentResolver.query(ContentResolver.java:262)

任何人都可以帮助我。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

段念尘 2024-12-16 13:34:29

尝试像这样使用它:

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

Try using it like:

Cursor groupCur = mcontext.getContentResolver().query(Calls.CONTENT_URI,
CallLogAdapter.PROJECTION, Calls.NUMBER + " ='" + number+"'", null,Calls.DEFAULT_SORT_ORDER);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文