* P.S此查询提供sqlite异常*
Cursor cur= db.rawQuery("SELECT " + Constants.Qt_um_stock_items_qty_BAL_DATE + " AS_ON_DT, " + " (IFNULL ( " + Constants.Qt_um_stock_items_qty_IN_QTY +", 0)-IFNULL ("
+Constants.Qt_um_stock_items_qty_OUT_QTY +", 0)) AS CL_QTY,"+ "(SELECT " + Constants.Stock_ItemsCODE + " || '-' || "
+ Constants.Stock_ItemsNAME + " FROM " + Constants.Qm_Stock_Items_TABLE + " WHERE " + Constants.Stock_ItemsID + " = "
+ Constants.Qt_um_stock_items_qty_STOCK_ITEM_ID+") AS ITEM," + "(SELECT " + Constants.UnitCODE + "|| '-' ||"
+ Constants.UnitNAME + " FROM " + Constants. Qm_Unit_TABLE + " WHERE " + Constants.UnitID + " = "
+ Constants.Qt_um_stock_items_qty_BASE_UNIT_ID+" ) AS UNIT FROM " + Constants.Qt_um_stock_items_qty_table +" WHERE "
+ Constants. Qt_um_stock_items_qty_STOCK_CENTRE_ID+"=?" + " AND " + Constants. Qt_um_stock_items_qty_STOCK_ITEM_ID
+ " IN " + "=?",new String[] {StockCenterId, StockItemId});
Log Cat
10-17 06:02:50.042: E/SQLiteLog(3608): (1) near "=": syntax error
10-17 06:02:50.054: D/AndroidRuntime(3608): Shutting down VM
10-17 06:02:50.054: W/dalvikvm(3608): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
10-17 06:02:50.114: E/AndroidRuntime(3608): FATAL EXCEPTION: main
10-17 06:02:50.114: E/AndroidRuntime(3608): android.database.sqlite.SQLiteException: near "=": syntax error (code 1): , while compiling: SELECT BAL_DATE AS_ON_DT, (IFNULL ( IN_QTY, 0)-IFNULL (OUT_QTY, 0)) AS CL_QTY,(SELECT CODE || '-' || NAME FROM qm_um_stock_items WHERE ID = STOCK_ITEM_ID) AS ITEM,(SELECT CODE|| '-' ||NAME FROM qm_um_unit WHERE ID = BASE_UNIT_ID ) AS UNIT FROM Qt_um_stock_items_qty WHERE STOCK_CENTER_ID =? AND STOCK_ITEM_ID IN (=?)
10-17 06:02:50.114: E/AndroidRuntime(3608): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
10-17 06:02:50.114: E/AndroidRuntime(3608): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
10-17 06:02:50.114: E/AndroidRuntime(3608): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
10-17 06:02:50.114: E/AndroidRuntime(3608): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
10-17 06:02:50.114: E/AndroidRuntime(3608): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
10-17 06:02:50.114: E/AndroidRuntime(3608): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
10-17 06:02:50.114: E/AndroidRuntime(3608): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
10-17 06:02:50.114: E/AndroidRuntime(3608): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
10-17 06:02:50.114: E/AndroidRuntime(3608): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1253)
10-17 06:02:50.114: E/AndroidRuntime(3608): at com.manacle.umma.activity.HeaderDb.getStockbal(HeaderDb.java:3901)
10-17 06:02:50.114: E/AndroidRuntime(3608): at com.manacle.umma.activity.StockBalrep$4.onClick(StockBalrep.java:185)
10-17 06:02:50.114: E/AndroidRuntime(3608): at android.view.View.performClick(View.java:4204)
10-17 06:02:50.114: E/AndroidRuntime(3608): at android.view.View$PerformClick.run(View.java:17355)
10-17 06:02:50.114: E/AndroidRuntime(3608): at android.os.Handler.handleCallback(Handler.java:725)
10-17 06:02:50.114: E/AndroidRuntime(3608): at android.os.Handler.dispatchMessage(Handler.java:92)
10-17 06:02:50.114: E/AndroidRuntime(3608): at android.os.Looper.loop(Looper.java:137)
10-17 06:02:50.114: E/AndroidRuntime(3608): at android.app.ActivityThread.main(ActivityThread.java:5041)
10-17 06:02:50.114: E/AndroidRuntime(3608): at java.lang.reflect.Method.invokeNative(Native Method)
10-17 06:02:50.114: E/AndroidRuntime(3608): at java.lang.reflect.Method.invoke(Method.java:511)
10-17 06:02:50.114: E/AndroidRuntime(3608): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-17 06:02:50.114: E/AndroidRuntime(3608): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
10-17 06:02:50.114: E/AndroidRuntime(3608): at dalvik.system.NativeStart.main(Native Method)
新的Log Cat:这显示没有这样的表qt_um_stock_items_qty但我在我的数据库中有这个表,我也可以使用我的数据库浏览器访问它
10-17 06:38:01.523:E / SQLiteLog(4107):( 1)没有这样的表:qt_um_stock_items_qty 10-17 06:38:01.523:D / AndroidRuntime(4107):关闭VM 10-17 06:38:01.523:W / dalvikvm(4107):threadid = 1:线程退出未捕获异常(组= 0x40a71930) 10-17 06:38:01.574:E / AndroidRuntime(4107):致命异常:主要 10-17 06:38:01.574:E / AndroidRuntime(4107):android.database.sqlite.SQLiteException:没有这样的表:qt_um_stock_items_qty(代码1):,编译时:SELECT BAL_DATE AS ON_DT,(IFNULL(IN_QTY,0) -IFNULL(OUT_QTY,0))AS CL_QTY,(SELECT CODE ||&#39; - &#39; || NAME FROM qm_um_stock_items WHERE ID = STOCK_ITEM_ID)AS ITEM,(SELECT CODE ||&#39; - &# 39; || NAME FROM qm_um_unit WHERE ID = BASE_UNIT_ID)AS UNIT FROM qt_um_stock_items_qty WHERE STOCK_CENTER_ID =? AND STOCK_ITEM_ID =? 10-17 06:38:01.574:E / AndroidRuntime(4107):在android.database.sqlite.SQLiteConnection.nativePrepareStatement(本机方法) 10-17 06:38:01.574:E / AndroidRuntime(4107):在android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882) 10-17 06:38:01.574:E / AndroidRuntime(4107):在android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493) 10-17 06:38:01.574:E / AndroidRuntime(4107):在android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 10-17 06:38:01.574:E / AndroidRuntime(4107):在android.database.sqlite.SQLiteProgram。(SQLiteProgram.java:58) 10-17 06:38:01.574:E / AndroidRuntime(4107):在android.database.sqlite.SQLiteQuery。(SQLiteQuery.java:37) 10-17 06:38:01.574:E / AndroidRuntime(4107):在android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44) 10-17 06:38:01.574:E / AndroidRuntime(4107):在android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314) 10-17 06:38:01.574:E / AndroidRuntime(4107):在android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1253) 10-17 06:38:01.574:E / AndroidRuntime(4107):at com.manacle.umma.activity.HeaderDb.getStockbal(HeaderDb.java:3901) 10-17 06:38:01.574:E / AndroidRuntime(4107):at com.manacle.umma.activity.StockBalrep $ 4.onClick(StockBalrep.java:185) 10-17 06:38:01.574:E / AndroidRuntime(4107):在android.view.View.performClick(View.java:4204) 10-17 06:38:01.574:E / AndroidRuntime(4107):在android.view.View $ PerformClick.run(View.java:17355) 10-17 06:38:01.574:E / AndroidRuntime(4107):在android.os.Handler.handleCallback(Handler.java:725) 10-17 06:38:01.574:E / AndroidRuntime(4107):在android.os.Handler.dispatchMessage(Handler.java:92) 10-17 06:38:01.574:E / AndroidRuntime(4107):在android.os.Looper.loop(Looper.java:137) 10-17 06:38:01.574:E / AndroidRuntime(4107):在android.app.ActivityThread.main(ActivityThread.java:5041) 10-17 06:38:01.574:E / AndroidRuntime(4107):at java.lang.reflect.Method.invokeNative(Native Method) 10-17 06:38:01.574:E / AndroidRuntime(4107):at java.lang.reflect.Method.invoke(Method.java:511) 10-17 06:38:01.574:E / AndroidRuntime(4107):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:793) 10-17 06:38:01.574:E / AndroidRuntime(4107):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 10-17 06:38:01.574:E / AndroidRuntime(4107):at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
android.database.sqlite.SQLiteException: near "=": syntax error (code 1): , while compiling: SELECT BAL_DATE AS_ON_DT, (IFNULL ( IN_QTY, 0)-IFNULL (OUT_QTY, 0)) AS CL_QTY,(SELECT CODE || '-' || NAME FROM qm_um_stock_items WHERE ID = STOCK_ITEM_ID) AS ITEM,(SELECT CODE|| '-' ||NAME FROM qm_um_unit WHERE ID = BASE_UNIT_ID ) AS UNIT FROM Qt_um_stock_items_qty WHERE STOCK_CENTER_ID =? AND STOCK_ITEM_ID IN (=?)
您发布的代码似乎并未生成此查询字符串。但是,最后一部分
AND STOCK_ITEM_ID IN (=?)
应该是
AND STOCK_ITEM_ID =?
或类似
"AND STOCK_ITEM_ID IN (" + list + ")"
其中list
是以逗号分隔的ID列表(您可以使用TextUtils.join()
)。