[7616] Implement .debug play cinematic and .debig play movie. Rename .debug playsound...
[AHbot.git] / src / shared / Database / QueryResultPostgre.cpp
blobaaae46c960c783ff809c49f15528d44e8e054d15
1 /*
2 * Copyright (C) 2005-2009 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
19 #ifdef DO_POSTGRESQL
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];
28 ASSERT(mCurrentRow);
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()
39 EndQuery();
42 bool QueryResultPostgre::NextRow()
44 if (!mResult)
45 return false;
47 if (mTableIndex >= mRowCount)
49 EndQuery();
50 return false;
53 char* pPQgetvalue;
54 for (int j = 0; j < mFieldCount; j++)
56 pPQgetvalue = PQgetvalue(mResult, mTableIndex, j);
57 if(pPQgetvalue && !(*pPQgetvalue))
58 pPQgetvalue = NULL;
60 mCurrentRow[j].SetValue(pPQgetvalue);
62 ++mTableIndex;
64 return true;
67 void QueryResultPostgre::EndQuery()
69 if (mCurrentRow)
71 delete [] mCurrentRow;
72 mCurrentRow = 0;
75 if (mResult)
77 PQclear(mResult);
78 mResult = 0;
82 // see types in #include <postgre/pg_type.h>
83 enum Field::DataTypes QueryResultPostgre::ConvertNativeType(Oid pOid ) const
85 switch (pOid)
87 case BPCHAROID:
88 case CIDOID:
89 case CIDROID:
90 case CIRCLEOID:
91 case INETOID:
92 case NAMEOID:
93 case TEXTOID:
94 case VARCHAROID:
95 return Field::DB_TYPE_STRING;
96 case CASHOID:
97 case FLOAT4OID:
98 case FLOAT8OID:
99 case NUMERICOID:
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
109 case INT2OID: // Int
110 case INT2VECTOROID: // Int
111 case INT4OID: // Int
112 case OIDOID: // Int
113 case CHAROID: // UInt
114 case INT8OID: // LongLong
115 return Field::DB_TYPE_INTEGER;
116 case BOOLOID:
117 return Field::DB_TYPE_BOOL; // Bool
119 case BOXOID: Rect;
120 case LINEOID: Rect;
121 case VARBITOID: BitArray;
122 case BYTEAOID: ByteArray;
124 case LSEGOID:
125 case OIDVECTOROID:
126 case PATHOID:
127 case POINTOID:
128 case POLYGONOID:
129 case REGPROCOID:
130 case TIDOID:
131 case TINTERVALOID:
132 case UNKNOWNOID:
133 case XIDOID:
134 default:
135 return Field::DB_TYPE_UNKNOWN;
137 return Field::DB_TYPE_UNKNOWN;
139 #endif