5 #ifndef BALL_FORMAT_DBINTERFACE_H
6 #define BALL_FORMAT_DBINTERFACE_H
14 #include <QSqlDatabase>
16 #include <QtCore/QVariant>
42 :
public Exception::GeneralException
45 InvalidQuery(
const char* file,
int line,
const String& s =
"<unknown query>") ;
46 virtual ~InvalidQuery() throw() {}
53 :
public Exception::GeneralException
56 NotConnected(
const char* file,
int line,
const String& s =
"<not connected>") ;
57 virtual ~NotConnected() throw() {}
64 class InconsistentTopology
65 :
public Exception::GeneralException
68 InconsistentTopology(
const char* file,
int line,
const String& s =
"<inconsistent topology>") ;
69 virtual ~InconsistentTopology() throw() {}
82 typedef std::vector<ID> IDVector;
87 typedef std::pair<String, String> ConformationMethod;
92 typedef std::pair<String, String> ChargeMethod;
106 static const String BALL_DEFAULT_DBRCFILE;
108 static const String BALL_DEFAULT_DATABASE_HOST;
110 static const Size BALL_DEFAULT_DATABASE_PORT;
112 static const String BALL_DEFAULT_DATABASE_DRIVER;
114 static const String BALL_DEFAULT_DATABASE_NAME;
116 static const String BALL_DEFAULT_DATABASE_SECTIONNAME;
125 virtual ~DBInterface() {}
131 void getTopology(ID topology, System& system);
136 ID newTopology(
const System& system,
const String& name,
const String& source_id, ID
id = 0);
138 void setTopology(ID topology,
const System& system);
141 IDVector getConformationList(ID topology_od);
143 IDVector getConformationList(ID topology_id, ID method_id);
145 void loadConformation(
const ID conformation, System& system);
148 ID storeConformation(ID topology_id, ID method_id,
const System& system,
double energy);
150 ID storeConformation(ID topology, ID method_ID,
const System& system);
153 IDVector getConformationMethods();
155 ConformationMethod getConformationMethod(ID method_id);
157 ID getConformationMethod(
const String& method,
const String& parameters);
159 ID newConformationMethod(
const String& method,
const String& parameters);
162 ID storeCharges(ID topology_id, ID method_id,
const System& system);
164 void loadCharges(
const ID charge_id, System& system);
166 IDVector getChargeMethods();
168 ChargeMethod getChargeMethod(DBInterface::ID method_id);
170 ID getChargeMethod(
const String& method,
const String& parameters);
172 ID newChargeMethod(
const String& method,
const String& parameters);
175 ErrorCode getError()
const {
return error_; }
177 void setError(
ErrorCode error) { error_ = error; }
179 bool good()
const {
return error_ == 0; }
192 (
const String& user,
const String& password,
193 const String& database_name =
"structures",
const String& host =
"diclofenac.informatik.uni-tuebingen.de",
194 Size port = 3306,
const String& driver =
"QMYSQL3");
221 QSqlQuery& executeQuery(
const String& query_string);
227 QSqlQuery& executeQuery();
230 QSqlQuery& query() {
return *query_; }
233 String executedQuery() {
return query_->executedQuery().toStdString();}
236 bool first() {
return query_->first(); }
239 bool last() {
return query_->last(); }
242 bool next() {
return query_->next(); }
247 IDVector extractIDs();
250 bool prev() {
return query_->previous(); }
256 Size size() {
return (
Size)query_->size(); }
259 QVariant value(
Position k) {
return query_->value(k); }
262 void prepare(
const String& s) { query_->prepare(s.c_str()); }
265 void addBindValue(
const QVariant& v) { query_->addBindValue(v); }
266 void addBindValue(
const QVariant& v1,
const QVariant& v2) { addBindValue(v1); addBindValue(v2);}
267 void addBindValue(
const QVariant& v1,
const QVariant& v2,
const QVariant& v3) { addBindValue(v1); addBindValue(v2); addBindValue(v3);}
268 void addBindValue(
const QVariant& v1,
const QVariant& v2,
const QVariant& v3,
const QVariant& v4) { addBindValue(v1); addBindValue(v2); addBindValue(v3); addBindValue(v4);}
274 bool getMOLFile(ID
id, String& file_text, String& name, String& source_id);
276 void addMOLFileToSystem(
const String& molfile, System& system);
282 static void assignCoordinates_(System& system,
const QByteArray& data);
284 static void extractCoordinates_(
const System& system, QByteArray& data);
286 static void assignCharges_(System& system,
const QByteArray& data);
288 static void extractCharges_(
const System& system, QByteArray& data);
290 static void encodeArray_(
const std::vector<float>& v, QByteArray& a);
292 static void decodeArray_(
const QByteArray& a, std::vector<float>& v);
302 String database_name_;
311 DBInterface(
const DBInterface& ) {}
315 #endif // BALL_FORMAT_DBINTERFACE_H