当前位置: 首页>>代码示例>>C++>>正文


C++ DatabaseConnection::finalize方法代码示例

本文整理汇总了C++中DatabaseConnection::finalize方法的典型用法代码示例。如果您正苦于以下问题:C++ DatabaseConnection::finalize方法的具体用法?C++ DatabaseConnection::finalize怎么用?C++ DatabaseConnection::finalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DatabaseConnection的用法示例。


在下文中一共展示了DatabaseConnection::finalize方法的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;
}
开发者ID:samwell,项目名称:SQLiteExample,代码行数:66,代码来源:SQLiteExample.cpp


注:本文中的DatabaseConnection::finalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。