17 , mysqlpp::sql_int_unsigned , db_schema_id
18 , mysqlpp::sql_char , major_release_number
19 , mysqlpp::sql_char , minor_release_number
20 , mysqlpp::sql_char , point_release_number
21 , mysqlpp::sql_timestamp , time
22 , mysqlpp::Null<mysqlpp::sql_text> , script_name
31 QwDatabase::
QwDatabase(const
string &major, const
string &minor, const
string &point) : Connection(), kValidVersionMajor(major), kValidVersionMinor(minor), kValidVersionPoint(point)
36 fDatabase=fDBServer=fDBUsername=fDBPassword=
"";
37 fVersionMajor=fVersionMinor=fVersionPoint=
"";
39 fAccessLevel = kQwDatabaseOff;
42 fValidConnection =
false;
53 QwDatabase::QwDatabase(
QwOptions &options,
const string &major,
const string &minor,
const string &point) : Connection(), kValidVersionMajor(major), kValidVersionMinor(minor), kValidVersionPoint(point)
74 QwDebug <<
"QwDatabase::~QwDatabase() : Good-bye World from QwDatabase destructor!" <<
QwLog::endl;
100 QwError <<
"QwDatabase::ValidateConnection() : No database supplied. Unable to connect." <<
QwLog::endl;
104 QwError <<
"QwDatabase::ValidateConnection() : No database username supplied. Unable to connect." <<
QwLog::endl;
108 QwError <<
"QwDatabase::ValidateConnection() : No database password supplied. Unable to connect." <<
QwLog::endl;
112 QwMessage <<
"QwDatabase::ValidateConnection() : No database server supplied. Attempting localhost." <<
QwLog::endl;
122 }
catch (std::exception
const&
e) {
135 QwDebug <<
"QwDatabase::ValidateConnection() : Made it past connect() call." <<
QwLog::endl;
141 QwMessage <<
"QwDatabase::ValidateConnection() : Successfully connected to requested database." <<
QwLog::endl;
143 QwError <<
"QwDatabase::ValidateConnection() : Unsuccessfully connected to requested database." <<
QwLog::endl;
161 QwError <<
"QwDatabase::ValidConnection() : Connected database schema inconsistent with current version of analyzer." <<
QwLog::endl;
164 QwError <<
" Please connect to a database supporting the required schema version." <<
QwLog::endl;
185 if (connected())
return true;
197 QwError <<
"QwDatabase::Connect() : Must establish valid connection to database." <<
QwLog::endl;
212 options.
AddOptions(
"Database options")(
"QwDatabase.accesslevel", po::value<string>(),
"database access level (OFF,RO,RW)");
213 options.
AddOptions(
"Database options")(
"QwDatabase.dbname", po::value<string>(),
"database name");
214 options.
AddOptions(
"Database options")(
"QwDatabase.dbserver", po::value<string>(),
"database server name");
215 options.
AddOptions(
"Database options")(
"QwDatabase.dbusername", po::value<string>(),
"database username");
216 options.
AddOptions(
"Database options")(
"QwDatabase.dbpassword", po::value<string>(),
"database password");
217 options.
AddOptions(
"Database options")(
"QwDatabase.dbport", po::value<int>()->default_value(0),
"database server port number (defaults to standard mysql port)");
227 if (options.
HasValue(
"QwDatabase.accesslevel")) {
228 string access = options.
GetValue<
string>(
"QwDatabase.accesslevel");
232 QwWarning <<
"QwDatabase::ProcessOptions : No access level specified; database access is OFF" <<
QwLog::endl;
235 if (options.
HasValue(
"QwDatabase.dbport")) {
238 if (options.
HasValue(
"QwDatabase.dbname")) {
241 if (options.
HasValue(
"QwDatabase.dbusername")) {
244 if (options.
HasValue(
"QwDatabase.dbpassword")) {
247 if (options.
HasValue(
"QwDatabase.dbserver")) {
254 void QwDatabase::ProcessOptions(
const TString& dbname,
const TString& username,
const TString& passwd,
const TString& dbhost,
const Int_t dbport,
const TString& accesslevel)
266 TString level = accesslevel.c_str();
272 QwWarning <<
"QwDatabase::SetAccessLevel : Unrecognized access level \""
273 << accesslevel <<
"\"; setting database access OFF"
287 printf(
"\nQwDatabase MySQL ");
293 printf(
" %s\n\n", server_status().c_str());
297 printf(
"There is no connection.\n");
322 mysqlpp::Query query = this->
Query();
324 query <<
"SELECT * FROM db_schema";
325 std::vector<db_schema> res;
327 QwDebug <<
"QwDatabase::StoreDBVersion => Number of rows returned: " << res.size() <<
QwLog::endl;
342 QwDebug <<
"QwDatabase::StoreDBVersion => db_schema_id = " << res.at(0).db_schema_id <<
QwLog::endl;
350 catch (
const mysqlpp::Exception& er)
#define QwMessage
Predefined log drain for regular messages.
UInt_t fDBPortNumber
Port number to connect to on server (mysql default port is 3306)
Bool_t ValidateConnection()
Checks that given connection parameters result in a valid connection.
QwDatabase(const string &major="00", const string &minor="00", const string &point="0000")
Simple constructor.
const string kValidVersionPoint
Bool_t Connect()
Open a connection to the database using the predefined parameters.
void ProcessOptions(QwOptions &options)
Processes the options contained in the QwOptions object.
A database interface class.
bool HasValue(const std::string &key)
Has this key been defined.
string fDBServer
Name of server carrying DB to connect to.
const string GetValidVersion()
virtual ~QwDatabase()
Destructor.
A class for handling connections to the Qweak database.
void SetAccessLevel(string accesslevel)
Sets the access level flag based on string labels: "off", "ro", "rw".
string fVersionMajor
Major version number of current DB schema.
const string GetVersion()
EQwDBAccessLevel fAccessLevel
Access level of the database instance.
po::options_description_easy_init AddOptions(const std::string &blockname="Specialized options")
Add an option to a named block or create new block.
const string kValidVersionMajor
T GetValue(const std::string &key)
Get a templated value.
#define QwDebug
Predefined log drain for debugging output.
string fDBPassword
DB account password.
const string kValidVersionMinor
Bool_t fValidConnection
True if a valid connection was established using defined connection information.
string fVersionPoint
Point version number of current DB schema.
mysqlpp::Query Query(const char *qstr=0)
string fDBUsername
Name of account to connect to DB server with.
sql_create_6(db_schema, 1, 2, mysqlpp::sql_int_unsigned, db_schema_id, mysqlpp::sql_char, major_release_number, mysqlpp::sql_char, minor_release_number, mysqlpp::sql_char, point_release_number, mysqlpp::sql_timestamp, time, mysqlpp::Null< mysqlpp::sql_text >, script_name) QwDatabase
string fVersionMinor
Minor version number of current DB schema.
string fDatabase
Name of database to connect to.
static std::ostream & endl(std::ostream &)
End of the line.
const string GetServerVersion()
#define QwWarning
Predefined log drain for warnings.
static void DefineOptions(QwOptions &options)
Defines available class options for QwOptions.
bool StoreDBVersion()
Retrieve database schema version information from database.
#define QwError
Predefined log drain for errors.