example_tc_mysql.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * Tencent is pleased to support the open source community by making Tars available.
  3. *
  4. * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
  5. *
  6. * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  7. * in compliance with the License. You may obtain a copy of the License at
  8. *
  9. * https://opensource.org/licenses/BSD-3-Clause
  10. *
  11. * Unless required by applicable law or agreed to in writing, software distributed
  12. * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  13. * CONDITIONS OF ANY KIND, either express or implied. See the License for the
  14. * specific language governing permissions and limitations under the License.
  15. */
  16. #include "util/tc_mysql.h"
  17. #include <iostream>
  18. using namespace tars;
  19. TC_Mysql mysql;
  20. void test()
  21. {
  22. // cout << mysql.getVariables("character_set_client") << endl;
  23. TC_Mysql::MysqlData data;
  24. data = mysql.queryRecord("select * from t_app_users");
  25. for(size_t i = 0; i < data.size(); i++)
  26. {
  27. cout << data[i]["ID"] << endl;
  28. }
  29. }
  30. void testInsert()
  31. {
  32. map<string, pair<TC_Mysql::FT, string> > m;
  33. m["ID"] = make_pair(TC_Mysql::DB_INT, "2334");
  34. m["USERID"] = make_pair(TC_Mysql::DB_STR, "abcttt");
  35. m["APP"] = make_pair(TC_Mysql::DB_STR, "abcapbbp");
  36. mysql.insertRecord("t_user_logs", m);
  37. mysql.replaceRecord("t_user_logs", m);
  38. mysql.updateRecord("t_user_logs", m, "where ID=2234");
  39. }
  40. int main(int argc, char *argv[])
  41. {
  42. try
  43. {
  44. try{
  45. mysql.init("172.25.38.21", "pc", "pc@sn", "db_dmqq_system");
  46. mysql.connect();
  47. }catch(exception &ex)
  48. {
  49. cout << ex.what() << endl;
  50. }
  51. mysql.execute("select * from t_app_users");
  52. test();
  53. // sleep(10);
  54. // test();
  55. }
  56. catch(exception &ex)
  57. {
  58. cout << ex.what() << endl;
  59. }
  60. return 0;
  61. }