1

I try to switch ID for 2 rows in my database.

I get syntax error (code 1) on this line: ourDatabase.update(LIVE_TABLE, cv, whereClause, whereArgs);

Its strange becuase if this the row i look for wasnt exists than if(c.getCount() < 1) should give me return.

This the error code:

06-15 11:27:19.225: W/dalvikvm(10025): threadid=1: thread exiting with uncaught exception (group=0x40cc6930)
06-15 11:27:19.235: E/AndroidRuntime(10025): FATAL EXCEPTION: main
06-15 11:27:19.235: E/AndroidRuntime(10025): android.database.sqlite.SQLiteException: near "79": syntax error (code 1): , while compiling: UPDATE live_table SET 79=? WHERE _id= ?
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1563)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1514)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at com.example.workoutlog.DataBaseMain.updateMoveLive(DataBaseMain.java:2050)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at com.example.workoutlog.LiveWorkoutPage.moveDown(LiveWorkoutPage.java:1756)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at com.example.workoutlog.LiveWorkoutPage.whatclicked(LiveWorkoutPage.java:1600)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at com.example.workoutlog.LiveWorkoutPage.onClick(LiveWorkoutPage.java:583)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.view.View.performClick(View.java:4211)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.view.View$PerformClick.run(View.java:17362)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.os.Handler.handleCallback(Handler.java:725)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.os.Handler.dispatchMessage(Handler.java:92)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.os.Looper.loop(Looper.java:137)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.app.ActivityThread.main(ActivityThread.java:5226)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at java.lang.reflect.Method.invokeNative(Native Method)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at java.lang.reflect.Method.invoke(Method.java:511)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at dalvik.system.NativeStart.main(Native Method)
06-15 11:27:37.122: I/Process(10025): Sending signal. PID: 10025 SIG: 9

this is my code:

public void updateMoveLive(String where, String to)
    {

        String whereClause = COLUMN_ID + "= ? ";  
        String[] whereArgs = new String[]{where};

        ContentValues cv = new ContentValues();

        String[] columns = new String[]{COLUMN_ID, COLUMN_ROUTINE_LIVE, COLUMN_INT};

        Cursor c = ourDatabase.query(LIVE_TABLE, columns, whereClause , whereArgs, null, null, null);

        if(c.getCount() < 1)
            return;

        int i = c.getColumnIndex(COLUMN_ID);
        c.moveToFirst();
        String tempID = c.getString(i);

        cv.put(to, COLUMN_ID);

        ourDatabase.update(LIVE_TABLE, cv, whereClause, whereArgs);

                whereClause = COLUMN_ID + "= ? ";
                whereArgs = new String[]{tempID};

                cv = new ContentValues();

                cv.put(where, COLUMN_ID);

                ourDatabase.update(LIVE_TABLE, cv, whereClause, whereArgs);
    }

1 Answer 1

2

The error seems to be in this line:

cv.put(to, COLUMN_ID);

Should be

cv.put(COLUMN_ID, to)

as the ContentValue is, by default, ContentValue(KEY, VALUE)

EDIT: In fact, there is another incorrect use below, on

cv = new ContentValues();
cv.put(where, COLUMN_ID);

Try fix these two...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.