当我尝试使用数据库打开我的数据库文件时,sqlite
它向我显示以下错误:
[2014-05-19 23:50:51] Failed to open database file db_penpal.db
[2014-05-19 23:50:51] null
这是否意味着我的数据库包含一些错误?如果是,我该如何解决?
提前致谢。
public class Database_handler extends SQLiteOpenHelper {
private static final int database_version = 1;
public static final String database_name = "db_e_pal.db";
public Database_handler(Context context) {
super(context, database_name, null, database_version);
}
@Override
public void onCreate(SQLiteDatabase db) {
//Creation de la table user
String create_t_user
= "CREATE TABLE IF NOT EXISTS user ("
+ "ID INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "username varchar(20) NOT NULL,"
+ "password varchar(20) NOT NULL,"
+ "connected INTEGER(0) NOT NULL);";
String create_t_friend_request
= "CREATE TABLE IF NOT EXISTS friend_request ("
+ "ID INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "username varchar(20) NOT NULL,"
+ "ID_last_message INTEGER NOT NULL);";
String create_t_friend
= "CREATE TABLE IF NOT EXISTS friend ("
+ "ID INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "username varchar(20) NOT NULL,"
+ "connected INTEGER(0) NOT NULL);";
String create_t_message
= "CREATE TABLE IF NOT EXISTS message ("
+ "ID INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "ID_friend INTEGER NOT NULL,"
+ "Sent bit(1) NOT NULL,"
+ "Body text NOT NULL,"
+ "DATE datetime NOT NULL);";
//execution des requetes
db.execSQL(create_t_user);
db.execSQL(create_t_friend_request);
db.execSQL(create_t_friend);
db.execSQL(create_t_message);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Supprimer les anciennes tables si elles existent
// Requetes pou les suppressions
String drop_t_user = "DROP TABLE IF EXISTS user";
String drop_t_message = "DROP TABLE IF EXISTS message";
String drop_t_friend = "DROP TABLE IF EXISTS friend";
String drop_t_friend_request = "DROP TABLE IF EXISTS friend_request";
// Suppression des tables
db.execSQL(drop_t_user);
db.execSQL(drop_t_message);
db.execSQL(drop_t_friend);
db.execSQL(drop_t_friend_request);
// Create tables again
onCreate(db);
}
//Les operation faites sur la bd "les CRUD"
//Vider la base de donnée
public void empty() {
SQLiteDatabase db = this.getWritableDatabase();
db.delete("user", null, null);
db.delete("message", null, null);
db.delete("friend", null, null);
db.delete("friend_request", null, null);
db.close();
}
}
这是日志:
05-20 04:35:10.757: D/dalvikvm(3907): GC_EXTERNAL_ALLOC freed 458K, 55% free 3317K/7303K,
external 1070K/1570K, paused 72ms
05-20 04:35:37.117: D/dalvikvm(3907): GC_CONCURRENT freed 435K, 47% free 3887K/7303K,
external 1530K/2027K, paused 4ms+5ms
05-20 04:35:37.117: D/Cursor(3907): Database path: db_e_pal.db
05-20 04:35:37.117: D/Cursor(3907): Table name : null
05-20 04:35:37.117: D/Cursor(3907): Database path: db_e_pal.db
05-20 04:35:37.117: D/Cursor(3907): Table name : null