From e61084f3a7d6868cde237bc074d18286f3837233 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Mon, 7 Nov 2011 20:09:38 +0100 Subject: removed deprecated files --- src/base/database.cpp | 135 ---------------- src/base/database.hpp | 111 ------------- src/base/stats.cpp | 386 -------------------------------------------- src/base/stats_database.cpp | 196 ---------------------- src/base/stats_database.hpp | 76 --------- 5 files changed, 904 deletions(-) delete mode 100644 src/base/database.cpp delete mode 100644 src/base/database.hpp delete mode 100644 src/base/stats.cpp delete mode 100644 src/base/stats_database.cpp delete mode 100644 src/base/stats_database.hpp (limited to 'src/base') diff --git a/src/base/database.cpp b/src/base/database.cpp deleted file mode 100644 index 998179c0..00000000 --- a/src/base/database.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* - * UltraStar Deluxe - Karaoke Game - * - * UltraStar Deluxe is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - */ - -#include "database.hpp" -#include -#include - -namespace usdx -{ - log4cxx::LoggerPtr Database::log = log4cxx::Logger::getLogger("usdx.base.Database"); - - Database::Database(const std::string filename) - { - if (SQLITE_OK != sqlite3_open_v2(filename.c_str(), &this->database, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL)) { - sqlite3_close(database); - throw "Error opening database."; - } - } - - Database::~Database(void) - { - /* frees database */ - LOG4CXX_DEBUG(log, "Closing Database"); - - sqlite3_close(database); - database = NULL; - } - - sqlite3_stmt *Database::sqlite_prepare(const std::wstring sqlStatement) - { - sqlite3_stmt *sqliteStatement; - if (SQLITE_OK != sqlite3_prepare16_v2(database, sqlStatement.c_str(), sqlStatement.length(), &sqliteStatement, NULL)) { - sqlite3_finalize(sqliteStatement); - - LOG4CXX_ERROR(log, L"Error '" << sqlite3_errmsg(database) << L"' in SQL '" << sqlStatement << L"'"); - throw "Error preparing statement."; - } - - return sqliteStatement; - } - - void Database::sqlite_exec(const std::wstring sqlStatement) - { - sqlite3_stmt *sqliteStatement = sqlite_prepare(sqlStatement); - sqlite3_step(sqliteStatement); - sqlite3_finalize(sqliteStatement); - } - - const bool Database::sqlite_table_exists(const std::wstring table) - { - std::wstring sql = L"select [name] from [sqlite_master] where [type] = 'table' and [tbl_name] = ?1;"; - sqlite3_stmt *sqliteStatement = sqlite_prepare(sql); - - // bind table name to parameter 1 and execute statement - sqlite3_bind_text16(sqliteStatement, 1, table.c_str(), table.length(), SQLITE_TRANSIENT); - int rc = sqlite3_step(sqliteStatement); - - // if rc is SQLITE_ROW, than result has at lease one row and so - // the table exists - bool result = false; - if (rc == SQLITE_ROW) { - result = true; - } - - sqlite3_finalize(sqliteStatement); - return result; - } - - const bool Database::sqlite_table_contains_column(const std::wstring table, const std::wstring column) - { - sqlite3_stmt *sqliteStatement = sqlite_prepare(L"PRAGMA TABLE_INFO([" + table + L"]);"); - bool result = false; - - int rc = sqlite3_step(sqliteStatement); - while (rc == SQLITE_ROW) { - const wchar_t *column_name = (const wchar_t*)sqlite3_column_blob(sqliteStatement, 1); - - if (column == std::wstring(column_name)) { - result = true; - break; - } - - rc = sqlite3_step(sqliteStatement); - } - - sqlite3_finalize(sqliteStatement); - return result; - } - - const int Database::get_version(void) - { - int result = -1; - sqlite3_stmt *sqliteStatement = sqlite_prepare(L"PRAGMA user_version;"); - - int rc = sqlite3_step(sqliteStatement); - if (rc == SQLITE_ROW) { - result = sqlite3_column_int(sqliteStatement, 0); - } - - sqlite3_finalize(sqliteStatement); - return result; - } - - void Database::set_version(const int version) - { - // format the PRAGMA statement (PRAGMA does _not_ support parameters) - std::wostringstream sqlStatementBuffer (std::wostringstream::out); - sqlStatementBuffer << L"PRAGMA user_version = " << version << L";"; - - sqlite_exec(sqlStatementBuffer.str()); - } -}; diff --git a/src/base/database.hpp b/src/base/database.hpp deleted file mode 100644 index 2a320f45..00000000 --- a/src/base/database.hpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - * UltraStar Deluxe - Karaoke Game - * - * UltraStar Deluxe is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - */ - -#ifndef DATABASE_HPP -#define DATABASE_HPP - -#include -#include -#include - -namespace usdx -{ - /** - * Abstract base class for all sqlite databases. - */ - class Database - { - private: - static log4cxx::LoggerPtr log; - - protected: - /** - * Internal reference to the sqlite database handle of the open - * sqlite database. - */ - sqlite3 *database; - - Database(std::string filename); - virtual ~Database(void); - - public: - /** - * Wrapper around the sqlite_prepare_v2 function with propper - * logging and exception throwing on error. - * - * @param sqlStatement SQL Statement for preparing to - * sqlite3_stmt - * @return Pointer to a sqlite3_stmt used for binding - * parameters and executing the statement. Need to be freed - * with sqlite3_finalize. - */ - sqlite3_stmt *sqlite_prepare(const std::wstring sqlStatement); - - /** - * Just a quick alias for sqlite_prepare, sqlite3_step and - * sqlite3_finalize. - */ - void sqlite_exec(const std::wstring sqlStatement); - - /** - * Check if the given table exists in the database. - * - * @param table Name to check if exists - * @return true, if table exists, false if not - */ - const bool sqlite_table_exists(const std::wstring table); - - /** - * Check if the given table has the given column by name. - * - * @param table Table to examine - * @param column Name of the column to check if exists - * @return true, if column exists in that table, false if not - */ - const bool sqlite_table_contains_column(const std::wstring table, const std::wstring column); - - /** - * Queries the user version from the sqlite database. This is a - * free settable additional field to identify the version of the - * schemata in the database. - * - * @see set_version(const int version) - * @return Value of the user_version setting of the sqlite - * database - */ - const int get_version(void); - - /** - * Set the user version of the database. - * - * @see get_version(void) - * @param version Current scheme version. - */ - void set_version(const int version); - }; -}; - -#endif diff --git a/src/base/stats.cpp b/src/base/stats.cpp deleted file mode 100644 index 7ad32e74..00000000 --- a/src/base/stats.cpp +++ /dev/null @@ -1,386 +0,0 @@ -/* - * UltraStar Deluxe - Karaoke Game - * - * UltraStar Deluxe is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - */ - -#include "stats.hpp" - -namespace usdx -{ - StatDatabase *Stats::db = NULL; - std::string Stats::filename = std::string(""); - - log4cxx::LoggerPtr Stats::log = - log4cxx::Logger::getLogger("usdx.base.Stats"); - - StatDatabase *Stats::get_database(void) - { - if (filename == "") - { - LOG4CXX_ERROR(log, "You have to set a filename first."); - throw "You have to set a filename first."; - } - - if (db == NULL) { - db = new StatDatabase(filename); - } - - return db; - } - - int Stats::get_count(std::wstring query) - { - int result = 0; - sqlite3_stmt *sqliteStatement = - get_database()->sqlite_prepare(query); - - int rc = sqlite3_step(sqliteStatement); - if (rc == SQLITE_ROW) { - result = sqlite3_column_int(sqliteStatement, 0); - } - - sqlite3_finalize(sqliteStatement); - return result; - - } - - void Stats::set_filename(std::string filename) - { - Stats::filename = filename; - - // close old database - delete db; - db = NULL; - } - - std::string Stats::get_filename(void) - { - return filename; - } - - time_t Stats::get_stat_reset(void) - { - int result = -1; - - sqlite3_stmt *sqliteStatement = get_database()->sqlite_prepare( - L"SELECT [ResetTime] FROM [" + - get_database()->usdx_statistics_info + L"];"); - - int rc = sqlite3_step(sqliteStatement); - if (rc == SQLITE_ROW) { - result = sqlite3_column_int(sqliteStatement, 0); - } - - sqlite3_finalize(sqliteStatement); - return (time_t)result; - } - -/* void Stats::add_score(Song *song, int level, const char* player, int score) - { - // TODO - // var - // ID: integer; - // TableData: TSQLiteTable; - // begin - // if not Assigned(ScoreDB) then - // Exit; - - // // Prevent 0 Scores from being added EDIT: ==> UScreenTop5.pas! - // //if (Score <= 0) then - // // Exit; - - // TableData := nil; - - // try - - // ID := ScoreDB.GetTableValue( - // 'SELECT [ID] FROM [' + cUS_Songs + '] ' + - // 'WHERE [Artist] = ? AND [Title] = ?', - // [Song.Artist, Song.Title]); - // if (ID = 0) then - // begin - // // Create song if it does not exist - // ScoreDB.ExecSQL( - // 'INSERT INTO [' + cUS_Songs + '] ' + - // '([ID], [Artist], [Title], [TimesPlayed]) VALUES ' + - // '(NULL, ?, ?, 0);', - // [Song.Artist, Song.Title]); - // // Get song-ID - // ID := ScoreDB.GetLastInsertRowID(); - // end; - // // Create new entry - // ScoreDB.ExecSQL( - // 'INSERT INTO [' + cUS_Scores + '] ' + - // '([SongID] ,[Difficulty], [Player], [Score], [Date]) VALUES ' + - // '(?, ?, ?, ?, ?);', - // [ID, Level, Name, Score, DateTimeToUnix(Now())]); - - // except on E: Exception do - // Log.LogError(E.Message, 'TDataBaseSystem.AddScore'); - // end; - - // TableData.Free; - } -*/ - -/* void Stats::add_song(Song *song) - { - // TODO - // if not Assigned(ScoreDB) then - // Exit; - - // try - // // Increase TimesPlayed - // ScoreDB.ExecSQL( - // 'UPDATE [' + cUS_Songs + '] ' + - // 'SET [TimesPlayed] = [TimesPlayed] + 1 ' + - // 'WHERE [Title] = ? AND [Artist] = ?;', - // [Song.Title, Song.Artist]); - // except on E: Exception do - // Log.LogError(E.Message, 'TDataBaseSystem.WriteScore'); - // end; - } -*/ - - StatResultBestScores::StatResultBestScores(wchar_t *singer, unsigned short score, unsigned short difficulty, - wchar_t* song_artist, wchar_t* song_title, time_t date) - { - this->singer = std::wstring(singer); - this->score = score; - this->difficulty = difficulty; - this->song_artist = std::wstring(song_artist); - this->song_title = std::wstring(song_title); - this->date = date; - this->next = NULL; - } - - StatResultBestScores::StatResultBestScores(wchar_t* song_artist, wchar_t* song_title) - { - this->next = NULL; - - // get score for this song from db - // TODO - // var - // TableData: TSQLiteUniTable; - // Difficulty: integer; - // I: integer; - // PlayerListed: boolean; - // begin - // if not Assigned(ScoreDB) then - // Exit; - - // TableData := nil; - // try - // // Search Song in DB - // TableData := ScoreDB.GetUniTable( - // 'SELECT [Difficulty], [Player], [Score], [Date] FROM [' + cUS_Scores + '] ' + - // 'WHERE [SongID] = (' + - // 'SELECT [ID] FROM [' + cUS_Songs + '] ' + - // 'WHERE [Artist] = ? AND [Title] = ? ' + - // 'LIMIT 1) ' + - // 'ORDER BY [Score] DESC;', //no LIMIT! see filter below! - // [Song.Artist, Song.Title]); - - // // Empty Old Scores - // SetLength(Song.Score[0], 0); //easy - // SetLength(Song.Score[1], 0); //medium - // SetLength(Song.Score[2], 0); //hard - - // // Go through all Entrys - // while (not TableData.EOF) do - // begin - // // Add one Entry to Array - // Difficulty := TableData.FieldAsInteger(TableData.FieldIndex['Difficulty']); - // if ((Difficulty >= 0) and (Difficulty <= 2)) and - // (Length(Song.Score[Difficulty]) < 5) then - // begin - // //filter player - // PlayerListed:=false; - // if (Length(Song.Score[Difficulty])>0) then - // begin - // for I := 0 to Length(Song.Score[Difficulty]) - 1 do - // begin - // if (Song.Score[Difficulty, I].Name = TableData.FieldByName['Player']) then - // begin - // PlayerListed:=true; - // break; - // end; - // end; - // end; - - // if not PlayerListed then - // begin - // SetLength(Song.Score[Difficulty], Length(Song.Score[Difficulty]) + 1); - - // Song.Score[Difficulty, High(Song.Score[Difficulty])].Name := - // TableData.FieldByName['Player']; - // Song.Score[Difficulty, High(Song.Score[Difficulty])].Score := - // TableData.FieldAsInteger(TableData.FieldIndex['Score']); - // Song.Score[Difficulty, High(Song.Score[Difficulty])].Date := - // FormatDate(TableData.FieldAsInteger(TableData.FieldIndex['Date'])); - // end; - // end; - - // TableData.Next; - // end; // while - - // except - // for Difficulty := 0 to 2 do - // begin - // SetLength(Song.Score[Difficulty], 1); - // Song.Score[Difficulty, 1].Name := 'Error Reading ScoreDB'; - // end; - // end; - - // TableData.Free; - } - - StatResultBestScores::~StatResultBestScores(void) - { - if (next) { - delete next; - next = NULL; - } - } - - StatResultBestScores *StatResultBestScores::get_next() - { - return next; - } - - int StatResultBestScores::get_count(void) - { - return Stats::get_count(L"SELECT COUNT([SongID]) FROM [" + - get_database()->usdx_scores + L"];"); - } - - StatResultBestScores *StatResultBestScores::get_stats() - { - // TODO - return NULL; - } - - - - StatResultBestSingers::StatResultBestSingers(wchar_t *singer, unsigned short average_score) - { - this->singer = std::wstring(singer); - this->average_score = average_score; - this->next = NULL; - } - - StatResultBestSingers::~StatResultBestSingers(void) - { - if (next) { - delete next; - next = NULL; - } - } - - StatResultBestSingers *StatResultBestSingers::get_next() - { - return next; - } - - int StatResultBestSingers::get_count(void) - { - return Stats::get_count( - L"SELECT COUNT(DISTINCT [Player]) FROM [" - + get_database()->usdx_scores + L"];"); - } - - StatResultBestSingers *StatResultBestSingers::get_stats() - { - // TODO - return NULL; - } - - - StatResultMostSungSong::StatResultMostSungSong(wchar_t* song_artist, wchar_t* song_title, unsigned short times_sung) - { - this->song_artist = std::wstring(song_artist); - this->song_title = std::wstring(song_title); - this->times_sung = times_sung; - this->next = NULL; - } - - StatResultMostSungSong::~StatResultMostSungSong(void) - { - if (next) { - delete next; - next = NULL; - } - } - - StatResultMostSungSong *StatResultMostSungSong::get_next() - { - return next; - } - - int StatResultMostSungSong::get_count(void) - { - return Stats::get_count(L"SELECT COUNT([ID]) FROM [" + - get_database()->usdx_scores + L"];"); - } - - StatResultMostSungSong *StatResultMostSungSong::get_stats() - { - // TODO - return NULL; - } - - - StatResultMostSungBand::StatResultMostSungBand(wchar_t* song_artist, unsigned short times_sung) - { - this->song_artist = std::wstring(song_artist); - this->times_sung = times_sung; - this->next = NULL; - } - - StatResultMostSungBand::~StatResultMostSungBand(void) - { - if (next) { - delete next; - next = NULL; - } - } - - StatResultMostSungBand *StatResultMostSungBand::get_next() - { - return next; - } - - int StatResultMostSungBand::get_count(void) - { - return Stats::get_count( - L"SELECT COUNT(DISTINCT [Artist]) FROM [" + - get_database()->usdx_scores + L"];"); - } - - StatResultMostSungBand *StatResultMostSungBand::get_stats() - { - // TODO - return NULL; - } -} diff --git a/src/base/stats_database.cpp b/src/base/stats_database.cpp deleted file mode 100644 index a46d9ccb..00000000 --- a/src/base/stats_database.cpp +++ /dev/null @@ -1,196 +0,0 @@ -/* - * UltraStar Deluxe - Karaoke Game - * - * UltraStar Deluxe is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - */ - -#include "stats_database.hpp" - -namespace usdx -{ - const int db_version = 1; - const std::wstring StatDatabase::usdx_scores = - L"us_scores"; - - const std::wstring StatDatabase::usdx_songs = - L"us_songs"; - - const std::wstring StatDatabase::usdx_statistics_info = - L"us_statistics_info"; - - log4cxx::LoggerPtr StatDatabase::log = - log4cxx::Logger::getLogger("usdx.base.StatDatabase"); - - StatDatabase::StatDatabase(const std::string filename) : - Database(filename) - { - LOG4CXX_DEBUG(log, "Initializing Database: " << filename); - - if (! sqlite_table_exists(usdx_statistics_info)) { - // add table usdx_statistics_info, needed in the - // conversion from 1.01 to 1.1 - LOG4CXX_INFO(log, L"Outdated song database found " << - L"- missing table'" << - usdx_statistics_info << L"'"); - - sqlite_exec(L"CREATE TABLE IF NOT EXISTS [" + - usdx_statistics_info + - L"] ([ResetTime] Integer);"); - - // insert creation timestamp - sqlite3_stmt *sqliteStatement = - sqlite_prepare(L"INSERT INTO [" + - usdx_statistics_info + - L"] ([ResetTime]) VALUES (?1);"); - - sqlite3_bind_int(sqliteStatement, 1, time(NULL)); - sqlite3_step(sqliteStatement); - sqlite3_finalize(sqliteStatement); - } - - int version = get_version(); - - bool finalizeConversion = false; - if (version == 0 && sqlite_table_exists(L"US_Scores")) { - // convert data from 1.01 to 1.1 - // part #1 - prearrangement: rename old tables - // to be able to insert new table structures - sqlite_exec(L"ALTER TABLE US_Scores RENAME TO us_scores_101;"); - sqlite_exec(L"ALTER TABLE US_Songs RENAME TO us_songs_101;"); - } - - if (version == 0) { - // Set version number after creation - set_version(db_version); - } - - // SQLite does not handle VARCHAR(n) or INT(n) as expected. - // Texts do not have a restricted length, no matter which type - // is used, so use the native TEXT type. INT(n) is always - // INTEGER. In addition, SQLiteTable3 will fail if other types - // than the native SQLite types are used (especially - // FieldAsInteger). Also take care to write the types in - // upper-case letters although SQLite does not care about this - - // SQLiteTable3 is very sensitive in this regard. - std::wstring sqlStatement; - - sqlStatement = L"CREATE TABLE IF NOT EXISTS ["; - sqlStatement += usdx_scores; - sqlStatement += L"] ("; - sqlStatement += L"[SongID] INTEGER NOT NULL, "; - sqlStatement += L"[Difficulty] INTEGER NOT NULL, "; - sqlStatement += L"[Player] TEXT NOT NULL, "; - sqlStatement += L"[Score] INTEGER NOT NULL, "; - sqlStatement += L"[Date] INTEGER NULL"; - sqlStatement += L");"; - - sqlite_exec(sqlStatement); - - sqlStatement = L"CREATE TABLE IF NOT EXISTS ["; - sqlStatement += usdx_songs; - sqlStatement += L"] ("; - sqlStatement += L"[ID] INTEGER PRIMARY KEY, "; - sqlStatement += L"[Artist] TEXT NOT NULL, "; - sqlStatement += L"[Title] TEXT NOT NULL, "; - sqlStatement += L"[TimesPlayed] INTEGER NOT NULL, "; - sqlStatement += L"[Rating] INTEGER NULL"; - sqlStatement += L");"; - - sqlite_exec(sqlStatement); - - if (finalizeConversion) { - // convert data from 1.01 to 1.1 - // part #2 - accomplishment - LOG4CXX_INFO(log, L"Outdated song database found - " << - L"begin conversion from V1.01 to V1.1"); - - // insert old values into new db-schemes (/tables) - sqlStatement = L"INSERT INTO ["; - sqlStatement += usdx_scores; - sqlStatement += L"] SELECT [SongID], "; - sqlStatement += L"[Difficulty], [Player], "; - sqlStatement += L"[Score] FROM [us_scores_101];"; - sqlite_exec(sqlStatement); - - sqlStatement = L"INSERT INTO ["; - sqlStatement += usdx_songs; - sqlStatement += L"] SELECT [ID], [Artist], "; - sqlStatement += L"[Title], [TimesPlayed], NULL "; - sqlStatement += L"FROM [us_songs_101];"; - sqlite_exec(sqlStatement); - - // now drop old tables - sqlite_exec(L"DROP TABLE us_scores_101;"); - sqlite_exec(L"DROP TABLE us_songs_101;"); - } - - // add column rating to cUS_Songs - // just for users of nightly builds and developers! - if (! sqlite_table_contains_column(usdx_songs, L"Rating")) { - LOG4CXX_INFO(log, L"Outdated song database found - " << - L"adding column rating to '" << - usdx_songs << L"'"); - - sqlite_exec(L"ALTER TABLE [" + usdx_songs + - L"] ADD COLUMN [Rating] INTEGER NULL;"); - } - - //add column date to cUS-Scores - if (! sqlite_table_contains_column(usdx_scores, L"Date")) { - LOG4CXX_INFO(log, L"Outdated score database found - " << - L"adding column date to '" << - usdx_scores << L"'"); - - sqlite_exec(L"ALTER TABLE [" + usdx_scores + - L"] ADD COLUMN [Date] INTEGER NULL;"); - } - } - - StatDatabase::~StatDatabase(void) - { - this->Database::~Database(); - } - - char* StatDatabase::format_date(char* time, - size_t max, - time_t timestamp) - { - if (timestamp != 0) { - struct tm tmp; - - if (localtime_r(×tamp, &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; - } -}; diff --git a/src/base/stats_database.hpp b/src/base/stats_database.hpp deleted file mode 100644 index 6e7f0d01..00000000 --- a/src/base/stats_database.hpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * UltraStar Deluxe - Karaoke Game - * - * UltraStar Deluxe is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - */ - -#ifndef STATS_DATABASE_HPP -#define STATS_DATABASE_HPP - -#include -#include -#include -#include "database.hpp" - -namespace usdx -{ - /** - * Wrapper for statistic database. - */ - class StatDatabase : public Database - { - private: - static log4cxx::LoggerPtr log; - - public: - StatDatabase(std::string filename); - ~StatDatabase(void); - - /** - * Convert a timestamp to a data representation in a string. - * - * @param time Pointer to a char buffer that will contain the - * the date string. - * @param max Maximum bytes that could be written to the buffer. - * @param timestamp Timestamp to convert to the string. - * @return Pointer to the buffer supplied as first parameter, - * containing: - * - only a '\\0' at first position if timestamp was - * 0 or if max was to short to contain the date - * - the date string with the terminating '\\0' - */ - static char* format_date(char* time, size_t max, time_t timestamp); - - static const std::wstring usdx_scores; - static const std::wstring usdx_songs; - static const std::wstring usdx_statistics_info; - - -#ifdef STAT_DATABASE_TEST - // for testing private members - friend class StatDatabaseTest; -#endif - }; -}; - -#endif -- cgit v1.2.3