34 size_t type_pos = connection_str.find(
"mysql://");
35 if(type_pos==string::npos)
37 throw JException(
"Invalid EventStore DB definition: "+connection_str);
41 connection_str.erase(0,8);
44 size_t at_pos = connection_str.find(
'@');
45 if(at_pos != string::npos)
50 if(at_pos == connection_str.length()-1) {
52 user_pass_str = connection_str.substr(0, at_pos);
53 connection_str =
string(
"");
54 }
else if(at_pos==0) {
56 connection_str = connection_str.substr(1);
57 user_pass_str =
string(
"");
60 user_pass_str = connection_str.substr(0,at_pos);
61 connection_str = connection_str.substr(at_pos+1);
65 size_t colon_pos = user_pass_str.find(
':');
66 if(colon_pos != string::npos) {
67 user_name = user_pass_str.substr(0,colon_pos);
68 password = user_pass_str.substr(colon_pos+1);
78 size_t white_pos = connection_str.find(
'/');
79 if(white_pos != string::npos)
81 database = connection_str.substr(white_pos+1);
82 connection_str.erase(white_pos);
86 size_t colon_pos = connection_str.find(
':');
87 if(colon_pos != string::npos)
89 string port_str = connection_str.substr(colon_pos+1);
90 connection_str.erase(colon_pos);
92 port = atoi(port_str.c_str());
115 DBptr = mysql_init(NULL);
117 throw JException(
"Unable to initialize MySQL connection information...");
161 string query_str =
"SELECT DISTINCT grade FROM Version WHERE state='active'";
170 if(mysql_query(
DBptr, query_str.c_str())) {
172 <<
"Query: " << query_str << endl;
181 <<
"Query: " << query_str << endl;
189 while((row = mysql_fetch_row(
DBresult))) {
190 grades.push_back(row[0]);
204 stringstream query_ss;
206 query_ss <<
"SELECT MAX(timeStamp) FROM Version WHERE timeStamp<='"
207 << timestamp <<
"' AND grade='" << grade <<
"' AND state='active'";
216 if(mysql_query(
DBptr, query_ss.str().c_str())) {
218 <<
"Query: " << query_ss.str() << endl;
227 <<
"Query: " << query_ss.str() << endl;
231 int num_returned_rows = mysql_num_rows(
DBresult);
232 if(num_returned_rows == 0) {
233 jerr <<
"Invalid timestamp: " + timestamp << endl;
239 string real_timestamp(row[0]);
246 query_ss <<
"SELECT DISTINCT view FROM Version,KeyFile WHERE timeStamp='"
247 << real_timestamp <<
"' AND Version.grade='" << grade
248 <<
"' AND Version.state='active' AND Version.graphid=KeyFile.graphid GROUP BY view";
251 if(mysql_query(
DBptr, query_ss.str().c_str())) {
253 <<
"Query: " << query_ss.str() << endl;
262 <<
"Query: " << query_ss.str() << endl;
267 while((row = mysql_fetch_row(
DBresult))) {
268 skims.push_back(row[0]);
bool GetGrades(vector< string > &grades)
string FormatMySQLError(string mysql_func_name)
DESDBProviderMySQL(string connection_str)
virtual ~DESDBProviderMySQL()
bool GetSkims(vector< string > &grades, string timestamp, string grade)