19 #include <boost/uuid/uuid.hpp>
22 #include <basic/database/sql_utils.hh>
23 #include <basic/database/schema_generator/PrimaryKey.hh>
24 #include <basic/database/schema_generator/ForeignKey.hh>
25 #include <basic/database/schema_generator/Column.hh>
26 #include <basic/database/schema_generator/Schema.hh>
27 #include <basic/database/schema_generator/Constraint.hh>
30 #include <basic/options/option.hh>
31 #include <basic/options/keys/inout.OptionKeys.gen.hh>
44 #include <utility/sql_database/DatabaseSessionManager.hh>
45 #include <utility/vector1.hh>
46 #include <basic/database/sql_utils.hh>
47 #include <utility/tag/Tag.hh>
50 #include <cppdb/frontend.h>
54 #include <utility/excn/Exceptions.hh>
62 using std::stringstream;
64 using basic::database::safely_prepare_statement;
87 using utility::sql_database::sessionOP;
88 using cppdb::statement;
101 scfxn_name_(scfxn_name)
104 utility_exit_with_message(
"ScoreFunctionFeatures may not be constructed with a null-pointer ScoreFunctionOP" );
113 scfxn_name_(src.scfxn_name_)
134 using namespace basic::database::schema_generator;
136 Column batch_id(
"batch_id",
new DbInteger(),
true);
137 Column score_function_name(
"score_function_name",
new DbText(255),
true);
138 Column score_type_id(
"score_type_id",
new DbInteger(),
true);
139 Column weight(
"weight",
new DbReal(),
true);
142 pkey_cols.push_back(batch_id);
143 pkey_cols.push_back(score_function_name);
144 pkey_cols.push_back(score_type_id);
146 Columns foreign_key_columns;
147 foreign_key_columns.push_back(batch_id);
148 foreign_key_columns.push_back(score_type_id);
150 reference_columns.push_back(
"batch_id");
151 reference_columns.push_back(
"score_type_id");
152 ForeignKey foreign_key(foreign_key_columns,
"score_types", reference_columns,
true);
154 Schema table(
"score_function_weights", PrimaryKey(pkey_cols));
155 table.add_foreign_key(foreign_key);
156 table.add_column(weight);
158 table.write(db_session);
165 dependencies.push_back(
"ScoreTypeFeatures");
178 if(tag->hasOption(
"scorefxn")){
182 stringstream error_msg;
184 <<
"The " <<
type_name() <<
" reporter requires a 'scorefxn' tag:" << endl
186 <<
" <feature name=" <<
type_name() <<
" scorefxn=(name_of_score_function) />" << endl;
187 throw utility::excn::EXCN_RosettaScriptsOption(error_msg.str());
195 boost::uuids::uuid
const struct_id,
201 scfxn_->energy_method_options().insert_score_function_method_options_rows(
210 utility::sql_database::sessionOP ){}
218 string statement_string;
219 switch(db_session->get_db_mode()){
220 case utility::sql_database::DatabaseMode::sqlite3:
221 statement_string =
"INSERT OR IGNORE INTO score_function_weights (batch_id, score_function_name, score_type_id, weight) VALUES (?,?,?,?);";
223 case utility::sql_database::DatabaseMode::mysql:
224 case utility::sql_database::DatabaseMode::postgres:
225 statement_string =
"INSERT IGNORE INTO score_function_weights (batch_id, score_function_name, score_type_id, weight) VALUES (?,?,?,?);";
228 utility_exit_with_message(
229 "Unrecognized database mode: '" +
230 name_from_database_mode(db_session->get_db_mode()) +
"'");
233 statement stmt(safely_prepare_statement(statement_string, db_session));
236 ScoreType type(static_cast<ScoreType>(score_type_id));
239 if(!weight)
continue;
242 stmt.bind(1, batch_id);
244 stmt.bind(3, score_type_id);
245 stmt.bind(4, weight);
246 basic::database::safely_write_to_database(stmt);