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();               
}
冋菿厡點
梦想是否无聊并不是别人来决定的,不管是什么样的梦想,自己拼命努力去追寻才是最重要的。
3
发布数
0
关注者
5157
累计阅读

热门教程文档

MyBatis
19小节
MySQL
34小节
Java
12小节
Next
43小节
Vue
25小节
广告