在单个Query中更新两个表

时间:2014-06-17 20:16:00

标签: android sqlite

这是我的代码:

      public void updateCustomerOnSubmit(String customerNumber, String customerEmail,   int pickupId, int statusId, int itemTypeId, int itemActionId, String itemSerial, String itemRemark){

    ContentValues c = updateCustomerInfoContentValues(customerNumber, customerEmail, statusId);
    String query = "UPDATE " + DatabaseConstant.PICKUP_CUSTOMER_DETAIL_TABLE 
            + " INNER JOIN " + DatabaseConstant.PICKUP_ITEM_DETAIL_TABLE 
            + " ON " +   DatabaseConstant.PICKUP_CUSTOMER_DETAIL_TABLE+"."+DatabaseConstant.CUSTOMER_ACCODE 
            +" = " + DatabaseConstant.PICKUP_ITEM_DETAIL_TABLE+"."+DatabaseConstant.CUSTOMER_ACCODE
            + " SET " + DatabaseConstant.CUSTOMER_CONTACT + "='" + customerNumber
            + "' ," + DatabaseConstant.CUSTOMER_EMAIL +  "='" + customerEmail 
            + "' ," + DatabaseConstant.CUSTOMER_STATUS + " = " + statusId
            + " , " + DatabaseConstant.ITEM_TYPE_ID + " = " + itemTypeId 
            + " , " + DatabaseConstant.ITEM_ACTION_ID + " = " + itemActionId 
            + " , "+ DatabaseConstant.ITEM_SERIAL  + " ='" + itemSerial 
            + "' , " + DatabaseConstant.PICKUPITEM_REMARK + " ='" + itemRemark
            + "' , " + DatabaseConstant.ITEM_STATUS + " = " + statusId
            + " WHERE " + DatabaseConstant.PICKUP_ITEM_DETAIL_TABLE+"."+DatabaseConstant.PICKUPITEM_ID + " = " + pickupId 
            + " AND " + DatabaseConstant.PICKUP_CUSTOMER_DETAIL_TABLE+"."+DatabaseConstant.PICKUP_ID + " = " + pickupId;
    Log.i("query", query);
    database.rawQuery(query, null);
    }

我的问题是,我是在正确的方式,而另一个是它抛出异常。 那就是:

   06-18 01:40:47.178: E/SQLiteLog(1516): (1) near "'INNER JOIN'": syntax error

我在日志中形成的查询是:

   UPDATE pickup_customer_detail 'INNER JOIN' pickup_item_detail ON pickup_customer_detail.customer_accode = pickup_item_detail.customer_accode SET customer_contact='9810530861' ,customer_email='vishal.nigam@computerware.co' ,status = 1 , item_type_id = 0 , item_action_id = 1 , item_serial ='5884626247' , pickupItem_remark ='thankß' , status = 1 WHERE pickup_item_detail.pickupItem_id = 3 AND pickup_customer_detail.pickup_id = 3

1 个答案:

答案 0 :(得分:0)

UPDATE语句只能更新一个表。

要更新两个表中的值,必须使用两个UPDATE语句。 (并使用execSQL,而不是rawQuery。)