Poco使用SQLite的事务

最近要导入一些数据,由于涉及主键与外键的关系,迫切需要得知插入后的自增字段,但又担心多客户端录入导致获取的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;
}

你可能感兴趣的:(c,String,session,sqlite,insert)