本文整理汇总了C++中TableColumns::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ TableColumns::reserve方法的具体用法?C++ TableColumns::reserve怎么用?C++ TableColumns::reserve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TableColumns
的用法示例。
在下文中一共展示了TableColumns::reserve方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getQueryColumnsInternal
Status getQueryColumnsInternal(const std::string& q,
TableColumns& columns,
sqlite3* db) {
// Turn the query into a prepared statement
sqlite3_stmt* stmt{nullptr};
auto rc = sqlite3_prepare_v2(
db, q.c_str(), static_cast<int>(q.length() + 1), &stmt, nullptr);
if (rc != SQLITE_OK || stmt == nullptr) {
if (stmt != nullptr) {
sqlite3_finalize(stmt);
}
return Status(1, sqlite3_errmsg(db));
}
// Get column count
auto num_columns = sqlite3_column_count(stmt);
TableColumns results;
results.reserve(num_columns);
// Get column names and types
Status status = Status();
bool unknown_type = false;
for (int i = 0; i < num_columns; ++i) {
auto col_name = sqlite3_column_name(stmt, i);
auto col_type = sqlite3_column_decltype(stmt, i);
if (col_name == nullptr) {
status = Status(1, "Could not get column type");
break;
}
if (col_type == nullptr) {
// Types are only returned for table columns (not expressions).
col_type = "UNKNOWN";
unknown_type = true;
}
results.push_back(std::make_tuple(
col_name, columnTypeName(col_type), ColumnOptions::DEFAULT));
}
// An unknown type means we have to parse the plan and SQLite opcodes.
if (unknown_type) {
QueryPlanner planner(q, db);
planner.applyTypes(results);
}
if (status.ok()) {
columns = std::move(results);
}
sqlite3_finalize(stmt);
return status;
}