Database Class Reference

The database manager. More...

#include <database.h>

List of all members.

Static Public Member Functions

static DbAttach getDatabases ()
static DbObjects getObjects (const QString type=0, const QString schema="main")
 Gather user objects from sqlite_master by type. It skips the resrved names "sqlite_%". See getSysObjects().
static DbObjects getSysObjects (const QString &schema="main")
 Gather "SYS schema" objects.
static QStringList getSysIndexes (const QString &table, const QString &schema)
 Gather "SYS indexes". System indexes are indexes created internally for UNIQUE constraints.
static bool execSql (QString statement)
 Execute a SQL statement with no DB returns.
static QString sessionName (const QString &schema)
 Create a session name for the new DB connection.
static bool dropTable (const QString &table, const QString &schema)
 Drop a table from the database.
static bool dropTrigger (const QString &name, const QString &schema)
 Drop a trigger from the database.
static FieldList tableFields (const QString &table, const QString &schema)
 Returns the list of fields in a table.
static QStringList indexFields (const QString &index, const QString &schema)
 Returns the list of columns in given index.
static bool dropView (const QString &view, const QString &schema)
 Drop a view from the database.
static bool dropIndex (const QString &name, const QString &schema)
 Drop an index from the database.
static bool exportSql (const QString &fileName)
 Exports the SQL code of a database to file If the file provided by fileName exists, it will be overriden.
static QString describeObject (const QString &name, const QString &schema="main")
static QString hex (const QByteArray &val)
 BLOB X'foo' notation. See sqlite3 internals as a reference.
static QString pragma (const QString &name)
 Query the DB for its specified PRAGMA setting.


Detailed Description

The database manager.

The Database class represents a single database file/object, and provides convinient methods for accessing specific elements in it (currently only tables and views). Though the application still doesn't use this capability, it is completly safe to have multipile Database object managing diffirent databases in the same time.

Internally, the class uses the QtSQL API for manipulating the database.

Almost all methods here are static so it's not needed to create a Database instance.

Author:
Igor Khanin

Petr Vanek <petr@scribus.info>


Member Function Documentation

DbAttach Database::getDatabases (  )  [static]

DbObjects Database::getObjects ( const QString  type = 0,
const QString  schema = "main" 
) [static]

Gather user objects from sqlite_master by type. It skips the resrved names "sqlite_%". See getSysObjects().

Parameters:
type a "enum" 'table', 'view', index etc. If it's empty all objects are selected.
schema a name of the DB schema
Return values:
DbObjects a map with "object name"/"its parent"

References SESSION_NAME.

Referenced by AnalyzeDialog::AnalyzeDialog(), TableTree::buildIndexes(), TableTree::buildTables(), TableTree::buildTriggers(), TableTree::buildViews(), getSysIndexes(), QueryEditorDialog::QueryEditorDialog(), and VacuumDialog::VacuumDialog().

DbObjects Database::getSysObjects ( const QString &  schema = "main"  )  [static]

Gather "SYS schema" objects.

Parameters:
schema a string with "attached db" name
Return values:
DbObjects with With reserved names "sqlite_%".

References SESSION_NAME.

Referenced by TableTree::buildCatalogue().

QStringList Database::getSysIndexes ( const QString &  table,
const QString &  schema 
) [static]

Gather "SYS indexes". System indexes are indexes created internally for UNIQUE constraints.

Parameters:
table a table name.
schema a string with "attached db" name
Return values:
DbObjects with With reserved names "sqlite_%".

References getObjects(), and SESSION_NAME.

Referenced by TableTree::buildSysIndexes().

bool Database::execSql ( QString  statement  )  [static]

Execute a SQL statement with no DB returns.

Parameters:
statement a SQL command like INSERT/CREATE/DROP. Selects are not important here.
Return values:
bool true on succes, false on error. Error are reported in this method already.

References SESSION_NAME.

QString Database::sessionName ( const QString &  schema  )  [static]

Create a session name for the new DB connection.

Parameters:
schema a schema name.
Return values:
QString string with "SQLITEMAN_schema" format.

References SESSION_NAME.

bool Database::dropTable ( const QString &  table,
const QString &  schema 
) [static]

Drop a table from the database.

Parameters:
table The name of the table to drop
schema a table own schema
Return values:
bool true on success, false on error. Error are reported in this method already.

References SESSION_NAME.

bool Database::dropTrigger ( const QString &  name,
const QString &  schema 
) [static]

Drop a trigger from the database.

Parameters:
name The name of the trigger to drop
schema a table own schema
Return values:
bool true on success, false on error. Error are reported in this method already.

References SESSION_NAME.

FieldList Database::tableFields ( const QString &  table,
const QString &  schema 
) [static]

Returns the list of fields in a table.

Parameters:
table The table to retrive the fields from
schema a name of the DB schema
Returns:
The list of fields in table

References DatabaseTableField::cid, DatabaseTableField::comment, DatabaseTableField::defval, DatabaseTableField::name, DatabaseTableField::notnull, DatabaseTableField::pk, SESSION_NAME, and DatabaseTableField::type.

Referenced by TableTree::buildColumns(), ConstraintsDialog::ConstraintsDialog(), CreateIndexDialog::CreateIndexDialog(), and PopulatorDialog::PopulatorDialog().

QStringList Database::indexFields ( const QString &  index,
const QString &  schema 
) [static]

Returns the list of columns in given index.

References SESSION_NAME.

bool Database::dropView ( const QString &  view,
const QString &  schema 
) [static]

Drop a view from the database.

Parameters:
view The name of the view to drop
schema a table own schema
Return values:
bool true on success, false on error. Error are reported in this method already.

References SESSION_NAME.

bool Database::dropIndex ( const QString &  name,
const QString &  schema 
) [static]

Drop an index from the database.

Parameters:
name The name of the index to drop
schema a table own schema
Return values:
bool true on success, false on error. Error are reported in this method already.

References SESSION_NAME.

bool Database::exportSql ( const QString &  fileName  )  [static]

Exports the SQL code of a database to file If the file provided by fileName exists, it will be overriden.

Parameters:
fileName The file to export the SQL to
Todo:
Currently, Only the tables and views are exported. This should be fixed.

References SESSION_NAME.

QString Database::describeObject ( const QString &  name,
const QString &  schema = "main" 
) [static]

References SESSION_NAME.

QString Database::hex ( const QByteArray &  val  )  [static]

BLOB X'foo' notation. See sqlite3 internals as a reference.

Parameters:
val a raw "encoded" QByteArray (string)
Return values:
QString with sqlite encoded X'blah' notation.

QString Database::pragma ( const QString &  name  )  [static]

Query the DB for its specified PRAGMA setting.

Parameters:
name a pragma name (PRAGMA name;)
Return values:
QString pragma value or "n/a" string if it is not set at all.

References SESSION_NAME.


The documentation for this class was generated from the following files:

Generated on Sat Jul 26 09:05:56 2008 for Sqliteman by  doxygen 1.5.5