123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- /*
- * @Description: 数据库测试
- * @Author: yct
- * @Date: 2020-07-18 21:46:45
- * @LastEditTime: 2020-07-20 14:56:48
- * @LastEditors: yct
- */ //test
- #include "../parkspace_allocation/parkspace_db_manager.h"
- using std::cout;
- using std::endl;
- int main()
- {
- Parkspace_db_manager *db = Parkspace_db_manager::get_instance_pointer();
- parkspace_proto::database_config ip;
- ip.set_db_ip("127.0.0.1");
- ip.set_db_port(3306);
- ip.set_db_username("wk");
- ip.set_db_passwd("123456");
- ip.set_db_name("test");
- ip.set_db_conn_pool_size(5);
- Error_manager ec = db->Parkspace_db_manager_init(ip);
- std::cout<<"init:"<<ec.to_string()<<std::endl;
- if ( db->is_connected() )
- {
- message::Parkspace_info parkspaceInfo;
- message::Car_info carInfo;
- carInfo.set_car_length(8);
- carInfo.set_car_width(3);
- carInfo.set_car_height(2);
- carInfo.set_license("鄂WKWKs5");
- parkspaceInfo.set_parkspace_id(14);
- parkspaceInfo.set_index(20);
- parkspaceInfo.set_direction(message::Direction::eBackward);
- parkspaceInfo.set_floor(4);
- parkspaceInfo.set_length(4);
- parkspaceInfo.set_width(2);
- parkspaceInfo.set_height(4);
- parkspaceInfo.set_parkspace_status(message::Parkspace_status::eParkspace_error);
- parkspaceInfo.set_allocated_car_info(&carInfo);
- parkspaceInfo.set_entry_time("2020/10/14 16:42:12");
- parkspaceInfo.set_leave_time("2020/10/15 16:44:22");
- parkspaceInfo.set_block_id(5);
- message::Vehicle_status vehicleStatus;
- vehicleStatus = message::eVehicle_in_garage;
- // 增加
- // ec = db->insert_vehicle(parkspaceInfo, vehicleStatus);
- // std::cout << "add:"<< " ec.to_string() = " << ec.to_string() << std::endl;
- // ec = db->insert_parking_record(parkspaceInfo);
- // std::cout << " add: " << ec << std::endl;
- //查询车位
- // message::Parkspace_info query_result;
- // ec = db->query_parkspace(19, quSery_result);
- // std::cout << "query:" << ec.to_string() << std::endl;
- // if ( ec==SUCCESS)
- // {
- // std::cout <<query_result.DebugString()<<std::endl;
- // }
- // //查询车辆
- // message::Vehicle_status vehicleStatus;
- // int park_record_id;
- // ec=db->query_vehicle("闽WKA81",vehicleStatus,park_record_id);
- // std::cout<<" query_vehicle:"<<ec<<std::endl;
- // if ( ec==SUCCESS )
- // {
- // std::cout << " park_record_id = " <<park_record_id << std::endl;
- // std::cout << " vehicleStatus = " <<vehicleStatus << std::endl;
- // }
- // 修改
- // ec = db->update_parkspace_status(parkspaceInfo);
- // ec = db->update_vehicle_status(parkspaceInfo,vehicleStatus);
- // cout<<"update: "<< ec.to_string() <<endl;
- }
- // if(db->mp_db_controller->is_connected())
- // {
- // // 增加
- // Error_manager ec = db->mp_db_controller->sql_insert("INSERT INTO my_test (content) VALUES ('ccc')");
- // // usleep(1000*3000);
- // cout<<"insert: "<< ec.to_string() <<endl;
- // // 查询
- // boost::shared_ptr<sql::ResultSet> query_result = nullptr;
- // // cout<<"---"<<endl;
- // ec = db->mp_db_controller->sql_query("SELECT * FROM my_test where id < 27", 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->mp_db_controller->sql_delete("DELETE FROM my_test WHERE id=2");
- // cout<<"delete: "<< ec.to_string() <<endl;
- // // 修改
- // ec = db->mp_db_controller->sql_update("UPDATE my_test SET content='modified_12345' WHERE id=3");
- // cout<<"update: "<< ec.to_string() <<endl;
- //
- // std::cout<<"---"<<std::endl;
- // }
- // else
- // {
- // cout<<"connection failed "<<endl;
- // }
- // getchar();
- return 0;
- }
|