2015-05-03 54 views
1
public synchronized void saveMatchValue(int photoRecOwner, 
     int[] photoRecAssign, float[] value) { 
    SQLiteDatabase database = databaseHelper.getWritableDatabase(); 
    database.beginTransaction(); 
    String sql = " UPDATE " + TypeContract.CTablePhotoMatch.TABLE_NAME 
      + " SET " + TypeContract.CTablePhotoMatch.VALUE + "=? " 
      + " WHERE " + TypeContract.CTablePhotoMatch.FK_OWNER 
      + "=? AND " + TypeContract.CTablePhotoMatch.FK_ASSIGN + "=? ;" 
      + " INSERT OR IGNORE INTO " 
      + TypeContract.CTablePhotoMatch.TABLE_NAME + "(" 
      + TypeContract.CTablePhotoMatch.FK_OWNER + "," 
      + TypeContract.CTablePhotoMatch.FK_ASSIGN + "," 
      + TypeContract.CTablePhotoMatch.VALUE + ") VALUES (?, ?, ?);"; 

    SQLiteStatement stmt = database.compileStatement(sql); 

    try { 

     int rows = photoRecAssign.length; 
     for (int i = 0; i < rows; i++) { 

      if (photoRecOwner > photoRecAssign[i]) { 
       stmt.bindLong(1, photoRecOwner); 
       // stmt.bindLong(index, value) 
       stmt.bindLong(2, photoRecAssign[i]); 

      } else { 
       stmt.bindLong(1, photoRecAssign[i]); 
       stmt.bindLong(2, photoRecOwner); 

      } 
      stmt.bindDouble(3, value[i]); 

      stmt.execute(); 
      stmt.clearBindings(); 

     } 
     database.setTransactionSuccessful(); 
    } finally { 
     stmt.close(); 
     // updtStmt.close(); 
     database.endTransaction(); 
     // database.close(); 
    } 
} 

沒有錯誤和編譯錯誤,SQLITE UDPATE或INSERT語句不想要執行

我不知道如果SQL語句的語法是正確的:混凝土:; ,但沒有編譯錯誤,插入和(可能更新)命令不會執行.... 我可以捕獲更多的細節?(sqlite statemenst)找出bug

+0

你爲什麼使用'bindDouble'? –

回答

1

您只能使用SQLiteStatement執行單一的陳述。 ;之後的SQL未執行。

拆分SQL以分別執行語句。

+0

是的,這是我原來的解決方案,但它非常播種..我需要一些快速解決方案 – user2165656