?? simple1.cc
字號:
#include <mysqlcppapi/mysqlcppapi.h>#include <iostream>#include <iomanip>int main() { // You may need to specify some connection parameters using the // Connection::set_*() members if the database is not on // the local machine or your database username is not the same as your // login name, etc.. try { mysqlcppapi::Connection con; // con.set_Host("example.com"); // con.set_User("mysql_user"); // con.set_Password("mysql_passwd"); con.connect(); con.select_database("mysql_cpp_data"); mysqlcppapi::Query query = con.create_Query(); // This creates a query object that is bound to con. query << "select * from stock"; // You can write to the query object like you would any other ostrem mysqlcppapi::Result_Store res = query.store(); // Query::store() executes the query and returns the results std::cout << "Query: " << query.preview() << std::endl; // Query::preview() simply returns a string with the current query // string in it. std::cout << "Records Found: " << res.size() << std::endl << std::endl; std::cout.setf(std::ios::left); std::cout << std::setw(17) << "Item" << std::setw(4) << "Num" << std::setw(7) << "Weight" << std::setw(7) << "Price" << "Date" << std::endl << std::endl; // The Result_Store class has a read-only Random Access Iterator for (mysqlcppapi::Result_Store::iterator i = res.begin(); i != res.end(); i++) { mysqlcppapi::Row row = *i; std::cout << std::setw(17) << row[0] << std::setw(4) << row[1] << std::setw(7) << row["weight"] // you can use either the index number or column name when // retrieving the colume data as demonstrated above. << std::setw(7) << row[3] << row[4] << std::endl; } } catch(mysqlcppapi::ex_BadQuery& er) { // handle any connection or query errors that may come up std::cerr << "Error: " << er.what() << std::endl; return -1; } catch(mysqlcppapi::ex_BadConversion& er) { // we still need to catch bad conversions in case something goes // wrong when the data is converted into stock std::cerr << "Error: Tried to convert \"" << er.get_Data() << "\" to a \"" << er.get_TypeName() << "\"." << std::endl; return -1; } return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -