pqxxcursor.h
1/* This file is part of the KDE project
2 Copyright (C) 2003 Adam Pigg <adam@piggz.co.uk>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef KEXIDB_CURSOR_PQXX_H
21#define KEXIDB_CURSOR_PQXX_H
22
23#include "config.h"
24
25#include <kexidb/cursor.h>
26#include <kexidb/connection.h>
27#include <kexidb/utils.h>
28
29#if 0
30#include <pqxx/all.h>
31#else
32#include <pqxx/pqxx>
33#endif
34
35#include <pqxx/binarystring>
36#include <migration/pqxx/pg_type.h>
37
38namespace KexiDB {
39
40class pqxxSqlCursor: public Cursor {
41public:
42 virtual ~pqxxSqlCursor();
43
44 virtual TQVariant value(uint i);
45 virtual const char** rowData() const;
46 virtual void storeCurrentRow(RowData &data) const;
47
48//TODO virtual const char *** bufferData()
49
50//TODO virtual int serverResult() const;
51
52//TODO virtual TQString serverResultName() const;
53
54//TODO virtual TQString serverErrorMsg() const;
55
56protected:
57 pqxxSqlCursor(Connection* conn, const TQString& statement = TQString(), uint options = NoOptions );
58 pqxxSqlCursor(Connection* conn, QuerySchema& query, uint options = NoOptions );
59 virtual void drv_clearServerResult();
60 virtual void drv_appendCurrentRecordToBuffer();
61 virtual void drv_bufferMovePointerNext();
62 virtual void drv_bufferMovePointerPrev();
63 virtual void drv_bufferMovePointerTo(TQ_LLONG to);
64 virtual bool drv_open();
65 virtual bool drv_close();
66 virtual void drv_getNextRecord();
67 virtual void drv_getPrevRecord();
68
69private:
70 pqxx::result* m_res;
71// pqxx::nontransaction* m_tran;
72 pqxx::connection* my_conn;
73 TQVariant pValue(uint pos)const;
74 bool m_implicityStarted : 1;
75 //TQByteArray processBinaryData(pqxx::binarystring*) const;
76 friend class pqxxSqlConnection;
77};
78
79inline TQVariant pgsqlCStrToVariant(const PQXX_FIELD_CLASS& r)
80{
81 switch(r.type())
82 {
83 case BOOLOID:
84 return TQString::fromLatin1(r.c_str(), r.size())=="true"; //TODO check formatting
85 case INT2OID:
86 case INT4OID:
87 case INT8OID:
88 return r.as(int());
89 case FLOAT4OID:
90 case FLOAT8OID:
91 case NUMERICOID:
92 return r.as(double());
93 case DATEOID:
94 return TQString::fromUtf8(r.c_str(), r.size()); //TODO check formatting
95 case TIMEOID:
96 return TQString::fromUtf8(r.c_str(), r.size()); //TODO check formatting
97 case TIMESTAMPOID:
98 return TQString::fromUtf8(r.c_str(), r.size()); //TODO check formatting
99 case BYTEAOID:
100 return KexiDB::pgsqlByteaToByteArray(r.c_str(), r.size());
101 case BPCHAROID:
102 case VARCHAROID:
103 case TEXTOID:
104 return TQString::fromUtf8(r.c_str(), r.size()); //utf8?
105 default:
106 return TQString::fromUtf8(r.c_str(), r.size()); //utf8?
107 }
108}
109
110}
111
112#endif
uint options() const
Definition cursor.h:118
QuerySchema * query() const
Definition cursor.h:104
High-level database connectivity library with database backend drivers.
TQValueVector< TQVariant > RowData
structure for storing single record with type information
Definition connection.h:47
KEXI_DB_EXPORT TQByteArray pgsqlByteaToByteArray(const char *data, int length)