sqlite 内存数据库的attach 我已经往内存数据库A插入了10W条数据,我现在想把A导入一个物理文件B(具有相同表结构),是不是应该用attach指令?有没有高人详细指点一下? sqlite3_open(":memory:",&db); ... ret = sqlite3_exec(db,"CREATE TABLE new_table1 (id integer primary key autoincrement,name vchar(32))",&zErrMsg); ret = sqlite3_exec(db,"begin transaction","insert into new_table1 (name) values ('123');","commit transaction",&zErrMsg); 到上面,数据库已经插入内存数据库了,然后再怎么导入物理文件B? sqlite3_open("c:/A.dat",&db); ret = sqlite3_exec(db,"attach A.dat as new_db2",&zErrMsg); ret = sqlite3_exec (db,"insert into new_db2.new_table2 (name) values('name')","detach new_db2",&zErrMsg); if (ret!=SQLITE_OK) MessageBox("附加数据库失败!"); 这样会提示"附加数据库失败!",不知道是那里写错了...
---------------------------------------------------
搞反了,应该把文件数据库attach到内存数据库中。sqlite3_open("c:/A.dat",&db); 这一句是多余的,应该去掉。 ret = sqlite3_exec(db,"attach 'c:/A.dat' as new_db2",&zErrMsg); 这样就可以从内存数据库中复制数据到文件数据库中了,文件数据库中没有表时使用(注意新表没有索引): create table new_db2.new_table1 as select * from new_table1; 有表时使用: insert into new_db2.new_table1 select * from new_table1;
-----------------------------------------------------
已经搞定~ ret = sqlite3_exec(db,"attach 'c:/A.dat' as new_db","insert into new_db.new_table2 (name) select name from new_table1",&zErrMsg); 300万条内存数据,10个字段,大概写入了631MB物理文件
引自:http://www.sqlite.com.cn/bbs/topicdisp.asp?tid=678 (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|