35
35
// Qserv headers
36
36
#include " css/CssAccess.h"
37
37
#include " css/CssError.h"
38
+ #include " cconfig/CzarConfig.h"
38
39
#include " qdisp/MessageStore.h"
39
40
#include " qmeta/Exceptions.h"
40
41
#include " qmeta/QMetaSelect.h"
41
42
#include " query/FromList.h"
42
43
#include " query/SelectStmt.h"
43
44
#include " sql/SqlConnection.h"
45
+ #include " sql/SqlConnectionFactory.h"
44
46
#include " sql/SqlErrorObject.h"
45
47
#include " sql/SqlBulkInsert.h"
46
48
#include " sql/statement.h"
@@ -61,12 +63,10 @@ namespace lsst::qserv::ccontrol {
61
63
62
64
// Constructor
63
65
UserQueryProcessList::UserQueryProcessList (std::shared_ptr<query::SelectStmt> const & statement,
64
- sql::SqlConnection* resultDbConn,
65
66
std::shared_ptr<qmeta::QMetaSelect> const & qMetaSelect,
66
67
qmeta::CzarId qMetaCzarId, std::string const & userQueryId,
67
68
std::string const & resultDb)
68
- : _resultDbConn(resultDbConn),
69
- _qMetaSelect (qMetaSelect),
69
+ : _qMetaSelect(qMetaSelect),
70
70
_qMetaCzarId (qMetaCzarId),
71
71
_messageStore(std::make_shared<qdisp::MessageStore>()),
72
72
_resultTableName(::g_nextResultTableId(userQueryId)),
@@ -90,12 +90,10 @@ UserQueryProcessList::UserQueryProcessList(std::shared_ptr<query::SelectStmt> co
90
90
}
91
91
}
92
92
93
- UserQueryProcessList::UserQueryProcessList (bool full, sql::SqlConnection* resultDbConn,
94
- std::shared_ptr<qmeta::QMetaSelect> const & qMetaSelect,
93
+ UserQueryProcessList::UserQueryProcessList (bool full, std::shared_ptr<qmeta::QMetaSelect> const & qMetaSelect,
95
94
qmeta::CzarId qMetaCzarId, std::string const & userQueryId,
96
95
std::string const & resultDb)
97
- : _resultDbConn(resultDbConn),
98
- _qMetaSelect(qMetaSelect),
96
+ : _qMetaSelect(qMetaSelect),
99
97
_qMetaCzarId(qMetaCzarId),
100
98
_messageStore(std::make_shared<qdisp::MessageStore>()),
101
99
_resultTableName(::g_nextResultTableId(userQueryId)),
@@ -156,8 +154,11 @@ void UserQueryProcessList::submit() {
156
154
if (col.colType .sqlType == " TIMESTAMP" ) createTable += " NULL" ;
157
155
}
158
156
createTable += ' )' ;
157
+
159
158
LOGS (_log, LOG_LVL_DEBUG, " creating result table: " << createTable);
160
- if (!_resultDbConn->runQuery (createTable, errObj)) {
159
+ auto const czarConfig = cconfig::CzarConfig::instance ();
160
+ auto const resultDbConn = sql::SqlConnectionFactory::make (czarConfig->getMySqlResultConfig ());
161
+ if (!resultDbConn->runQuery (createTable, errObj)) {
161
162
LOGS (_log, LOG_LVL_ERROR, " failed to create result table: " << errObj.errMsg ());
162
163
std::string message = " Internal failure, failed to create result table: " + errObj.errMsg ();
163
164
_messageStore->addMessage (-1 , " PROCESSLIST" , 1051 , message, MessageSeverity::MSG_ERROR);
@@ -172,7 +173,7 @@ void UserQueryProcessList::submit() {
172
173
}
173
174
174
175
// copy stuff over to result table
175
- sql::SqlBulkInsert bulkInsert (_resultDbConn , _resultTableName, resColumns);
176
+ sql::SqlBulkInsert bulkInsert (resultDbConn. get () , _resultTableName, resColumns);
176
177
for (auto & row : *results) {
177
178
std::vector<std::string> values;
178
179
for (unsigned i = 0 ; i != row.size (); ++i) {
@@ -191,7 +192,7 @@ void UserQueryProcessList::submit() {
191
192
values.push_back (std::string (ptr, ptr + len));
192
193
} else {
193
194
// everything else should be quoted
194
- values.push_back (" '" + _resultDbConn ->escapeString (std::string (ptr, ptr + len)) + " '" );
195
+ values.push_back (" '" + resultDbConn ->escapeString (std::string (ptr, ptr + len)) + " '" );
195
196
}
196
197
}
197
198
0 commit comments