Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes

Database Class Reference
[Global code used by all commands]

Manages the database connection and queries. More...

#include <database.hpp>

Inheritance diagram for Database:
DataManager GlobalParserDatabase PreparserDatabase

List of all members.

Public Types

enum  DocumentStatus { Waiting = 0, Parsed = 1, Processing = 2, Error = 3 }
 

The status of the document in the database.

More...
enum  Encoding { None, Utf8 }
 

The database encoding.

More...

Public Member Functions

 Database ()
 Database (const QString &host, const QString &dbName, const QString &userName, const QString &password)
 Initializes the database connection.
 ~Database ()
void configureDatabase (OptionManager &optionManager)
 Configures the database.
void set (const QString &host, const QString &dbName, const QString &userName, const QString &password)
 Initializes the database connection.

Static Public Member Functions

static void configureOptions (OptionManager &optionManager)
 Configures the option manager for database options (t, d, u, w, x).

Protected Member Functions

void copy (const QString &tableTarget, const QString &data)
 Performs a COPY query.
QByteArray encodeStringForDatabase (const QString &string) const
 Encodes a string for SQL queries, depending on the database-encoding option.
QString encodeStringFromDatabase (const char *string) const
 Encodes a string sent by the database, depending on the database-encoding option.
QByteArray escapeString (const QString &string)
 Escapes the string delimiter, then quotes the whole string.

Static Protected Member Functions

static QString & escapeCopyString (QString &string)
 Escapes the copy delimiter and newline characters, then quotes the whole string.

Protected Attributes

PGconn * _connection
Encoding _encoding

Detailed Description

Manages the database connection and queries.

This class uses the C libpq library as PosgreSQL API.


Member Enumeration Documentation

The status of the document in the database.

Enumerator:
Waiting 

Document hasn't been indexed.

Parsed 

Document has been indexed.

Processing 

Document is currently being indexed.

Error 

Document can not be indexed because of bad data.

The database encoding.

Enumerator:
None 

Unspecified, will use locale if detected.

Utf8 

Constructor & Destructor Documentation

Database::Database (  ) 
Database::~Database (  ) 
Database::Database ( const QString &  host,
const QString &  dbName,
const QString &  userName,
const QString &  password 
)

Initializes the database connection.

Exceptions:
DatabaseException If connection fails

Member Function Documentation

void Database::configureDatabase ( OptionManager optionManager  ) 

Configures the database.

Exceptions:
DatabaseException From Database::set()
void Database::configureOptions ( OptionManager optionManager  )  [static]

Configures the option manager for database options (t, d, u, w, x).

Exceptions:
Exception If options can not be added
void Database::copy ( const QString &  tableTarget,
const QString &  data 
) [protected]

Performs a COPY query.

Exceptions:
DatabaseException 
Todo:
send by blocks
QByteArray Database::encodeStringForDatabase ( const QString &  string  )  const [protected]

Encodes a string for SQL queries, depending on the database-encoding option.

QString Database::encodeStringFromDatabase ( const char *  string  )  const [protected]

Encodes a string sent by the database, depending on the database-encoding option.

QString & Database::escapeCopyString ( QString &  string  )  [static, protected]

Escapes the copy delimiter and newline characters, then quotes the whole string.

QByteArray Database::escapeString ( const QString &  string  )  [protected]

Escapes the string delimiter, then quotes the whole string.

void Database::set ( const QString &  host,
const QString &  dbName,
const QString &  userName,
const QString &  password 
)

Initializes the database connection.

Exceptions:
DatabaseException If connection fails

Member Data Documentation

PGconn* Database::_connection [protected]
All Classes Functions Variables Typedefs Enumerations Enumerator