EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PyDatabase.cpp
Go to the documentation of this file.
1 /*
2  ------------------------------------------------------------------------------------
3  LICENSE:
4  ------------------------------------------------------------------------------------
5  This file is part of EVEmu: EVE Online Server Emulator
6  Copyright 2006 - 2021 The EVEmu Team
7  For the latest information visit https://evemu.dev
8  ------------------------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  http://www.gnu.org/copyleft/lesser.txt.
22  ------------------------------------------------------------------------------------
23  Author: Bloody.Rabbit
24  Updates: Allan
25 */
26 
27 #include "eve-common.h"
29 #include "utils/EVEUtils.h"
30 
31 /************************************************************************/
32 /* DBRowDescriptor */
33 /************************************************************************/
35 : PyObjectEx_Type1( new PyToken( "blue.DBRowDescriptor" ), _CreateArgs() )
36 {
37 }
38 
40 : PyObjectEx_Type1( new PyToken( "blue.DBRowDescriptor" ), _CreateArgs(), keywords )
41 {
42 }
43 
45 : PyObjectEx_Type1( new PyToken( "blue.DBRowDescriptor" ), _CreateArgs() )
46 {
47  uint32 cc(res.ColumnCount());
48  for (uint32 i(0); i < cc; ++i)
49  AddColumn( res.ColumnName( i ), res.ColumnType( i ) );
50 }
51 
53 : PyObjectEx_Type1( new PyToken( "blue.DBRowDescriptor" ), _CreateArgs() )
54 {
55  uint32 cc(row.ColumnCount());
56  for (uint32 i(0); i < cc; ++i)
57  AddColumn( row.ColumnName( i ), row.ColumnType( i ) );
58 }
59 
61 {
62  return _GetColumnList()->size();
63 }
64 
66 {
67  return _GetColumn( index )->GetItem( 0 )->AsString();
68 }
69 
71 {
72  return (DBTYPE)_GetColumn( index )->GetItem( 1 )->AsInt()->value();
73 }
74 
75 uint32 DBRowDescriptor::FindColumn( const char* name ) const
76 {
77  uint32 cc(ColumnCount());
78  PyString* stringName = new PyString( name );
79 
80  for( uint32 i(0); i < cc; ++i ) {
81  if( stringName->hash() == GetColumnName( i )->hash() ) {
82  PyDecRef( stringName );
83  return i;
84  }
85  }
86 
87  PyDecRef( stringName );
88  return cc;
89 }
90 
92 {
93  return DBTYPE_IsCompatible( GetColumnType( index ), value );
94 }
95 
96 void DBRowDescriptor::AddColumn( const char* name, DBTYPE type )
97 {
98  PyTuple* col = new PyTuple( 2 );
99  col->SetItem( 0, new PyString( name ) );
100  col->SetItem( 1, new PyInt( type ) );
101  _GetColumnList()->items.push_back( col );
102 }
103 
105 {
106  return GetArgs()->GetItem( 0 )->AsTuple();
107 }
108 
109 PyTuple* DBRowDescriptor::_GetColumn( size_t index ) const
110 {
111  return _GetColumnList()->GetItem( index )->AsTuple();
112 }
113 
115 {
116  PyTuple* columnList = new PyTuple( 0 );
117  PyTuple* args = new PyTuple( 1 );
118  args->SetItem( 0, columnList );
119 
120  return args;
121 }
122 
123 /************************************************************************/
124 /* CRowSet */
125 /************************************************************************/
127 : PyObjectEx_Type2( _CreateArgs(), _CreateKeywords( *rowDesc ) )
128 {
129 
130 }
131 
133 {
134  //DBRowDescriptor* rowDesc = _GetRowDesc();
135  PyPackedRow* row = new PyPackedRow( _GetRowDesc() );
136 
137  list().AddItem( row );
138  return row;
139 }
140 
142 {
143  PyRep* r(FindKeyword( "header" ));
144  if (r != nullptr)
145  return (DBRowDescriptor*)r->AsObjectEx();
146  return nullptr;
147 }
148 
149 /*PyList* CRowSet::_GetColumnList() const
150 {
151  PyRep* r = FindKeyword( "columns" );
152  assert( r );
153 
154  return r->AsList();
155 }
156 */
157 
159 {
160  PyTuple* args = new PyTuple( 1 );
161  args->SetItem( 0, new PyToken( "dbutil.CRowset" ) );
162  return args;
163 }
164 
166 {
167  assert( rowDesc );
168 
169  PyDict* keywords = new PyDict();
170  keywords->SetItemString( "header", rowDesc );
171 
172  //The Type_2 i had no longer used this
173  //uint32 cc = rowDesc->ColumnCount();
174  //PyList* columns = new PyList( cc );
175  //for( uint32 i(0); i < cc; ++i )
176  // columns->SetItem( i, new PyString( *rowDesc->GetColumnName( i ) ) );
177  //keywords->SetItemString( "columns", columns );
178 
179  return keywords;
180 }
181 
182 /************************************************************************/
183 /* CIndexedRowSet */
184 /************************************************************************/
186 : PyObjectEx_Type2( _CreateArgs(), _CreateKeywords( *rowDesc ) )
187 {
188 
189 }
190 
192 {
193  //DBRowDescriptor* rowDesc = _GetRowDesc();
194  PyPackedRow* row = new PyPackedRow( _GetRowDesc() );
195 
196  dict().SetItem( key , row );
197  return row;
198 }
199 
201 {
202  PyRep* r(FindKeyword( "header" ));
203  if (r != nullptr)
204  return (DBRowDescriptor*)r->AsObjectEx();
205  return nullptr;
206 }
207 
209 {
210  PyTuple* args = new PyTuple( 1 );
211  args->SetItem( 0, new PyToken( "dbutil.CIndexedRowset" ) );
212  return args;
213 }
214 
216 {
217  assert( rowDesc );
218 
219  PyDict* keywords = new PyDict();
220  keywords->SetItemString( "header", rowDesc );
221  keywords->SetItemString( "columnName", rowDesc->GetColumnName(0) );
222 
223  return keywords;
224 }
225 
226 
227 /************************************************************************/
228 /* CFilterRowSet */
229 /************************************************************************/
231 : PyObjectEx_Type2( _CreateArgs(), _CreateKeywords( *rowDesc ) )
232 {
233 
234 }
235 
237 {
238  DBRowDescriptor* rowDesc = _GetRowDesc();
239  CRowSet* row = new CRowSet( &rowDesc );
240 
241  dict().SetItem( key , row );
242  return row;
243 }
244 
246 {
247  PyRep* r(FindKeyword( "header" ));
248  if (r != nullptr)
249  return (DBRowDescriptor*)r->AsObjectEx();
250  return nullptr;
251 }
252 
254 {
255  PyTuple* args = new PyTuple( 1 );
256  args->SetItem( 0, new PyToken( "dbutil.CFilterRowset" ) );
257  return args;
258 }
259 
261 {
262  assert( rowDesc );
263 
264  PyDict* keywords = new PyDict();
265  keywords->SetItemString( "header", rowDesc );
266  keywords->SetItemString( "columnName", rowDesc->GetColumnName(0) );
267 
268  return keywords;
269 }
Base Python wire object.
Definition: PyRep.h:66
list_type & list()
Definition: PyRep.h:889
PyTuple * AsTuple()
Definition: PyRep.h:138
DBRowDescriptor * _GetRowDesc() const
Definition: PyDatabase.cpp:245
static PyTuple * _CreateArgs()
Definition: PyDatabase.cpp:158
PyRep * GetItem(size_t index) const
Returns Python object.
Definition: PyRep.h:602
Python string.
Definition: PyRep.h:430
int32 value() const
Definition: PyRep.h:247
Python's dictionary.
Definition: PyRep.h:719
size_t size() const
Definition: PyRep.h:591
PyTuple * GetArgs() const
Definition: PyRep.cpp:835
PyRep * FindKeyword(const char *keyword) const
Definition: PyRep.cpp:959
void AddColumn(const char *name, DBTYPE type)
Definition: PyDatabase.cpp:96
PyTuple * _GetColumn(size_t index) const
Definition: PyDatabase.cpp:109
CRowSet(DBRowDescriptor **rowDesc)
Definition: PyDatabase.cpp:126
CIndexedRowSet(DBRowDescriptor **rowDesc)
Definition: PyDatabase.cpp:185
CRowSet * NewRowset(PyRep *key)
Definition: PyDatabase.cpp:236
CFilterRowSet(DBRowDescriptor **rowDesc)
Definition: PyDatabase.cpp:230
Python tuple.
Definition: PyRep.h:567
PyTuple * _GetColumnList() const
Definition: PyDatabase.cpp:104
void AddItem(PyRep *i)
Definition: PyRep.h:701
PyString * GetColumnName(uint32 index) const
Definition: PyDatabase.cpp:65
static PyTuple * _CreateArgs()
Definition: PyDatabase.cpp:114
* args
bool DBTYPE_IsCompatible(DBTYPE type, const PyRep *rep)
Definition: EVEUtils.cpp:42
bool VerifyValue(uint32 index, PyRep *value)
Verifies value for certain column.
Definition: PyDatabase.cpp:91
DBTYPE GetColumnType(uint32 index) const
Definition: PyDatabase.cpp:70
Python object "blue.DBRowDescriptor".
Definition: PyDatabase.h:41
uint32 ColumnCount() const
Definition: PyDatabase.cpp:60
uint32 ColumnCount() const
Definition: dbcore.h:76
void SetItem(size_t index, PyRep *object)
Stores Python object.
Definition: PyRep.h:610
Python object "dbutil.CRowset".
Definition: PyDatabase.h:124
DBTYPE
Definition: dbtype.h:67
PyPackedRow * NewRow(PyRep *key)
Definition: PyDatabase.cpp:191
Python integer.
Definition: PyRep.h:231
const char * ColumnName(uint32 index) const
Definition: dbcore.h:114
PyString * AsString()
Definition: PyRep.h:132
DBRowDescriptor * _GetRowDesc() const
Definition: PyDatabase.cpp:200
dict_type & dict()
Definition: PyRep.h:892
static PyTuple * _CreateArgs()
Definition: PyDatabase.cpp:208
#define PyDecRef(op)
Definition: PyRep.h:57
const char * ColumnName(uint32 index) const
Definition: dbcore.cpp:569
unsigned __int32 uint32
Definition: eve-compat.h:50
static PyTuple * _CreateArgs()
Definition: PyDatabase.cpp:253
Python token (eg. class name).
Definition: PyRep.h:522
Wrapper class for PyObjectEx of type 1.
Definition: PyRep.h:911
int32 hash() const
virtual function to generate a hash value of a object.
Definition: PyRep.cpp:460
DBRowDescriptor * _GetRowDesc() const
Definition: PyDatabase.cpp:141
static PyDict * _CreateKeywords(DBRowDescriptor *rowDesc)
Definition: PyDatabase.cpp:165
PyPackedRow * NewRow()
Definition: PyDatabase.cpp:132
static PyDict * _CreateKeywords(DBRowDescriptor *rowDesc)
Definition: PyDatabase.cpp:215
Packed row.
Definition: PyRep.h:961
storage_type items
Definition: PyRep.h:628
typeID Spawn an NPC with the specified type text Search for items matching the specified query() type() key(value)-Send an OnRemoteMessage" ) COMMAND( setbpattr
uint32 ColumnCount() const
Definition: dbcore.h:113
uint32 FindColumn(const char *name) const
Definition: PyDatabase.cpp:75
PyInt * AsInt()
Definition: PyRep.h:122
PyObjectEx * AsObjectEx()
Definition: PyRep.h:154
void SetItem(PyRep *key, PyRep *value)
SetItem adds or sets a database entry.
Definition: PyRep.cpp:713
Wrapper class for PyObjectEx of type 2.
Definition: PyRep.h:938
DBTYPE ColumnType(uint32 index) const
Definition: dbcore.cpp:580
static PyDict * _CreateKeywords(DBRowDescriptor *rowDesc)
Definition: PyDatabase.cpp:260
Python list.
Definition: PyRep.h:639
void SetItemString(const char *key, PyRep *value)
SetItemString adds or sets a database entry.
Definition: PyRep.h:812
DBTYPE ColumnType(uint32 index) const
Definition: dbcore.h:115