EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LiveUpdateDB.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: caytchen
24 */
25 
26 #include "eve-server.h"
27 
28 #include "LiveUpdateDB.h"
29 
31 {
32  const char* query = "SELECT"
33  " updateID,"
34  " updateName,"
35  " description,"
36  " machoVersionMin,"
37  " machoVersionMax,"
38  " buildNumberMin," //5
39  " buildNumberMax,"
40  " methodName,"
41  " objectID,"
42  " codeType,"
43  " code" //10
44  " FROM liveupdates";
45  DBQueryResult res;
46 
47  if (!sDatabase.RunQuery(res, query))
48  {
49  codelog(DATABASE__ERROR, "Couldn't get live updates from database: %s", res.error.c_str());
50  return nullptr;
51  }
52 
53  // setup the descriptor
54  DBRowDescriptor* header = new DBRowDescriptor();
55  header->AddColumn("updateID", DBTYPE_I4);
56  header->AddColumn("updateName", DBTYPE_WSTR);
57  header->AddColumn("description", DBTYPE_WSTR);
58  header->AddColumn("machoVersionMin", DBTYPE_I4);
59  header->AddColumn("machoVersionMax", DBTYPE_I4);
60  header->AddColumn("buildNumberMin", DBTYPE_I4);
61  header->AddColumn("buildNumberMax", DBTYPE_I4);
62  header->AddColumn("code", DBTYPE_STR);
63 
64  // we need to manually create PyPackedRows since we don't want everything from the query in them
65  PyList* list = new PyList(res.GetRowCount());
66  int listIndex = 0;
67  DBResultRow row;
68  while (res.GetRow(row))
69  {
70  PyPackedRow* packedRow = new PyPackedRow(header);
71  for (int i = 0; i < 7; i++)
72  packedRow->SetField(i, DBColumnToPyRep(row, i));
73 
74  LiveUpdateInner inner;
75  // binary data so we can't expect strlen to get it right
76  inner.code = std::string(row.GetText(10), row.ColumnLength(10));
77  inner.codeType = row.GetText(9);
78  inner.objectID = row.GetText(8);
79  inner.methodName = row.GetText(7);
80  packedRow->SetField(static_cast<uint32>(7) /* code */, inner.Encode());
81 
82  list->SetItem(listIndex++, packedRow);
83  }
84  list->Dump(NET__PRES_DEBUG, " ");
85 
86  return list;
87 }
#define sDatabase
Definition: dbcore.h:199
uint32 ColumnLength(uint32 index) const
Definition: dbcore.cpp:624
const char * GetText(uint32 index) const
Definition: dbcore.h:104
void AddColumn(const char *name, DBTYPE type)
Definition: PyDatabase.cpp:96
void Dump(FILE *into, const char *pfx) const
Dumps object to file.
Definition: PyRep.cpp:84
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
const char * c_str() const
Definition: dbcore.h:48
Python object "blue.DBRowDescriptor".
Definition: PyDatabase.h:41
#define codelog(type, fmt,...)
Definition: logsys.h:128
void SetItem(size_t index, PyRep *object)
Stores Python object.
Definition: PyRep.h:682
DBerror error
Definition: dbcore.h:69
bool SetField(uint32 index, PyRep *value)
Definition: PyRep.cpp:1031
size_t GetRowCount()
Definition: dbcore.h:72
Packed row.
Definition: PyRep.h:961
PyList * GenerateUpdates()
Python list.
Definition: PyRep.h:639
PyRep * DBColumnToPyRep(const DBResultRow &row, uint32 index)
Definition: EVEDBUtils.cpp:36