kexi

pqxxmigrate.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Adam Pigg <adam@piggz.co.uk>
00003    Copyright (C) 2006 Jaroslaw Staniek <js@iidea.pl>
00004 
00005    This program is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this program; see the file COPYING.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef PQXXIMPORT_H
00022 #define PQXXIMPORT_H
00023 
00024 #include <migration/keximigrate.h>
00025 
00026 //Kexi Includes
00027 #include <kexidb/field.h>
00028 #include <kexidb/connection.h>
00029 
00030 #include <pqxx/pqxx>
00031 
00032 namespace KexiMigration
00033 {
00034     class PqxxMigrate : public KexiMigrate
00035     {
00036         Q_OBJECT
00037         KEXIMIGRATION_DRIVER
00038 
00039         public:
00040             PqxxMigrate(QObject *parent, const char *name, const QStringList &args = QStringList());
00041             virtual ~PqxxMigrate();
00042             
00043         protected:
00044             //Driver specific function to return table names
00045             virtual bool drv_tableNames(QStringList& tablenames);
00046             
00047             //Driver specific implementation to read a table schema
00048             virtual bool drv_readTableSchema(
00049                 const QString& originalName, KexiDB::TableSchema& tableSchema);
00050             
00051             //Driver specific connection implementation
00052             virtual bool drv_connect();
00053             virtual bool drv_disconnect();
00054 
00055             virtual tristate drv_queryStringListFromSQL(
00056                 const QString& sqlStatement, uint columnNumber, QStringList& stringList, 
00057                 int numRecords = -1);
00058 
00066 
00067             virtual tristate drv_fetchRecordFromSQL(const QString& sqlStatement, 
00068                 KexiDB::RowData& data, bool &firstRecord);
00069 
00070             virtual bool drv_copyTable(const QString& srcTable, 
00071                 KexiDB::Connection *destConn, KexiDB::TableSchema* dstTable);
00072         
00073         private:
00074             //lowlevel functions/objects
00075             //database connection
00076             pqxx::connection* m_conn;
00077 
00078             //transaction
00079             pqxx::nontransaction* m_trans;
00080 
00081             //lowlevel result
00082             pqxx::result* m_res;
00083 
00085             pqxx::result::const_iterator m_fetchRecordFromSQL_iter;
00086 
00087             //perform a query on the database
00088             bool query(const QString& statement);
00089 
00090             //Clear the result info
00091             void clearResultInfo ();
00092             
00093             pqxx::oid tableOid(const QString& tablename);
00094             
00095             //Convert the pqxx type to a kexi type
00096             KexiDB::Field::Type type(int t, const QString& fname);
00097             
00098             //Find out the field constraints
00099             //Return whether or not the field is a pkey
00100             bool primaryKey(pqxx::oid table, int col) const;
00101             
00102             //Return whether or not the field is unique
00103             bool uniqueKey(pqxx::oid table, int col) const;
00104             
00105             //Return whether or not the field is a foreign key
00106             bool foreignKey(pqxx::oid table, int col) const;
00107             
00108             //Return whether or not the field is not null
00109             bool notNull(pqxx::oid table, int col) const;
00110             
00111             //Return whether or not the field is not empty
00112             bool notEmpty(pqxx::oid table, int col) const;
00113             
00114             //Return whether or not the field is auto incrementing
00115             bool autoInc(pqxx::oid table, int col) const;
00116         
00117     };
00118 }
00119 
00120 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys