123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- /*
- * @Description: 数据库测试
- * @Author: yct
- * @Date: 2020-07-18 21:46:45
- * @LastEditTime: 2020-07-20 14:56:48
- * @LastEditors: yct
- */
- #include "../parkspace_allocation/database_controller.h"
- using std::cout;
- using std::endl;
- int main()
- {
- Database_controller *db = Database_controller::get_instance_pointer();
- db->database_controller_init("127.0.0.1", 3306, "yct", "123456", "test");
- // usleep(1000*1000);
- if(db->is_connected())
- {
- // 增加
- Error_manager ec = db->sql_insert("INSERT INTO my_test (content) VALUES ('aaa')");
- // usleep(1000*3000);
- cout<<"insert: "<< ec.to_string() <<endl;
- // 查询
- boost::shared_ptr<sql::ResultSet> query_result = nullptr;
- // cout<<"---"<<endl;
- ec = db->sql_query("SELECT * FROM my_test where id < 5", query_result);
- cout<<"search: "<< ec.to_string() <<endl;
- while(query_result!=nullptr && query_result->next())
- {
- cout << query_result->getInt("id") << endl;
- if(query_result->getString("content") != ""){
- cout << query_result->getInt("numm") << endl;
- cout << query_result->getString("content") << endl;
- }
- }
- // 删除
- ec = db->sql_delete("DELETE FROM my_test WHERE id=2");
- cout<<"delete: "<< ec.to_string() <<endl;
- // 修改
- ec = db->sql_update("UPDATE my_test SET content='modified_12345' WHERE id=3");
- cout<<"update: "<< ec.to_string() <<endl;
- for (size_t i = 0; i < 5; i++)
- {
- usleep(1000 * 5000);
- ec = db->sql_query("SELECT id,content FROM my_test where id < 5", query_result);
- cout << "search: " << ec.to_string() << endl;
- }
- }else{
- cout<<"connection failed "<<endl;
- }
- getchar();
- return 0;
- }
|