Skip to content

Commit

Permalink
Use more namespace for SQLite stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
teusbenschop committed Jun 9, 2024
1 parent fbb21e6 commit 257f9e8
Show file tree
Hide file tree
Showing 31 changed files with 476 additions and 464 deletions.
2 changes: 1 addition & 1 deletion database/abbottsmith.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ constexpr const auto filename {"abbottsmith"};

void create ()
{
filter_url_unlink (database_sqlite_file (filename));
filter_url_unlink (database::sqlite::file (filename));

SqliteDatabase sql (filename);

Expand Down
8 changes: 4 additions & 4 deletions database/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ std::string fragment ()

std::string path (const std::string& resource, int book)
{
return filter_url_create_path ({database_logic_databases (), filename (filter_url_urlencode (resource), book) + database_sqlite_suffix ()});
return filter_url_create_path ({database_logic_databases (), filename (filter_url_urlencode (resource), book) + database::sqlite::suffix ()});
}


Expand Down Expand Up @@ -87,7 +87,7 @@ void remove (const std::string& resource)

void remove (const std::string& resource, int book)
{
const std::string file = database_sqlite_file (filename (resource, book));
const std::string file = database::sqlite::file (filename (resource, book));
if (file_or_dir_exists (file)) {
filter_url_unlink (file);
}
Expand All @@ -108,7 +108,7 @@ bool exists (const std::string& resource)
// Returns true if the cache for the $resource $book exists.
bool exists (const std::string& resource, int book)
{
const std::string file = database_sqlite_file (filename (resource, book));
const std::string file = database::sqlite::file (filename (resource, book));
return file_or_dir_exists (file);
}

Expand Down Expand Up @@ -258,7 +258,7 @@ void ready (const std::string& resource, const int book, const bool ready)

int size (const std::string& resource, const int book)
{
const std::string file = database_sqlite_file (filename (resource, book));
const std::string file = database::sqlite::file (filename (resource, book));
return filter_url_filesize (file);
}

Expand Down
4 changes: 2 additions & 2 deletions database/git.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ void Database_Git::create ()

void Database_Git::optimize ()
{
bool healthy_database = database_sqlite_healthy (name ());
bool healthy_database = database::sqlite::healthy (name ());
if (!healthy_database) {
filter_url_unlink (database_sqlite_file (name ()));
filter_url_unlink (database::sqlite::file (name ()));
create ();
}

Expand Down
2 changes: 1 addition & 1 deletion database/hebrewlexicon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const char * Database_HebrewLexicon::filename ()

void Database_HebrewLexicon::create ()
{
filter_url_unlink (database_sqlite_file (filename ()));
filter_url_unlink (database::sqlite::file (filename ()));

SqliteDatabase sql = SqliteDatabase (filename ());

Expand Down
28 changes: 14 additions & 14 deletions database/imageresources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ std::string Database_ImageResources::databaseFile ()
sqlite3 * Database_ImageResources::connect (std::string name)
{
std::string path = filter_url_create_path ({resourceFolder (name), databaseFile ()});
return database_sqlite_connect (path);
return database::sqlite::connect (path);
}


Expand All @@ -82,8 +82,8 @@ void Database_ImageResources::create (std::string name)
" end integer,"
" image text"
");";
database_sqlite_exec (db, sql);
database_sqlite_disconnect (db);
database::sqlite::exec (db, sql);
database::sqlite::disconnect (db);
}


Expand All @@ -106,9 +106,9 @@ void Database_ImageResources::erase (std::string name, std::string image)
sql.add ("DELETE FROM passages WHERE image =");
sql.add (image);
sql.add (";");
database_sqlite_exec (db, sql.sql);
database::sqlite::exec (db, sql.sql);
}
database_sqlite_disconnect (db);
database::sqlite::disconnect (db);
}


Expand Down Expand Up @@ -141,7 +141,7 @@ void Database_ImageResources::assign (std::string name, std::string image,
sql.add ("DELETE FROM passages WHERE image =");
sql.add (image);
sql.add (";");
database_sqlite_exec (db, sql.sql);
database::sqlite::exec (db, sql.sql);
}
{
SqliteSQL sql = SqliteSQL ();
Expand All @@ -152,9 +152,9 @@ void Database_ImageResources::assign (std::string name, std::string image,
sql.add (",");
sql.add (image);
sql.add (");");
database_sqlite_exec (db, sql.sql);
database::sqlite::exec (db, sql.sql);
}
database_sqlite_disconnect (db);
database::sqlite::disconnect (db);
}


Expand All @@ -168,8 +168,8 @@ std::vector <std::string> Database_ImageResources::get (std::string name, int bo
sql.add (passage);
sql.add ("ORDER BY start;");
sqlite3 * db = connect (name);
std::vector <std::string> images = database_sqlite_query (db, sql.sql) ["image"];
database_sqlite_disconnect (db);
std::vector <std::string> images = database::sqlite::query (db, sql.sql) ["image"];
database::sqlite::disconnect (db);
return images;
}

Expand All @@ -180,8 +180,8 @@ std::vector <std::string> Database_ImageResources::get (std::string name)
SqliteSQL sql = SqliteSQL ();
sql.add ("SELECT image FROM passages ORDER by start;");
sqlite3 * db = connect (name);
std::vector <std::string> images = database_sqlite_query (db, sql.sql) ["image"];
database_sqlite_disconnect (db);
std::vector <std::string> images = database::sqlite::query (db, sql.sql) ["image"];
database::sqlite::disconnect (db);

// Get images from the folder.
std::vector <std::string> files = filter_url_scandir (resourceFolder (name));
Expand Down Expand Up @@ -216,8 +216,8 @@ void Database_ImageResources::get (std::string name, std::string image,
sql.add (image);
sql.add ("ORDER by start;");
sqlite3 * db = connect (name);
std::map <std::string, std::vector <std::string> > results = database_sqlite_query (db, sql.sql);
database_sqlite_disconnect (db);
std::map <std::string, std::vector <std::string> > results = database::sqlite::query (db, sql.sql);
database::sqlite::disconnect (db);
std::vector <std::string> start = results["start"];
std::vector <std::string> end = results["end"];

Expand Down
64 changes: 32 additions & 32 deletions database/jobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

sqlite3 * Database_Jobs::connect ()
{
return database_sqlite_connect ("jobs");
return database::sqlite::connect ("jobs");
}


void Database_Jobs::create ()
{
sqlite3 * db = connect ();
database_sqlite_exec (db, "DROP TABLE IF EXISTS jobs");
database::sqlite::exec (db, "DROP TABLE IF EXISTS jobs");
std::string sql = "CREATE TABLE IF NOT EXISTS jobs ("
" id integer,"
" timestamp integer,"
Expand All @@ -49,16 +49,16 @@ void Database_Jobs::create ()
" progress text,"
" result text"
");";
database_sqlite_exec (db, sql);
database_sqlite_disconnect (db);
database::sqlite::exec (db, sql);
database::sqlite::disconnect (db);
}


void Database_Jobs::optimize ()
{
sqlite3 * db = connect ();
database_sqlite_exec (db, "VACUUM;");
database_sqlite_disconnect (db);
database::sqlite::exec (db, "VACUUM;");
database::sqlite::disconnect (db);
}


Expand All @@ -71,8 +71,8 @@ void Database_Jobs::trim ()
sql.add (timestamp);
sql.add (";");
sqlite3 * db = connect ();
database_sqlite_exec (db, sql.sql);
database_sqlite_disconnect (db);
database::sqlite::exec (db, sql.sql);
database::sqlite::disconnect (db);
}


Expand All @@ -83,8 +83,8 @@ bool Database_Jobs::id_exists (int id)
sql.add (id);
sql.add (";");
sqlite3 * db = connect ();
std::vector <std::string> result = database_sqlite_query (db, sql.sql) ["id"];
database_sqlite_disconnect (db);
std::vector <std::string> result = database::sqlite::query (db, sql.sql) ["id"];
database::sqlite::disconnect (db);
return !result.empty ();
}

