Reputation: 635
In my application i have an database in that i have 2 tables.I have 2 following queries:
1.Is it possible to create database with some default value?? 2.I have 1 screen in that i have 5 edit boxes,1 save button.When user press the save button the 5 edit boxes value should be updated (replace the old) in the database?
Please help me.
This is for creating database:
private static final String DATABASE_SPIN=
"create table spinner(_id integer primary key autoincrement,"+" spin text not null);";
This is exesql:
public void onCreate(SQLiteDatabase db)
{
db.execSQL(DATABASE_SPIN);
}
My populate code is:
Cursor c=db.getAllTitlesSpin();
startManagingCursor(c);
int spinColumnIndex = c.getColumnIndexOrThrow("spin");
// String group[]=getResources().getStringArray(R.array.group_array);
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s2.setAdapter(adapter1);
if (c.moveToFirst()) {
do {
adapter1.add(c.getString(spinColumnIndex));
}
while (c.moveToNext());
if (db != null) {
db.close();
}
}
Upvotes: 0
Views: 201
Reputation: 10190
Each time a row is inserted into the table by an INSERT statement that does not provide explicit values for all table columns the values stored in the new row are determined by their default values, as follows:
If the default value of the column is a constant NULL, text, blob or signed-number value, then that value is used directly in the new row.
If the default value of a column is an expression in parentheses, then the expression is evaluated once for each row inserted and the results used in the new row.
If the default value of a column is CURRENT_TIME, CURRENT_DATE or CURRENT_TIMESTAMP, then the value used in the new row is a text representation of the current UTC date and/or time. For CURRENT_TIME, the format of the value is "HH:MM:SS". For CURRENT_DATE, "YYYY-MM-DD". The format for CURRENT_TIMESTAMP is "YYYY-MM-DD HH:MM:SS".
Select
query (CREATE TABLE ... AS SELECT Statements )INSERT INTO Destination SELECT * FROM Source;
Upvotes: 1
Reputation: 5278
If you are storing just the 5 values ever, SharedPreferences are a better way to do it.
Upvotes: 0