SQLite 文件使用 Memory 模式 4年前

SQLiteConnection source = new SQLiteConnection("Data Source=c:\\test.db");
source.Open();

using (SQLiteConnection destination = new SQLiteConnection("Data Source=:memory:"))
{
  destination.Open();               

  // copy db file to memory
  source.BackupDatabase(destination, "main", "main",-1, null, 0);
  source.Close();

  // insert, select ,...        
  using (SQLiteCommand command = new SQLiteCommand())
  {
    command.CommandText = "INSERT INTO t1 (x) VALUES('some new value');";

    command.Connection = destination;
    command.ExecuteNonQuery();
  }             

  source = new SQLiteConnection("Data Source=c:\\test.db");
  source.Open();

  // save memory db to file
  destination.BackupDatabase(source, "main", "main",-1, null, 0);
  source.Close();               
}
M
Mike隋
只要轻唤你的名字,我们的羁绊就永远不会消逝。
2
发布数
2
关注者
1326
累计阅读

热门教程文档

爬虫
6小节
HTML
32小节
CSS
33小节
Lua
21小节
Gin
17小节
广告