if (mysql.error)
panic("could not connect to database server\n%s\n", mysql.error);
+ mysql.query("LOCK TABLES runs WRITE");
+ if (mysql.error)
+ panic("could not lock tables\n%s\n", mysql.error);
+
remove(name);
- cleanup();
+// cleanup();
setup(name, sample, user, project);
+ mysql.query("UNLOCK TABLES");
+ if (mysql.error)
+ panic("could not unlock tables\n%s\n", mysql.error);
}
void
stringstream sql;
ccprintf(sql, "DELETE FROM runs WHERE rn_name=\"%s\"", name);
mysql.query(sql);
+ if (mysql.error)
+ panic("could not delete run\n%s\n", mysql.error);
}
void
mysql.query(select);
MySQL::Result result = mysql.store_result();
if (!result)
- panic("could not get a run\n%s\n", mysql.error);
+ panic("could not find stat\n%s\n", mysql.error);
assert(result.num_fields() == 16);
MySQL::Row row = result.fetch_row();
if (!row)
- panic("could not get a run\n%s\n", mysql.error);
+ panic("could not get stat row\n%s\n", mysql.error);
bool tb;
int8_t ti8;
unsigned
SetupBin(const string &bin)
{
- MySQL::Connection &mysql = MySqlDB.conn();
- assert(mysql.connected());
+ static map<string, int> binmap;
using namespace MySQL;
+ map<string,int>::const_iterator i = binmap.find(bin);
+ if (i != binmap.end())
+ return (*i).second;
+
+ Connection &mysql = MySqlDB.conn();
+ assert(mysql.connected());
+
+ mysql.query("LOCK TABLES bins WRITE");
+ if (mysql.error)
+ panic("could not lock bin table\n%s\n", mysql.error);
+
+ uint16_t bin_id;
+
stringstream select;
+ stringstream insert;
ccprintf(select, "SELECT bn_id FROM bins WHERE bn_name=\"%s\"", bin);
mysql.query(select);
MySQL::Result result = mysql.store_result();
if (result) {
assert(result.num_fields() == 1);
- Row row = result.fetch_row();
+ MySQL::Row row = result.fetch_row();
if (row) {
- uint16_t bin_id;
to_number(row[0], bin_id);
- return bin_id;
+ goto exit;
}
}
- stringstream insert;
ccprintf(insert, "INSERT INTO bins(bn_name) values(\"%s\")", bin);
mysql.query(insert);
if (mysql.error)
- panic("could not get a run\n%s\n", mysql.error);
+ panic("could not get a bin\n%s\n", mysql.error);
+
+ bin_id = mysql.insert_id();
+ binmap.insert(make_pair(bin, bin_id));
+
+ exit:
+ mysql.query("UNLOCK TABLES");
+ if (mysql.error)
+ panic("could not unlock tables\n%s\n", mysql.error);
- return mysql.insert_id();
+ return bin_id;
}
InsertData::InsertData()
MySQL::Connection &mysql = MySqlDB.conn();
assert(mysql.connected());
mysql.query(query);
+ if (mysql.error)
+ panic("could not insert data\n%s\n", mysql.error);
}
query[0] = '\0';
size = 0;
first = true;
strcpy(query, "INSERT INTO "
- "data(dt_stat,dt_x,dt_y,dt_run,dt_sample,dt_bin,dt_data) "
+ "data(dt_stat,dt_x,dt_y,dt_run,dt_tick,dt_bin,dt_data) "
"values");
size = strlen(query);
}
first = false;
size += sprintf(query + size, "(%u,%d,%d,%u,%llu,%u,\"%f\")",
- stat, x, y, MySqlDB.run(), (unsigned long long)sample,
+ stat, x, y, MySqlDB.run(), (unsigned long long)tick,
bin, data);
}
stat, x, y, name, descr);
mysql.query(insert);
+// if (mysql.error)
+// panic("could not insert subdata\n%s\n", mysql.error);
}
void
stat, formula);
mysql.query(insert_formula);
+// if (mysql.error)
+// panic("could not insert formula\n%s\n", mysql.error);
stringstream insert_ref;
ccprintf(insert_ref,
"INSERT INTO formula_ref(fr_stat,fr_run) values(%d, %d)",
stat, MySqlDB.run());
- mysql.query(insert_ref);
+ mysql.query(insert_ref);
+// if (mysql.error)
+// panic("could not insert formula reference\n%s\n", mysql.error);
}
void
ccprintf(update, "UPDATE stats SET st_prereq=%d WHERE st_id=%d",
prereq, stat);
mysql.query(update);
+ if (mysql.error)
+ panic("could not update prereq\n%s\n", mysql.error);
}
void
* set up all stats!
*/
using namespace Database;
+
+ MySQL::Connection &mysql = MySqlDB.conn();
+ mysql.query("LOCK TABLES "
+ "stats WRITE, "
+ "bins WRITE, "
+ "subdata WRITE, "
+ "formulas WRITE, "
+ "formula_ref WRITE");
+ if (mysql.error)
+ panic("could not lock tables\n%s\n", mysql.error);
+
stat_list_t::const_iterator i, end = stats().end();
for (i = stats().begin(); i != end; ++i)
(*i)->visit(*this);
}
}
+ mysql.query("UNLOCK TABLES");
+ if (mysql.error)
+ panic("could not unlock tables\n%s\n", mysql.error);
+
configured = true;
}
if (!data.subnames.empty()) {
InsertSubData subdata;
subdata.stat = statid;
- subdata.y = 0;
+ subdata.y = -1;
for (int i = 0; i < data.subnames.size(); ++i) {
subdata.x = i;
subdata.name = data.subnames[i];
if (!data.y_subnames.empty()) {
InsertSubData subdata;
subdata.stat = statid;
- subdata.x = 0;
+ subdata.x = -1;
subdata.descr = "";
for (int i = 0; i < data.y_subnames.size(); ++i) {
subdata.y = i;
{
configure(data, "FORMULA");
insert(data.id, stat.setup());
+ InsertFormula(find(data.id), data.str());
}
void
configure();
// store sample #
- newdata.sample = curTick;
+ newdata.tick = curTick;
if (bins().empty()) {
output(string(""));
void
MySql::output(const FormulaData &data)
{
- InsertFormula(find(data.id), data.str());
}
/*