kexi

pqxxcursor.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003 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 KEXIDB_CURSOR_PQXX_H
00021 #define KEXIDB_CURSOR_PQXX_H
00022 
00023 #include <kexidb/cursor.h>
00024 #include <kexidb/connection.h>
00025 #include <kexidb/utils.h>
00026 
00027 #if 0
00028 #include <pqxx/all.h>
00029 #else
00030 #include <pqxx/pqxx>
00031 #endif
00032 
00033 #include <pqxx/binarystring>
00034 #include <migration/pqxx/pg_type.h>
00035 
00036 namespace KexiDB {
00037 
00038 class pqxxSqlCursor: public Cursor {
00039 public:
00040     virtual ~pqxxSqlCursor();
00041 
00042     virtual QVariant value(uint i);
00043     virtual const char** rowData() const;
00044     virtual void storeCurrentRow(RowData &data) const;
00045 
00046 //TODO      virtual const char *** bufferData()
00047         
00048 //TODO  virtual int serverResult() const;
00049         
00050 //TODO  virtual QString serverResultName() const;
00051 
00052 //TODO  virtual QString serverErrorMsg() const;
00053         
00054 protected:
00055     pqxxSqlCursor(Connection* conn, const QString& statement = QString::null, uint options = NoOptions );
00056     pqxxSqlCursor(Connection* conn, QuerySchema& query, uint options = NoOptions );
00057     virtual void drv_clearServerResult();
00058     virtual void drv_appendCurrentRecordToBuffer();
00059     virtual void drv_bufferMovePointerNext();
00060     virtual void drv_bufferMovePointerPrev();
00061     virtual void drv_bufferMovePointerTo(Q_LLONG to);
00062     virtual bool drv_open();
00063     virtual bool drv_close();
00064     virtual void drv_getNextRecord();
00065     virtual void drv_getPrevRecord();
00066 
00067 private:
00068     pqxx::result* m_res;
00069 //  pqxx::nontransaction* m_tran;
00070     pqxx::connection* my_conn;
00071     QVariant pValue(uint pos)const;
00072     bool m_implicityStarted : 1;
00073     //QByteArray processBinaryData(pqxx::binarystring*) const;
00074     friend class pqxxSqlConnection;
00075 };
00076 
00077 inline QVariant pgsqlCStrToVariant(const pqxx::result::field& r)
00078 {
00079     switch(r.type())
00080     {
00081         case BOOLOID:
00082             return QString::fromLatin1(r.c_str(), r.size())=="true"; //TODO check formatting
00083         case INT2OID:
00084         case INT4OID:
00085         case INT8OID:
00086             return r.as(int());
00087         case FLOAT4OID:
00088         case FLOAT8OID:
00089         case NUMERICOID:
00090             return r.as(double());
00091         case DATEOID:
00092             return QString::fromUtf8(r.c_str(), r.size()); //TODO check formatting
00093         case TIMEOID:
00094             return QString::fromUtf8(r.c_str(), r.size()); //TODO check formatting
00095         case TIMESTAMPOID:
00096             return QString::fromUtf8(r.c_str(), r.size()); //TODO check formatting
00097         case BYTEAOID:
00098             return KexiDB::pgsqlByteaToByteArray(r.c_str(), r.size());
00099         case BPCHAROID:
00100         case VARCHAROID:
00101         case TEXTOID:
00102             return QString::fromUtf8(r.c_str(), r.size()); //utf8?
00103         default:
00104             return QString::fromUtf8(r.c_str(), r.size()); //utf8?
00105     }
00106 }
00107 
00108 }
00109 
00110 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys