#include #include "../../shared/DatabaseWithRetry.h" #include "../../shared/GlobalConfigFile.h" #include "../../shared/MiscSQL.h" #include "../history_server/HistoryFileWriter.h" #include "../FieldLists.h" // This is valid mysql, and it's only a date. A date with a time would // cause problems. static bool verifyMysqlDate(std::string const &date) { return (date.length() == 10) && (mysqlToTimeT(date) > 0); } // Assume date is a valid mysql date. (I.e. we don't bother to quote it.) // This will return the empty string if the date is too old. static std::string getTableName(std::string const &date, DatabaseWithRetry &database) { std::string sql = "SELECT DATE(MIN(timestamp)) <= '" + date + "' FROM alerts"; if (database.tryQueryUntilSuccess(sql)->getBooleanField(0)) // The alerts table has the data. (The data might also be in an archive // table, but alerts is our preference.) return "alerts"; if (getConfigItem("dont_use_archive") == "1") // We are only allowed to use the alerts table, but the data is not in // that table. Some database servers only have the alerts table. return ""; // Look for the archive table. Return "" if we can't find it. sql = "SELECT table_name FROM alert_shards WHERE date = '" + date + "' AND live='Y'"; return database.tryQueryUntilSuccess(sql)->getStringField(0); } int main(int argc, char **argv) { if (!addConfigItemsFromCommandLine(argv + 1)) { return 1; } configItemsComplete(); const std::string date = getConfigItem("date"); if (date.empty()) { std::cerr<<"Date is required. -i date"< '" + lastTimeStamp + "') OR (timestamp = '" + lastTimeStamp + "' AND id > " + lastId + ")) AND (timestamp < '" + date + "' + INTERVAL 1 DAY) ORDER BY timestamp, id LIMIT " + ntoa(REQUEST_COUNT); //std::cout<rowIsValid(); result->nextRow()) { lastTimeStamp = result->getStringField("timestamp"); lastId = result->getStringField("id"); Record::Ref record = DatabaseFieldInfo::makeRecord(result, fieldList); historyFileWriter.addRecord(record); if (historyFileWriter.inErrorState()) break; } if (result->numRows() < REQUEST_COUNT) break; } } std::cout<<"Writing index."<