最近我收到很多关于HTC Desire系列的抱怨,并且在调用sql语句时失败了.我收到了来自用户的报告,其中包含以下内容的日志快照.
I/Database( 2348): sqlite returned: error code = 8, msg = statement aborts at 1: [pragma journal_mode = WAL;]
E/Database( 2348): sqlite3_exec to set journal_mode of /data/data/my.app.package/files/localized_db_en_uk-1.sqlite to WAL failed
Run Code Online (Sandbox Code Playgroud)
然后我的应用程序基本上在火焰中燃烧,因为打开数据库的调用导致严重的运行时错误,当光标保持打开时,它会显示出来.此时不应该有光标,因为我们正试图打开它.
这只发生在HTC Desire HD和Z.我的代码基本上执行以下操作(稍微更改以隔离问题区域).
SQLiteDatabase db;
String dbName;
public SQLiteDatabase loadDb(Context context) throws IOException{
//Close any old db handle
if (db != null && db.isOpen()) {
db.close();
}
// The name of the database to use from the bundled assets.
String dbAsset = "/asset_dir/"+dbName+".sqlite";
InputStream myInput = context.getAssets().open(dbAsset, Context.MODE_PRIVATE); …Run Code Online (Sandbox Code Playgroud) 我正在使用以下代码在android中创建一个数据库:
public class PackageDBHelper extends SQLiteOpenHelper{
//The Android's default system path of your application database.
private static String DB_PATH = "/data/data/com.myapp/databases/";
private static String DB_NAME = "my_db.db";
public SQLiteDatabase db;
private final Context myContext;
public PackageDBHelper(Context context) {
super(context, DB_NAME, null, 1);
this.myContext = context;
}
public void createDataBase() throws IOException{
boolean dbExist = checkDataBase();
if(dbExist){
//do nothing - database already exist
}else{
//By calling this method and empty database will be created into the default system path
//of your …Run Code Online (Sandbox Code Playgroud)