Ananas Library  0.9.5
adatabase.h
1 /****************************************************************************
2 ** $Id: adatabase.h,v 1.56 2008/10/25 21:42:30 leader Exp $
3 **
4 ** Header file of the ananas database of Ananas
5 ** Designer and Engine applications
6 **
7 ** Created : 20031201
8 **
9 ** Copyright (C) 2003-2004 Leader InfoTech. All rights reserved.
10 ** Copyright (C) 2003-2005 Grigory Panov <gr1313 at mail dot ru >, Yoshkar-Ola
11 **
12 ** This file is part of the Library of the Ananas
13 ** automation accounting system.
14 **
15 ** This file may be distributed and/or modified under the terms of the
16 ** GNU General Public License version 2 as published by the Free Software
17 ** Foundation and appearing in the file LICENSE.GPL included in the
18 ** packaging of this file.
19 **
20 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
21 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 **
23 ** See http://www.leaderit.ru/page=ananas or email sales@leaderit.ru
24 ** See http://www.leaderit.ru/gpl/ for GPL licensing information.
25 **
26 ** Contact org@leaderit.ru if any conditions of this licensing are
27 ** not clear to you.
28 **
29 **********************************************************************/
30 
31 #ifndef ADATABASE_H
32 #define ADATABASE_H
33 #include <qobject.h>
34 #include <qstringlist.h>
35 #include <qsqldatabase.h>
36 #include <qdict.h>
37 #include "acfg.h"
38 #include <qwidget.h>
39 #include <qdataschema.h>
40 
45 #define db_document_header "dh%1"
46 #define db_document_table "dt%1_%2"
47 #define db_catalog_element "ce%1"
48 #define db_catalog_group "cg%1"
49 #define db_iregister "ri%1"
50 #define db_aregister "ra%1"
51 #define db_areg_remainder "ra%1_rem"
52 #define db_user_roles "usr_rl"
53 #define db_users "usr"
54 #define db_roles "rl"
55 #define db_right_roles "r_rl"
56 #define db_indices "idc"
57 #define db_areg_dim "ra%1_d%2"
58 
59 class aDatabase;
60 class aCfgRc;
61 class aDataTable;
62 //class QDataSchema;
63 
64 
77 class ANANAS_EXPORT aDatabase: public QObject
78 {
79  Q_OBJECT
80 
81 public slots:
82 
83 public:
84  //enum DBOperations { DBO_Insert, DBO_Update, DBO_View, DBO_Delete };
85  enum DBPermission {
86  DBP_NoAccess = 0,
87  DBP_View = 1 << 0,
88  DBP_Update = 1 << 1,
89  DBP_Insert = 1 << 2,
90  DBP_Delete = 1 << 3,
91  DBP_Execute = 1 << 4,
92  DBP_TurnOn = 1 << 5,
93  DBP_TurnOff = 1 << 6,
94  DBP_All = 0xFFFF
95  };
104  enum dbServer
105  {
119  sybase };
120 
121 
130  QDataSchema *qds;
131 
132  aDatabase();
133  ~aDatabase();
134  bool init( aCfgRc *rc, const QString &dbname = QString::null );
135  bool init( const QString &rcname, const QString &dbname = QString::null );
136  bool prepareDatabaseConnect( aCfgRc *rc );
137  void done();
138  QSqlDatabase* db(const QString &dbname = QString::null );
139  bool checkStructure();
140  bool create();
141  bool drop( const QString &);
142  bool update();
143  Q_ULLONG uid( int otype );
144  int uidType ( Q_ULLONG uid );
145  aDataTable* table( const QString & name = QString::null );
146  bool tableExists( const QString & name );
147  void markDeleted(Q_ULLONG uid);
148  void deleteMarked();
149  QString driverName();
150 
151  bool isAccessRights( int md_type, Q_ULLONG obj_id, DBPermission req_operation );
152 
153  static QStringList supportedDriverList();
154  static QStringList getUniqueIndices(const QString & flddef);
155  static QString tableDbName( aCfg &md, aCfgItem context, long * tid);
156  static QString tableDbName( aCfg &md, aCfgItem context);
157 
158  bool exchangeDataSystables ( QDomDocument &xml, bool import );
159  bool exchangeDataCatalogues ( QDomDocument &xml, bool import );
160  bool exchangeDataDocuments ( QDomDocument &xml, bool import );
161  bool exchangeDataJournals ( QDomDocument &xml, bool import );
162  bool exchangeDataInfoRegisters ( QDomDocument &xml, bool import );
163  bool exchangeDataAccumulationRegisters ( QDomDocument &xml, bool import );
164  bool exchangeDataUniques ( QDomDocument &xml, bool import );
165 
166  bool transaction();
167  bool commit();
168  bool rollback();
169 
170  QStringList users();
171  int loginUsersCount();
172  bool login( const QString &username, const QString &password, int applicationId = 0 );
173  void logout();
174  void netupdate();
175 
176  bool isObjectLocked( Q_ULLONG id );
177  bool objectLock( Q_ULLONG id );
178  void objectUnlock( Q_ULLONG id=0 );
179 // QDataSchema *qds();
180 
181  int rolePermission( int role_id, int md_id );
182  void setRolePermission( int role_id, int md_id, int new_permission );
183 
184  static aDatabase *database();
185 signals:
186  void refresh();
187 protected:
188  void timerEvent ( QTimerEvent * );
189 private:
197  QSqlDatabase *dataBase;
198  int v_user_id, v_app_id;
199 
200  int v_updatesCount;
201 
202  int updatesCount();
203  bool exportTableData(QDomDocument& xml, const QString &tableName);
204  bool importTableData(QDomDocument& xml, const QString &tableName);
205  void reportError(QSqlError er, const QString &query);
206 
207  bool isExists(const QString fname, QStringList *f_lst, QString &match);
208  bool createdb( bool update );
209  bool dumpTable( QDomDocument& xml, const QString &tableName);
210  void fillFeatures();
211  QString feature(const QString& fetureName);
212 
213  QMap<QString, QString> featuresMySQL, featuresSQLite, featuresPostgreSQL;
214  QMap<int, int> accessRights;
215 };
216 
217 #endif
Definition: acfgrc.h:52
Definition: adatabase.h:107
dbServer
Definition: adatabase.h:104
Definition: adatabase.h:111
aCfg cfg
Definition: adatabase.h:129
Definition: adatabase.h:113
Definition: acfg.h:436
Definition: asqltable.h:54
Definition: adatabase.h:77
Definition: adatabase.h:117
Definition: adatabase.h:115
Definition: adatabase.h:109