⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 complic1.cc

📁 有关MYSQL的开源码
💻 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 + -