热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

保存到磁盘的内存数据库。-Savingtodiskanin-memorydatabase

Imadeadatabasethroughsqliteinc++.我用c++通过sqlite创建了一个数据库。Thedbhasbeencreatedinmemory

I made a database through sqlite in c++.

我用c++通过sqlite创建了一个数据库。

The db has been created in memory (using the ":memory:" parameter insted of a filename), in order to have a very quick behavior.

db已经在内存中创建(使用“:内存:”一个文件名的参数),以便有一个非常快的行为。

The database is created by the following lines:

数据库由以下几行创建:

sqlite3* mem_database;
if((SQLITE_OK == sqlite3_open(":memory:", &mem_database)){
    // The db has been correctly created and
    // I can do some stuff with it.
}
sqlite3_close(mem_database);

My problem is: how can I write the in-memory database to disk? (through c/c++ of course).

我的问题是:如何将内存数据库写入磁盘?(当然通过c / c++)。

I read something about the ATTACH and DETACH sqlite commands, but I can get them working only with the sqlite interactive shell (not from c/c++ code).

我读了一些关于ATTACH和DETACH sqlite命令的东西,但是我可以让它们只使用sqlite交互式shell(而不是c/c++代码)。

Greets.

问候。

2 个解决方案

#1


19  

Check out this example: Loading and Saving In-Memory Databases

查看这个示例:装入和保存内存中的数据库

#2


2  

Use transaction statement before doing anything to the table. This ensures fast handling and rollbacks as well. This way, you don't need to implement the database in memory directly.

在对表执行任何操作之前,请使用事务语句。这也保证了快速处理和回滚。这样,您就不需要直接在内存中实现数据库。


推荐阅读
author-avatar
MrTkinG
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有