Advertisement
Guest User

Untitled

a guest
Feb 9th, 2021
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. /*Standard C++ includes*/
  2. #include <stdlib.h>
  3. #include <iostream>
  4.  
  5. #include <mysqlx/xdevapi.h>
  6. using ::std::cout;
  7. using ::std::endl;
  8.  
  9. using namespace ::mysqlx;
  10.  
  11. int main(int argc, const char* argv[])
  12. {
  13.     try {
  14.         const char* url = (argc > 1 ? argv[1] : "mysqlx://pct@127.0.0.1");
  15.         cout << "Creating session on " << url << " ..." << endl;
  16.  
  17.         Session sess(url);
  18.  
  19.         {
  20.             cout << "Connected!" << endl;
  21.  
  22.             // Create the Schema "testSchema"; This code creates a schema without issue
  23.             cout << "Creating Schema..." << endl;
  24.             sess.dropSchema("testSchema");         
  25.             Schema mySchema = sess.createSchema("testSchema");
  26.             cout << "Schema Created!" << endl;
  27.  
  28.  
  29.             // Create the Table "testTable"; This code runs like normal, but the schema doesn't show
  30.             cout << "Creating Table..." << endl;
  31.             SqlStatement sqlcomm = sess.sql("USE testSchema SHOW tables;");
  32.             sqlcomm.execute();
  33.         }
  34.     }
  35.     catch (const mysqlx::Error& err)
  36.     {
  37.         cout << "MYSQL ERROR: " << err << endl;
  38.         return 1;
  39.     }
  40.     catch (std::exception& ex)
  41.     {
  42.         cout << "STD EXCEPTION: " << ex.what() << endl;
  43.         return 1;
  44.     }
  45.     catch (const char* ex)
  46.     {
  47.         cout << "EXCEPTION: " << ex << endl;
  48.         return 1;
  49.     }
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement