kexi

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 <migration/pqxx/pg_type.h>
36
37namespace KexiDB {
38
39class pqxxSqlCursor: public Cursor {
40public:
41 virtual ~pqxxSqlCursor();
42
43 virtual TQVariant value(uint i);
44 virtual const char** rowData() const;
45 virtual void storeCurrentRow(RowData &data) const;
46
47//TODO virtual const char *** bufferData()
48
49//TODO virtual int serverResult() const;
50
51//TODO virtual TQString serverResultName() const;
52
53//TODO virtual TQString serverErrorMsg() const;
54
55protected:
56 pqxxSqlCursor(Connection* conn, const TQString& statement = TQString(), uint options = NoOptions );
57 pqxxSqlCursor(Connection* conn, QuerySchema& query, uint options = NoOptions );
58 virtual void drv_clearServerResult();
60 virtual void drv_bufferMovePointerNext();
61 virtual void drv_bufferMovePointerPrev();
62 virtual void drv_bufferMovePointerTo(TQ_LLONG to);
63 virtual bool drv_open();
64 virtual bool drv_close();
65 virtual void drv_getNextRecord();
66 virtual void drv_getPrevRecord();
67
68private:
69 pqxx::result* m_res;
70// pqxx::nontransaction* m_tran;
71 pqxx::connection* my_conn;
72 TQVariant pValue(uint pos)const;
73 bool m_implicityStarted : 1;
74 friend class pqxxSqlConnection;
75};
76
77inline TQVariant pgsqlCStrToVariant(const PQXX_FIELD_CLASS& r)
78{
79 switch(r.type())
80 {
81 case BOOLOID:
82 return TQString::fromLatin1(r.c_str(), r.size())=="true"; //TODO check formatting
83 case INT2OID:
84 case INT4OID:
85 case INT8OID:
86 return r.as(int());
87 case FLOAT4OID:
88 case FLOAT8OID:
89 case NUMERICOID:
90 return r.as(double());
91 case DATEOID:
92 return TQString::fromUtf8(r.c_str(), r.size()); //TODO check formatting
93 case TIMEOID:
94 return TQString::fromUtf8(r.c_str(), r.size()); //TODO check formatting
95 case TIMESTAMPOID:
96 return TQString::fromUtf8(r.c_str(), r.size()); //TODO check formatting
97 case BYTEAOID:
98 return KexiDB::pgsqlByteaToByteArray(r.c_str(), r.size());
99 case BPCHAROID:
100 case VARCHAROID:
101 case TEXTOID:
102 return TQString::fromUtf8(r.c_str(), r.size()); //utf8?
103 default:
104 return TQString::fromUtf8(r.c_str(), r.size()); //utf8?
105 }
106}
107
108}
109
110#endif
Provides database cursor functionality.
Definition cursor.h:67
virtual void drv_appendCurrentRecordToBuffer()=0
virtual void drv_bufferMovePointerNext()=0
virtual void drv_bufferMovePointerPrev()=0
uint options() const
Definition cursor.h:118
virtual const char ** rowData() const =0
QuerySchema * query() const
Definition cursor.h:104
virtual void drv_clearServerResult()=0
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)