wcdb icon indicating copy to clipboard operation
wcdb copied to clipboard

Fatal Exception: java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase:

Open mikelhm opened this issue 4 years ago • 2 comments

The language of WCDB

e.g. Java

The version of WCDB

e.g. v1.0.8

The platform of WCDB

e.g. Android

The installation of WCDB

e.g. Maven

What's the issue?

SQLiteCipherSpec cipherSpec = new SQLiteCipherSpec() // 指定加密方式,使用默认加密可以省略 .setPageSize(4096) .setKDFIteration(64000);

WCDBOpenHelperFactory factory = new WCDBOpenHelperFactory() .passphrase("passphrase".getBytes()) // 指定加密DB密钥,非加密DB去掉此行 .cipherSpec(cipherSpec) // 指定加密方式,使用默认加密可以省略 .writeAheadLoggingEnabled(true) // 打开WAL以及读写并发,可以省略让Room决定是否要打开 .asyncCheckpointEnabled(true); // 打开异步Checkpoint优化,不需要可以省略

AppDatabase db = Room.databaseBuilder(this, AppDatabase.class, "app-db") //.allowMainThreadQueries() // 允许主线程执行DB操作,一般不推荐 .openHelperFactory(factory) // 重要:使用WCDB打开Room .build();

When I addMigration to add a new Tablesuch as

AppDatabase db = Room.databaseBuilder(this, AppDatabase.class, "app-db") .addMigration(XXX) .openHelperFactory(factory) // 重要:使用WCDB打开Room .build();

The problem occurs :

Fatal Exception: java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase:

mikelhm avatar May 21 '20 03:05 mikelhm

When I remove .openHelperFactory(factory) , There is nothing wrong

So I think my SQL to add a new Table is OK

mikelhm avatar May 21 '20 03:05 mikelhm

@mikelhm 你好,请问你现在解决这个问题了么?我这边也会报这个异常

wjlight avatar Aug 24 '21 07:08 wjlight

Please try v2.1.0.

Qiuwen-chen avatar Mar 08 '24 03:03 Qiuwen-chen