Expand All @@ -107,8 +107,8 @@ int Database_Jobs::get_new_id ()
sql.add (timestamp);
sql.add (");");
sqlite3 * db = connect ();
database_sqlite_exec (db, sql.sql);
database_sqlite_disconnect (db);
database::sqlite::exec (db, sql.sql);
database::sqlite::disconnect (db);
return id;
}

Expand All @@ -122,8 +122,8 @@ void Database_Jobs::set_level (int id, int level)
sql.add (id);
sql.add (";");
sqlite3 * db = connect ();
database_sqlite_exec (db, sql.sql);
database_sqlite_disconnect (db);
database::sqlite::exec (db, sql.sql);
database::sqlite::disconnect (db);
}


Expand All @@ -134,8 +134,8 @@ int Database_Jobs::get_level (int id)
sql.add (id);
sql.add (";");
sqlite3 * db = connect ();
std::vector <std::string> levels = database_sqlite_query (db, sql.sql) ["level"];
database_sqlite_disconnect (db);
std::vector <std::string> levels = database::sqlite::query (db, sql.sql) ["level"];
database::sqlite::disconnect (db);
if (!levels.empty()) {
return filter::strings::convert_to_int (levels[0]);
}
Expand All @@ -152,8 +152,8 @@ void Database_Jobs::set_start (int id, std::string start)
sql.add (id);
sql.add (";");
sqlite3 * db = connect ();
database_sqlite_exec (db, sql.sql);
database_sqlite_disconnect (db);
database::sqlite::exec (db, sql.sql);
database::sqlite::disconnect (db);
}


