0

我正在尝试在 Mozilla 平台中使用存储机制(在 thundebird 3.0 中)。

每次测试后使用以下代码擦除数据库中存在的表:

function tearDown()
{
  let database = new Database();

  let req1 = "SELECT name FROM sqlite_master WHERE type='table'";
  let statement = database.connection.createStatement(req1);
  let tables = [];
  while(statement.executeStep()) {
    tables.push(statement.row.name);
  }
  statement.reset();
  for(table in tables) {
    let req2 = "DROP TABLE " + tables[table];
    database.connection.executeSimpleSQL(req2);
  }
}

但是我在( ) 期间executeSimpleSQL出现错误,似乎 SQLite 没有从第一条语句中释放锁。我试过, ,但没有任何效果。如何正确释放第一条语句的锁?req2NS_ERROR_FILE_IS_LOCKEDreset()finalize()

4

2 回答 2

2

回答自己:我忘记在我的应用程序的先前代码中发布先前的语句。

最后的故事:当你使用

statement.executeStep()

查看:

  • 确保此语句的最后一次调用返回 false
  • 或者永远不会忘记发布它:

    statement.reset();

于 2009-10-30T15:32:01.010 回答
1
var statement = dbConn.createStatement("SELECT COUNT(name) AS nameOcurrences FROM Table1 WHERE name = '" + aName + "';");

var occurrences;

while(statement.executeStep()) {
   occurrences = statement.row.nameOcurrences; 
}
于 2013-03-11T15:40:14.433 回答