gpt4 book ai didi

database - SQLite:我应该在断开连接之前分离附加的数据库吗?

转载 作者:搜寻专家 更新时间:2023-10-30 19:45:05 25 4
gpt4 key购买 nike

我应该在调用 $dbh->disconnect 之前分离附加的数据库吗?或者在这种情况下可以省略 DETACH 吗?

use DBI;

my $dbh = DBI->connect( "DBI:SQLite:dbname=my_db_1", ...

$dbh->do( "ATTACH DATABASE 'my_db_2' AS data" );
...
$dbh->do( "DETACH DATABASE data" );
$dbh->disconnect;

最佳答案

除非主数据库是内存数据库并且日志模式不是WAL(Write Ahead Logging),否则关闭数据库就可以了; 即便如此,也可能极少遇到问题。我认为 detach 是为您想要单独分离数据库的情况提供的。因此,除非另有规定,否则这实际上是个人选择的问题。

这是基于以下内容:-

Transactions involving multiple attached databases are atomic,assuming that the main database is not ":memory:" and the journal_modeis not WAL.

If the main database is ":memory:" or if the journal_modeis WAL, then transactions continue to be atomic within each individualdatabase file. But if the host computer crashes in the middle of aCOMMIT where two or more database files are updated, some of thosefiles might get the changes where others might not.

ATTACH DATABASE

This, from Tech On The Net状态:-

When the database connection is closed, the attached database will beautomatically be detached.

还有

To remove an attached database from your connection, use the DETACHDATABASE command or close the database connection.

关于database - SQLite:我应该在断开连接之前分离附加的数据库吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48536572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com