Expand All @@ -164,8 +164,8 @@ std::string Database_Jobs::get_start (int id)
sql.add (id);
sql.add (";");
sqlite3 * db = connect ();
std::vector <std::string> result = database_sqlite_query (db, sql.sql) ["start"];
database_sqlite_disconnect (db);
std::vector <std::string> result = database::sqlite::query (db, sql.sql) ["start"];
database::sqlite::disconnect (db);
if (!result.empty()) {
auto start = result[0];
return start;
Expand All @@ -183,8 +183,8 @@ void Database_Jobs::set_percentage (int id, int percentage)
sql.add (id);
sql.add (";");
sqlite3 * db = connect ();
database_sqlite_exec (db, sql.sql);
database_sqlite_disconnect (db);
database::sqlite::exec (db, sql.sql);
database::sqlite::disconnect (db);
}


Expand All @@ -195,8 +195,8 @@ std::string Database_Jobs::get_percentage (int id)
sql.add (id);
sql.add (";");
sqlite3 * db = connect ();
std::vector <std::string> percentages = database_sqlite_query (db, sql.sql) ["percentage"];
database_sqlite_disconnect (db);
std::vector <std::string> percentages = database::sqlite::query (db, sql.sql) ["percentage"];
database::sqlite::disconnect (db);
if (!percentages.empty()) {
return percentages[0];
}
Expand All @@ -213,8 +213,8 @@ void Database_Jobs::set_progress (int id, std::string progress)
sql.add (id);
sql.add (";");
sqlite3 * db = connect ();
database_sqlite_exec (db, sql.sql);
database_sqlite_disconnect (db);
database::sqlite::exec (db, sql.sql);
database::sqlite::disconnect (db);
}


Expand All @@ -225,8 +225,8 @@ std::string Database_Jobs::get_progress (int id)
sql.add (id);
sql.add (";");
sqlite3 * db = connect ();
std::vector <std::string> progress = database_sqlite_query (db, sql.sql) ["progress"];
database_sqlite_disconnect (db);
std::vector <std::string> progress = database::sqlite::query (db, sql.sql) ["progress"];
database::sqlite::disconnect (db);
if (!progress.empty()) {
return progress[0];
}
Expand All @@ -243,8 +243,8 @@ void Database_Jobs::set_result (int id, std::string result)
sql.add (id);
sql.add (";");
sqlite3 * db = connect ();
database_sqlite_exec (db, sql.sql);
database_sqlite_disconnect (db);
database::sqlite::exec (db, sql.sql);
database::sqlite::disconnect (db);
}


