Poco使用SQLite的事务
发布时间:2020-12-12 20:27:45 所属栏目:百科 来源:网络整理
导读:最近要导入一些数据,由于涉及主键与外键的关系,迫切需要得知插入后的自增字段,但又担心多客户端录入导致获取的rowid不一致。于是采用了事务。 #include iostream#include string#include "Poco/Data/Common.h"#include "Poco/Data/SQLite/Connector.h"usin
最近要导入一些数据,由于涉及主键与外键的关系,迫切需要得知插入后的自增字段,但又担心多客户端录入导致获取的rowid不一致。于是采用了事务。
#include <iostream> #include <string> #include "Poco/Data/Common.h" #include "Poco/Data/SQLite/Connector.h" using namespace Poco::Data; using namespace std; int main() { std::string caseno="CNO1311"; SQLite::Connector::registerConnector(); Session ses("SQLite","C:EviChain.db"); ses<<"BEGIN TRANSACTION",now; ses<<"Insert INTO [Case](CaseNo) VALUES (:cno)",use(caseno),now; ses<<"SELECT DISTINCT(LAST_INSERT_ROWID()) AS RowID FROM [Case]",into(count),now; ses<<"COMMIT TRANSACTION",now; SQLite::Connector::unregisterConnector(); return 0; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |