[4362] Applied MaNGOS coding style to src/shared/Database.
[mangos-git.git] / src / shared / Database / QueryResultPostgre.cpp
blob3e1fe4b6a5c5827a7751770d2a8c708ac7646fee
1 /*
2 * Copyright (C) 2005,2006,2007 MaNGOS <http://www.mangosproject.org/>
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
19 #ifdef DO_POSTGRESQL
21 #include "DatabaseEnv.h"
23 QueryResultPostgre::QueryResultPostgre(PGresult *result, uint64 rowCount, uint32 fieldCount) :
24 QueryResult(rowCount, fieldCount), mResult(result)
27 mCurrentRow = new Field[mFieldCount];
28 ASSERT(mCurrentRow);
30 for (uint32 i = 0; i < mFieldCount; i++)
32 mCurrentRow[i].SetName(PQfname(result, i));
33 //mCurrentRow[i].SetType(ConvertNativeType(PQftype( result, i )));
34 mCurrentRow[i].SetType(Field::DB_TYPE_UNKNOWN);
38 QueryResultPostgre::~QueryResultPostgre()
40 EndQuery();
43 bool QueryResultPostgre::NextRow()
45 if (!mResult)
46 return false;
48 if (mTableIndex >= mRowCount)
50 EndQuery();
51 return false;
54 for (int j = 0; j < mFieldCount; j++)
56 mCurrentRow[j].SetValue(PQgetvalue(mResult, mTableIndex, j));
59 return true;
62 void QueryResultPostgre::EndQuery()
64 if (mCurrentRow)
66 delete [] mCurrentRow;
67 mCurrentRow = 0;
70 if (mResult)
72 PQclear(mResult);
73 mResult = 0;
77 // dummy -> all is set to "uknown"
78 enum Field::DataTypes QueryResultPostgre::ConvertNativeType(Oid pOid ) const
80 switch (pOid)
83 // temporarry commented out until proper resolution found
84 // case FIELD_TYPE_DATE:
85 // case FIELD_TYPE_TIME:
86 // case FIELD_TYPE_DATETIME:
87 // case FIELD_TYPE_YEAR:
88 // case FIELD_TYPE_STRING:
89 // case FIELD_TYPE_VAR_STRING:
90 // case FIELD_TYPE_BLOB:
91 // case FIELD_TYPE_SET:
92 // case FIELD_TYPE_NULL:
93 // return Field::DB_TYPE_STRING;
94 // case FIELD_TYPE_TINY:
96 // case FIELD_TYPE_SHORT:
97 // case FIELD_TYPE_LONG:
98 // case FIELD_TYPE_INT24:
99 // case FIELD_TYPE_LONGLONG:
100 // case FIELD_TYPE_ENUM:
101 // return Field::DB_TYPE_INTEGER;
102 // case FIELD_TYPE_DECIMAL:
103 // case FIELD_TYPE_FLOAT:
104 // case FIELD_TYPE_DOUBLE:
105 // return Field::DB_TYPE_FLOAT;
106 default:
107 return Field::DB_TYPE_UNKNOWN;
110 #endif