Tôi đã làm theo hướng dẫn chuẩn để xây dựng cơ sở dữ liệu với Android. Tôi đã tạo ra một lớp được gọi là DbHelper mở rộng SQLiteOpenHelper. Tôi đã ghi đè trình xử lý tạo để thực hiện chuỗi.Thực hiện nhiều câu lệnh với SQLiteDatabase.execSQL
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DbDefinitions.DB_CREATE);
}
DbDefinitions.DB_CREATE là chuỗi tĩnh tôi đã tạo.
public static final String TABLE_MESSAGES = "messages";
public static final String TABLE_FRIENDS = "friends";
public static final String STATE_OK = "STATE_OK";
public static final String DB_CREATE =
"create table " + TABLE_MESSAGES + " (_id integer primary key, user_id integer not null, created_on integer, subject text not null, summary text not null, messagetext text null, read integer not null, status text not null default '" + STATE_OK + "'); " +
"create table " + TABLE_FRIENDS + " (_id integer primary key, user_id integer not null, friend_id integer not null, created_on integer, status text not null default '" + STATE_OK + "');";
Tôi muốn sử dụng 1 Chuỗi để thực thi nhiều câu lệnh SQL. Làm thế nào tôi có thể làm điều này như SQLiteDatabase.execSQL chỉ cho phép 1 tuyên bố?
Cảm ơn, chỉ là những gì tôi cần làm việc giống như một nét duyên dáng. –
nếu như ';' nằm trong trường văn bản? –
**; ** ở cuối câu lệnh SQL hoàn toàn vô dụng. –