1

I am getting this error

android.database.sqlite.SQLiteException: near "SELECT": syntax error: , while compiling: SELECT _id, c_type, s_name, s_numb, user_name, password FROM accounts WHERE SELECT * FROM TableName LIMIT 1 OFFSET 1

Here is the code the code that creates the problem . My intent is to get the ROWID of ith record from the table and then use that ROWID to delete an entry from the table.

public void deleteEntry(long i) {
    String[] columns = new String[]{KEY_ROWID, KEY_CTYPE, KEY_SNAME, KEY_SNUMB, KEY_USRN, KEY_PASS};
    Cursor cursor = ourDatabase.query(DATABASE_TABLE,columns,"SELECT * FROM " +DATABASE_TABLE+" LIMIT 1 OFFSET "+i, null, null, null, null, null);
    if (cursor != null && cursor.moveToFirst())
    {
        cursor.moveToFirst();
        long rowIds = cursor.getLong(0);
        ourDatabase.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowIds, null);
    }
  //  ourDatabase.delete(DATABASE_TABLE, KEY_SNUMB + "=" + siteNum, null);
    //return ourDatabase.insert(DATABASE_TABLE,null,cv);
}
2
  • What do you mean by ith record? THe query looks wrong in the where filter Commented Nov 12, 2013 at 11:02
  • I am passing int i in the parameters if `i =5' then I need 5th record. Commented Nov 12, 2013 at 11:08

1 Answer 1

1

I achieved the result by changing the approach, but as I am learning android and am a beginner I would like to know how to fix the code I mentioned in the question

String[] columns = new String[]{KEY_ROWID, KEY_CTYPE, KEY_SNAME, KEY_SNUMB, KEY_USRN, KEY_PASS};
    Cursor cursor = ourDatabase.query(DATABASE_TABLE, null, null, null, null, null, null);
    if (cursor != null && cursor.moveToFirst()) {
        cursor.moveToFirst();
        for(int x=0;x<i;x++)
        {
            cursor.moveToNext();
        }
        long rowIds = cursor.getLong(0);
        ourDatabase.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowIds, null);
    }
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.