本文整理汇总了C++中SQLiteDatabase::beginTransaction方法的典型用法代码示例。如果您正苦于以下问题:C++ SQLiteDatabase::beginTransaction方法的具体用法?C++ SQLiteDatabase::beginTransaction怎么用?C++ SQLiteDatabase::beginTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQLiteDatabase
的用法示例。
在下文中一共展示了SQLiteDatabase::beginTransaction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test
// A test function.
void SQLiteDatabase::test()
{
// Sample usage code follows...
std::string strFileName = "sqlite3.txt";
SQLiteDatabase db;
try {
Verbose::out(1, "*");
Verbose::out(1, "Create/Open database: sqlite3.txt");
db.open(strFileName);
SQLiteRecordset rset(db);
Verbose::out(1, "create table Test1 (Id int primary key, Name varchar(255))");
db.execute("create table Test1 (Id int primary key, Name varchar(255))");
Verbose::out(2, "create table Test1 (Id int primary key, Name varchar(255))");
db.execute("create table Test2 (Id int primary key, Name varchar(255))");
Verbose::out(1, "Begin transaction...");
db.beginTransaction();
for (int iIndex = 1; (iIndex < 10); iIndex++)
{
std::string strSQL = "insert into Test1 values (" + ::getInt(iIndex) + ", 'Test1-" + ::getInt(iIndex) + "')";
Verbose::out(1, "\t" + strSQL);
db.execute(strSQL);
}
for (int iIndex = 1; (iIndex < 10); iIndex++)
{
std::string strSQL = "insert into Test2 values (" + ::getInt(iIndex) + ", 'Test2-" + ::getInt(iIndex) + "')";
Verbose::out(1, "\t" + strSQL);
db.execute(strSQL);
}
Verbose::out(1, "Commit transaction...");
db.commitTransaction();
Verbose::out(1, "select Test1.id, Test1.Name, Test2.Name from Test1, Test2 where Test1.Id = Test2.id");
rset.open("select Test1.id, Test1.Name, Test2.Name from Test1, Test2 where Test1.Id = Test2.id");
while (rset.fetch())
{
int iID = rset.getInteger(0);
std::string strName = rset.getString(1);
std::string strName2 = rset.getString(2);
Verbose::out(1, "\tfetched: " + ::getInt(iID) + ", " + strName + ", " + strName2);
}
rset.close();
Verbose::out(1, "drop table Test1");
db.execute("drop table Test1");
Verbose::out(1, "drop table Test2");
db.execute("drop table Test2");
Verbose::out(1, "Closing SQLite database");
db.close();
Verbose::out(1, "*");
} catch (SQLiteException& e) {db.rollbackTransaction(); db.close(); Verbose::out(1, e.getMessage());}
// End sample usage code
}