cosmetics, whitespace

Change-Id: I1212dfeff33d7bcb8b699233279fbf05014ea3bd
This commit is contained in:
Horst Schirmeier
2013-03-23 18:04:37 +01:00
parent 95402cee5d
commit 1d25372283
3 changed files with 19 additions and 22 deletions

View File

@ -8,8 +8,8 @@ static fail::Logger log("Database", true);
using namespace fail;
Database::Database(const std::string &username, const std::string &host, const std::string &database) {
handle = mysql_init(0);
last_result = 0;
handle = mysql_init(0);
last_result = 0;
mysql_options(handle, MYSQL_READ_DEFAULT_FILE, "~/.my.cnf");
if (!mysql_real_connect(handle, host.c_str(),
username.c_str(),
@ -28,16 +28,16 @@ MYSQL_RES* Database::query(char const *query, bool get_result)
}
if (get_result) {
if (last_result != 0) {
mysql_free_result(last_result);
last_result = 0;
}
if (last_result != 0) {
mysql_free_result(last_result);
last_result = 0;
}
MYSQL_RES *res = mysql_store_result(handle);
if (!res && mysql_errno(handle)) {
std::cerr << "mysql_store_result for query '" << query << "' failed: " << mysql_error(handle) << std::endl;
return 0;
}
last_result = res;
last_result = res;
return res;
}
return (MYSQL_RES *) 1; // Invalid PTR!!!
@ -91,11 +91,11 @@ int Database::get_fspmethod_id(const std::string &method)
return 0;
}
std::stringstream ss;
std::stringstream ss;
ss << "SELECT id FROM fspmethod WHERE method = '" << method << "'";
MYSQL_RES *res = query(ss.str().c_str(), true);
int id;
int id;
if (!res) {
return 0;
@ -120,15 +120,15 @@ void Database::cmdline_setup() {
CommandLine &cmd = CommandLine::Inst();
DATABASE = cmd.addOption("d", "database", Arg::Required,
"-d/--database\t MYSQL Database (default: taken from ~/.my.cnf)");
"-d/--database\t MYSQL Database (default: taken from ~/.my.cnf)");
HOSTNAME = cmd.addOption("H", "hostname", Arg::Required,
"-h/--hostname\t MYSQL Hostname (default: taken from ~/.my.cnf)");
"-h/--hostname\t MYSQL Hostname (default: taken from ~/.my.cnf)");
USERNAME = cmd.addOption("u", "username", Arg::Required,
"-u/--username\t MYSQL Username (default: taken from ~/.my.cnf, or your current user)");
"-u/--username\t MYSQL Username (default: taken from ~/.my.cnf, or your current user)");
}
Database * Database::cmdline_connect() {
std::string username, hostname, database;
std::string username, hostname, database;
CommandLine &cmd = CommandLine::Inst();
@ -149,6 +149,3 @@ Database * Database::cmdline_connect() {
return new Database(username, hostname, database);
}

View File

@ -23,7 +23,7 @@ bool Importer::clear_database() {
ss << "DELETE FROM trace WHERE variant_id = " << m_variant_id;
bool ret = db->query(ss.str().c_str()) == 0 ? false : true;
log << "delted " << db->affected_rows() << " rows from trace table" << std::endl;
log << "deleted " << db->affected_rows() << " rows from trace table" << std::endl;
return ret;
}

View File

@ -56,12 +56,12 @@ int main(int argc, char *argv[]) {
cmd.add_args(argv[i]);
CommandLine::option_handle IGNORE = cmd.addOption("", "", Arg::None, "USAGE: import-trace [options]");
CommandLine::option_handle HELP = cmd.addOption("h", "help", Arg::None, "-h,--help\t Print usage and exit");
CommandLine::option_handle HELP = cmd.addOption("h", "help", Arg::None, "-h/--help\t Print usage and exit");
CommandLine::option_handle TRACE_FILE = cmd.addOption("t", "trace-file", Arg::Required,
"-t/--trace-file\t File to save the execution trace to\n");
"-t/--trace-file\t File to load the execution trace from\n");
// setup the datbase command line options
Database::cmdline_setup();
// setup the database command line options
Database::cmdline_setup();
CommandLine::option_handle VARIANT = cmd.addOption("v", "variant", Arg::Required,
"-v/--variant\t Variant label (default: \"none\")");
@ -111,7 +111,7 @@ int main(int argc, char *argv[]) {
trace_file = "trace.pb";
ProtoIStream ps = openProtoStream(trace_file);
Database *db = Database::cmdline_connect();
Database *db = Database::cmdline_connect();
if (cmd[VARIANT].count() > 0)
variant = std::string(cmd[VARIANT].first()->arg);