Expand All @@ -255,8 +255,8 @@ std::string Database_Jobs::get_result (int id)
sql.add (id);
sql.add (";");
sqlite3 * db = connect ();
std::vector <std::string> result = database_sqlite_query (db, sql.sql) ["result"];
database_sqlite_disconnect (db);
std::vector <std::string> result = database::sqlite::query (db, sql.sql) ["result"];
database::sqlite::disconnect (db);
if (!result.empty()) {
return result[0];
}
Expand Down
26 changes: 13 additions & 13 deletions database/localization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ Database_Localization::Database_Localization (const std::string& language_in)

sqlite3 * Database_Localization::connect ()
{
return database_sqlite_connect ("localization_" + language);
return database::sqlite::connect ("localization_" + language);
}


void Database_Localization::create (std::string po)
{
sqlite3 * db = connect ();
database_sqlite_exec (db, "PRAGMA temp_store = MEMORY;");
database_sqlite_exec (db, "PRAGMA synchronous = OFF;");
database_sqlite_exec (db, "PRAGMA journal_mode = OFF;");
database_sqlite_exec (db, "DROP TABLE IF EXISTS localization;");
database_sqlite_exec (db, "VACUUM;");
database_sqlite_exec (db, "CREATE TABLE IF NOT EXISTS localization (msgid text, msgstr text);");
database::sqlite::exec (db, "PRAGMA temp_store = MEMORY;");
database::sqlite::exec (db, "PRAGMA synchronous = OFF;");
database::sqlite::exec (db, "PRAGMA journal_mode = OFF;");
database::sqlite::exec (db, "DROP TABLE IF EXISTS localization;");
database::sqlite::exec (db, "VACUUM;");
database::sqlite::exec (db, "CREATE TABLE IF NOT EXISTS localization (msgid text, msgstr text);");
std::unordered_map <std::string, std::string> translations = locale_logic_read_msgid_msgstr (po);
for (auto & element : translations) {
SqliteSQL sql = SqliteSQL ();
Expand All @@ -60,9 +60,9 @@ void Database_Localization::create (std::string po)
sql.add (",");
sql.add (element.second);
sql.add (");");
database_sqlite_exec (db, sql.sql);
database::sqlite::exec (db, sql.sql);
}
database_sqlite_disconnect (db);
database::sqlite::disconnect (db);
}


Expand All @@ -73,8 +73,8 @@ std::string Database_Localization::translate (const std::string& english)
sql.add (english);
sql.add (";");
sqlite3 * db = connect ();
std::vector <std::string> msgstrs = database_sqlite_query (db, sql.sql) ["msgstr"];
database_sqlite_disconnect (db);
std::vector <std::string> msgstrs = database::sqlite::query (db, sql.sql) ["msgstr"];
database::sqlite::disconnect (db);
if (!msgstrs.empty ()) if (!msgstrs[0].empty ()) return msgstrs [0];
return english;
}
Expand All @@ -87,8 +87,8 @@ std::string Database_Localization::backtranslate (const std::string& localizatio
sql.add (localization);
sql.add (";");
sqlite3 * db = connect ();
std::vector <std::string> msgids = database_sqlite_query (db, sql.sql) ["msgid"];
database_sqlite_disconnect (db);
std::vector <std::string> msgids = database::sqlite::query (db, sql.sql) ["msgid"];
database::sqlite::disconnect (db);
if (!msgids.empty ()) if (!msgids[0].empty ()) return msgids [0];
return localization;
}
Loading

0 comments on commit 257f9e8

Please sign in to comment.