Ananas Library 0.9.5
aDatabase Class Reference

#include <adatabase.h>

Inheritance diagram for aDatabase:

Public Types

enum  DBPermission {
  DBP_NoAccess = 0 , DBP_View = 1 << 0 , DBP_Update = 1 << 1 , DBP_Insert = 1 << 2 ,
  DBP_Delete = 1 << 3 , DBP_Execute = 1 << 4 , DBP_TurnOn = 1 << 5 , DBP_TurnOff = 1 << 6 ,
  DBP_All = 0xFFFF
}
 
enum  dbServer {
  unknown , mysql , postgresql , odbc ,
  oracle , mssql , sybase , unknown ,
  mysql , postgresql , odbc , oracle ,
  mssql , sybase
}
 
enum  dbServer {
  unknown , mysql , postgresql , odbc ,
  oracle , mssql , sybase , unknown ,
  mysql , postgresql , odbc , oracle ,
  mssql , sybase
}
 

Signals

void refresh ()
 

Public Member Functions

 aDatabase ()
 
 ~aDatabase ()
 
bool init (aCfgRc *rc, const QString &dbname=QString::null)
 Creates database on SQL server.
 
bool init (const QString &rcname, const QString &dbname=QString::null)
 Creates database on SQL server. This is overloaded method, provided for convenience.
 
bool prepareDatabaseConnect (aCfgRc *rc)
 
void done ()
 
QSqlDatabase * db (const QString &dbname=QString::null)
 Returns database connection.
 
bool checkStructure ()
 
bool create ()
 
bool drop (const QString &)
 
bool update ()
 
Q_ULLONG uid (int otype)
 
int uidType (Q_ULLONG uid)
 
aDataTabletable (const QString &name=QString::null)
 
bool tableExists (const QString &name)
 
void markDeleted (Q_ULLONG uid)
 
void deleteMarked ()
 
QString driverName ()
 
bool isAccessRights (int md_type, Q_ULLONG obj_id, DBPermission req_operation)
 
bool exchangeDataSystables (QDomDocument &xml, bool import)
 
bool exchangeDataCatalogues (QDomDocument &xml, bool import)
 
bool exchangeDataDocuments (QDomDocument &xml, bool import)
 
bool exchangeDataJournals (QDomDocument &xml, bool import)
 
bool exchangeDataInfoRegisters (QDomDocument &xml, bool import)
 
bool exchangeDataAccumulationRegisters (QDomDocument &xml, bool import)
 
bool exchangeDataUniques (QDomDocument &xml, bool import)
 
bool transaction ()
 
bool commit ()
 
bool rollback ()
 
QStringList users ()
 
int loginUsersCount ()
 
bool login (const QString &username, const QString &password, int applicationId=0)
 
void logout ()
 
void netupdate ()
 
bool isObjectLocked (Q_ULLONG id)
 
bool objectLock (Q_ULLONG id)
 
void objectUnlock (Q_ULLONG id=0)
 
int rolePermission (int role_id, int md_id)
 
void setRolePermission (int role_id, int md_id, int new_permission)
 
bool init (aCfgRc *rc, const QString &dbname=QString::null)
 
bool init (const QString &rcname, const QString &dbname=QString::null)
 
void done ()
 
QSqlDatabase * db (const QString &dbname=QString::null)
 
bool checkStructure ()
 
bool create ()
 
bool drop (const QString &)
 
bool update ()
 
Q_ULLONG uid (int otype)
 
int uidType (Q_ULLONG uid)
 
aDataTabletable (const QString &name=QString::null)
 
bool tableExists (const QString &name)
 
void markDeleted (Q_ULLONG uid)
 
void deleteMarked ()
 
QString driverName ()
 
bool exchangeDataSystables (QDomDocument &xml, bool import)
 
bool exchangeDataCatalogues (QDomDocument &xml, bool import)
 
bool exchangeDataDocuments (QDomDocument &xml, bool import)
 
bool exchangeDataJournals (QDomDocument &xml, bool import)
 
bool exchangeDataInfoRegisters (QDomDocument &xml, bool import)
 
bool exchangeDataAccumulationRegisters (QDomDocument &xml, bool import)
 
bool exchangeDataUniques (QDomDocument &xml, bool import)
 

Static Public Member Functions

static QStringList supportedDriverList ()
 
static QStringList getUniqueIndices (const QString &flddef)
 
