?? complic1.cc
字號:
#include <mysqlcppapi/mysqlcppapi.h>#include <iostream>#include <iomanip>int main() { try { // its in one big try block mysqlcppapi::Connection con; con.connect(); con.select_database("mysql_cpp_data"); mysqlcppapi::Query query = con.create_Query(); query << "select * from stock" << std::ends; mysqlcppapi::Result_Store res = query.store(); std::cout << "Query: " << query.preview() << std::endl; std::cout << "Records Found: " << res.size() << std::endl << std::endl; mysqlcppapi::Row row; 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; mysqlcppapi::Result_Store::iterator i; std::cout.precision(3); for (i = res.begin(); i != res.end(); i++) { row = *i; std::cout << std::setw(17) << row["item"] << "," << std::setw(4) << row[1] << std::setw(7) << (double) row[2] // This is converting the row to a double so that we // can set the precision of it. // ColData has the nice feature that it will convert to // any of the basic c++ types. if there is a problem // in the conversion it will throw an exception (which I // cache below). To test it try changing the 2 in row[2] // to row[0] << std::setw(7) << (double)row[3]; mysqlcppapi::Date date = row["sdate"]; // The ColData is implicitly converted to a date here. std::cout.setf(std::ios::right); std::cout.fill('0'); std::cout << std::setw(2) << date.month << "-" << std::setw(2) << date.day << std::endl; std::cout.fill(' '); std::cout.unsetf(std::ios::right); } return 0; } 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) { // handle bad conversions std::cerr << "Error: Tried to convert \"" << er.get_Data() << "\" to a \"" << er.get_TypeName() << "\"." << std::endl; return -1; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -