我正在开发android使用SQLite,插入时我有android.database.sqlite.SQLiteException:靠近“If”......这是我的代码:
String query =
" If Exists(Select " + orderID + " From Print Where " + categoryNum + "= " + itemID + " and " + orderID + " = " + holdedOrderID + " )" +
" BEGIN " +
" UPDATE Print Set " + qty + " = " + qty + "+ " + QTY +
" Where " + categoryNum + "= " + itemID + " and " + orderID + " = " + holdedOrderID +
" END " +
" Else " +
" BEGIN " +
" Insert Into orderDetails ( " + PRODUCT_NAME +","+ categoryName +","+ categoryNum +","+ orderID +","+ price +","+ qty + " , " + tabelNumber +")"
+ " Values (" + "'" + itemName + "'" +","+ "'" +itemCategory + "'" +","+ itemID +","+ "'" + holdedOrderID + "'" + ","+ itemPrice +","+ QTY +","+ "'" +tableNumberz + "'" + ") " +
" END";
mDb.execSQL(query);
答案 0 :(得分:0)
SQLite没有IF语句。
但奇怪的巧合是,Java拥有它:
String selection = categoryNum + "= " + itemID + " and " + orderID + " = " + holdedOrderID;
if (DatabaseUtils.queryNumEntries(mDb, "Print", selection) > 0) {
mDb.execSQL("UPDATE ...");
} else {
mDb.insert(...);
}