Exemple #1
0
int Database_MorphGnt::get_id (const char * table_row, string item)
{
  SqliteDatabase sql = SqliteDatabase (filename ());
  // Two iterations to be sure a rowid can be returned.
  for (unsigned int i = 0; i < 2; i++) {
    // Check on the rowid and return it if it's there.
    sql.clear ();
    sql.add ("SELECT rowid FROM");
    sql.add (table_row);
    sql.add ("WHERE");
    sql.add (table_row);
    sql.add ("=");
    sql.add (item);
    sql.add (";");
    vector <string> result = sql.query () ["rowid"];
    if (!result.empty ()) return convert_to_int (result [0]);
    // The rowid was not found: Insert the word into the table.
    // The rowid will now be found during the second iteration.
    sql.clear ();
    sql.add ("INSERT INTO");
    sql.add (table_row);
    sql.add ("VALUES (");
    sql.add (item);
    sql.add (");");
    sql.execute ();
  }
  return 0;
}
Exemple #2
0
void Database_Kjv::create ()
{
  SqliteDatabase sql = SqliteDatabase (filename ());
  sql.add ("DROP TABLE IF EXISTS kjv2;");
  sql.execute ();

  sql.clear ();
  sql.add ("CREATE TABLE kjv2 (book int, chapter int, verse int, strong int, english int);");
  sql.execute ();

  sql.clear ();
  sql.add ("DROP TABLE IF EXISTS strong;");
  sql.execute ();

  sql.clear ();
  sql.add ("CREATE TABLE IF NOT EXISTS strong (strong text);");
  sql.execute ();
  
  sql.clear ();
  sql.add ("DROP TABLE IF EXISTS english;");
  sql.execute ();

  sql.clear ();
  sql.add ("CREATE TABLE IF NOT EXISTS english (english text);");
  sql.execute ();
  
  sql.clear ();
  sql.add ("VACUUM;");
  sql.execute ();
}
Exemple #3
0
void Database_Kjv::optimize ()
{
  SqliteDatabase sql = SqliteDatabase (filename ());
  sql.add ("VACUUM;");
  sql.execute ();
}
Exemple #4
0
// Sets the login security tokens for a user.
// Also store whether the device is touch-enabled.
// It only writes to the table if the combination of username and tokens differs from what the table already contains.
void Database_Login::setTokens (string username, string address, string agent, string fingerprint, bool touch)
{
  if (username == getUsername (address, agent, fingerprint)) return;
  address = md5 (address);
  agent = md5 (agent);
  fingerprint = md5 (fingerprint);
  SqliteDatabase sql (database ());
  sql.add ("INSERT INTO logins (username, address, agent, fingerprint, touch, timestamp) VALUES (");
  sql.add (username);
  sql.add (",");
  sql.add (address);
  sql.add (",");
  sql.add (agent);
  sql.add (",");
  sql.add (fingerprint);
  sql.add (",");
  sql.add (touch);
  sql.add (",");
  sql.add (timestamp ());
  sql.add (");");
  sql.execute ();
}
Exemple #5
0
void Database_Kjv::store (int book, int chapter, int verse, string strong, string english)
{
  int strongid = get_id ("strong", strong);
  int englishid = get_id ("english", english);
  SqliteDatabase sql = SqliteDatabase (filename ());
  sql.add ("PRAGMA temp_store = MEMORY;");
  sql.execute ();
  sql.clear ();
  sql.add ("PRAGMA synchronous = OFF;");
  sql.execute ();
  sql.clear ();
  sql.add ("PRAGMA journal_mode = OFF;");
  sql.execute ();
  sql.clear ();
  sql.add ("INSERT INTO kjv2 VALUES (");
  sql.add (book);
  sql.add (",");
  sql.add (chapter);
  sql.add (",");
  sql.add (verse);
  sql.add (",");
  sql.add (strongid);
  sql.add (",");
  sql.add (englishid);
  sql.add (");");
  sql.execute ();
}
Exemple #6
0
void Database_HebrewLexicon::optimize ()
{
  SqliteDatabase sql = SqliteDatabase (filename ());
  sql.add ("VACUUM;");
  sql.execute ();
}
Exemple #7
0
void Database_Login::testTimestamp ()
{
  SqliteDatabase sql (database ());
  sql.add ("UPDATE logins SET timestamp = timestamp - 370;");
  sql.execute ();
}
Exemple #8
0
// Remove the login security tokens for a user based on the tokens themselves.
void Database_Login::removeTokens (string username, string address, string agent, string fingerprint)
{
  address = md5 (address);
  agent = md5 (agent);
  fingerprint = md5 (fingerprint);
  SqliteDatabase sql (database ());
  sql.add ("DELETE FROM logins WHERE username ="******"AND address =");
  sql.add (address);
  sql.add ("AND agent =");
  sql.add (agent);
  sql.add ("AND fingerprint =");
  sql.add (fingerprint);
  sql.add (";");
  sql.execute ();
}
Exemple #9
0
void Database_Login::renameTokens (string username_existing, string username_new,
                                   string address, string agent, string fingerprint)
{
  address = md5 (address);
  agent = md5 (agent);
  fingerprint = md5 (fingerprint);
  SqliteDatabase sql (database ());
  sql.add ("UPDATE logins SET username ="******"WHERE username ="******"AND address =");
  sql.add (address);
  sql.add ("AND agent =");
  sql.add (agent);
  sql.add ("AND fingerprint =");
  sql.add (fingerprint);
  sql.add (";");
  sql.execute ();
}
void Database_Privileges::getBible (string username, string bible, bool & read, bool & write)
{
  SqliteDatabase sql (database ());
  sql.add ("SELECT write FROM bibles WHERE username ="******"AND bible =");
  sql.add (bible);
  sql.add (";");
  vector <string> result = sql.query () ["write"];
  read = (!result.empty());
  sql.clear ();
  sql.add ("SELECT write FROM bibles WHERE username ="******"AND bible =");
  sql.add (bible);
  sql.add ("AND write;");
  result = sql.query () ["write"];
  write = (!result.empty());
}
void Database_Privileges::setFeature (string username, int feature, bool enabled)
{
  SqliteDatabase sql (database ());
  sql.add ("DELETE FROM features WHERE username ="******"AND feature =");
  sql.add (feature);
  sql.add (";");
  sql.execute ();
  if (enabled) {
    sql.clear ();
    sql.add ("INSERT INTO features VALUES (");
    sql.add (username);
    sql.add (",");
    sql.add (feature);
    sql.add (");");
    sql.execute ();
  }
}
// Give a privilege to a $username to access $bible to read it, or also to $write it.
void Database_Privileges::setBible (string username, string bible, bool write)
{
  // First remove any entry.
  removeBibleBook (username, bible, 0);
  // Store the new entry.
  SqliteDatabase sql (database ());
  sql.add ("INSERT INTO bibles VALUES (");
  sql.add (username);
  sql.add (",");
  sql.add (bible);
  sql.add (",");
  sql.add (0);
  sql.add (",");
  sql.add (write);
  sql.add (");");
  sql.execute ();
}
Exemple #13
0
void Database_MorphHb::create ()
{
    SqliteDatabase sql = SqliteDatabase (filename ());
    sql.add ("DROP TABLE IF EXISTS morphhb;");
    sql.execute ();

    sql.clear ();
    sql.add ("CREATE TABLE morphhb (book int, chapter int, verse int, parsing int, word int);");
    sql.execute ();

    sql.clear ();
    sql.add ("DROP TABLE IF EXISTS parsing;");
    sql.execute ();

    sql.clear ();
    sql.add ("CREATE TABLE IF NOT EXISTS parsing (parsing text);");
    sql.execute ();

    sql.clear ();
    sql.add ("DROP TABLE IF EXISTS word;");
    sql.execute ();

    sql.clear ();
    sql.add ("CREATE TABLE IF NOT EXISTS word (word text);");
    sql.execute ();
}
Exemple #14
0
void Database_MorphHb::store (int book, int chapter, int verse, string parsing, string word)
{
    int parsing_id = get_id ("parsing", parsing);
    int word_id = get_id ("word", word);
    SqliteDatabase sql = SqliteDatabase (filename ());
    sql.add ("PRAGMA temp_store = MEMORY;");
    sql.execute ();
    sql.clear ();
    sql.add ("PRAGMA synchronous = OFF;");
    sql.execute ();
    sql.clear ();
    sql.add ("PRAGMA journal_mode = OFF;");
    sql.execute ();
    sql.clear ();
    sql.add ("INSERT INTO morphhb VALUES (");
    sql.add (book);
    sql.add (",");
    sql.add (chapter);
    sql.add (",");
    sql.add (verse);
    sql.add (",");
    sql.add (parsing_id);
    sql.add (",");
    sql.add (word_id);
    sql.add (");");
    sql.execute ();
}
Exemple #15
0
string Database_MorphGnt::get_item (const char * item, int rowid)
{
  // The $rowid refers to the main table.
  // Update it so it refers to the sub table.
  SqliteDatabase sql = SqliteDatabase (filename ());
  sql.add ("SELECT");
  sql.add (item);
  sql.add ("FROM morphgnt WHERE rowid =");
  sql.add (rowid);
  sql.add (";");
  vector <string> result = sql.query () [item];
  rowid = 0;
  if (!result.empty ()) rowid = convert_to_int (result [0]);
  // Retrieve the requested value from the sub table.
  sql.clear ();
  sql.add ("SELECT");
  sql.add (item);
  sql.add ("FROM");
  sql.add (item);
  sql.add ("WHERE rowid =");
  sql.add (rowid);
  sql.add (";");
  result = sql.query () [item];
  if (!result.empty ()) return result [0];
  // Not found.
  return "";
}
Exemple #16
0
// Returns the username that matches the remote IP $address and the browser's user $agent,
// and the other fingerprints from the user.
string Database_Login::getUsername (string address, string agent, string fingerprint)
{
  address = md5 (address);
  agent = md5 (agent);
  fingerprint = md5 (fingerprint);
  SqliteDatabase sql (database ());
  sql.add ("SELECT rowid, timestamp, username FROM logins WHERE address =");
  sql.add (address);
  sql.add ("AND agent =");
  sql.add (agent);
  sql.add ("AND fingerprint =");
  sql.add (fingerprint);
  sql.add (";");
  map <string, vector <string> > result = sql.query ();
  if (result.empty()) return "";
  string username = result ["username"][0];
  int stamp = convert_to_int (result ["timestamp"] [0]);
  if (stamp != timestamp ()) {
    // Touch the timestamp. This occurs once a day.
    int rowid = convert_to_int (result ["rowid"] [0]);
    sql.clear ();
    sql.add ("UPDATE logins SET timestamp =");
    sql.add (timestamp ());
    sql.add ("WHERE rowid =");
    sql.add (rowid);
    sql.execute ();
  }
  return username;
}
Exemple #17
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 ();
}
Exemple #18
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 ();
}