Eneboo - Documentación para desarrolladores
src/flbase/FLSqlCursor.h
Ir a la documentación de este archivo.
00001 /***************************************************************************
00002                       FLSqlCursor.h  -  description
00003                          -------------------
00004 begin                : Fri Jul 27 2001
00005 copyright            : (C) 2001-2005 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 FLSQLCURSOR_H
00020 #define FLSQLCURSOR_H
00021 
00022 #include <qvaluelist.h>
00023 #include <qvariant.h>
00024 #include <qsqlcursor.h>
00025 #include <qsqlindex.h>
00026 #include <qobject.h>
00027 #include <qmessagebox.h>
00028 #include <qdatetime.h>
00029 #include <qregexp.h>
00030 #include <qptrstack.h>
00031 #include <qptrqueue.h>
00032 #include <qdict.h>
00033 #include <qvaluestack.h>
00034 #include <qlabel.h>
00035 
00036 class FLTableMetaData;
00037 class FLRelationMetaData;
00038 class FLAction;
00039 class FLSqlSavePoint;
00040 class FLSqlDatabase;
00041 class FLSqlCursor;
00042 class FLAccessControl;
00043 
00044 class FLSqlCursorPrivate
00045 {
00046 public:
00047 
00048   FLSqlCursorPrivate();
00049   ~FLSqlCursorPrivate();
00050 
00057   QSqlRecord *buffer_;
00058 
00064   QSqlRecord *bufferCopy_;
00065 
00069   FLTableMetaData *metadata_;
00070 
00074   int modeAccess_;
00075 
00079   FLSqlCursor *cursorRelation_;
00080 
00084   FLRelationMetaData *relation;
00085 
00091   bool edition;
00092 
00098   bool browse;
00099 
00106   QString mainFilter_;
00107 
00112   const FLAction *action_;
00113 
00118   bool askForCancelChanges_;
00119 
00123   bool activatedCheckIntegrity_;
00124 
00128   bool activatedCommitActions_;
00129 
00137   QObject *ctxt_;
00138 
00142   QTimer *timer;
00143 
00148   bool populated_;
00149 
00153   QString query_;
00154 
00158   QString queryOrderBy_;
00159 
00163   FLSqlDatabase *db_;
00164 
00170   QMap < QString, int > mapPosByPK;
00171 
00175   QValueStack < int > transactionsOpened;
00176 
00183   QString persistentFilter_;
00184 
00188   FLSqlCursor *cursor_;
00189 
00193   bool inLoopRisksLocks_;
00194   bool inRisksLocks_;
00195   QLabel *modalRisksLocks_;
00196   QTimer *timerRisksLocks_;
00197 
00201   void doAcl();
00202   void undoAcl();
00203   FLAccessControl *acTable_;
00204   QString acPermTable_;
00205   QString acPermBackupTable_;
00206   QStringList acosTable_;
00207   QStringList acosBackupTable_;
00208   QString acosCondName_;
00209   int acosCond_;
00210   QVariant acosCondVal_;
00211   int lastAt_;
00212   bool aclDone_;
00213   QStringList fieldsNamesUnlock_;
00214   int idAc_, idAcos_, idCond_;
00215   QString id_;
00216   bool isQuery_;
00217   bool isSysTable_;
00218 };
00219 
00249 class FL_EXPORT FLSqlCursor: public QObject, public QSqlCursor
00250 {
00251 
00252   Q_OBJECT
00253 
00254 public:
00255 
00265   FLSqlCursor(const QString &name = QString::null, bool autopopulate = true,
00266               const QString &connectionName = "default", FLSqlCursor *cR = 0,
00267               FLRelationMetaData *r = 0, QObject *parent = 0);
00268 
00272   FLSqlCursor(const QString &name, bool autopopulate, QSqlDatabase *db, FLSqlCursor *cR = 0,
00273               FLRelationMetaData *r = 0, QObject *parent = 0);
00274 
00278   ~FLSqlCursor();
00279 
00283   enum Mode {
00285     INSERT = 0,
00287     EDIT = 1,
00289     DEL = 2,
00291     BROWSE = 3
00292   };
00293 
00297   enum AcosConditionEval {
00299     VALUE = 0,
00301     REGEXP = 1,
00303     FUNCTION = 2
00304   };
00305 
00311   FLTableMetaData *metadata() const {
00312     return d->metadata_;
00313   }
00314 
00321   int modeAccess() const {
00322     return d->modeAccess_;
00323   }
00324 
00330   QString mainFilter() const {
00331     return d->mainFilter_;
00332   }
00333 
00339   const FLAction *action() const {
00340     return d->action_;
00341   }
00342 
00348   void setAction(const FLAction *a) {
00349     d->action_ = a;
00350   }
00351 
00357   void setMainFilter(const QString &f);
00358 
00365   void setModeAccess(const int m) {
00366     d->modeAccess_ = m;
00367   }
00368 
00381   void setAtomicValueBuffer(const QString &fN, const QString &functionName);
00382 
00389   void setValueBuffer(const QString &fN, const QVariant &v);
00390 
00396   QVariant valueBuffer(const QString &fN);
00397 
00403   QVariant valueBufferCopy(const QString &fN) const;
00404 
00410   void setEdition(bool b);
00416   void setBrowse(bool b);
00417 
00425   void setContext(QObject *c);
00426 
00434   QObject *context() const {
00435     return d->ctxt_;
00436   }
00437 
00448   bool fieldDisabled(const QString &fN);
00449 
00455   static bool inTransaction();
00456 
00466   bool transaction(bool lock = false);
00467 
00473   bool rollback();
00474 
00482   bool commit(bool notify = true);
00483 
00491   void openFormInMode(int m, bool cont = true);
00492 
00499   void updateBufferCopy();
00500 
00508   bool isModifiedBuffer();
00509 
00515   void setAskForCancelChanges(bool a) {
00516     d->askForCancelChanges_ = a;
00517   }
00518 
00524   void setActivatedCheckIntegrity(bool a) {
00525     d->activatedCheckIntegrity_ = a;
00526   }
00527 
00533   void setActivatedCommitActions(bool a) {
00534     d->activatedCommitActions_ = a;
00535   }
00536 
00542   QString msgCheckIntegrity();
00543 
00557   bool checkIntegrity(bool showError = true);
00558 
00562   FLSqlCursor *cursorRelation() const {
00563     return d->cursorRelation_;
00564   }
00565   FLRelationMetaData *relation() const {
00566     return d->relation;
00567   }
00568 
00575   void setUnLock(const QString &fN, bool v);
00576 
00582   bool isLocked();
00583 
00589   bool bufferIsNull(int i) const;
00590 
00596   bool bufferIsNull(const QString &name) const;
00597 
00603   void bufferSetNull(int i) const;
00604 
00610   void bufferSetNull(const QString &name) const;
00611 
00617   bool bufferCopyIsNull(int i) const;
00618 
00624   bool bufferCopyIsNull(const QString &name) const;
00625 
00631   void bufferCopySetNull(int i) const;
00632 
00638   void bufferCopySetNull(const QString &name) const;
00639 
00651   int atFrom();
00652 
00669   int atFromBinarySearch(const QString &fN, const QString &v, bool orderAsc = true);
00670 
00674   bool exec(const QString &query);
00675 
00676 #ifdef FL_DEBUG
00677   static long countRefCursor;
00678 #endif
00679 
00683   FLSqlDatabase *db() const {
00684     return d->db_;
00685   }
00686 
00687 protected:
00688 
00692   QVariant calculateField(const QString &name);
00693 
00697   void afterSeek();
00698 
00699 public slots:
00700 
00712   void refresh(const QString &fN = QString::null);
00713 
00722   void refreshDelayed(int msec = 50);
00723 
00737   bool refreshBuffer();
00738 
00744   bool setEditMode();
00745 
00754   bool seek(int i, bool relative = false, bool emite = false);
00755 
00764   bool next(bool emite = true);
00765 
00774   bool prev(bool emite = true);
00775 
00784   bool first(bool emite = true);
00785 
00794   bool last(bool emite = true);
00795 
00802   int del(bool invalidate = true);
00803 
00807   bool select(const QString &filter, const QSqlIndex &sort = QSqlIndex());
00808 
00812   void setSort(const QSqlIndex &sort);
00813 
00817   QString baseFilter();
00818 
00822   QString curFilter();
00823 
00827   void setFilter(const QString &filter);
00828 
00833   void insertRecord();
00834 
00839   void editRecord();
00840 
00845   void browseRecord();
00846 
00850   void deleteRecord();
00851 
00856   void copyRecord();
00857 
00863   void chooseRecord();
00864 
00885   bool commitBuffer(bool emite = true, bool checkLocks = false);
00886 
00893   bool commitBufferCursorRelation();
00894 
00898   static int transactionLevel();
00899 
00903   QStringList transactionsOpened();
00904 
00912   void rollbackOpened(int count = -1, const QString &msg = QString::null);
00913 
00921   void commitOpened(int count = -1, const QString &msg = QString::null);
00922 
00931   void checkRisksLocks(bool terminate = false);
00932 
00940   void setAcTable(const QString &ac);
00941 
00953   void setAcosTable(const QStringList &acos);
00954 
00979   void setAcosCondition(const QString &condName, AcosConditionEval cond, const QVariant &condVal);
00980 
00986   QStringList concurrencyFields();
00987 
00988 private:
00989 
00993   FLSqlCursorPrivate *d;
00994 
00998   static int transaction_;
00999 
01003   static QPtrStack < FLSqlSavePoint > * stackSavePoints;
01004 
01008   static QPtrQueue < FLSqlSavePoint > * queueSavePoints;
01009 
01013   static FLSqlSavePoint *currentSavePoint;
01014 
01019   void populateCursor();
01020 
01026   void setNotGenerateds();
01027 
01031   void clearMapPosByPK();
01032 
01033 signals:
01034 
01038   void newBuffer();
01039 
01044   void bufferChanged(const QString &);
01045 
01049   void cursorUpdated();
01050 
01054   void recordChoosed();
01055 
01059   void currentChanged(int);
01060 
01064   void autoCommit();
01065 
01069   void bufferCommited();
01070 
01071 private slots:
01072 
01074   void clearPersistentFilter();
01075 };
01076 
01077 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'