static QString tableDbName (aCfg &md, aCfgItem context, long *tid)
 
static QString tableDbName (aCfg &md, aCfgItem context)
 
static aDatabasedatabase ()
 
static QStringList supportedDriverList ()
 
static QStringList getUniqueIndices (const QString &flddef)
 
static QString tableDbName (aCfg &md, aCfgItem context, long *tid)
 
static QString tableDbName (aCfg &md, aCfgItem context)
 

Public Attributes

aCfg cfg
 
QDataSchema * qds
 
QSqlDatabase * ddb
 

Protected Member Functions

void timerEvent (QTimerEvent *)
 

Detailed Description

Database abstraction layer class. Used for working with SQL database on metadata context.

Member Enumeration Documentation

◆ dbServer [1/2]

type of database drivers

Enumerator
unknown 

Unknown driver (not supported)

mysql 

MySQL driver

postgresql 

PostgreSQL driver

odbc 

ODBC driver (not supported)

oracle 

Oracle driver (not supported)

mssql 

MSSQL driver (not supported)

sybase 

Sybase driver (not supported)

unknown 

Unknown driver (not supported)

mysql 

MySQL driver

postgresql 

PostgreSQL driver

odbc 

ODBC driver (not supported)

oracle 

Oracle driver (not supported)

mssql 

MSSQL driver (not supported)

sybase 

Sybase driver (not supported)

◆ dbServer [2/2]

type of database drivers

Enumerator
unknown 

Unknown driver (not supported)

mysql 

MySQL driver

postgresql 

PostgreSQL driver

odbc 

ODBC driver (not supported)

oracle 

Oracle driver (not supported)

mssql 

MSSQL driver (not supported)

sybase 

Sybase driver (not supported)

unknown 

Unknown driver (not supported)

mysql 

MySQL driver

postgresql 

PostgreSQL driver

odbc 

ODBC driver (not supported)

oracle 

Oracle driver (not supported)

mssql 

MSSQL driver (not supported)

sybase 

Sybase driver (not supported)

Constructor & Destructor Documentation

◆ aDatabase()

aDatabase::aDatabase ( )

Constructor has no arguments.

◆ ~aDatabase()

aDatabase::~aDatabase ( )

Destructor.

References done().

Member Function Documentation

◆ checkStructure()

bool aDatabase::checkStructure ( )

Check database structure.

Returns
true, if structure is valid.

Check database structure. Don't implemented.

Returns
true, if structure is valid.

◆ create()

bool aDatabase::create ( )

Helper method.

See also
createdb()

◆ db()

QSqlDatabase * aDatabase::db ( const QString & dbname = QString::null)

Returns database connection.

Parameters
dbname(in) - database connection name. Default value used if dbname is empty.
Returns
database connection.

Returns database connection.

Parameters
dbname(in) - database connection name. Default value used if dbname is empty.
Returns
database connection.

Referenced by deleteMarked(), done(), driverName(), init(), aExtSQL::init(), markDeleted(), uid(), and uidType().

◆ deleteMarked()

void aDatabase::deleteMarked ( )

Delete all marked records.

See also
markDeleted(Q_ULLONG uid)

References db().

◆ done()

void aDatabase::done ( )

Closes database connection.

References db().

Referenced by prepareDatabaseConnect(), and ~aDatabase().

◆ driverName()

QString aDatabase::driverName ( )

Return current database driver name. Translate name for unicode MySQL driver to standart name.

Returns
QT current Database driver name

References db().

Referenced by uid().

◆ getUniqueIndices()

QStringList aDatabase::getUniqueIndices ( const QString & flddefs)
static

getUniqueIndices procedure parses table definition and returns list of string in form 'U'<num>'%1('<field-list>')' Syntax of index field of table definition is extended to allow using of multicolumn indices. For each multicolumn index column 'U'<num> character sequence should be added to index field of column definition, where <num> is a number of multicolumn index. Example: Definition "a c 20 * pu1,b c 30 * iu1,c d * * u2,d n 10 3 u2" leads to creation of two multicolumn indices: (a,b) and (c,d).

Parameters
flddefs(in) - database table definition
Returns
list of string in form 'U'<num>'%1('<field-list>')'

returned strings can be easily used to create SQL-query for index creation as follows: query="create unique index "+tablename+"_uniq_"+retval.arg(" on "+tablename)

◆ init() [1/2]

