kexi

pqxxmigrate.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Adam Pigg <adam@piggz.co.uk>
00003 
00004    This program is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef PQXXIMPORT_H
00021 #define PQXXIMPORT_H
00022 
00023 #include <migration/keximigrate.h>
00024 
00025 //Kexi Includes
00026 #include <kexidb/field.h>
00027 #include <kexidb/connection.h>
00028 
00029 #include <pqxx/all.h>
00030 
00031 namespace KexiMigration
00032 {
00033     class PqxxMigrate : public KexiMigrate
00034     {
00035         Q_OBJECT
00036         KEXIMIGRATION_DRIVER
00037 
00038         public:
00039 //          PqxxMigrate();
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 bool drv_copyTable(const QString& srcTable, 
00056                 KexiDB::Connection *destConn, KexiDB::TableSchema* dstTable);
00057 //TODO: move this somewhere to low level class (MIGRATION?)
00058             //virtual bool drv_getTablesList( QStringList &list );
00059 //TODO: move this somewhere to low level class (MIGRATION?)
00060             //virtual bool drv_containsTable( const QString &tableName );
00061         
00062         private:
00063             //lowlevel functions/objects
00064             //database connection
00065             pqxx::connection* m_conn;
00066             //transaction
00067             pqxx::nontransaction* m_trans;
00068             //lowlevel result
00069             pqxx::result* m_res;
00070             //perform a query on the database
00071             bool query(const QString& statement);
00072             //Clear the result info
00073             void clearResultInfo ();
00074             
00075             pqxx::oid tableOid(const QString& tablename);
00076             
00077             //Convert the pqxx type to a kexi type
00078             KexiDB::Field::Type type(int t, const QString& fname);
00079             
00080             //Find out the field constraints
00081             //Return whether or not the field is a pkey
00082             bool primaryKey(pqxx::oid table, int col) const;
00083             
00084             //Return whether or not the field is unique
00085             bool uniqueKey(pqxx::oid table, int col) const;
00086             
00087             //Return whether or not the field is a foreign key
00088             bool foreignKey(pqxx::oid table, int col) const;
00089             
00090             //Return whether or not the field is not null
00091             bool notNull(pqxx::oid table, int col) const;
00092             
00093             //Return whether or not the field is not empty
00094             bool notEmpty(pqxx::oid table, int col) const;
00095             
00096             //Return whether or not the field is auto incrementing
00097             bool autoInc(pqxx::oid table, int col) const;
00098         
00099     };
00100 }
00101 
00102 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys