本文整理汇总了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;
};