kexi

pqxxmigrate.h
1/* This file is part of the KDE project
2 Copyright (C) 2004 Adam Pigg <adam@piggz.co.uk>
3 Copyright (C) 2006 Jaroslaw Staniek <js@iidea.pl>
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this program; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#ifndef PQXXIMPORT_H
22#define PQXXIMPORT_H
23
24#include <migration/keximigrate.h>
25
26//Kexi Includes
27#include <kexidb/field.h>
28#include <kexidb/connection.h>
29
30#include <pqxx/pqxx>
31
32namespace KexiMigration
33{
34 class PqxxMigrate : public KexiMigrate
35 {
36 TQ_OBJECT
37
38 KEXIMIGRATION_DRIVER
39
40 public:
41 PqxxMigrate(TQObject *parent, const char *name, const TQStringList &args = TQStringList());
42 virtual ~PqxxMigrate();
43
44 protected:
45 //Driver specific function to return table names
46 virtual bool drv_tableNames(TQStringList& tablenames);
47
48 //Driver specific implementation to read a table schema
49 virtual bool drv_readTableSchema(
50 const TQString& originalName, KexiDB::TableSchema& tableSchema);
51
52 //Driver specific connection implementation
53 virtual bool drv_connect();
54 virtual bool drv_disconnect();
55
56 virtual tristate drv_queryStringListFromSQL(
57 const TQString& sqlStatement, uint columnNumber, TQStringList& stringList,
58 int numRecords = -1);
59
68 virtual tristate drv_fetchRecordFromSQL(const TQString& sqlStatement,
69 KexiDB::RowData& data, bool &firstRecord);
70
71 virtual bool drv_copyTable(const TQString& srcTable,
72 KexiDB::Connection *destConn, KexiDB::TableSchema* dstTable);
73
74 private:
75 //lowlevel functions/objects
76 //database connection
77 pqxx::connection* m_conn;
78
79 //transaction
80 pqxx::nontransaction* m_trans;
81
82 //lowlevel result
83 pqxx::result* m_res;
84
86 pqxx::result::const_iterator m_fetchRecordFromSQL_iter;
87
88 //perform a query on the database
89 bool query(const TQString& statement);
90
91 //Clear the result info
92 void clearResultInfo ();
93
94 pqxx::oid tableOid(const TQString& tablename);
95
96 //Convert the pqxx type to a kexi type
97 KexiDB::Field::Type type(int t, const TQString& fname);
98
99 //Find out the field constraints
100 //Return whether or not the field is a pkey
101 bool primaryKey(pqxx::oid table, int col) const;
102
103 //Return whether or not the field is unique
104 bool uniqueKey(pqxx::oid table, int col) const;
105
106 //Return whether or not the field is a foreign key
107 bool foreignKey(pqxx::oid table, int col) const;
108
109 //Return whether or not the field is not null
110 bool notNull(pqxx::oid table, int col) const;
111
112 //Return whether or not the field is not empty
113 bool notEmpty(pqxx::oid table, int col) const;
114
115 //Return whether or not the field is auto incrementing
116 bool autoInc(pqxx::oid table, int col) const;
117
118 };
119}
120
121#endif
Imports non-native databases into Kexi projects.
Definition keximigrate.h:79
virtual bool drv_connect()=0
Connect to source database (driver specific).
KexiMigration::Data * data() const
Definition keximigrate.h:87
virtual bool drv_disconnect()=0
Disconnect from source database (driver specific).
TQValueVector< TQVariant > RowData
structure for storing single record with type information
Definition connection.h:47
Framework for importing databases into native KexiDB databases.