EMdF database

Overview

The EMdF database classes are structured in the following hierarchy:

  • EMdFDB
    • PgEMdFDB
    • MySQLEMdFDB
    • SQLiteEMdFDB (for SQLite 2)
    • SQLite3EMdFDB (for SQLite 3)

Boolean return value

For the functions which return a boolean, the return value generally means the following:

  • true: No error.
  • false: An error occurred. Use the error interface to get to know what the error was. The values of any reference parameters which should have returned something are undefined.

The only exceptions to this rule are the transaction interface methods and the ConnectionOk() method.

Special 'emdf' database name

All of the backends recognize the special database name 'emdf' (without the quotes). This is a valid database name, but will not associate the connection with any database.

Hence, you can use 'emdf' as a default database name used until you issue a 'USE DATABASE' MQL statement or call the EMdFDB::useDatabase() method.

On PostgreSQL, the user is actually connected to the 'template1' database.

On MySQL, the user is connected with no default associated database.

On SQLite (2 and 3), the user is not connected to any database.

C++ interface

emdfdb.h


#include <emdfdb.h>

class EMdFDBException {};
class EMdFDBDBError : public EMdFDBException {};

class EMdFDB {
public:
  //
  // Construction and destruction
  EMdFDB();
  virtual ~EMdFDB();        

  // Get backend-name
  static std::string getBackendName(void);

  //
  // Database manipulation
  virtual bool useDatabase(const std::string& db_name);

  // min_m and max_m
  bool getMin_m(monad_m& /* out */ min_m);
  bool getMax_m(monad_m& /* out */ max_m);
  bool getAll_m_1(SetOfMonads& /* out */ all_m_1);

  // Indices
  bool createIndicesOnDatabase(const std::string& database_name);
  bool dropIndicesOnDatabase(const std::string& database_name);
  bool createIndicesOnObjectType(const std::string& object_type_name);
  bool dropIndicesOnObjectType(const std::string& object_type_name);
  bool createIndicesOnObjectType(const std::string& database_name, 
                                 const std::string& object_type_name);
  bool dropIndicesOnObjectType(const std::string& database_name, 
                               const std::string& object_type_name);
    

  // DB maintenance
  virtual bool vacuum(bool bAnalyze);

  // Transactions
  virtual bool beginTransaction(void);
  virtual bool commitTransaction(void);
  virtual bool abortTransaction(void);

  //
  // Error messages
  virtual std::string errorMessage(void);
  virtual bool connectionOk(void);
  void clearLocalError(void);
  std::string getLocalError(void);
};

PgEMdFDB


#include <pgemdfdb.h>

class PgEMdFDB : public EMdFDB {
public:
  PgEMdFDB(std::string host,         // Hostname to connect to 
                                     // (e.g., "localhost"),
           std::string user,         // PostgreSQL user (e.g., "emdf")
           std::string passwd,       // PostgreSQL password (e.g., "changeme"),
           std::string database_name // Initial database to connect to 
                                     // (e.g., "emdf").
          );
  virtual ~PgEMdFDB();
};


MySQLEMdFDB


#include <mysqlemdfdb.h>

class MySQLEMdFDB : public EMdFDB {
public:
  MySQLEMdFDB(std::string host,         // Hostname to connect to 
                                        // (e.g., "localhost"),
              std::string user,         // MySQL user (e.g., "emdf")
              std::string passwd,       // MySQL password (e.g., "changeme"),
              std::string database_name // Initial database to connect to 
                                        // (e.g., "emdf").
             );
  virtual ~MySQLEMdFDB();
};


SQLiteEMdFDB


#include <sqliteemdfdb.h>

class SQLiteEMdFDB : public EMdFDB {
public:
  SQLiteEMdFDB(std::string database_name, // Initial database to connect to 
                                          // (e.g., "emdf").
               std::string database_key, // "Key" to use with encrypted SQLite dbs.
                                          // Is ignored if there is no encryption available.
                                          // (can be purchased separately from the Emdros author)
              );
  virtual ~SQLiteEMdFDB();
};

SQLite3EMdFDB


#include <sqlite3emdfdb.h>

class SQLite3EMdFDB : public EMdFDB {
public:
  SQLite3EMdFDB(std::string database_name, // Initial database to connect to 
                                           // (e.g., "emdf").
                std::string database_key, // "Key" to use with encrypted SQLite dbs.
                                           // Is ignored if there is no encryption available.
                                           // (can be purchased separately from the Emdros author)
              );
  virtual ~SQLite3EMdFDB();
};



Previous:EMdFOutput
Up:Part II: APIs
Next:Transactions