00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef ADATABASE_H
00032 #define ADATABASE_H
00033 #include <qobject.h>
00034 #include <qstringlist.h>
00035 #include <qsqldatabase.h>
00036 #include <qdict.h>
00037 #include "acfg.h"
00038 #include <qwidget.h>
00039
00044 #define db_document_header "dh%1"
00045 #define db_document_table "dt%1_%2"
00046 #define db_catalog_element "ce%1"
00047 #define db_catalog_group "cg%1"
00048 #define db_iregister "ri%1"
00049 #define db_aregister "ra%1"
00050 #define db_areg_remainder "ra%1_rem"
00051 #define db_user_roles "usr_rl"
00052 #define db_users "usr"
00053 #define db_roles "rl"
00054 #define db_right_roles "r_rl"
00055 #define db_indices "idc"
00056 #define db_areg_dim "ra%1_d%2"
00057
00058 class aDatabase;
00059 class aCfgRc;
00060 class aDataTable;
00061
00062
00063
00076 class ANANAS_EXPORT aDatabase: public QObject
00077 {
00078 Q_OBJECT
00079
00080 public slots:
00081 public:
00090 enum dbServer
00091 {
00093 unknown,
00095 mysql,
00097 postgresql,
00099 odbc,
00101 oracle,
00103 mssql,
00105 sybase };
00106
00107
00115 aCfg cfg;
00116
00117 aDatabase();
00118 ~aDatabase();
00119 bool init( aCfgRc *rc, const QString &dbname = QString::null );
00120 bool init( const QString &rcname, const QString &dbname = QString::null );
00121 bool prepareDatabaseConnect( aCfgRc *rc );
00122 void done();
00123 QSqlDatabase* db(const QString &dbname = QString::null );
00124 bool checkStructure();
00125 bool create();
00126 bool drop( const QString &);
00127 bool update();
00128 Q_ULLONG uid( int otype );
00129 int uidType ( Q_ULLONG uid );
00130 aDataTable* table( const QString & name = QString::null );
00131 bool tableExists( const QString & name );
00132 void markDeleted(Q_ULLONG uid);
00133 void deleteMarked();
00134 QString driverName();
00135
00136 static QStringList supportedDriverList();
00137 static QStringList getUniqueIndices(const QString & flddef);
00138 static QString tableDbName( aCfg &md, aCfgItem context, long * tid);
00139 static QString tableDbName( aCfg &md, aCfgItem context);
00140
00141 bool exchangeDataSystables ( QDomDocument &xml, bool import );
00142 bool exchangeDataCatalogues ( QDomDocument &xml, bool import );
00143 bool exchangeDataDocuments ( QDomDocument &xml, bool import );
00144 bool exchangeDataJournals ( QDomDocument &xml, bool import );
00145 bool exchangeDataInfoRegisters ( QDomDocument &xml, bool import );
00146 bool exchangeDataAccumulationRegisters ( QDomDocument &xml, bool import );
00147 bool exchangeDataUniques ( QDomDocument &xml, bool import );
00148
00149 bool transaction();
00150 bool commit();
00151 bool rollback();
00152 private:
00160 QSqlDatabase *dataBase;
00161
00162 bool exportTableData(QDomDocument& xml, const QString &tableName);
00163 bool importTableData(QDomDocument& xml, const QString &tableName);
00164 void reportError(QSqlError er, const QString &query);
00165
00166 QString fieldtype( const QString &tdef );
00167 void checkIndices(const QString &table, const QString &flddef, QStringList &ui_add, QStringList &ui_drop);
00168 bool isExists(const QString fname, QStringList *f_lst, QString &match);
00169 QString fieldsDef( aCfgItem context, const QString &idx=QString::null);
00170 QString sysFieldsDef ( aCfgItem context );
00171 QString convFieldsDef( const QString flddef, QString &idxdef, QString &pkey );
00172 bool createdb( bool update );
00173 bool createIndexes(const QString &table, const QString &indexl, const QStringList & uidc=QStringList());
00174 bool dropIndexes(const QString &table, const QStringList &indices=QStringList());
00175 bool verifyTable( const QString &table, const QString &flddef,
00176 QString &f_drop, QString &f_add, QString &f_upd,
00177 QString &i_drop, QString &i_add, QStringList & ui_drop, QStringList & ui_add);
00178 bool createTable(int update, const QString table, QString flddef );
00179 bool createSystables( bool update );
00180 bool createCatalogues( bool update );
00181 bool createDocuments( bool update );
00182 bool createJournals( bool update );
00183 bool createInformationRegisters( bool update );
00184 bool createAccumulationRegisters( bool update );
00185 bool createARegisters( bool update );
00186 bool dumpTable( QDomDocument& xml, const QString &tableName);
00187 void fillFeatures();
00188 QString feature(const QString& fetureName);
00189
00190 QMap<QString, QString> featuresMySQL, featuresSQLite, featuresPostgreSQL;
00191
00192 };
00193
00194 #endif