本文整理汇总了C++中DatabaseConnection::getText方法的典型用法代码示例。如果您正苦于以下问题:C++ DatabaseConnection::getText方法的具体用法?C++ DatabaseConnection::getText怎么用?C++ DatabaseConnection::getText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseConnection
的用法示例。
在下文中一共展示了DatabaseConnection::getText方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
DatabaseConnection db;
try {
db.execute(const_cast<char *>("SELECT * FROM test2;"));
// Example: Listing all columns from executed query
cout << "Lists all columns from table" << endl;
list<string> columns = db.getColumns();
for(list<string>::iterator i = columns.begin(); i != columns.end(); i++)
cout << (*i) << endl;
// Example: Extracting specific data types into acceptable data types
cout << endl << "Extract specific data types" << endl;
int intTest = db.getInt(const_cast<char *>("intTest"));
double doubleTest = db.getDouble(const_cast<char *>("doubleTest"));
int numericTest = db.getInt(const_cast<char *>("numericTest"));
string blobTest = db.getText(const_cast<char *>("blobTest"));
string textTest = db.getText(const_cast<char *>("textTest"));
cout << "INT: " << intTest << endl;
cout << "DOUBLE: " << doubleTest << endl;
cout << "NUMERIC: " << numericTest << endl;
cout << "BLOB: " << blobTest << endl;
cout << "TEXT: " << textTest << endl;
// Resets the pointer back to the beginning
db.reset();
// Example: Extract any type of data types
cout << endl << "Extract any type of data types" << endl;
cout << "NUMERICTEST: " << db.getColumn(const_cast<char *>("numericTest")) << " TEXTTEST: " << db.getColumn(const_cast<char *>("textTest")) << endl;
// Got new set of data. Why? Because I can.
db.finalize();
db.execute(const_cast<char *>("SELECT * FROM test;"));
// Example: Extract all data obtained from executing the query
cout << endl << "Extract all data from query and store in a list of multimaps" << endl;
list<multimap<string, string> > results = db.fetchAll();
list<multimap<string, string> >::iterator rows = results.begin();
while(rows != results.end()) {
multimap<string, string>::iterator row = (*rows).begin();
while(row != (*rows).end()) {
cout << (*row).first << " " << (*row).second << " ";
row++;
}
cout << endl;
rows++;
}
} catch (DatabaseConnectionException e) {
cout << e.getMessage();
}
// Deletes pointer to query
db.finalize();
// Deletes pointer to database connection
db.close();
return 0;
}