与HTC Desire HD的源码问题源码、问题、HTC、Desire

2023-09-12 06:21:36 作者:半生輕狂客

最近我已经获得了很多有关的HTC Desire系列的投诉并没有在调用SQL语句。我从用户使用包含以下日志快照收到的报告。

Recently I have been getting a lot of complaints about the HTC Desire series and it failing while invoking sql statements. I have received reports from users with log snapshots that contain the following.

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

其次是我的应用程序基本上是燃烧的火焰,因为调用打开数据库会导致严重的运行错误表现为光标保持打开。不应该有一个光标在这一点上,我们正在试图打开它。

followed by my app basically burning in flames because the call to open the database results in a serious runtime error that manifests itself as the cursor being left open. There shouldn't be a cursor at this point as we are trying to open it.

这仅发生与HTC Desire HD的和Z.我的code主要做了以下的(变化不大隔离问题区域)。

This only occurs with the HTC Desire HD and Z. My code basically does the following (changed a little to isolate the problem area).

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);

  // Create a file in the app's file directory since sqlite requires a path
  // Not ideal but we will copy the file out of our bundled assets and open it
  // it in another location.
  FileOutputStream myOutput = context.openFileOutput(dbName, Context.MODE_PRIVATE);

  byte[] buffer = new byte[1024];
  int length;
  while ((length = myInput.read(buffer)) > 0) {
      myOutput.write(buffer, 0, length);
  }

  // Close the streams
  myOutput.flush();
  // Guarantee Write!
  myOutput.getFD().sync();
  myOutput.close();
  myInput.close();
  // Not grab the newly written file
  File fileObj = context.getFileStreamPath(dbName);
  // and open the database
  return db = SQLiteDatabase.openDatabase(fileObj.getAbsolutePath(), null, SQLiteDatabase.OPEN_READONLY | SQLiteDatabase.NO_LOCALIZED_COLLATORS);
}

可悲的是这款手机仅在英国上市,我没有一个在我的库存。我只得到这种类型的HTC Desire的系列报道。我不知道是什么改变了,因为这code一直没有任何问题。是否有什么我失踪?

Sadly this phone is only available in the UK and I don't have one in my inventory. I am only getting reports of this type from the HTC Desire series. I don't know what changed as this code has been working without any problem. Is there something I am missing?

推荐答案

简短的回答:尝试删除 SQLiteDatabase.OPEN_READONLY

Short answer: try removing SQLiteDatabase.OPEN_READONLY.

再回应:

在沃的预写日志,在SQLite的一个相对较新的功能,据我所知。在WAL SQLite的文档说这是不可能打开只读WAL数据库。现在,似乎更在只读介质的范围内,但它可能仍然适用于 OPEN_READONLY

The "WAL" is the write-ahead log, a relatively new feature in SQLite as I understand it. The SQLite docs on WAL say "It is not possible to open read-only WAL databases." Now, that appears to be more in the context of read-only media, but it might hold true for OPEN_READONLY.

我会感到有些吃惊,如果这会有所帮助,因为它presumes是:

I'd be somewhat surprised if this helps, as it presumes that:

在沃尔玛未在标准Android使用 HTC启用沃尔玛在这两个设备 在一些特别的东西你的环境(例如,你schlepping出资产的二进制数据库)是导致此问题,在一个普通的只读数据库仍然正常工作,因为我无法想象,这些设备将已通过兼容性测试,破只读数据库支持

不过,我倒觉得它至少是值得一试。

But, I would think it is at least worth a shot.

您也可以考虑从包装二进制数据库到包装的SQL语句来构建/填充数据库,并执行它们的切换。而这将是比较慢(慢得多,如果你不使用事务),它可能是不易于数据库文件特有的问题。

You might also consider switching from packaging the binary database to packaging the SQL statements to build/populate the database and executing them. While this will be slower (much slower if you don't use transactions), it might be less prone to database file-specific issues.