diff options
Diffstat (limited to 'src/database/database.cpp')
-rw-r--r-- | src/database/database.cpp | 43 |
1 files changed, 9 insertions, 34 deletions
diff --git a/src/database/database.cpp b/src/database/database.cpp index c935139..a09dfe3 100644 --- a/src/database/database.cpp +++ b/src/database/database.cpp @@ -48,7 +48,6 @@ void Database::open(const std::string& filename) Database::db = std::move(new_db); Database::muc_log_lines.create(*Database::db); Database::muc_log_lines.upgrade(*Database::db); - convert_date_format(*Database::db, Database::muc_log_lines); Database::global_options.create(*Database::db); Database::global_options.upgrade(*Database::db); Database::irc_server_options.create(*Database::db); @@ -60,9 +59,9 @@ void Database::open(const std::string& filename) Database::after_connection_commands.create(*Database::db); Database::after_connection_commands.upgrade(*Database::db); create_index<Database::Owner, Database::IrcChanName, Database::IrcServerName>(*Database::db, "archive_index", Database::muc_log_lines.get_name()); - Database::db->init_session(); } + Database::GlobalOptions Database::get_global_options(const std::string& owner) { auto request = select(Database::global_options); @@ -171,7 +170,7 @@ Database::IrcChannelOptions Database::get_irc_channel_options_with_server_and_gl } std::string Database::store_muc_message(const std::string& owner, const std::string& chan_name, - const std::string& server_name, DateTime::time_point date, + const std::string& server_name, Database::time_point date, const std::string& body, const std::string& nick) { auto line = Database::muc_log_lines.row(); @@ -182,7 +181,7 @@ std::string Database::store_muc_message(const std::string& owner, const std::str line.col<Owner>() = owner; line.col<IrcChanName>() = chan_name; line.col<IrcServerName>() = server_name; - line.col<Date>() = date; + line.col<Date>() = std::chrono::duration_cast<std::chrono::seconds>(date.time_since_epoch()).count(); line.col<Body>() = body; line.col<Nick>() = nick; @@ -206,21 +205,13 @@ std::vector<Database::MucLogLine> Database::get_muc_logs(const std::string& owne { const auto start_time = utils::parse_datetime(start); if (start_time != -1) - { - DateTime datetime(start_time); - DatetimeWriter writer(datetime, *Database::db); - request << " and " << Database::Date{} << ">=" << writer; - } + request << " and " << Database::Date{} << ">=" << start_time; } if (!end.empty()) { const auto end_time = utils::parse_datetime(end); if (end_time != -1) - { - DateTime datetime(end_time); - DatetimeWriter writer(datetime, *Database::db); - request << " and " << Database::Date{} << "<=" << writer; - } + request << " and " << Database::Date{} << "<=" << end_time; } if (reference_record_id != Id::unset_value) { @@ -233,9 +224,9 @@ std::vector<Database::MucLogLine> Database::get_muc_logs(const std::string& owne } if (paging == Database::Paging::first) - request.order_by() << Database::Date{} << " ASC"; + request.order_by() << Database::Date{} << " ASC, " << Id{} << " ASC "; else - request.order_by() << Database::Date{} << " DESC"; + request.order_by() << Database::Date{} << " DESC, " << Id{} << " DESC "; if (limit >= 0) request.limit() << limit; @@ -261,21 +252,13 @@ Database::MucLogLine Database::get_muc_log(const std::string& owner, const std:: { const auto start_time = utils::parse_datetime(start); if (start_time != -1) - { - DateTime datetime(start_time); - DatetimeWriter writer(datetime, *Database::db); - request << " and " << Database::Date{} << ">=" << writer; - } + request << " and " << Database::Date{} << ">=" << start_time; } if (!end.empty()) { const auto end_time = utils::parse_datetime(end); if (end_time != -1) - { - DateTime datetime(end_time); - DatetimeWriter writer(datetime, *Database::db); - request << " and " << Database::Date{} << "<=" << writer; - } + request << " and " << Database::Date{} << "<=" << end_time; } auto result = request.execute(*Database::db); @@ -359,12 +342,4 @@ Transaction::~Transaction() log_error("Failed to end SQL transaction: ", std::get<std::string>(result)); } } - -void Transaction::rollback() -{ - this->success = false; - const auto result = Database::raw_exec("ROLLBACK"); - if (std::get<bool>(result) == false) - log_error("Failed to rollback SQL transaction: ", std::get<std::string>(result)); -} #endif |