Eneboo - Documentación para desarrolladores
src/flbase/aqsobjects/AQObjects.h
Ir a la documentación de este archivo.
00001 /***************************************************************************
00002  AQObjects.h
00003  -------------------
00004  begin                : 09/02/2011
00005  copyright            : (C) 2003-2011 by InfoSiAL S.L.
00006  email                : mail@infosial.com
00007  ***************************************************************************/
00008 /***************************************************************************
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; version 2 of the License.               *
00012  ***************************************************************************/
00013 /***************************************************************************
00014  Este  programa es software libre. Puede redistribuirlo y/o modificarlo
00015  bajo  los  términos  de  la  Licencia  Pública General de GNU   en  su
00016  versión 2, publicada  por  la  Free  Software Foundation.
00017  ***************************************************************************/
00018 
00019 #ifndef AQOBJECTS_H_
00020 #define AQOBJECTS_H_
00021 
00022 #include "AQS_p.h"
00023 #include "AQPackager.h"
00024 #include "AQCompilerQSA.h"
00025 #include "AQZipReader.h"
00026 #include "AQZipWriter.h"
00027 #include "AQOds.h"
00028 
00029 #include "FLSqlDatabase.h"
00030 #include "FLManager.h"
00031 #include "FLManagerModules.h"
00032 #include "FLRelationMetaData.h"
00033 #include "FLFieldMetaData.h"
00034 #include "FLTableMetaData.h"
00035 #include "FLAction.h"
00036 #include "FLSqlCursor.h"
00037 #include "FLSqlQuery.h"
00038 #include "FLSettings.h"
00039 #include "FLVar.h"
00040 #include "FLReportEngine.h"
00041 #include "FLReportViewer.h"
00042 #include "FLJasperEngine.h"
00043 #include "FLSqlConnections.h"
00044 
00045 class AQJasperEngine : public FLJasperEngine
00046 {
00047   Q_OBJECT
00048 
00049 public:
00050   AQJasperEngine(QObject *parent = 0) : FLJasperEngine(parent) {}
00051 };
00052 
00053 class AQReportViewer : public FLReportViewer
00054 {
00055   Q_OBJECT
00056 
00057 public:
00058   AQReportViewer(QWidget *parent = 0,
00059                  const char *name = 0,
00060                  bool embedInParent = false,
00061                  FLReportEngine *rptEngine = 0) :
00062     FLReportViewer(parent, name, embedInParent, rptEngine) {}
00063 };
00064 
00065 class AQReportEngine : public FLReportEngine
00066 {
00067   Q_OBJECT
00068 
00069 public:
00070   AQReportEngine(QObject *parent = 0) : FLReportEngine(parent) {}
00071 };
00072 
00073 class AQVar : public FLVar
00074 {
00075 public:
00076   AQVar() : FLVar() {}
00077 };
00078 
00079 class AQSettings : public FLSettings
00080 {
00081 public:
00082   AQSettings() : FLSettings() {}
00083 };
00084 
00085 class AQSqlDatabase : public FLSqlDatabase
00086 {
00087 public:
00088   AQSqlDatabase() : FLSqlDatabase() {}
00089 };
00090 
00091 class AQManager : public FLManager
00092 {
00093 public:
00094   AQManager() : FLManager() {}
00095 };
00096 
00097 class AQManagerModules : public FLManagerModules
00098 {
00099 public:
00100   AQManagerModules() : FLManagerModules() {}
00101 };
00102 
00103 class AQActionMD: public FLAction
00104 {
00105 public:
00106   AQActionMD() : FLAction() {}
00107 };
00108 
00109 class AQRelationMD : public FLRelationMetaData
00110 {
00111 public:
00112   AQRelationMD(const QString &fT, const QString &fF, int rC,
00113                bool dC = false, bool uC = false, bool cI = true) :
00114     FLRelationMetaData(fT, fF, rC, dC, uC, cI) {}
00115 };
00116 
00117 class AQFieldMD : public FLFieldMetaData
00118 {
00119 public:
00120   AQFieldMD(const QString &n, const QString &a, bool aN, bool iPK, int t,
00121             int l = 0, bool c = false, bool v = true, bool ed = false,
00122             int pI = 4, int pD = 0, bool iNX = false, bool uNI = false,
00123             bool coun = false, const QVariant &defValue = QVariant(), bool oT = false,
00124             const QString &rX = QString::null, bool vG = true, bool gen = true, bool iCK = false) :
00125     FLFieldMetaData(n, a, aN, iPK, t,
00126                     l, c, v, ed,
00127                     pI, pD, iNX, uNI,
00128                     coun, defValue, oT,
00129                     rX, vG, gen, iCK) {}
00130 };
00131 
00132 class AQTableMD : public FLTableMetaData
00133 {
00134 public:
00135   AQTableMD(const QString &n, const QString &a, const QString &q = QString::null) :
00136     FLTableMetaData(n, a, q) {}
00137 };
00138 
00139 class AQSqlCursor : public FLSqlCursor
00140 {
00141 public:
00142   AQSqlCursor(const QString &name = QString::null, bool autopopulate = true,
00143               const QString &connectionName = "default", FLSqlCursor *cR = 0,
00144               FLRelationMetaData *r = 0, QObject *parent = 0) :
00145     FLSqlCursor(name, autopopulate, connectionName, cR, r, parent) {}
00146 
00147   AQSqlCursor(const QString &name, bool autopopulate, QSqlDatabase *db, FLSqlCursor *cR = 0,
00148               FLRelationMetaData *r = 0, QObject *parent = 0) :
00149     FLSqlCursor(name, autopopulate, db, cR, r, parent) {}
00150 
00151   AQSqlCursor(const QString &name, QObject *parent,
00152               const QString &connectionName = "default") :
00153     FLSqlCursor(name, true, connectionName, 0, 0, parent) {}
00154 
00155   AQSqlCursor(const QString &name, const QString &connectionName) :
00156     FLSqlCursor(name, true, connectionName) {}
00157 };
00158 
00159 class AQSqlQuery : public FLSqlQuery
00160 {
00161 public:
00162   AQSqlQuery(QObject *parent = 0, const QString &connectionName = "default") :
00163     FLSqlQuery(parent, connectionName) {}
00164 };
00165 
00166 class AQSql : public QObject
00167 {
00168   Q_OBJECT
00169 
00170   Q_ENUMS(ModeAccess)
00171   Q_ENUMS(ConnOptions)
00172   Q_ENUMS(SpecialType)
00173   Q_ENUMS(Cardinality)
00174   Q_ENUMS(TableType)
00175   Q_ENUMS(SqlErrorType)
00176 
00177 public:
00178   enum ModeAccess {
00179     Insert = 0,
00180     Edit = 1,
00181     Del = 2,
00182     Browse = 3
00183   };
00184 
00185   enum ConnOptions {
00186     User = 0,
00187     Password = 1,
00188     Port = 2,
00189     Host = 3
00190   };
00191 
00192   enum SpecialType {
00193     Serial = 100,
00194     Unlock = 200,
00195     Check = 300
00196   };
00197 
00198   enum Cardinality {
00199     RELATION_1M = 0,
00200     RELATION_M1 = 1
00201   };
00202 
00203   enum TableType {
00204     Tables = 0x01,
00205     SystemTables = 0x02,
00206     Views = 0x04,
00207     AllTables = 0xff
00208   };
00209 
00210   enum SqlErrorType {
00211     SqlErrorNone,
00212     SqlErrorConnection,
00213     SqlErrorStatement,
00214     SqlErrorTransaction,
00215     SqlErrorUnknown
00216   };
00217 
00218   AQSql() : QObject(0, "aqs_aqsql") {}
00219 
00220 public slots:
00236   bool addDatabase(const QString &driverAlias, const QString &nameDB, const QString &user,
00237                    const QString &password, const QString &host, int port,
00238                    const QString &connectionName) {
00239     return FLSqlConnections::addDatabase(driverAlias, nameDB, user, password, host, port, connectionName);
00240   }
00241 
00251   bool addDatabase(FLSqlDatabase *db, const QString &connectionName = "default") {
00252     return FLSqlConnections::addDatabase(db, connectionName);
00253   }
00254 
00264   bool addDatabase(const QString &newConnName, const QString &sourceConnName = "default") {
00265     FLSqlDatabase *srcDb = FLSqlConnections::database(sourceConnName);
00266     if (!srcDb)
00267       return false;
00268     return FLSqlConnections::addDatabase(srcDb->driverName(), srcDb->database(),
00269                                          srcDb->user(), srcDb->password(), srcDb->host(),
00270                                          srcDb->port(), newConnName);
00271   }
00272 
00281   bool removeDatabase(const QString &connectionName) {
00282     return FLSqlConnections::removeDatabase(connectionName);
00283   }
00284 
00291   FLSqlDatabase *database(const QString &connectionName = "default") {
00292     return FLSqlConnections::database(connectionName);
00293   }
00294 
00298   void finish() {
00299     FLSqlConnections::finish();
00300   }
00301 
00318   bool insert(FLSqlCursor *cur, const QStringList &fields,
00319               const QValueList<QVariant> &values) {
00320     if (!cur) {
00321       if (cur->lastError().type() != QSqlError::None) {
00322         globalAQSInterpreter->throwError(cur->lastError().driverText() + ":" +
00323                                          cur->lastError().databaseText());
00324       }
00325       return false;
00326     }
00327 
00328     int fieldsCount = fields.size();
00329     int valuesCount = values.size();
00330 
00331     cur->setModeAccess(Insert);
00332     cur->refreshBuffer();
00333     for (int i = 0; i < fieldsCount; ++i)
00334       cur->setValueBuffer(fields[i], (i < valuesCount ? values[i] : QVariant()));
00335 
00336     bool ok = cur->commitBuffer();
00337     if (!ok && cur->lastError().type() != QSqlError::None) {
00338       globalAQSInterpreter->throwError(cur->lastError().driverText() + ":" +
00339                                        cur->lastError().databaseText());
00340     }
00341     return ok;
00342   }
00343 
00344   bool insert(const QString &table, const QStringList &fields,
00345               const QValueList<QVariant> &values, const QString &connName = "default") {
00346     AQSqlCursor cur(table, true, connName);
00347     return insert(&cur, fields, values);
00348   }
00349 
00367   bool update(FLSqlCursor *cur, const QStringList &fields,
00368               const QValueList<QVariant> &values, const QString &where = "") {
00369     if (!cur || !cur->select(where)) {
00370       if (cur->lastError().type() != QSqlError::None) {
00371         globalAQSInterpreter->throwError(cur->lastError().driverText() + ":" +
00372                                          cur->lastError().databaseText());
00373       }
00374       return false;
00375     }
00376 
00377     int fieldsCount = fields.size();
00378     int valuesCount = values.size();
00379 
00380     while (cur->next()) {
00381       cur->setModeAccess(Edit);
00382       cur->refreshBuffer();
00383       for (int i = 0; i < fieldsCount; ++i)
00384         cur->setValueBuffer(fields[i], (i < valuesCount ? values[i] : QVariant()));
00385       if (!cur->commitBuffer()) {
00386         if (cur->lastError().type() != QSqlError::None) {
00387           globalAQSInterpreter->throwError(cur->lastError().driverText() + ":" +
00388                                            cur->lastError().databaseText());
00389         }
00390         return false;
00391       }
00392     }
00393     return true;
00394   }
00395 
00396   bool update(const QString &table, const QStringList &fields,
00397               const QValueList<QVariant> &values, const QString &where = "",
00398               const QString &connName = "default") {
00399     AQSqlCursor cur(table, true, connName);
00400     cur.setForwardOnly(true);
00401     return update(&cur, fields, values, where);
00402   }
00403 
00418   bool del(FLSqlCursor *cur, const QString &where = "") {
00419     if (!cur || !cur->select(where)) {
00420       if (cur->lastError().type() != QSqlError::None) {
00421         globalAQSInterpreter->throwError(cur->lastError().driverText() + ":" +
00422                                          cur->lastError().databaseText());
00423       }
00424       return false;
00425     }
00426 
00427     while (cur->next()) {
00428       cur->setModeAccess(Del);
00429       cur->refreshBuffer();
00430       if (!cur->commitBuffer()) {
00431         if (cur->lastError().type() != QSqlError::None) {
00432           globalAQSInterpreter->throwError(cur->lastError().driverText() + ":" +
00433                                            cur->lastError().databaseText());
00434         }
00435         return false;
00436       }
00437     }
00438     return true;
00439   }
00440 
00441   bool del(const QString &table, const QString &where = "",
00442            const QString &connName = "default") {
00443     AQSqlCursor cur(table, true, connName);
00444     cur.setForwardOnly(true);
00445     return del(&cur, where);
00446   }
00447 
00491   QValueList<QVariant> select(const QString &select,
00492                               const QString &from,
00493                               const QString &where = QString::null,
00494                               const QString &orderBy = QString::null,
00495                               const QString &connName = "default") {
00496     AQSqlQuery qry(0, connName);
00497     qry.setTablesList(from);
00498     qry.setSelect(select);
00499     qry.setFrom(from);
00500     qry.setWhere(where);
00501     qry.setOrderBy(orderBy);
00502     qry.setForwardOnly(true);
00503     if (!qry.exec()) {
00504       if (qry.lastError().type() != QSqlError::None) {
00505         globalAQSInterpreter->throwError(qry.lastError().driverText() + ":" +
00506                                          qry.lastError().databaseText());
00507       }
00508       return QVariantList();
00509     }
00510 
00511     QVariantList ret;
00512     int countFields = qry.fieldList().count();
00513 
00514     ret.append(qry.size());
00515     ret.append(countFields);
00516     ret.append(qry.fieldList());
00517 
00518     while (qry.next()) {
00519       for (int i = 0; i < countFields; ++i)
00520         ret.append(qry.value(i));
00521     }
00522 
00523     return ret;
00524   }
00525 
00539   QValueList<QVariant> selectForUpdate(const QString &select,
00540                                        const QString &from,
00541                                        const QString &where = QString::null,
00542                                        bool nowait = false,
00543                                        const QString &connName = "default") {
00544     AQSqlQuery qry(0, connName);
00545     qry.setTablesList(from);
00546     qry.setSelect(select);
00547     qry.setFrom(from);
00548     QString w(where.isEmpty() ? "1=1" : w);
00549     qry.setWhere(nowait ?
00550                  w + QString::fromLatin1(" FOR UPDATE NOWAIT") :
00551                  w + QString::fromLatin1(" FOR UPDATE"));
00552     qry.setForwardOnly(true);
00553     if (!qry.exec()) {
00554       if (qry.lastError().type() != QSqlError::None) {
00555         globalAQSInterpreter->throwError(qry.lastError().driverText() + ":" +
00556                                          qry.lastError().databaseText());
00557       }
00558       return QVariantList();
00559     }
00560 
00561     QVariantList ret;
00562     int countFields = qry.fieldList().count();
00563 
00564     ret.append(qry.size());
00565     ret.append(countFields);
00566     ret.append(qry.fieldList());
00567 
00568     while (qry.next()) {
00569       for (int i = 0; i < countFields; ++i)
00570         ret.append(qry.value(i));
00571     }
00572 
00573     return ret;
00574   }
00575 };
00576 
00577 #include "FLFieldDB.h"
00578 #include "FLTableDB.h"
00579 #include "FLDataTable.h"
00580 
00581 class AQFieldDB : public FLFieldDB
00582 {
00583 public:
00584   AQFieldDB(QWidget *parent = 0, const char *name = 0) :
00585     FLFieldDB(parent, name) {}
00586 };
00587 
00588 class AQTableDB : public FLTableDB
00589 {
00590 public:
00591   AQTableDB(QWidget *parent = 0, const char *name = 0) :
00592     FLTableDB(parent, name) {}
00593 };
00594 
00595 class AQDataTableDB : public FLDataTable
00596 {
00597 public:
00598   AQDataTableDB(QWidget *parent = 0, const char *name = 0, bool popup = false) :
00599     FLDataTable(parent, name, popup) {}
00600 };
00601 
00602 #include "FLDigiDoc.h"
00603 
00604 class AQDigiDoc : public FLDigiDoc
00605 {
00606 public:
00607   AQDigiDoc(const QString &configfile = QString::null) :
00608     FLDigiDoc(configfile) {}
00609 };
00610 
00611 #include "FLFormDB.h"
00612 #include "FLFormRecordDB.h"
00613 #include "FLFormSearchDB.h"
00614 
00615 class AQFormDB : public FLFormDB
00616 {
00617 public:
00618   explicit AQFormDB(QWidget *parent = 0, const char *name = 0, WFlags f = 0) :
00619     FLFormDB(parent, name, f) {}
00620 
00621   AQFormDB(const QString &actionName, QWidget *parent = 0, WFlags f = 0) :
00622     FLFormDB(actionName, parent, f) {}
00623 
00624   AQFormDB(FLSqlCursor *cursor, const QString &actionName = QString::null,
00625            QWidget *parent = 0, WFlags f = 0) :
00626     FLFormDB(cursor, actionName, parent, f) {}
00627 };
00628 
00629 
00630 class AQFormRecordDB : public FLFormRecordDB
00631 {
00632 public:
00633   AQFormRecordDB(FLSqlCursor *cursor, const QString &actionName = QString::null,
00634                  QWidget *parent = 0, bool showAcceptContinue = true):
00635     FLFormRecordDB(cursor, actionName, parent) {}
00636 };
00637 
00638 class AQFormSearchDB : public FLFormSearchDB
00639 {
00640 public:
00641   AQFormSearchDB(const QString &actionName, QWidget *parent = 0) :
00642     FLFormSearchDB(actionName, parent) {}
00643 
00644   AQFormSearchDB(FLSqlCursor *cursor, const QString &actionName = QString::null,
00645                  QWidget *parent = 0) :
00646     FLFormSearchDB(cursor, actionName, parent) {}
00647 };
00648 
00649 #endif /* AQOBJECTS_H_ */
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'