1 回答

TA貢獻(xiàn)1846條經(jīng)驗(yàn) 獲得超7個(gè)贊
該backup to語法不是本機(jī) SQLite SQL 語法,而是由 Xerial JDBC 驅(qū)動(dòng)程序根據(jù)此處的文檔提供:
將整個(gè)數(shù)據(jù)庫(kù)備份到 backup.db 文件中:
// Create a memory database
Connection conn = DriverManager.getConnection("jdbc:sqlite:");
Statement stmt = conn.createStatement();
// Do some updates
stmt.executeUpdate("create table sample(id, name)");
stmt.executeUpdate("insert into sample values(1, \"leo\")");
stmt.executeUpdate("insert into sample values(2, \"yui\")");
// Dump the database contents to a file
stmt.executeUpdate("backup to backup.db");
Restore the database from a backup file:
// Create a memory database
Connection conn = DriverManager.getConnection("jdbc:sqlite:");
// Restore the database from a backup file
Statement stat = conn.createStatement();
stat.executeUpdate("restore from backup.db");
如果您對(duì)他們的來源進(jìn)行逆向工程,您可以看到該命令被攔截,并轉(zhuǎn)換為以下特定方法org.sqlite.core.NativeDB:
native synchronized int backup(byte[] dbNameUtf8, byte[] destFileNameUtf8,
ProgressObserver observer) throws SQLException;
即它綁定到 SQLite 備份 API,它只能對(duì)實(shí)際文件進(jìn)行操作,不能對(duì)內(nèi)存中的數(shù)據(jù)結(jié)構(gòu)進(jìn)行操作。
因此,恐怕您無法使用當(dāng)前版本的 SQLite 攔截該備份并將其發(fā)送到byte[]變量中,而無需編寫中間臨時(shí)文件,無論是直接使用 jOOQ 或 JDBC 還是本機(jī) SQLite
添加回答
舉報(bào)