| | 76 | |
|---|
| | 77 | void test_009(connection_base &, transaction_base &T) |
|---|
| | 78 | { |
|---|
| | 79 | PrepareContents(); |
|---|
| | 80 | |
|---|
| | 81 | // Select our original and destination table names |
|---|
| | 82 | const string TableName = "pqxxtesttable"; |
|---|
| | 83 | |
|---|
| | 84 | const string Column = "content"; |
|---|
| | 85 | |
|---|
| | 86 | // Create table. If the table already existed, better to fail now. |
|---|
| | 87 | stringstream ctq; |
|---|
| | 88 | ctq << "CREATE TABLE " << TableName << '(' << Column << " VARCHAR)"; |
|---|
| | 89 | T.exec(ctq); |
|---|
| | 90 | |
|---|
| | 91 | FillTable(T, TableName, Column); |
|---|
| | 92 | CheckTable(T, TableName); |
|---|
| | 93 | |
|---|
| | 94 | T.exec(("DROP TABLE " + TableName).c_str()); |
|---|
| | 95 | T.commit(); |
|---|
| 89 | | try |
|---|
| 90 | | { |
|---|
| 91 | | const char *ConnStr = argv[1]; |
|---|
| 92 | | |
|---|
| 93 | | PrepareContents(); |
|---|
| 94 | | |
|---|
| 95 | | // Set up two connections to the backend: one to read our original table, |
|---|
| 96 | | // and another to write our copy |
|---|
| 97 | | connection C(ConnStr); |
|---|
| 98 | | |
|---|
| 99 | | // Select our original and destination table names |
|---|
| 100 | | string TableName = "pqxxtesttable"; |
|---|
| 101 | | if (argc > 2) TableName = argv[2]; |
|---|
| 102 | | |
|---|
| 103 | | string Column = "content"; |
|---|
| 104 | | if (argc > 3) Column = argv[3]; |
|---|
| 105 | | |
|---|
| 106 | | work T(C, "test9"); |
|---|
| 107 | | |
|---|
| 108 | | // Create table. If the table already existed, better to fail now. |
|---|
| 109 | | stringstream ctq; |
|---|
| 110 | | ctq << "CREATE TABLE " << TableName << '(' << Column << " VARCHAR)"; |
|---|
| 111 | | T.exec(ctq); |
|---|
| 112 | | |
|---|
| 113 | | FillTable(T, TableName, Column); |
|---|
| 114 | | CheckTable(T, TableName); |
|---|
| 115 | | |
|---|
| 116 | | T.exec(("DROP TABLE " + TableName).c_str()); |
|---|
| 117 | | T.commit(); |
|---|
| 118 | | } |
|---|
| 119 | | catch (const sql_error &e) |
|---|
| 120 | | { |
|---|
| 121 | | // If we're interested in the text of a failed query, we can write separate |
|---|
| 122 | | // exception handling code for this type of exception |
|---|
| 123 | | cerr << "SQL error: " << e.what() << endl |
|---|
| 124 | | << "Query was: '" << e.query() << "'" << endl; |
|---|
| 125 | | return 1; |
|---|
| 126 | | } |
|---|
| 127 | | catch (const exception &e) |
|---|
| 128 | | { |
|---|
| 129 | | // All exceptions thrown by libpqxx are derived from std::exception |
|---|
| 130 | | cerr << "Exception: " << e.what() << endl; |
|---|
| 131 | | return 2; |
|---|
| 132 | | } |
|---|
| 133 | | catch (...) |
|---|
| 134 | | { |
|---|
| 135 | | // This is really unexpected (see above) |
|---|
| 136 | | cerr << "Unhandled exception" << endl; |
|---|
| 137 | | return 100; |
|---|
| 138 | | } |
|---|
| 139 | | |
|---|
| 140 | | return 0; |
|---|
| | 103 | test::TestCase<> test009("test_009", test_009); |
|---|
| | 104 | return test::pqxxtest(test009); |
|---|