从之前终止的数据库连接中提交SQLite中的现有日志文件

时间:2022-05-28 12:23:37

I'm prototyping a script that creates large SQLite databases with a four day time limit. The time limit was reached before the script finished and the connection.commit() command would be executed. The script is dropped and the database connection terminated but the journal is still in the file directory where the database was being created.

我正在创建一个脚本,该脚本创建具有四天时间限制的大型SQLite数据库。在脚本完成之前达到了时间限制,并且将执行connection.commit()命令。删除脚本并终止数据库连接,但日志仍在创建数据库的文件目录中。

I'd like to commit the existing journal to see if the current script is on the right track. Initially I just try (using the Python sqlite3 module on iPython):

我想提交现有的日志,看看当前的脚本是否在正确的轨道上。最初我只是尝试(在iPython上使用Python sqlite3模块):

connection = sqlite3.connect('mydatabase')

connection.commit()

but I suspect I need to specify that I want to commit the existing journal. I tried passing the journal name as an argument in commit(), but commit() doesn't take arguments in the sqlite3 Python module.

但我怀疑我需要指定我想提交现有的期刊。我尝试将日志名称作为参数传递给commit(),但是commit()不接受sqlite3 Python模块中的参数。

In the future I'll incrementally .commit()

将来我会逐步增加.commit()

1 个解决方案

#1


3  

When SQLite is changing a database, some new data is in SQLite's cache, will other new data has been written to disk. When SQLite is killed in the middle of a transaction, all data in the cache has been lost, so the state of the database will be inconsistent. In that situation, the only option is to roll back the transaction to get back into a consistent state.

当SQLite正在更改数据库时,一些新数据在SQLite的缓存中,其他新数据将被写入磁盘。当SQLite在事务中被杀死时,缓存中的所有数据都已丢失,因此数据库的状态将不一致。在这种情况下,唯一的选择是回滚事务以恢复到一致状态。

The -journal file actually contains the old data, the new data has been written into the actual DB file. If you really want to see the changes made by your partial transaction, you can try to delete the -journal file (which prevents SQLite from doing the automaticlly rollback) and then opening the database, but the state of the database then is inconsistent, so it's likely that you won't be able to access all data.

-journal文件实际上包含旧数据,新数据已写入实际的DB文件中。如果你真的想看到部分事务所做的更改,你可以尝试删除-journal文件(这会阻止SQLite进行自动回滚),然后打开数据库,但数据库的状态则不一致,所以您可能无法访问所有数据。

#1


3  

When SQLite is changing a database, some new data is in SQLite's cache, will other new data has been written to disk. When SQLite is killed in the middle of a transaction, all data in the cache has been lost, so the state of the database will be inconsistent. In that situation, the only option is to roll back the transaction to get back into a consistent state.

当SQLite正在更改数据库时,一些新数据在SQLite的缓存中,其他新数据将被写入磁盘。当SQLite在事务中被杀死时,缓存中的所有数据都已丢失,因此数据库的状态将不一致。在这种情况下,唯一的选择是回滚事务以恢复到一致状态。

The -journal file actually contains the old data, the new data has been written into the actual DB file. If you really want to see the changes made by your partial transaction, you can try to delete the -journal file (which prevents SQLite from doing the automaticlly rollback) and then opening the database, but the state of the database then is inconsistent, so it's likely that you won't be able to access all data.

-journal文件实际上包含旧数据,新数据已写入实际的DB文件中。如果你真的想看到部分事务所做的更改,你可以尝试删除-journal文件(这会阻止SQLite进行自动回滚),然后打开数据库,但数据库的状态则不一致,所以您可能无法访问所有数据。