Advertisement
Guest User

Untitled

a guest
Mar 14th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. std::string _dbConnString = "host=" + host + ";user=" + user + ";password=" + password + ";db="+db
  2. +";compress=true;auto-reconnect=true";
  3.  
  4.  
  5. std::string getkey(int userID, int exchangeID) {
  6. Poco::Data::MySQL::Connector::registerConnector();
  7.  
  8. std::string key;
  9.  
  10. {
  11. // 0. connect & create table
  12. Session session(Poco::Data::MySQL::Connector::KEY, "host=" + host + ";user=" + user + ";password=" + password +";db=" + db);
  13.  
  14.  
  15.  
  16. Statement selectn(session);
  17. selectn << "SELECT key FROM API WHERE user_id=? ", into(api_key), use(userID), now;
  18.  
  19. }
  20. catch (const Poco::Data::ConnectionFailedException &ce)
  21. {
  22. std::cout << ce.displayText() << std::endl;
  23. }
  24. catch (const Poco::Data::MySQL::StatementException &se)
  25. {
  26. std::cout << se.displayText() << std::endl;
  27. }
  28.  
  29.  
  30. Poco::Data::MySQL::Connector::unregisterConnector();
  31.  
  32. return key;
  33.  
  34. }
  35.  
  36. std::string getuser(int userID, int exchangeID) {
  37. Poco::Data::MySQL::Connector::registerConnector();
  38.  
  39. std::string user;
  40. try
  41. {
  42. // 0. connect & create table
  43. Session session(Poco::Data::MySQL::Connector::KEY, "host=" + host + ";user=" + user + ";password=" + password +";db=" + db);
  44.  
  45.  
  46.  
  47. Statement selectn(session);
  48. selectn << "SELECT user FROM API WHERE user_id=? ", into(user), use(userID), now;
  49.  
  50. }
  51. catch (const Poco::Data::ConnectionFailedException &ce)
  52. {
  53. std::cout << ce.displayText() << std::endl;
  54. }
  55. catch (const Poco::Data::MySQL::StatementException &se)
  56. {
  57. std::cout << se.displayText() << std::endl;
  58. }
  59.  
  60.  
  61. Poco::Data::MySQL::Connector::unregisterConnector();
  62.  
  63. return user;
  64.  
  65. }
  66.  
  67. std::string key = getkey(user_id,exchange_id); //no error
  68. std::string user = getuser(user_id,exchange_id); //segmentation fault
  69.  
  70. std::string user = getuser(user_id,exchange_id); //no error
  71. std::string key = getkey(user_id,exchange_id); //segmentation fault
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement