diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2010-01-05 20:15:48 +0100 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2013-01-05 17:17:43 +0100 |
commit | 19d2a7165559e5fc55e9128553433ee9fedb4bd8 (patch) | |
tree | 7425b2be763343c44b307a5e26280a060c1d9549 /src | |
parent | d491aaab13a7719fe31c7474f09d86f3cd0c53f7 (diff) | |
download | usdx-19d2a7165559e5fc55e9128553433ee9fedb4bd8.tar.gz usdx-19d2a7165559e5fc55e9128553433ee9fedb4bd8.tar.xz usdx-19d2a7165559e5fc55e9128553433ee9fedb4bd8.zip |
implement get_stat_reset, format_date; added some tests
Diffstat (limited to '')
-rw-r--r-- | src/base/database.cpp | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/src/base/database.cpp b/src/base/database.cpp index 33b5f0b6..a6ae3c06 100644 --- a/src/base/database.cpp +++ b/src/base/database.cpp @@ -300,40 +300,40 @@ namespace usdx */ time_t StatDatabase::get_stat_reset(void) { - // TODO - // var - // Query: string; - // begin - // Result := 0; + std::string sqlStatement = "SELECT [ResetTime] FROM ["; + sqlStatement += usdx_statistics_info + std::string("];"); - // if not Assigned(ScoreDB) then - // Exit; + sqlite3_stmt *sqliteStatement; + int result = -1; - // try - // Query := 'SELECT [ResetTime] FROM [' + cUS_Statistics_Info + '];'; - // Result := UnixToDateTime(ScoreDB.GetTableValue(Query)); - // except on E: Exception do - // Log.LogError(E.Message, 'TDataBaseSystem.GetStatReset'); - // end; - return 0; + if (SQLITE_OK != sqlite3_prepare_v2(database, sqlStatement.c_str(), sqlStatement.length(), &sqliteStatement, NULL)) { + sqlite3_finalize(sqliteStatement); + throw "Error preparing statement."; + } + + int rc = sqlite3_step(sqliteStatement); + if (rc == SQLITE_DONE || rc == SQLITE_ROW) { + result = sqlite3_column_int(sqliteStatement, 0); + } + + sqlite3_finalize(sqliteStatement); + return (time_t)result; } char* StatDatabase::format_date(char* time, size_t max, time_t timestamp) { - // TODO - // if (timestamp != 0) { - // struct tm *tmp = localtime(×tamp); - // if (tmp) { - // if (strftime(time, max, Language.Translate("STAT_FORMAT_DATE"), tmp)) { - // return time; - // } - // } - // } - - // if (max > 0) { - // time[0] = '\0'; - // return time; - // } + if (timestamp != 0) { + struct tm *tmp = localtime(×tamp); + if (tmp) { + strftime(time, max, "%d.%m.%y" /* TODO: Language.Translate("STAT_FORMAT_DATE")*/, tmp); + return time; + } + } + + if (max > 0) { + time[0] = '\0'; + return time; + } return NULL; } |