本文整理汇总了C++中CppSQLite3Statement::reset方法的典型用法代码示例。如果您正苦于以下问题:C++ CppSQLite3Statement::reset方法的具体用法?C++ CppSQLite3Statement::reset怎么用?C++ CppSQLite3Statement::reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CppSQLite3Statement
的用法示例。
在下文中一共展示了CppSQLite3Statement::reset方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: testCppSQLite
//.........这里部分代码省略.........
// use CppSQLiteTable::setRow() method
//////////////////////////////////////////////////////////////////
cout << endl << "getTable() test" << endl;
CppSQLite3Table t = db->getTable("select * from emp order by 1;");
for (fld = 0; fld < t.numFields(); fld++)
{
cout << t.fieldName(fld) << "|";
}
cout << endl;
for (int row = 0; row < t.numRows(); row++)
{
t.setRow(row);
for (int fld = 0; fld < t.numFields(); fld++)
{
if (!t.fieldIsNull(fld))
cout << t.fieldValue(fld) << "|";
else
cout << "NULL" << "|";
}
cout << endl;
}
////////////////////////////////////////////////////////////////////
// Test CppSQLiteBinary by storing/retrieving some binary data, checking
// it afterwards to make sure it is the same
//////////////////////////////////////////////////////////////////
cout << endl << "Binary data test" << endl;
db->execDML("create table bindata(desc char(10), data blob);");
unsigned char bin[256];
CppSQLite3Binary blob;
for (i = 0; i < sizeof bin; i++)
{
bin[i] = i;
}
blob.setBinary(bin, sizeof bin);
bufSQL.format("insert into bindata values ('testing', %Q);",
blob.getEncoded());
db->execDML(bufSQL);
cout << "Stored binary Length: " << sizeof bin << endl;
q = db->execQuery("select data from bindata where desc = 'testing';");
if (!q.eof())
{
blob.setEncoded((unsigned char*)q.fieldValue("data"));
cout << "Retrieved binary Length: "
<< blob.getBinaryLength() << endl;
}
const unsigned char* pbin = blob.getBinary();
for (i = 0; i < sizeof bin; i++)
{
if (pbin[i] != i)
{
cout << "Problem: i: ," << i << " bin[i]: "
<< pbin[i] << endl;
}
}
/////////////////////////////////////////////////////////
// Pre-compiled Statements Demo
/////////////////////////////////////////////////////////////
cout << endl << "Transaction test, creating " << nRowsToCreate;
cout << " rows please wait..." << endl;
db->execDML("drop table emp;");
db->execDML("create table emp(empno int, empname char(20));");
tmStart = time(0);
db->execDML("begin transaction;");
CppSQLite3Statement stmt = db->compileStatement(
"insert into emp values (?, ?);");
for (i = 0; i < nRowsToCreate; i++)
{
char buf[16];
sprintf(buf, "EmpName%06d", i);
stmt.bind(1, i);
stmt.bind(2, buf);
stmt.execDML();
stmt.reset();
}
db->execDML("commit transaction;");
tmEnd = time(0);
cout << db->execScalar("select count(*) from emp;")
<< " rows in emp table in ";
cout << tmEnd-tmStart << " seconds (that was even faster!)" << endl;
cout << endl << "End of tests" << endl;
}
catch (CppSQLite3Exception& e)
{
cerr << e.errorCode() << ":" << e.errorMessage() << endl;
}
}
示例3: ERROR
EXPORT_C gint32 CContactDb::UpdateEntity(CDbEntity * pEntity)
{
int i;
char sql[256] = {0};
OpenDatabase();
try
{
m_dbBeluga.execDML("begin transaction;");
/* update contact entity */
strcpy(sql, "update contact set ");
for (i=1; i<ContactField_EndFlag; i++)
{
GString * fieldName = (GString*)g_ptr_array_index(m_pFieldsName, i);
strcat(sql, fieldName->str);
strcat(sql, " = ?");
if (i != ContactField_EndFlag - 1)
strcat(sql, ", ");
}
strcat(sql, "where cid = ?;");
CppSQLite3Statement statement = m_dbBeluga.compileStatement(sql);
GString * idValue = NULL;
if (ECode_No_Error == pEntity->GetFieldValue(0, &idValue))
{
statement.bind(ContactField_EndFlag, idValue->str);
g_string_free(idValue, TRUE);
}
else
statement.bindNull(ContactField_EndFlag);
for (i=1; i<ContactField_EndFlag; i++)
{
GString * fieldValue = NULL;
if (ECode_No_Error == pEntity->GetFieldValue(i, &fieldValue))
{
statement.bind(i, fieldValue->str);
g_string_free(fieldValue, TRUE);
}
else
statement.bindNull(i);
}
statement.execDML();
statement.reset();
/* update contact_ext entity */
CContact * contact = (CContact*)pEntity;
GString * fieldValue = NULL;
contact->GetFieldValue(ContactField_Type, &fieldValue);
if (ContactType_Phone == atoi(fieldValue->str))
{
CPhoneContact * phonecontact = (CPhoneContact*)pEntity;
GString * fieldId = NULL;
phonecontact->GetFieldValue(ContactField_Id, &fieldId);
memset(sql, 0, sizeof(sql));
sprintf(sql, "delete from contact_ext where cid = %d;", atoi(fieldId->str));
m_dbBeluga.execDML(sql);
/* insert phones */
GHashTable * phones = NULL;
phonecontact->GetAllPhones(&phones);
g_hash_table_foreach(phones, update_contact_ext_row, phonecontact);
g_hash_table_destroy(phones);
/* insert emails */
GHashTable * emails = NULL;
phonecontact->GetAllEmails(&emails);
g_hash_table_foreach(emails, update_contact_ext_row, phonecontact);
g_hash_table_destroy(emails);
/* insert ims */
GHashTable * ims = NULL;
phonecontact->GetAllIMs(&ims);
g_hash_table_foreach(ims, update_contact_ext_row, phonecontact);
g_hash_table_destroy(ims);
/* insert addresses */
GPtrArray * addresses = NULL;
phonecontact->GetAllAddresses(&addresses);
for (guint32 j=0; j<addresses->len; j++)
{
memset(sql, 0, sizeof(sql));
stAddress * addr = (stAddress*)g_ptr_array_index(addresses, j);
sprintf(sql, "insert into address values(NULL, %d, '%s', '%s', '%s', '%s', '%s', '%s');",
addr->atype, addr->block, addr->street, addr->district,
addr->city, addr->state, addr->country, addr->postcode);
guint32 nAddrId = m_dbBeluga.execScalar("select max(aid) from address;");
memset(sql, 0, sizeof(sql));
sprintf(sql, "insert into contact_ext values(NULL, %d, %d, %d);",
atoi(fieldId->str), addr->atype, nAddrId);
m_dbBeluga.execDML(sql);
}
freeAddressArray(addresses);
g_string_free(fieldId, TRUE);
}
g_string_free(fieldValue, TRUE);
m_dbBeluga.execDML("commit transaction;");
//.........这里部分代码省略.........
示例4: values
int Maxthon3PlugIn::ImportFavoriteData( PFAVORITELINEDATA pData, int32& nDataNum )
{
if (pData == NULL || nDataNum == 0)
{
return ERROR_INVALID_PARAM;
}
#define MAX_BUFFER_LEN 4096
CppSQLite3DB m_SqliteDatabase;
wchar_t szInsert[MAX_BUFFER_LEN] = {0};
wchar_t szDelete[MAX_BUFFER_LEN] = {0};
if (m_pMemFavoriteDB != NULL)
{
m_SqliteDatabase.openmem(m_pMemFavoriteDB, "");
int i = 0;
m_SqliteDatabase.execDML(StringHelper::UnicodeToUtf8(L"delete from MyFavNodes where parent_id <> ''").c_str());
m_SqliteDatabase.execDML("begin transaction");
for (int i = 0; i < nDataNum; i++)
{
if (pData[i].bDelete == true)
{
continue;
}
swprintf_s(szInsert, MAX_BUFFER_LEN-1, L"insert into MyFavNodes"
L"(id,parent_id,type,title,url,most_fav,visit_count,norder,add_date,shortcut)"
L" values(?,?,%d,?,?,0,0,%d,%d,0)",
pData[i].bFolder == true ? IT_FOLDER : IT_URL,
pData[i].nOrder,
(int32)pData[i].nAddTimes);
CppSQLite3Statement sqliteStatement = m_SqliteDatabase.compileStatement(StringHelper::UnicodeToANSI(szInsert).c_str());
std::string strTemp1 = StringHelper::StringToHex(
StringHelper::ANSIToUnicode(CMD5Checksum::GetMD5((BYTE *)&pData[i].nId, sizeof(int32))));
sqliteStatement.bind(1, (unsigned char *)strTemp1.c_str(), strTemp1.length());
if (pData[i].nPid == 0)
{
unsigned char szParentNode[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
sqliteStatement.bind(2, szParentNode, 16);
}
else
{
strTemp1 = StringHelper::StringToHex(StringHelper::ANSIToUnicode(
CMD5Checksum::GetMD5((BYTE *)&pData[i].nPid, sizeof(int32))).c_str());
sqliteStatement.bind(2, (unsigned char *)strTemp1.c_str(), strTemp1.length());
}
sqliteStatement.bind(3, (unsigned char *)pData[i].szTitle, (wcslen(pData[i].szTitle) + 1) * sizeof(wchar_t));
sqliteStatement.bind(4, (unsigned char *)pData[i].szUrl, (wcslen(pData[i].szUrl) + 1) * sizeof(wchar_t));
sqliteStatement.execDML();
sqliteStatement.reset();
}
m_SqliteDatabase.execDML("commit transaction");
SaveDatabase();
return ERROR_OK;
}
return ERROR_SQLITE_ERROR;
}