Esempio n. 1
0
void Database_MorphGnt::create ()
{
  filter_url_unlink (database_sqlite_file (filename ()));

  SqliteDatabase sql = SqliteDatabase (filename ());
  
  sql.clear ();
  sql.add ("CREATE TABLE morphgnt (book int, chapter int, verse int, pos int, parsing int, word int, lemma int);");
  sql.execute ();
  
  sql.clear ();
  sql.add ("CREATE TABLE IF NOT EXISTS pos (pos text);");
  sql.execute ();
  
  sql.clear ();
  sql.add ("CREATE TABLE IF NOT EXISTS parsing (parsing text);");
  sql.execute ();
  
  sql.clear ();
  sql.add ("CREATE TABLE IF NOT EXISTS word (word text);");
  sql.execute ();

  sql.clear ();
  sql.add ("CREATE TABLE IF NOT EXISTS lemma (lemma text);");
  sql.execute ();
}
Esempio n. 2
0
void Database_HebrewLexicon::create ()
{
  filter_url_unlink (database_sqlite_file (filename ()));
  
  SqliteDatabase sql = SqliteDatabase (filename ());

  sql.clear ();
  sql.add ("CREATE TABLE IF NOT EXISTS aug (aug text, target text);");
  sql.execute ();
  
  sql.clear ();
  sql.add ("CREATE TABLE IF NOT EXISTS bdb (id text, definition text);");
  sql.execute ();
  
  sql.clear ();
  sql.add ("CREATE TABLE IF NOT EXISTS map (id text, bdb text);");
  sql.execute ();
  
  sql.clear ();
  sql.add ("CREATE TABLE IF NOT EXISTS pos (code text, name text);");
  sql.execute ();
  
  sql.clear ();
  sql.add ("CREATE TABLE IF NOT EXISTS strong (strong text, definition text);");
  sql.execute ();
}
Esempio n. 3
0
void Database_State::create ()
{
  bool healthy_database = database_sqlite_healthy (name ());
  if (!healthy_database) {
    filter_url_unlink (database_sqlite_file (name ()));
  }

  sqlite3 * db = connect ();
  string sql;
  
  // On Android, this pragma prevents the following error: VACUUM; Unable to open database file.
  sql = "PRAGMA temp_store = MEMORY;";
  database_sqlite_exec (db, sql);
  
  sql =
    "CREATE TABLE IF NOT EXISTS notes ("
    " first integer,"
    " last integer,"
    " value text"
    ");";
  database_sqlite_exec (db, sql);
  
  sql = "DELETE FROM notes;";
  database_sqlite_exec (db, sql);
  
  // Here something weird was going on when doing a VACUUM at this stage.
  // On Android, it always would say this: VACUUM; Unable to open database file.
  // Testing on the existence of the database file, right before the VACUUM operation, showed that the database file did exist. The question is then: If the file exists, why does it fail to open it?
  // It also was tried to delay with 100 milliseconds before doing the VACUUM. But this made no difference. It would still give the error.
  // It also was tried to close the connection to the database, then open it again. This made no difference either.
  // It now does not VACUUM a newly created database, but only when it was created.
  // Later on, the PRAGMA as above was used to solve the issue.
  sql = "VACUUM;";
  database_sqlite_exec (db, sql);

  sql =
    "CREATE TABLE IF NOT EXISTS export ("
    " bible text,"
    " book integer,"
    " format integer"
  ");";
  database_sqlite_exec (db, sql);
  
  sql =
    "CREATE TABLE IF NOT EXISTS exported ("
    " bible text,"
    " book integer,"
    " state boolean"
    ");";
  database_sqlite_exec (db, sql);
  
  database_sqlite_disconnect (db);
}
Esempio n. 4
0
void Database_Login::optimize ()
{
  if (!healthy ()) {
    // (Re)create damaged or non-existing database.
    filter_url_unlink (database_sqlite_file (database ()));
    create ();
  }
  // Vacuum it.
  SqliteDatabase sql (database ());
  // On Android, this pragma prevents the following error: VACUUM; Unable to open database file.
  sql.add ("PRAGMA temp_store = MEMORY;");
  sql.execute ();
  sql.clear ();
  sql.add ("VACUUM;");
  sql.execute ();
}
Esempio n. 5
0
// Does an integrity check on the database.
// Returns true if healthy, false otherwise.
bool database_sqlite_healthy (string database)
{
  string file = database_sqlite_file (database);
  bool ok = false;
  // Do an integrity check on the database.
  // An empty file appears healthy too, so deal with that.
  if (filter_url_filesize (file) > 0) {
    sqlite3 * db = database_sqlite_connect (database);
    string query = "PRAGMA integrity_check;";
    map <string, vector <string> > result = database_sqlite_query (db, query);
    vector <string> health = result ["integrity_check"];
    if (health.size () == 1) {
      if (health [0] == "ok") ok = true;
    }
    database_sqlite_disconnect (db);
  }
  return ok;
}
Esempio n. 6
0
void Database_Logs::rotate ()
{
  // Remove the database that was used in older versions of Bibledit.
  // Since February 2016 Bibledit no longer uses a database for storing the journal.
  // Reasons that a database is no longer used:
  // 1. Simpler system.
  // 2. Android has VACUUM errors due to a locked database.
  string old_database_file = database_sqlite_file ("logs2");
  if (file_exists (old_database_file)) {
    filter_url_unlink (old_database_file);
  }

  
  // Use a mechanism that handles huge amounts of entries.
  // The PHP function scandir choked on this or took a very long time.
  // The PHP functions opendir / readdir / closedir handled it better.
  // But now, in C++, with the new journal mechanism, this is no longer relevant.
  string directory = folder ();
  vector <string> files = filter_url_scandir (directory);

  
  // Timestamp for removing older records, depending on whether it's a tiny journal.
#ifdef HAVE_TINYJOURNAL
  int oldtimestamp = filter_date_seconds_since_epoch () - (14400);
#else
  int oldtimestamp = filter_date_seconds_since_epoch () - (6 * 86400);
#endif

  
  // Limit the available the journal entrie count in the filesystem.
  // This speeds up subsequent reading of the Journal by the users.
  // In previous versions of Bibledit, there were certain conditions
  // that led to an infinite loop, as had been noticed at times,
  // and this quickly exhausted the available inodes on the filesystem.
#ifdef HAVE_TINYJOURNAL
  int limitfilecount = files.size () - 200;
#else
  int limitfilecount = files.size () - 2000;
#endif

  
  bool filtered_entries = false;
  for (unsigned int i = 0; i < files.size(); i++) {
    string path = filter_url_create_path (directory, files [i]);

    // Limit the number of journal entries.
    if ((int)i < limitfilecount) {
      filter_url_unlink (path);
      continue;
    }
    
    // Remove expired entries.
    int timestamp = convert_to_int (files [i].substr (0, 10));
    if (timestamp < oldtimestamp) {
      filter_url_unlink (path);
      continue;
    }

    // Filtering of certain entries.
    string entry = filter_url_file_get_contents (path);
    if (journal_logic_filter_entry (entry)) {
      filtered_entries = true;
      filter_url_unlink (path);
      continue;
    }

  }

  if (filtered_entries) {
    log (journal_logic_filtered_message ());
  }
}
Esempio n. 7
0
sqlite3 * database_sqlite_connect (string database)
{
  return database_sqlite_connect_file (database_sqlite_file (database));
}