本文整理汇总了C++中DataTable::getRows方法的典型用法代码示例。如果您正苦于以下问题:C++ DataTable::getRows方法的具体用法?C++ DataTable::getRows怎么用?C++ DataTable::getRows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataTable
的用法示例。
在下文中一共展示了DataTable::getRows方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: executeSqlInsert
int SqliteClient::executeSqlInsert(const DataTable& table)
{
Locker locker(&_sqliteDbMutex);
if(table.getName().empty())
return -1;
if(table.columnCount() == 0)
return -2;
if(table.rowCount() == 0)
return -3;
// such like '"INSERT INTO example VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)";'
string valuesStr = "";
int columnCount = table.columnCount();
for (int i = 0; i < columnCount; i++)
{
if(i != 0)
{
valuesStr += ", ";
}
valuesStr += Convert::convertStr("?%d", i + 1);
}
string sql = Convert::convertStr("INSERT INTO [%s] VALUES (%s)", table.getName().c_str(), valuesStr.c_str());
sqlite3_stmt *stmt;
int result = sqlite3_prepare_v2(_sqliteDb, sql.c_str(), sql.length(), &stmt, 0);
if(result != SQLITE_OK)
{
printErrorInfo("sqlite3_prepare_v2", sql);
return result;
}
result = execute("BEGIN TRANSACTION");
if(result != SQLITE_OK)
{
return result;
}
int rowCount = table.rowCount();
for (int i = 0; i < rowCount; i++)
{
const DataRow* row = table.getRows()->at(i);
for (int j = 0; j < columnCount; j++)
{
const DataCell* cell = row->getCells()->at(j);
if(cell != NULL)
{
ValueTypes type = cell->getType();
const Value value = cell->getValue();
switch (type)
{
case Null:
sqlite3_bind_null(stmt, j + 1);
break;
case Integer:
sqlite3_bind_int(stmt, j + 1, value.nValue);
break;
case DateTime:
case String:
result = sqlite3_bind_text(stmt, j + 1, value.strValue, strlen(value.strValue), SQLITE_TRANSIENT);
break;
case Float:
sqlite3_bind_double(stmt, j + 1, value.dValue);
break;
default:
assert(false);
break;
}
}
}
result = sqlite3_step(stmt);
if (result != SQLITE_DONE)
{
printErrorInfo("sqlite3_step", sql);
}
result = sqlite3_reset(stmt);
if(result != SQLITE_OK)
{
printErrorInfo("sqlite3_reset", sql);
}
}
result = execute("COMMIT TRANSACTION");
if(result != SQLITE_OK)
{
return result;
}
sqlite3_finalize(stmt);
if(result != SQLITE_OK)
{
printErrorInfo("sqlite3_finalize", sql);
return result;
}
return SQLITE_OK;
}