bool aDatabase::init ( aCfgRc * rc,
const QString & dbname = QString::null )

Creates database on SQL server.

Uses rc file parameters values and makes connection to database server. Then creates database with name obtained from rc file.

Parameters
rc(in) - rc object reference.
dbname(in) - unused now.
Returns
true, if no error
See also
init( const QString &rcname, const QString &dbname )

Creates database on SQL server. Reads rc file and makes connection to database server. Then creates database with name obtained from rc file.

See also
init( const QString &rcname, const QString &dbname )
Parameters
rc(in) - rc object reference.
dbname(in) - unused now.
Returns
true, if no error

References cfg, db(), prepareDatabaseConnect(), aLog::print(), and aCfgRc::value().

Referenced by init().

◆ init() [2/2]

bool aDatabase::init ( const QString & rcname,
const QString & dbname = QString::null )

Creates database on SQL server. This is overloaded method, provided for convenience.

/en

Parameters
rcname(in) - rc file name
dbname(in) - not used
Returns
true, if no error /_en /ru

Вспомогательный метод для установления соединения с БД на SQL сервере или ее создания.

Перегружет метод init( aCfgRc *rc, const QString &dbname ) и использует его.

Parameters
rcname(in) - имя файла ресурсов, содержащего параметры соединения с базой данных.
dbname(in) - имя базы данных. (не используется, берется из файла ресурсов)
Returns
true, если файл ресурсов успешно прочитан, false - в противном случае. /_ru

This is overloaded method, provided for convenience.

See also
init( aCfgRc *rc, const QString &dbname )
Parameters
rcname(in) - rc file name.
dbname(in) - parameter to pass trough.
Returns
true, if no error

References cfg, and init().

◆ markDeleted()

void aDatabase::markDeleted ( Q_ULLONG uid)

Sets delete flag to true in system table for uid.

See also
deleteMarked()
Parameters
uid- id for mark deleted

References db(), and uid().

◆ prepareDatabaseConnect()

bool aDatabase::prepareDatabaseConnect ( aCfgRc * dbParams)

References done(), and aCfgRc::value().

Referenced by init().

◆ table()

aDataTable * aDatabase::table ( const QString & name = QString::null)

Creates aDataTable object for browsing and editing sql table in current database.

Parameters
name(in) - sql table name.
Returns
newly created object.

References tableExists().

◆ tableDbName() [1/2]

QString aDatabase::tableDbName ( aCfg & md,
aCfgItem context )
static

Helper metod. Returns sql table name for metadata object.

See also
tableDbName( aCfg &md, aCfgItem context, long * tid )
Parameters
md(in) - metadata tree object.
context(in) - node of metadata tree which represents metadata Class.
Returns
sql table name.

References tableDbName().

◆ tableDbName() [2/2]

QString aDatabase::tableDbName ( aCfg & md,
aCfgItem context,
long * tid )
static

Returns sql table name for metadata object.

See also
tableDbName( aCfg &md, aCfgItem context, long * tid )
Parameters
md(in) - metadata tree object.
context(in) - node of metadata tree which represents metadata Class.
tid(out) - id of metadata Class.
Returns
sql table name.

References aCfg::id(), aCfg::objClass(), and aCfg::parent().

Referenced by aCatalogue::initObject(), aCatGroup::initObject(), aDocJournal::initObject(), aDocument::initObject(), aExtSQL::SqlTableName(), and tableDbName().

◆ tableExists()

bool aDatabase::tableExists ( const QString & name)

Checks table existence.

Parameters
name(in) - table name to check for.
Returns
true, if table exists in current database

Referenced by table().

◆ uid()

Q_ULLONG aDatabase::uid ( int otype)

Generates new unique id for system object.

Parameters
otype(in) - object type (e.g. document, catalog, journal etc.)
Returns
newly generated unique id.

References db(), driverName(), aLog::print(), and uid().

Referenced by markDeleted(), uid(), and uidType().

◆ uidType()

int aDatabase::uidType ( Q_ULLONG uid)

Returns type of object identified by its uid.

See also
uid( int otype )
Parameters
uid(in) - object's uid.
Returns
object's type

References db(), aLog::print(), and uid().

◆ update()

bool aDatabase::update ( )

Helper method.

See also
createdb()

Member Data Documentation

◆ cfg

◆ ddb

QSqlDatabase* aDatabase::ddb

link to database


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