db_test.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * @Description: 数据库测试
  3. * @Author: yct
  4. * @Date: 2020-07-18 21:46:45
  5. * @LastEditTime: 2020-07-20 14:56:48
  6. * @LastEditors: yct
  7. */ //test
  8. #include "../parkspace_allocation/parkspace_db_manager.h"
  9. using std::cout;
  10. using std::endl;
  11. int main()
  12. {
  13. Parkspace_db_manager *db = Parkspace_db_manager::get_instance_pointer();
  14. parkspace_proto::database_config ip;
  15. ip.set_db_ip("127.0.0.1");
  16. ip.set_db_port(3306);
  17. ip.set_db_username("wk");
  18. ip.set_db_passwd("123456");
  19. ip.set_db_name("test");
  20. ip.set_db_conn_pool_size(5);
  21. Error_manager ec = db->Parkspace_db_manager_init(ip);
  22. std::cout<<"init:"<<ec.to_string()<<std::endl;
  23. if ( db->is_connected() )
  24. {
  25. message::Parkspace_info parkspaceInfo;
  26. message::Car_info carInfo;
  27. carInfo.set_car_length(8);
  28. carInfo.set_car_width(3);
  29. carInfo.set_car_height(2);
  30. carInfo.set_license("鄂WKWKs5");
  31. parkspaceInfo.set_parkspace_id(14);
  32. parkspaceInfo.set_index(20);
  33. parkspaceInfo.set_direction(message::Direction::eBackward);
  34. parkspaceInfo.set_floor(4);
  35. parkspaceInfo.set_length(4);
  36. parkspaceInfo.set_width(2);
  37. parkspaceInfo.set_height(4);
  38. parkspaceInfo.set_parkspace_status(message::Parkspace_status::eParkspace_error);
  39. parkspaceInfo.set_allocated_car_info(&carInfo);
  40. parkspaceInfo.set_entry_time("2020/10/14 16:42:12");
  41. parkspaceInfo.set_leave_time("2020/10/15 16:44:22");
  42. parkspaceInfo.set_block_id(5);
  43. message::Vehicle_status vehicleStatus;
  44. vehicleStatus = message::eVehicle_in_garage;
  45. // 增加
  46. // ec = db->insert_vehicle(parkspaceInfo, vehicleStatus);
  47. // std::cout << "add:"<< " ec.to_string() = " << ec.to_string() << std::endl;
  48. // ec = db->insert_parking_record(parkspaceInfo);
  49. // std::cout << " add: " << ec << std::endl;
  50. //查询车位
  51. // message::Parkspace_info query_result;
  52. // ec = db->query_parkspace(19, quSery_result);
  53. // std::cout << "query:" << ec.to_string() << std::endl;
  54. // if ( ec==SUCCESS)
  55. // {
  56. // std::cout <<query_result.DebugString()<<std::endl;
  57. // }
  58. // //查询车辆
  59. // message::Vehicle_status vehicleStatus;
  60. // int park_record_id;
  61. // ec=db->query_vehicle("闽WKA81",vehicleStatus,park_record_id);
  62. // std::cout<<" query_vehicle:"<<ec<<std::endl;
  63. // if ( ec==SUCCESS )
  64. // {
  65. // std::cout << " park_record_id = " <<park_record_id << std::endl;
  66. // std::cout << " vehicleStatus = " <<vehicleStatus << std::endl;
  67. // }
  68. // 修改
  69. // ec = db->update_parkspace_status(parkspaceInfo);
  70. // ec = db->update_vehicle_status(parkspaceInfo,vehicleStatus);
  71. // cout<<"update: "<< ec.to_string() <<endl;
  72. }
  73. // if(db->mp_db_controller->is_connected())
  74. // {
  75. // // 增加
  76. // Error_manager ec = db->mp_db_controller->sql_insert("INSERT INTO my_test (content) VALUES ('ccc')");
  77. // // usleep(1000*3000);
  78. // cout<<"insert: "<< ec.to_string() <<endl;
  79. // // 查询
  80. // boost::shared_ptr<sql::ResultSet> query_result = nullptr;
  81. // // cout<<"---"<<endl;
  82. // ec = db->mp_db_controller->sql_query("SELECT * FROM my_test where id < 27", query_result);
  83. // cout<<"search: "<< ec.to_string() <<endl;
  84. // while(query_result!=nullptr && query_result->next())
  85. // {
  86. // cout << query_result->getInt("id") << endl;
  87. // if(query_result->getString("content") != ""){
  88. // cout << query_result->getInt("numm") << endl;
  89. // cout << query_result->getString("content") << endl;
  90. // }
  91. // }
  92. // // 删除
  93. // ec = db->mp_db_controller->sql_delete("DELETE FROM my_test WHERE id=2");
  94. // cout<<"delete: "<< ec.to_string() <<endl;
  95. // // 修改
  96. // ec = db->mp_db_controller->sql_update("UPDATE my_test SET content='modified_12345' WHERE id=3");
  97. // cout<<"update: "<< ec.to_string() <<endl;
  98. //
  99. // std::cout<<"---"<<std::endl;
  100. // }
  101. // else
  102. // {
  103. // cout<<"connection failed "<<endl;
  104. // }
  105. // getchar();
  106. return 0;
  107. }