i'm developing an app in which i create a database with several tables:
public class Database extends SQLiteOpenHelper {
private static final String DB_NAME = "db";
private static final int DB_VERSION = 1;
public Database(Context context) {
super(context,DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String table = "CREATE TABLE users(";
table += "_id TEXT PRIMARY KEY,";
table += "cat TEXT NOT NULL,";
table += "city TEXT NOT NULL,";
table += "country TEXT NOT NULL,";
table += "addr TEXT,";
String table2 = "CREATE TABLE special(";
table2 += "idspec TEXT PRIMARY KEY);";
String table3 = "CREATE TABLE places(";
table3 += "id TEXT PRIMARY KEY,";
table3 += "text TEXT NOT NULL,";
table3 += "data TEXT NOT NULL,";
table3 += "user TEXT REFERENCES users(_id));";
String table4 = "CREATE TABLE average(";
table4 += "user TEXT PRIMARY KEY,";
table4 += "place INTEGER NOT NULL,";
table4 += "avg REAL NOT NULL);";
db.execSQL(table);
db.execSQL(table2);
db.execSQL(table3);
db.execSQL(table4);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
I want to add further table that has about 70 entries that i will read in other classes. So, how to add a pre-filled table? Maybe, there is a best way to reach the same purpose, sorry if i don't know it.
Aucun commentaire:
Enregistrer un commentaire