| | |
| | | #include <iostream> |
| | | #include <mysql++.h> |
| | | #include <AppConfig.h> |
| | | #include <QtCore/QMutex> |
| | | |
| | | using namespace std; |
| | | |
| | | static mysqlpp::Connection* conn; |
| | | class BaseDao { |
| | | public: |
| | | static QMutex m_mutexVisit; |
| | | private: |
| | | static mysqlpp::Connection* conn; |
| | | public: |
| | | static mysqlpp::SimpleResult add(std::map<std::string, std::string>& columns, string tableName) { |
| | | initConnection(); |
| | |
| | | return rowDataList; |
| | | } |
| | | |
| | | static Json::Value findJsonArray(string sql) { |
| | | static Json::Value findJsonArray(string sql, std::map<std::string, std::string>& whereColumns) { |
| | | sql = sql + getWhereColumnNameValuePair(whereColumns); |
| | | initConnection(); |
| | | mysqlpp::Query query = conn->query(sql); |
| | | Json::Value rowList; |
| | |
| | | rowList.append(row); |
| | | } |
| | | } else { |
| | | cout << "error " <<query.error() << endl; |
| | | cout << "query failed" << endl; |
| | | } |
| | | return rowList; |
| | |
| | | return updateSql; |
| | | } |
| | | static void doConnect() { |
| | | // if (conn->connect( |
| | | // appConfig.getStringProperty("database").c_str(), |
| | | // appConfig.getStringProperty("db_host").c_str(), |
| | | // appConfig.getStringProperty("db_user").c_str(), |
| | | // appConfig.getStringProperty("db_password").c_str(), |
| | | // appConfig.getIntProperty("db_port") |
| | | // )) { |
| | | cout << "db_host=" << appConfig.getStringProperty("db_host").c_str() << endl; |
| | | if (conn->connect( |
| | | "basic_business_table", |
| | | "127.0.0.1", |
| | | "root", |
| | | "root", |
| | | 3306 |
| | | appConfig.getStringProperty("database").c_str(), |
| | | appConfig.getStringProperty("db_host").c_str(), |
| | | appConfig.getStringProperty("db_user").c_str(), |
| | | appConfig.getStringProperty("db_password").c_str(), |
| | | appConfig.getIntProperty("db_port") |
| | | )) { |
| | | // if (conn->connect( |
| | | // "EGEyesForVSS", |
| | | // "192.168.1.148", |
| | | // "root", |
| | | // "123456", |
| | | // 3306 |
| | | // )) { |
| | | cout << "connect success" << endl; |
| | | } else { |
| | | cout << "connect failed" << endl; |