Android - Sqlite Insert Not Inserting
Solution 1:
Try to put a semicolon at the end of table creation query. In your case as show below
private String pictureTable() {
return "CREATE TABLE geophoto_db_pictures ( picid integer,"
+ "name varying character(50),"
+ "city varying character(20) NOT NULL,"
+ "zipcode varying character(20) NOT NULL,"
+ "country varying character(20) NOT NULL,"
+ "picdate datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,"
+ "tags varying character(200),"
+ "image varying character(200) NOT NULL,"
+ "uploaded integer NOT NULL DEFAULT 0, PRIMARY KEY (picid));";
}
While providing a query through an external String
, you will need to provide SQL
query with an end of statement ;
. Using the primitive SQLite
does not require ;
as it just takes arguments and create function query itself. I have experienced both cases and I ended up understanding the way I have put it here.
Solution 2:
The problem you are facing is that you are trying to use rawQuery()
to insert a record, when you should be using execSQL()
instead (see this answer).
So, the correct code for executeWriteQuery
would be as follows:
privatevoidexecuteWrite(String command){
Log.d(LOG_TAG, "execute write");
SQLiteDatabase db = getWritableDatabase();
db.execSQL(command);
Log.d(LOG_TAG, "write executed");
}
Also, consider using insert()
instead as that will allow you to get a return value to determine whether or not the data was inserted successfully.
Post a Comment for "Android - Sqlite Insert Not Inserting"