15 #include <utility/sql_database/DatabaseSessionManager.hh>
16 #include <utility/excn/Exceptions.hh>
17 #include <basic/database/sql_utils.hh>
20 #include <cppdb/frontend.h>
21 #include <utility/exit.hh>
22 #include <utility/string_util.hh>
23 #include <boost/uuid/uuid.hpp>
24 #include <boost/uuid/uuid_io.hpp>
27 #include <utility/vector1.hh>
38 cppdb::statement statement,
41 cppdb::result result(basic::database::safely_read_from_database(statement));
48 throw utility::excn::EXCN_Msg_Exception(
"No result found");
53 utility::sql_database::sessionOP db_session,
57 if( input_tag.empty()){
64 " batches ON structures.batch_id = batches.batch_id\n"
66 " batches.protocol_id = ?;";
67 cppdb::statement statement(basic::database::safely_prepare_statement(statement_string,db_session));
68 statement.bind(1,protocol_id);
77 " batches ON structures.batch_id = batches.batch_id\n"
79 " structures.input_tag=?\n"
81 " batches.protocol_id=?;";
82 cppdb::statement statement(basic::database::safely_prepare_statement(statement_string,db_session));
83 statement.bind(1,input_tag);
84 statement.bind(2,protocol_id);
90 utility::sql_database::sessionOP db_session,
102 "batches ON score_types.batch_id = batches.batch_id\n"
104 "batches.protocol_id=?\n"
106 "score_type_name=?\n";
108 cppdb::statement statement(basic::database::safely_prepare_statement(statement_string,db_session));
109 statement.bind(1,protocol_id);
110 statement.bind(2,score_term);
113 }
catch(utility::excn::EXCN_Msg_Exception &){
120 utility::sql_database::sessionOP db_session,
126 if(input_tag.empty()){
129 " job_string_real_data.struct_id\n"
131 " job_string_real_data\n"
133 " structures ON job_string_real_data.struct_id = structures.struct_id\n"
135 " batches ON structures.batch_id = batches.batch_id\n"
137 " job_string_real_data.data_key = ? AND batches.protocol_id = ?\n"
139 " job_string_real_data.data_value\n"
141 cppdb::statement statement(basic::database::safely_prepare_statement(statement_string,db_session));
142 statement.bind(1,score_term);
143 statement.bind(2,protocol_id);
144 statement.bind(3,cutoff_index-1);
151 " job_string_real_data.struct_id\n"
153 " job_string_real_data\n"
155 " structures ON job_string_real_data.struct_id = structures.struct_id\n"
157 " batches ON structures.batch_id = batches.batch_id\n"
159 " job_string_real_data.data_key = ?\n"
161 " structures.input_tag = ?\n"
163 " batches.protocol_id = ?\n"
165 " job_string_real_data.data_value\n"
167 cppdb::statement statement(basic::database::safely_prepare_statement(statement_string,db_session));
168 statement.bind(1,score_term);
169 statement.bind(2,input_tag);
170 statement.bind(3,protocol_id);
171 statement.bind(4,cutoff_index-1);
177 utility::sql_database::sessionOP db_session,
183 if(input_tag.empty()){
186 " structure_scores.struct_id\n"
188 " structure_scores\n"
190 " structures ON structure_scores.struct_id = structures.struct_id\n"
192 " batches ON structures.batch_id = batches.batch_id\n"
194 " structure_scores.score_type_id = ?\n"
196 " batches.protocol_id = ?\n"
198 " structure_scores.score_value\n"
200 cppdb::statement statement(basic::database::safely_prepare_statement(statement_string,db_session));
201 statement.bind(1,score_type_id);
202 statement.bind(2,protocol_id);
203 statement.bind(3,cutoff_index-1);
209 " structure_scores.struct_id\n"
211 " structure_scores\n"
213 " structures ON structure_scores.struct_id = structures.struct_id\n"
215 " batches ON structures.batch_id = batches.batch_id\n"
217 " structure_scores.score_type_id = ?\n"
219 " structures.input_tag = ?\n"
221 " batches.protocol_id =?\n"
223 " structure_scores.score_value\n"
225 cppdb::statement statement(basic::database::safely_prepare_statement(statement_string,db_session));
226 statement.bind(1,score_type_id);
227 statement.bind(2,input_tag);
228 statement.bind(3,protocol_id);
229 statement.bind(4,cutoff_index-1);
235 utility::sql_database::sessionOP db_session,
240 if(input_tag.empty()){
243 " job_string_real_data.struct_id\n"
245 " job_string_real_data\n"
247 " structures ON job_string_real_data.struct_id = structures.struct_id\n"
249 " batches ON structures.batch_id = batches.batch_id\n"
251 " job_string_real_data.data_key = ?\n"
253 " batches.protocol_id = ?\n"
255 " job_string_real_data.data_value DESC\n"
257 cppdb::statement statement(basic::database::safely_prepare_statement(statement_string,db_session));
258 statement.bind(1,score_term);
259 statement.bind(2,protocol_id);
265 " job_string_real_data.struct_id\n"
267 " job_string_real_data\n"
269 " structures ON job_string_real_data.struct_id = structures.struct_id\n"
271 " batches ON structures.batch_id = batches.batch_id\n"
273 " job_string_real_data.data_key = ?\n"
275 " structures.input_tag = ?\n"
277 " batches.protocol_id = ?\n"
279 " job_string_real_data.data_value DESC\n"
281 cppdb::statement statement(basic::database::safely_prepare_statement(statement_string,db_session));
282 statement.bind(1,score_term);
283 statement.bind(2,input_tag);
284 statement.bind(3,protocol_id);
290 utility::sql_database::sessionOP db_session,
295 if(input_tag.empty()){
298 " structure_scores.struct_id\n"
300 " structure_scores\n"
302 " structures ON structure_scores.struct_id = structures.struct_id\n"
304 " batches ON structures.batch_id = batches.batch_id\n"
306 " structure_scores.score_type_id = ?\n"
308 " batches.protocol_id = ?\n"
310 " structure_scores.score_value DESC\n"
312 cppdb::statement statement(basic::database::safely_prepare_statement(statement_string,db_session));
313 statement.bind(1,score_type_id);
314 statement.bind(2,protocol_id);
320 " structure_scores.struct_id\n"
322 " structure_scores\n"
324 " structures ON structure_scores.struct_id = structures.struct_id\n"
326 " batches ON structures.batch_id = batches.batch_id\n"
328 " structure_scores.score_type_id = ?\n"
330 " structures.input_tag = ?\n"
332 " batches.protocol_id = ?\n"
334 " structure_scores.score_value DESC\n"
336 cppdb::statement statement(basic::database::safely_prepare_statement(statement_string,db_session));
337 statement.bind(1,score_type_id);
338 statement.bind(2,input_tag);
339 statement.bind(3,protocol_id);
347 utility::sql_database::sessionOP db_session,
357 utility::sql_database::sessionOP db_session,
367 }
catch(utility::excn::EXCN_Msg_Exception){
368 utility_exit_with_message(
"No nth lowest "+score_term+
" with input_tag "+input_tag+
", where n="+utility::to_string(cutoff_index));
372 return boost::uuids::uuid();
377 utility::sql_database::sessionOP db_session,
387 }
catch(utility::excn::EXCN_Msg_Exception){
388 utility_exit_with_message(
"No nth lowest score_type_id: "+utility::to_string(score_type_id)+
", with input_tag "+input_tag+
", where n="+utility::to_string(cutoff_index));
392 return boost::uuids::uuid();
396 utility::sql_database::sessionOP db_session,
405 utility::sql_database::sessionOP db_session,
414 utility::sql_database::sessionOP db_session,
423 }
catch(utility::excn::EXCN_Msg_Exception){
424 utility_exit_with_message(
"No "+score_term+
" with input_tag "+input_tag);
428 return boost::uuids::uuid();
432 utility::sql_database::sessionOP db_session,
441 }
catch(utility::excn::EXCN_Msg_Exception){
442 utility_exit_with_message(
"No score_type_id: "+utility::to_string(score_type_id)+
", with input_tag "+input_tag);
446 return boost::uuids::uuid();
451 utility::sql_database::sessionOP db_session,
452 boost::uuids::uuid
const & struct_id,
458 " job_string_real_data.data_value\n"
460 " job_string_real_data\n"
462 " job_string_real_data.data_key = ?\n"
464 " job_string_real_data.struct_id = ?\n;";
465 cppdb::statement statement(basic::database::safely_prepare_statement(statement_string,db_session));
466 statement.bind(1,score_term);
467 statement.bind(2,struct_id);
471 }
catch(utility::excn::EXCN_Msg_Exception){
472 utility_exit_with_message(
"No "+score_term+
" with struct_id "+to_string(struct_id));
481 utility::sql_database::sessionOP db_session,
482 boost::uuids::uuid
const & struct_id,
488 " structure_scores.score_value\n"
490 " structure_scores\n"
492 " structure_scores.struct_id = ?\n"
494 " structure_scores.score_type_id = ?;";
495 cppdb::statement statement(basic::database::safely_prepare_statement(statement_string,db_session));
496 statement.bind(1,struct_id);
497 statement.bind(2,score_type_id);
501 }
catch(utility::excn::EXCN_Msg_Exception){
502 utility_exit_with_message(
"No score_type_id:"+utility::to_string(score_type_id)+
", with struct_id "+to_string(struct_id));