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
00040
00041 #define db_document_header "dh%1"
00042 #define db_document_table "dt%1_%2"
00043 #define db_catalog_element "ce%1"
00044 #define db_catalog_group "cg%1"
00045 #define db_iregister "ri%1"
00046 #define db_aregister "ra%1"
00047 #define db_areg_remainder "ra%1_rem"
00048 #define db_user_roles "usr_rl"
00049 #define db_users "usr"
00050 #define db_roles "rl"
00051 #define db_right_roles "r_rl"
00052 #define db_indices "idc"
00053 #define db_areg_dim "ra%1_d%2"
00054
00055 class aDatabase;
00056 class aCfgRc;
00057 class aDataTable;
00058
00059
00060
00073 class aDataDriver: public QObject
00074 {
00075 Q_OBJECT
00076 public:
00077 aDataDriver();
00078 ~aDataDriver();
00079 };
00080
00081
00082 class aDataDriver_SQLITE: public aDataDriver
00083 {
00084 Q_OBJECT
00085 public:
00086 aDataDriver_SQLITE();
00087 ~aDataDriver_SQLITE();
00088
00089 };
00090
00091 class aDataDriver_MYSQL: public aDataDriver
00092 {
00093 Q_OBJECT
00094 public:
00095 aDataDriver_MYSQL();
00096 ~aDataDriver_MYSQL();
00097
00098 };
00099
00100
00101 class aDataDriver_PGSQL: public aDataDriver
00102 {
00103 Q_OBJECT
00104 public:
00105 aDataDriver_PGSQL();
00106 ~aDataDriver_PGSQL();
00107
00108 };
00109
00110
00123 class ANANAS_EXPORT aDatabase: public QObject
00124 {
00125 Q_OBJECT
00126
00127 public slots:
00128 public:
00130 enum dbServer
00131 {
00133 unknown,
00135 mysql,
00137 postgresql,
00139 odbc,
00141 oracle,
00143 mssql,
00145 sybase };
00147 QSqlDatabase *ddb;
00149 aCfg cfg;
00150
00151 aDatabase();
00152 ~aDatabase();
00153 bool init( aCfgRc *rc, const QString &dbname = QString::null );
00154 bool init( const QString &rcname, const QString &dbname = QString::null );
00155 void done();
00156 QSqlDatabase* db(const QString &dbname = QString::null );
00157 bool checkStructure();
00158 bool create();
00159 bool drop( const QString &);
00160 bool update();
00161 Q_ULLONG uid( int otype );
00162
00163 int uidType ( Q_ULLONG uid );
00164 aDataTable *table( const QString & name = QString::null );
00165 bool tableExists( const QString & name );
00166 void markDeleted(Q_ULLONG uid);
00167 void deleteMarked();
00168 QString driverName();
00169
00170
00171 static QStringList supportedDriverList();
00172 static QStringList getUniqueIndices(const QString & flddef);
00173
00174 static QString tableDbName( aCfg &md, aCfgItem context, long * tid);
00175 static QString tableDbName( aCfg &md, aCfgItem context);
00176
00177 bool exchangeDataSystables ( QDomDocument &xml, bool import );
00178 bool exchangeDataCatalogues ( QDomDocument &xml, bool import );
00179 bool exchangeDataDocuments ( QDomDocument &xml, bool import );
00180 bool exchangeDataJournals ( QDomDocument &xml, bool import );
00181 bool exchangeDataInfoRegisters ( QDomDocument &xml, bool import );
00182 bool exchangeDataAccumulationRegisters ( QDomDocument &xml, bool import );
00183 bool exchangeDataUniques ( QDomDocument &xml, bool import );
00184
00185
00186 private:
00187 bool exportTableData(QDomDocument& xml, const QString &tableName);
00188 bool importTableData(QDomDocument& xml, const QString &tableName);
00189 void reportError(QSqlError er, const QString &query);
00190
00191 QString fieldtype( const QString &tdef );
00192 void checkIndices(const QString &table, const QString &flddef, QStringList &ui_add, QStringList &ui_drop);
00193 bool isExists(const QString fname, QStringList *f_lst, QString &match);
00194 QString fieldsDef( aCfgItem context, const QString &idx=QString::null);
00195 QString sysFieldsDef ( aCfgItem context );
00196 QString convFieldsDef( const QString flddef, QString &idxdef, QString &pkey );
00197 bool createdb( bool update );
00198 bool createIndexes(const QString &table, const QString &indexl, const QStringList & uidc=QStringList());
00199 bool dropIndexes(const QString &table, const QStringList &indices=QStringList());
00200 bool verifyTable( const QString &table, const QString &flddef,
00201 QString &f_drop, QString &f_add, QString &f_upd,
00202 QString &i_drop, QString &i_add, QStringList & ui_drop, QStringList & ui_add);
00203 bool createTable(int update, const QString table, QString flddef );
00204 bool createSystables( bool update );
00205 bool createCatalogues( bool update );
00206 bool createDocuments( bool update );
00207 bool createJournals( bool update );
00208 bool createInformationRegisters( bool update );
00209 bool createAccumulationRegisters( bool update );
00210 bool dumpTable( QDomDocument& xml, const QString &tableName);
00211 void fillFeatures();
00212 QString feature(const QString& fetureName);
00213
00214 QMap<QString, QString> featuresMySQL, featuresSQLite, featuresPostgreSQL;
00215
00216 };
00217
00218 #endif