如何倾倒的SQLite内存数据库与ADO.NET文件? [英] How to dump SQLite in-memory database into file with ADO.NET?
问题描述
我使用 System.Data.SQLite.dll
来使用SQLite的内存数据库。节目结束后,我想在内存数据库转储到下次使用.db3文件。我如何在C#中实现这一目标?
I am using System.Data.SQLite.dll
to make use of the SQLite in-memory database. After the program finishes, I would like to dump the in-memory database into a .db3 file for next use. How can I achieve this in C#?
推荐答案
据我所知有没有内置功能来做到这一点的System.Data.SQLite.dll。该功能确实与SQLite的核心始终保持了sqlite3.exe客户但不存在
To the best of my knowledge there is not built-in functionality to accomplish this in System.Data.SQLite.dll. The functionality does however exist in the sqlite3.exe client maintained along with the SQLite core.
这是我将如何system.data.sqlite.dll做到这一点:
This is how I would do it with system.data.sqlite.dll:
-
获取SQL语句来创建新的数据库结构。
Obtain SQL statements to create new database structure.
select sql from sqlite_master where name not like 'sqlite_%';
获取所有用户表的名称。
Obtain names of all user tables.
select name
from sqlite_master
where type='table' and name not like 'sqlite_%';
创建一些新的SQLiteConnection磁盘上的数据库。
Create the on-disk database in some new SQLiteConnection.
执行所有以前获得的SQL语句在磁盘上的数据库中创建数据库结构。
Execute all previously obtained SQL statements to create the database structure in the on-disk database.
关闭独立连接到磁盘上的数据库。
Close the separate connection to the on-disk database.
附加磁盘上的数据库的内存数据库。
Attach the on-disk database to the in-memory database.
attach 'ondisk.db3' as 'ondisk';
有关较早获得每个用户表,从内存到上复制内容。-disk数据库
For each user table obtained earlier, copy the content from the in-memory to the on-disk database.
insert into ondisk.TableX select * from main.TableX;
insert into ondisk.TableY select * from main.TableY;
这篇关于如何倾倒的SQLite内存数据库与ADO.NET文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!