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


C++ MySQL::hasNext方法代码示例

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


在下文中一共展示了MySQL::hasNext方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main ( ) {
	/* Create MySQL object */
	MySQL sql;
	
	/* Open Database */
	std::cout << "Connecting to 'localhost' using 'test' database" << std::endl;
	assert ( sql.connect ( "localhost", "root", "blue23", "test" ) == true );
	std::cout << "Opening was successful" << std::endl;	

	/* Create a table */		
	std::cout << "Creating table tbl1 (one int, two int)" << std::endl;
	assert ( sql.exec ( "create table tbl1 (one int, two int);" ) == 1 );
	std::cout << "Created table tbl1" << std::endl;
	
	/* Insert values */
	std::cout << "Insert values ( 10, 10 ) into tbl1" << std::endl; 
	assert ( sql.exec ( "insert into tbl1 (one, two) VALUES ( 10, 10 )" ) == 1 );
	std::cout << "Inserted values successfully" << std::endl;

	/* Query values */
	std::cout << "Query values to make sure of integraty" << std::endl;
	assert ( sql.query ( "select * from tbl1" ) == 1);
	std::cout << "Query was successful" << std::endl;
	
	/* Integraty of values */
	std::cout << "Checking to see if query returned results" << std::endl;
	assert ( sql.hasNext ( ) );
	std::cout << "Results were returned" << std::endl;

	/* Check to see that we get a total of two columns ( one, two ) from query */
	std::cout << "Checking to see if a record has two entries ( one, two )" << std::endl;
	std::vector<std::string> l = sql.next ( );
	assert( l.size() == 2 );
	std::cout << "Integraty was achieved for record count" << std::endl;
	
	/* Check Integraty of inserted row ( 10, 10 ) */
	std::cout << "Checking to see one = 10" << std::endl;
	assert( l[0].compare ( "10" ) == 0 );
	std::cout << "Checking to see two = 10" << std::endl; 
	assert( l[1].compare ( "10" ) == 0 );
	
	/* Clear out values */
	std::cout << "Clearing values from database" << std::endl;
	assert ( sql.query ( "delete from tbl1" ) == 1 );
	std::cout << "Database values were cleared" << std::endl;
	
	/* Remove table */
	std::cout << "Removing table tbl1 from database" << std::endl;
	assert ( sql.query ( "DROP TABLE IF EXISTS tbl1" ) == 1);
	std::cout << "Table tbl1 was removed from database" << std::endl;

	/* Close database */
	std::cout << "Database attempting to close" << std::endl;
	sql.disconnect ();
	std::cout << "Database closed" << std::endl;
	
	/* Closing statements */
	std::cout << "Finished unit testing :D" << std::endl;
	return 1;	
};
开发者ID:RodolfoSilva,项目名称:scribble-websocket-server,代码行数:60,代码来源:unit_mysql.cpp


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