Eneboo - Documentación para desarrolladores
|
00001 /*************************************************************************** 00002 qsql_psql.h 00003 ------------------- 00004 begin : mie Sep 15 2004 00005 copyright : (C) 2004-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 ** 00020 ** Definition of PostgreSQL driver classes 00021 ** 00022 ** Created : 001103 00023 ** 00024 ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 00025 ** 00026 ** This file is part of the sql module of the Qt GUI Toolkit. 00027 ** 00028 ** This file may be distributed under the terms of the Q Public License 00029 ** as defined by Trolltech AS of Norway and appearing in the file 00030 ** LICENSE.QPL included in the packaging of this file. 00031 ** 00032 ** This file may be distributed and/or modified under the terms of the 00033 ** GNU General Public License version 2 as published by the Free Software 00034 ** Foundation and appearing in the file LICENSE.GPL included in the 00035 ** packaging of this file. 00036 ** 00037 ** Licensees holding valid Qt Enterprise Edition licenses may use this 00038 ** file in accordance with the Qt Commercial License Agreement provided 00039 ** with the Software. 00040 ** 00041 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00042 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00043 ** 00044 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 00045 ** information about Qt Commercial License Agreements. 00046 ** See http://www.trolltech.com/qpl/ for QPL licensing information. 00047 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 00048 ** 00049 ** Contact info@trolltech.com if any conditions of this licensing are 00050 ** not clear to you. 00051 ** 00052 **********************************************************************/ 00053 00054 #ifndef QSQL_PSQL_H 00055 #define QSQL_PSQL_H 00056 00057 #include <qdict.h> 00058 #include <qsqlresult.h> 00059 #include <qsqldriver.h> 00060 #include <qmessagebox.h> 00061 #include <qptrvector.h> 00062 #include <libpq-fe.h> 00063 #include <FLManager.h> 00064 #include <FLManagerModules.h> 00065 #include <FLTableMetaData.h> 00066 #include <FLFieldMetaData.h> 00067 #include <FLRelationMetaData.h> 00068 #include <FLUtil.h> 00069 #include <FLSqlDatabase.h> 00070 #include <FLSqlDriver.h> 00071 #include <FLSqlCursor.h> 00072 #include <FLDiskCache.h> 00073 00074 #ifdef QT_PLUGIN 00075 #define Q_EXPORT_SQLDRIVER_PSQL 00076 #else 00077 #define Q_EXPORT_SQLDRIVER_PSQL Q_EXPORT 00078 #endif 00079 00080 class QPSQLPrivate; 00081 class QPSQLDriver; 00082 class QSqlRecordInfo; 00083 00084 class QPSQLDriver : public FLSqlDriver 00085 { 00086 00087 Q_OBJECT 00088 00089 public: 00090 00091 enum Protocol { 00092 Version6 = 6, 00093 Version7 = 7, 00094 Version71 = 8, 00095 Version73 = 9, 00096 Version74 = 10, 00097 Version8 = 11, 00098 Version81 = 12, 00099 Version82 = 13, 00100 Version83 = 14, 00101 Version84 = 15, 00102 Version9 = 16, 00103 Version91 = 17 00104 }; 00105 00106 QPSQLDriver(QObject *parent = 0, const char *name = 0); 00107 QPSQLDriver(PGconn *conn, QObject *parent = 0, const char *name = 0); 00108 ~QPSQLDriver(); 00109 bool hasFeature(DriverFeature f) const; 00110 bool open(const QString &db, const QString &user = QString::null, 00111 const QString &password = QString::null, const QString &host = QString::null, int port = -1); 00112 void close(); 00113 QSqlQuery createQuery() const; 00114 QStringList tables(const QString &user) const; 00115 QSqlIndex primaryIndex(const QString &tablename) const; 00116 QSqlRecord record(const QString &tablename) const; 00117 QSqlRecord record(const QSqlQuery &query) const; 00118 QSqlRecordInfo recordInfo(const QString &tablename) const; 00119 QSqlRecordInfo recordInfo(const QSqlQuery &query) const; 00120 00121 Protocol protocol() const { 00122 return pro; 00123 } 00124 PGconn *connection(); 00125 QString formatValue(const QSqlField *field, bool trimStrings) const; 00126 00127 // ### remove me for 4.0 00128 bool open(const QString &db, const QString &user, const QString &password, 00129 const QString &host, int port, const QString &connOpts); 00130 00131 bool tryConnect(const QString &db, const QString &user = QString::null, 00132 const QString &password = QString::null, const QString &host = QString::null, int port = -1); 00133 QString sqlCreateTable(FLTableMetaData *tmd); 00134 QString formatValueLike(int t, const QVariant &v, const bool upper = false); 00135 QString formatValue(int t, const QVariant &v, const bool upper = false); 00136 QVariant nextSerialVal(const QString &table, const QString &field); 00137 int atFrom(FLSqlCursor *cur); 00138 bool alterTable(const QString &mtd1, const QString &mtd2, const QString &key = QString::null); 00139 bool canSavePoint(); 00140 bool savePoint(const QString &n); 00141 bool releaseSavePoint(const QString &n); 00142 bool rollbackSavePoint(const QString &n); 00143 QStringList rowsLockeds(const QString &table, const QString &primaryKeyValue = QString::null); 00144 QStringList locksStatus(); 00145 QStringList detectLocks(); 00146 QStringList detectRisksLocks(const QString &table = QString::null, const QString &primaryKeyValue = QString::null); 00147 bool regenTable(const QString &n, FLTableMetaData *tmd); 00148 int backendId() const; 00149 00150 private slots: 00151 00152 void Mr_Proper(); 00153 00154 protected: 00155 00156 bool beginTransaction(); 00157 bool commitTransaction(); 00158 bool rollbackTransaction(); 00159 00160 private: 00161 00162 QSqlIndex primaryIndex2(const QString &tablename) const; 00163 QSqlRecord record2(const QString &tablename) const; 00164 QSqlRecord record(FLTableMetaData *mtd) const; 00165 bool constraintExists(const QString &name) const; 00166 bool alterTable(FLTableMetaData *newMTD); 00167 QSqlRecordInfo recordInfo2(const QString &tablename) const; 00168 bool alterTable2(const QString &mtd1, const QString &mtd2, const QString &key = QString::null, bool force = false); 00169 int insertMulti(const QString &tablename, QPtrList<QSqlRecord> * records); 00170 #ifndef FL_QUICK_CLIENT 00171 void createIndex(const QString &fieldName, const QString &tableName, bool textOp, bool noUpper = false) const; 00172 static QDict < bool > * dictIndexes; 00173 #endif 00174 void init(); 00175 Protocol pro; 00176 QPSQLPrivate *d; 00177 }; 00178 00179 class QPSQLResult : public QSqlResult 00180 { 00181 00182 friend class QPSQLDriver; 00183 00184 public: 00185 00186 QPSQLResult(const QPSQLDriver *db, const QPSQLPrivate *p); 00187 ~QPSQLResult(); 00188 PGresult *result(); 00189 00190 protected: 00191 00192 void cleanup(); 00193 bool fetch(int i); 00194 bool fetchFirst(); 00195 bool fetchLast(); 00196 QVariant data(int i); 00197 bool isNull(int field); 00198 bool reset(const QString &query); 00199 int size(); 00200 int numRowsAffected(); 00201 00202 private: 00203 00204 void calcSize(); 00205 bool nextResult(int i); 00206 void closeCursor(); 00207 bool openCursor(); 00208 void cleanupCache(); 00209 int currentSize; 00210 QPSQLPrivate *d; 00211 00212 static int cursorCounter; 00213 }; 00214 00215 #endif