i am having a issue with the Android SQLite Database. I want to set some default values, when i create the database with onCreate(). The database gets created but the table is empty.
//Datenbank anlegen private static final String CREATETABLE_SETTINGS = "CREATE TABLE " + TABLE_SETTINGS + " (\n" + "id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\n" + "level TEXT DEFAULT 'hard',\n" + "design TEXT DEFAULT 'dark',\n" + "sound INTEGER DEFAULT '1',\n" + "music INTEGER DEFAULT '1',\n" + "vibration INTEGER DEFAULT '1',\n" + "control INTEGER DEFAULT '1');" ;
I don't know why the default values aren't working.
Thanks for every answer and excuse my bad language.
DEFAULT
in a column definition is only applied if no or a null value is supplied for a column when inserting or updating rows. The code you posted does not insert any rows.
To insert a row with default values, consider
"INSERT INTO " + TABLE_SETTINGS + "(id) VALUES(NULL)"
(You need to specify at least one column when inserting.)