2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
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
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "DatabaseEnv.h"
23 QueryResultPostgre::QueryResultPostgre(PGresult
*result
, uint64 rowCount
, uint32 fieldCount
) :
24 QueryResult(rowCount
, fieldCount
), mResult(result
), mTableIndex(0)
27 mCurrentRow
= new Field
[mFieldCount
];
30 for (uint32 i
= 0; i
< mFieldCount
; i
++)
32 mFieldNames
[i
] = PQfname(result
, i
);
33 mCurrentRow
[i
].SetType(ConvertNativeType(PQftype( result
, i
)));
37 QueryResultPostgre::~QueryResultPostgre()
42 bool QueryResultPostgre::NextRow()
47 if (mTableIndex
>= mRowCount
)
54 for (int j
= 0; j
< mFieldCount
; j
++)
56 pPQgetvalue
= PQgetvalue(mResult
, mTableIndex
, j
);
57 if(pPQgetvalue
&& !(*pPQgetvalue
))
60 mCurrentRow
[j
].SetValue(pPQgetvalue
);
67 void QueryResultPostgre::EndQuery()
71 delete [] mCurrentRow
;
82 // see types in #include <postgre/pg_type.h>
83 enum Field::DataTypes
QueryResultPostgre::ConvertNativeType(Oid pOid
) const
95 return Field::DB_TYPE_STRING
;
100 return Field::DB_TYPE_FLOAT
;
101 case DATEOID
: // Date
102 case RELTIMEOID
: // Date
103 case TIMEOID
: // Time
104 case TIMETZOID
: // Time
105 case ABSTIMEOID
: // DateTime
106 case INTERVALOID
: // DateTime
107 case TIMESTAMPOID
: // DateTime
108 case TIMESTAMPTZOID
: // DateTime
110 case INT2VECTOROID
: // Int
113 case CHAROID
: // UInt
114 case INT8OID
: // LongLong
115 return Field::DB_TYPE_INTEGER
;
117 return Field::DB_TYPE_BOOL
; // Bool
121 case VARBITOID: BitArray;
122 case BYTEAOID: ByteArray;
135 return Field::DB_TYPE_UNKNOWN
;
137 return Field::DB_TYPE_UNKNOWN
;