执行此查询时,我遇到致命异常:
ArrayList<Selection_AppFilter_CompDescriptions> destinations =
new ArrayList<Selection_AppFilter_CompDescriptions>();
String query =
"SELECT "+APP_FILTER+", "+COMPONENT_DESCRIPTION+" FROM "+
"(SELECT "+APP_FILTER+", "+COMPONENT_DESCRIPTION+", "+COMPONENT_APP_ID+", CO."+COMPONENT_ID+" AS 'comp_id' "+
" FROM "+APP_TABLE+" AS A JOIN "+COMPONENT_TABLE+" AS CO "+
"ON A."+APP_ID+" = CO."+COMPONENT_APP_ID+" ) AS Y JOIN "+
"(SELECT "+CHANNEL_RECEIVER_ID+", "+CHANNEL_RECEIVER_COMPONENT_ID+
" FROM "+CHANNEL_TABLE+" AS Ch JOIN "+
"(SELECT C."+COMPONENT_ID+", "+COMPONENT_APP_ID+" FROM "+COMPONENT_TABLE+" AS C "+
"WHERE C."+COMPONENT_APP_ID+" = "+
"(SELECT "+APP_ID+" AS 'sender_id' FROM "+APP_TABLE +
"WHERE "+APP_FILTER+" = ?) AND C."+COMPONENT_DESCRIPTION+" = ?) AS Z "+
"ON Ch.sender_id = Z."+COMPONENT_APP_ID+" AND Ch."+CHANNEL_RECEIVER_COMPONENT_ID+" = Z."+COMPONENT_ID+") AS X "+
"ON Y.comp_id = X."+CHANNEL_RECEIVER_COMPONENT_ID+" AND Y."+COMPONENT_APP_ID+" = X."+CHANNEL_RECEIVER_ID;
String[] args = {senderFilter, senderCompDescription};
this.openReadableDB();
Cursor cursor = this.registry.rawQuery(query, args);
日志说明如下:
11-30 18:54:30.798: E/AndroidRuntime(31137): FATAL EXCEPTION: main
11-30 18:54:30.798: E/AndroidRuntime(31137): Process: com.example.app_talker_service, PID: 31137
11-30 18:54:30.798: E/AndroidRuntime(31137): java.lang.RuntimeException: Unable to create service com.example.app_talker_service.Talker_Service: android.database.sqlite.SQLiteException: near "=": syntax error (code 1): , while compiling: SELECT app_filter, comp_description FROM (SELECT app_filter, comp_description, app_id, CO._id AS 'comp_id' FROM app AS A JOIN component AS CO ON A._id = CO.app_id ) AS Y JOIN (SELECT receiver_id, receiver_component_id FROM channel AS Ch JOIN (SELECT C._id, app_id FROM component AS C WHERE C.app_id = (SELECT _id AS 'sender_id' FROM appWHERE app_filter = ?) AND C.comp_description = ?) AS Z ON Ch.sender_id = Z.app_id AND Ch.receiver_component_id = Z._id) AS X ON Y.comp_id = X.receiver_component_id AND Y.app_id = X.receiver_id
11-30 18:54:30.798: E/AndroidRuntime(31137): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2568)
11-30 18:54:30.798: E/AndroidRuntime(31137): at android.app.ActivityThread.access$1800(ActivityThread.java:135)
11-30 18:54:30.798: E/AndroidRuntime(31137): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
11-30 18:54:30.798: E/AndroidRuntime(31137): at android.os.Handler.dispatchMessage(Handler.java:102)
11-30 18:54:30.798: E/AndroidRuntime(31137): at android.os.Looper.loop(Looper.java:136)
11-30 18:54:30.798: E/AndroidRuntime(31137): at android.app.ActivityThread.main(ActivityThread.java:5001)
11-30 18:54:30.798: E/AndroidRuntime(31137): at java.lang.reflect.Method.invokeNative(Native Method)
11-30 18:54:30.798: E/AndroidRuntime(31137): at java.lang.reflect.Method.invoke(Method.java:515)
11-30 18:54:30.798: E/AndroidRuntime(31137): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
11-30 18:54:30.798: E/AndroidRuntime(31137): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
11-30 18:54:30.798: E/AndroidRuntime(31137): at dalvik.system.NativeStart.main(Native Method)
11-30 18:54:30.798: E/AndroidRuntime(31137): Caused by: android.database.sqlite.SQLiteException: near "=": syntax error (code 1): , while compiling: SELECT app_filter, comp_description FROM (SELECT app_filter, comp_description, app_id, CO._id AS 'comp_id' FROM app AS A JOIN component AS CO ON A._id = CO.app_id ) AS Y JOIN (SELECT receiver_id, receiver_component_id FROM channel AS Ch JOIN (SELECT C._id, app_id FROM component AS C WHERE C.app_id = (SELECT _id AS 'sender_id' FROM appWHERE app_filter = ?) AND C.comp_description = ?) AS Z ON Ch.sender_id = Z.app_id AND Ch.receiver_component_id = Z._id) AS X ON Y.comp_id = X.receiver_component_id AND Y.app_id = X.receiver_id
11-30 18:54:30.798: E/AndroidRuntime(31137): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
11-30 18:54:30.798: E/AndroidRuntime(31137): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
11-30 18:54:30.798: E/AndroidRuntime(31137): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
11-30 18:54:30.798: E/AndroidRuntime(31137): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
11-30 18:54:30.798: E/AndroidRuntime(31137): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
11-30 18:54:30.798: E/AndroidRuntime(31137): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
11-30 18:54:30.798: E/AndroidRuntime(31137): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
11-30 18:54:30.798: E/AndroidRuntime(31137): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
11-30 18:54:30.798: E/AndroidRuntime(31137): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1253)
11-30 18:54:30.798: E/AndroidRuntime(31137): at com.example.app_talker_service.RegistryDB.getDestinations(RegistryDB.java:514)
11-30 18:54:30.798: E/AndroidRuntime(31137): at com.example.app_talker_service.Talker_Service.onCreate(Talker_Service.java:81)
11-30 18:54:30.798: E/AndroidRuntime(31137): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2558)
11-30 18:54:30.798: E/AndroidRuntime(31137): ... 10 more
11-30 18:54:30.798: W/ActivityManager(751): Force finishing activity com.example.app_talker_service/.ConnectionManagerActivity
11-30 18:54:30.808: D/dalvikvm(31137): GC_CONCURRENT freed 240K, 2% free 17005K/17280K, paused 2ms+1ms, total 17ms
11-30 18:54:30.878: D/dalvikvm(751): GC_FOR_ALLOC freed 1293K, 14% free 37333K/43296K, paused 65ms, total 65ms
11-30 18:54:30.928: D/dalvikvm(751): GC_FOR_ALLOC freed 878K, 14% free 37292K/43296K, paused 55ms, total 55ms
11-30 18:54:31.438: W/ActivityManager(751): Activity pause timeout for ActivityRecord{431b8488 u0 com.example.app_talker_service/.ConnectionManagerActivity t37 f}
11-30 18:54:31.558: W/HandlerScheduledExecuto(1040): Task does not implement UiTask. Consider using NamedUiRunnable for eww@431ed308
11-30 18:54:40.658: E/WindowManager(751): Starting window AppWindowToken{43b25ee0 token=Token{434343a0 ActivityRecord{431b8488 u0 com.example.app_talker_service/.ConnectionManagerActivity t37}}} timed out
11-30 18:54:41.268: D/dalvikvm(1076): GC_CONCURRENT freed 454K, 4% free 18273K/18868K, paused 2ms+4ms, total 50ms
11-30 18:54:41.558: W/ActivityManager(751): Activity destroy timeout for ActivityRecord{431b8488 u0 com.example.app_talker_service/.ConnectionManagerActivity t37 f}
11-30 18:54:50.778: W/ActivityManager(751): Timeout executing service: ServiceRecord{43417008 u0 com.example.app_talker_service/.Talker_Service}
11-30 18:54:50.838: I/ActivityManager(751): Crashing app skipping ANR: ProcessRecord{4367ce88 31137:com.example.app_talker_service/u0a80} Executing service com.example.app_talker_service/.Talker_Service
11-30 18:55:32.608: D/AbstractMetricsFactoryImpl(2816): record : No data points in metrics event
11-30 18:55:35.048: I/PowerManagerService(751): Going to sleep due to screen timeout...
11-30 18:55:35.548: D/SurfaceFlinger(183): Screen released, type=0 flinger=0xb86b3450
11-30 18:55:35.548: D/qdhwcomposer(183): hwc_blank: Blanking display: 0
11-30 18:55:35.848: D/qdhwcomposer(183): hwc_blank: Done blanking display: 0
11-30 18:55:35.848: D/SurfaceControl(751): Excessive delay in blankDisplay() while turning screen off: 297ms
11-30 18:55:35.968: D/NfcService(1017): NFC-C OFF
11-30 18:55:40.918: V/KeyguardHostView(857): Initial transport state: 0, pbstate=0
11-30 18:55:40.978: D/dalvikvm(857): GC_FOR_ALLOC freed 5090K, 42% free 23579K/40584K, paused 14ms, total 15ms
11-30 18:55:40.998: V/KeyguardHostView(857): hide transport, gen:85
11-30 18:55:40.998: V/KeyguardHostView(857): music state changed: 0
11-30 18:55:41.038: W/View(857): requestLayout() improperly called by android.widget.TextClock{43c4aa30 V.ED.... ......ID 157,0-724,320 #7f0a0047 app:id/clock_view} during layout: running second layout pass
11-30 18:55:41.038: W/View(857): requestLayout() improperly called by android.widget.TextClock{43d552e0 V.ED.... ......ID 157,0-475,57 #7f0a004c app:id/date_view} during layout: running second layout pass
11-30 18:55:41.038: W/View(857): requestLayout() improperly called by android.widget.TextView{440e4508 V.ED.... ......ID 499,0-724,57 #7f0a004d app:id/alarm_status} during layout: running second layout pass
11-30 18:55:41.048: D/PhoneStatusBar(857): disable: < expand icons alerts ticker system_info BACK* HOME* RECENT* CLOCK* search >
11-30 18:56:10.038: D/dalvikvm(30984): GC_CONCURRENT freed 414K, 3% free 17273K/17768K, paused 9ms+7ms, total 58ms
11-30 18:56:32.358: D/dalvikvm(1263): GC_CONCURRENT freed 748K, 5% free 19241K/20120K, paused 7ms+2ms, total 24ms
11-30 18:56:32.478: I/GCoreUlr(1263): Successfully inserted location
11-30 18:56:32.478: I/GCoreUlr(1263): Not calling LocationReporter, hasMoved: false, elapsed millis: 1038329, request: Stationary(3600000)
11-30 18:57:05.718: I/Metrics:BatchTransmitte(2816): QueuePusher.sendBatches - Drained batch queue.; Number of NORMAL queue batches sent: 0
11-30 18:57:05.808: I/Metrics:BatchTransmitte(2816): QueuePusher.sendBatches - Drained batch queue.; Number of HIGH queue batches sent: 0
11-30 18:57:38.238: D/dalvikvm(2816): GC_FOR_ALLOC freed 283K, 7% free 20945K/22352K, paused 39ms, total 40ms
11-30 18:58:35.248: D/dalvikvm(30984): GC_CONCURRENT freed 389K, 3% free 17273K/17768K, paused 9ms+6ms, total 57ms
11-30 18:58:44.698: D/dalvikvm(31019): GC_FOR_ALLOC freed 206K, 3% free 18467K/18948K, paused 12ms, total 13ms
11-30 18:58:44.748: D/dalvikvm(31019): GC_CONCURRENT freed 420K, 3% free 18493K/18956K, paused 2ms+1ms, total 15ms
11-30 18:58:44.798: D/dalvikvm(31019): GC_CONCURRENT freed 453K, 3% free 18492K/18984K, paused 2ms+1ms, total 15ms
11-30 18:58:44.858: D/dalvikvm(31019): GC_CONCURRENT freed 497K, 3% free 18520K/19060K, paused 2ms+2ms, total 18ms
11-30 18:58:44.918: D/dalvikvm(31019): GC_CONCURRENT freed 575K, 4% free 18528K/19144K, paused 1ms+1ms, total 15ms
11-30 18:58:44.918: D/dalvikvm(31019): WAIT_FOR_CONCURRENT_GC blocked 6ms
11-30 18:59:30.968: I/Process(31137): Sending signal. PID: 31137 SIG: 9
11-30 18:59:31.028: I/ActivityManager(751): Process com.example.app_talker_service (pid 31137) has died.
11-30 18:59:31.028: I/WindowState(751): WIN DEATH: Window{4348ff58 u0 com.example.app_talker_service/com.example.app_talker_service.ConnectionManagerActivity}
11-30 18:59:31.028: A/ActivityManager(751): Service ServiceRecord{43417008 u0 com.example.app_talker_service/.Talker_Service} in process ProcessRecord{4367ce88 31137:com.example.app_talker_service/u0a80} not same as in map: null
11-30 19:00:32.608: D/AbstractMetricsFactoryImpl(2816): record : No data points in metrics event
11-30 19:00:43.658: I/EventLogService(1127): Aggregate from 1417368601084 (log), 1417368601084 (data)
11-30 19:00:43.748: I/ServiceDumpSys(1127): dumping service [account]
它说“=”附近有语法错误,任何人都可以帮我找到它吗?如果它当然是一个明显的语法错误......
答案 0 :(得分:2)
<强>更新强>
你有'app'和'WHERE'这样连接:
... (SELECT _id AS 'sender_id' FROM appWHERE app_filter = ?) ...
所以在'WHERE'之前插入空格(标有 - &gt;):
... "(SELECT "+APP_ID+" AS 'sender_id' FROM "+APP_TABLE +
--> " WHERE "+APP_FILTER+" = ?) ...