本文整理汇总了C++中CppSQLite3DB::lastRowId方法的典型用法代码示例。如果您正苦于以下问题:C++ CppSQLite3DB::lastRowId方法的具体用法?C++ CppSQLite3DB::lastRowId怎么用?C++ CppSQLite3DB::lastRowId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CppSQLite3DB
的用法示例。
在下文中一共展示了CppSQLite3DB::lastRowId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ExportToSqliteDB
//##ModelId=474D30760272
bool CClip_ImportExport::ExportToSqliteDB(CppSQLite3DB &db)
{
bool bRet = false;
try
{
//Add to Main Table
m_Desc.Replace(_T("'"), _T("''"));
db.execDMLEx(_T("insert into Main values(NULL, %d, '%s');"), CURRENT_EXPORT_VERSION, m_Desc);
long lId = (long)db.lastRowId();
//Add to Data table
CClipFormat* pCF;
CppSQLite3Statement stmt = db.compileStatement(_T("insert into Data values (NULL, ?, ?, ?, ?);"));
for(int i = m_Formats.GetSize()-1; i >= 0 ; i--)
{
pCF = & m_Formats.ElementAt(i);
stmt.bind(1, lId);
stmt.bind(2, GetFormatName(pCF->m_cfType));
long lOriginalSize = GlobalSize(pCF->m_hgData);
stmt.bind(3, lOriginalSize);
const unsigned char *Data = (const unsigned char *)GlobalLock(pCF->m_hgData);
if(Data)
{
//First compress the data
long lZippedSize = compressBound(lOriginalSize);
Bytef *pZipped = new Bytef[lZippedSize];
if(pZipped)
{
int nZipReturn = compress(pZipped, (uLongf *)&lZippedSize, (const Bytef *)Data, lOriginalSize);
if(nZipReturn == Z_OK)
{
stmt.bind(4, pZipped, lZippedSize);
}
delete []pZipped;
pZipped = NULL;
}
}
GlobalUnlock(pCF->m_hgData);
stmt.execDML();
stmt.reset();
m_Formats.RemoveAt(i);
}
bRet = true;
}
CATCH_SQLITE_EXCEPTION_AND_RETURN(false)
return bRet;
}
示例2: InsertReocord
int CDBObject::InsertReocord(const char* pProvider, const char* pDVRName, string pId,
int pChannelId, const char* pDVRAddr, int state, int type, const char* path, const char* file, const char* startTime, const char* endTime)
{
char szSql[MAX_PATH] = {0};
sprintf_s(szSql, "insert into Record values(NULL, '%s', '%s', '%s' , '%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ",
pId.c_str(), pDVRName, pProvider, pChannelId, pId.c_str(), pDVRAddr, file, path, "", "", startTime, endTime);
CppSQLite3DB db;
db.open(g_szFile);
int nRet2 = db.execDML("begin transaction;");
string strSql = szSql;
nRet2 = db.execDML(ASCII2UTF_8(strSql).c_str());
nRet2 = db.execDML("commit transaction;");
return (int)(db.lastRowId());
}
示例3: testCppSQLite
void testCppSQLite()
{
try
{
int i, fld;
time_t tmStart, tmEnd;
remove(gszFile);
CppSQLite3DB* db = getSQLiteDB();
cout << "SQLite Version: " << db->SQLiteVersion() << endl;
cout << endl << "Creating emp table" << endl;
db->execDML("create table emp(empno int, empname char(20));");
///////////////////////////////////////////////////////////////
// Execute some DML, and print number of rows affected by each one
///////////////////////////////////////////////////////////////
cout << endl << "DML tests" << endl;
int nRows = db->execDML("insert into emp values (7, 'David Beckham');");
cout << nRows << " rows inserted" << endl;
nRows = db->execDML(
"update emp set empname = 'Christiano Ronaldo' where empno = 7;");
cout << nRows << " rows updated" << endl;
nRows = db->execDML("delete from emp where empno = 7;");
cout << nRows << " rows deleted" << endl;
/////////////////////////////////////////////////////////////////
// Transaction Demo
// The transaction could just as easily have been rolled back
/////////////////////////////////////////////////////////////////
int nRowsToCreate(50000);
cout << endl << "Transaction test, creating " << nRowsToCreate;
cout << " rows please wait..." << endl;
tmStart = time(0);
db->execDML("begin transaction;");
for (i = 0; i < nRowsToCreate; i++)
{
char buf[128];
sprintf(buf, "insert into emp values (%d, 'Empname%06d');", i, i);
db->execDML(buf);
}
db->execDML("commit transaction;");
tmEnd = time(0);
////////////////////////////////////////////////////////////////
// Demonstrate CppSQLiteDB::execScalar()
////////////////////////////////////////////////////////////////
cout << db->execScalar("select count(*) from emp;")
<< " rows in emp table in ";
cout << tmEnd-tmStart << " seconds (that was fast!)" << endl;
////////////////////////////////////////////////////////////////
// Re-create emp table with auto-increment field
////////////////////////////////////////////////////////////////
cout << endl << "Auto increment test" << endl;
db->execDML("drop table emp;");
db->execDML(
"create table emp(empno integer primary key, empname char(20));");
cout << nRows << " rows deleted" << endl;
for (i = 0; i < 5; i++)
{
char buf[128];
sprintf(buf,
"insert into emp (empname) values ('Empname%06d');", i+1);
db->execDML(buf);
cout << " primary key: " << db->lastRowId() << endl;
}
///////////////////////////////////////////////////////////////////
// Query data and also show results of inserts into auto-increment field
//////////////////////////////////////////////////////////////////
cout << endl << "Select statement test" << endl;
CppSQLite3Query q = db->execQuery("select * from emp order by 1;");
for (fld = 0; fld < q.numFields(); fld++)
{
cout << q.fieldName(fld) << "(" << q.fieldDeclType(fld) << ")|";
}
cout << endl;
while (!q.eof())
{
cout << q.fieldValue(0) << "|";
cout << q.fieldValue(1) << "|" << endl;
q.nextRow();
}
///////////////////////////////////////////////////////////////
// SQLite's printf() functionality. Handles embedded quotes and NULLs
////////////////////////////////////////////////////////////////
cout << endl << "SQLite sprintf test" << endl;
CppSQLite3Buffer bufSQL;
bufSQL.format("insert into emp (empname) values (%Q);", "He's bad");
cout << (const char*)bufSQL << endl;
db->execDML(bufSQL);
//.........这里部分代码省略.........