Ananas Library  0.9.5
adatabase_old.h
1 /****************************************************************************
2 ** $Id: adatabase_old.h,v 1.1 2007/03/17 11:12:35 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 
40 
41 #define db_document_header "dh%1"
42 #define db_document_table "dt%1_%2"
43 #define db_catalog_element "ce%1"
44 #define db_catalog_group "cg%1"
45 #define db_iregister "ri%1"
46 #define db_aregister "ra%1"
47 #define db_areg_remainder "ra%1_rem"
48 #define db_user_roles "usr_rl"
49 #define db_users "usr"
50 #define db_roles "rl"
51 #define db_right_roles "r_rl"
52 #define db_indices "idc"
53 #define db_areg_dim "ra%1_d%2"
54 
55 class aDatabase;
56 class aCfgRc;
57 class aDataTable;
58 
59 //extern aDatabase database;
60 
73 class aDataDriver: public QObject
74 {
75  Q_OBJECT
76 public:
77  aDataDriver();
78  ~aDataDriver();
79 };
80 
81 
83 {
84  Q_OBJECT
85 public:
88 
89 };
90 
92 {
93  Q_OBJECT
94 public:
97 
98 };
99 
100 
102 {
103  Q_OBJECT
104 public:
107 
108 };
109 
110 
123 class ANANAS_EXPORT aDatabase: public QObject
124 {
125  Q_OBJECT
126 
127 public slots:
128 public:
130  enum dbServer
131  {
133  unknown,
135  mysql,
137  postgresql,
139  odbc,
141  oracle,
143  mssql,
145  sybase };
147  QSqlDatabase *ddb;
149  aCfg cfg;
150 
151  aDatabase();
152  ~aDatabase();
153  bool init( aCfgRc *rc, const QString &dbname = QString::null );
154  bool init( const QString &rcname, const QString &dbname = QString::null );
155  void done();
156  QSqlDatabase* db(const QString &dbname = QString::null );
157  bool checkStructure();
158  bool create();
159  bool drop( const QString &);
160  bool update();
161  Q_ULLONG uid( int otype );
162 // int otype( Q_ULLONG uid );
163  int uidType ( Q_ULLONG uid );
164  aDataTable *table( const QString & name = QString::null );
165  bool tableExists( const QString & name );
166  void markDeleted(Q_ULLONG uid);
167  void deleteMarked();
168  QString driverName();
169 
170 // static QString tableDbName( aCfg &md, aCfgItem context, long * tid = 0 );
171  static QStringList supportedDriverList();
172  static QStringList getUniqueIndices(const QString & flddef);
173 
174  static QString tableDbName( aCfg &md, aCfgItem context, long * tid);
175  static QString tableDbName( aCfg &md, aCfgItem context);
176 
177  bool exchangeDataSystables ( QDomDocument &xml, bool import );
178  bool exchangeDataCatalogues ( QDomDocument &xml, bool import );
179  bool exchangeDataDocuments ( QDomDocument &xml, bool import );
180  bool exchangeDataJournals ( QDomDocument &xml, bool import );
181  bool exchangeDataInfoRegisters ( QDomDocument &xml, bool import );
182  bool exchangeDataAccumulationRegisters ( QDomDocument &xml, bool import );
183  bool exchangeDataUniques ( QDomDocument &xml, bool import );
184 
185 
186 private:
187  bool exportTableData(QDomDocument& xml, const QString &tableName);
188  bool importTableData(QDomDocument& xml, const QString &tableName);
189  void reportError(QSqlError er, const QString &query);
190 
191  QString fieldtype( const QString &tdef );
192  void checkIndices(const QString &table, const QString &flddef, QStringList &ui_add, QStringList &ui_drop);
193  bool isExists(const QString fname, QStringList *f_lst, QString &match);
194  QString fieldsDef( aCfgItem context, const QString &idx=QString::null);
195  QString sysFieldsDef ( aCfgItem context );
196  QString convFieldsDef( const QString flddef, QString &idxdef, QString &pkey );
197  bool createdb( bool update );
198  bool createIndexes(const QString &table, const QString &indexl, const QStringList & uidc=QStringList());
199  bool dropIndexes(const QString &table, const QStringList &indices=QStringList());
200  bool verifyTable( const QString &table, const QString &flddef,
201  QString &f_drop, QString &f_add, QString &f_upd,
202  QString &i_drop, QString &i_add, QStringList & ui_drop, QStringList & ui_add);
203  bool createTable(int update, const QString table, QString flddef );
204  bool createSystables( bool update );
205  bool createCatalogues( bool update );
206  bool createDocuments( bool update );
207  bool createJournals( bool update );
208  bool createInformationRegisters( bool update );
209  bool createAccumulationRegisters( bool update );
210  bool dumpTable( QDomDocument& xml, const QString &tableName);
211  void fillFeatures();
212  QString feature(const QString& fetureName);
213 
214  QMap<QString, QString> featuresMySQL, featuresSQLite, featuresPostgreSQL;
215 
216 };
217 
218 #endif
Definition: acfgrc.h:52
Definition: adatabase_old.h:73
Definition: adatabase_old.h:91
dbServer
Definition: adatabase.h:104
QSqlDatabase * ddb
Definition: adatabase_old.h:147
Definition: adatabase_old.h:101
Definition: adatabase_old.h:82
Definition: acfg.h:436
Definition: asqltable.h:54
Definition: adatabase.h:77