Repository navigation
Expand file tree
/
Copy pathTmpRowset.h
More file actions
144 lines (118 loc) · 3.29 KB
/
Copy pathTmpRowset.h
File metadata and controls
144 lines (118 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright © 2005 CCP ehf.
/*
*************************************************************************
TmpRowset.h
Project: EVE Server Database Access
Description:
Classes that store a rowset temporarily during traversal. We cannot
create python rowsets directly since this happens on a thread, and python
is'nt multithreaded. So, here we create something very similar to python
rowsets.
Dependencies:
Python
*************************************************************************
*/
#ifndef _TMPROWSET_H_
#define _TMPROWSET_H_
#include <string.h> //for _strdup()
#include <vector>
#include <string>
#include <atlstr.h>
#include <atldbcli.h>
#include "Utils.h"
#include "DelayedException.h"
#include "StringStore.h"
#include "BlockAllocator.h"
#include "RowDescriptor.h"
#include "Row.h"
#include "Accessor.h"
//A temporary thing, use this to locate the place where we are getting error results with no exception
template <class T>
void ForceException(T v, const char *msg){
if (!v && !PyErr_Occurred( )) {
std::string s("Forced Exception, Notify Kris! : ");
s += msg;
PyErr_SetString(PyExc_RuntimeError, s.c_str());
}
}
class ToPythonCtxt
{
public:
ToPythonCtxt(PyObject *blue, PyObject *beNice, int beNiceEvery, PyObject *getMem) :
mBlue(blue), mBeNice(beNice), mBeNiceEvery(beNiceEvery), mGetMem(getMem)
{
mRowCounter = mTotalPyBytes = mLastPyBytes = 0;
}
size_t GetMem() const
{
if (!mGetMem)
return 0;
BluePy m(PyObject_CallObject(mGetMem, 0));
if (m) {
size_t now;
if (sizeof(size_t) == 4)
now = PyLong_AsUnsignedLongMask( m );
else
now = (size_t)PyLong_AsUnsignedLongLongMask( m );
if (now != (size_t)-1)
return now;
}
PyErr_Clear();
return 0;
}
bool BeNice() const
{
if (!mBeNice)
return true;
BluePy r(PyObject_CallObject(mBeNice, 0));
return r ? true : false;
}
PyObject *mBlue;
PyObject *mBeNice;
PyObject *mGetMem;
size_t mRowCounter;
size_t mTotalPyBytes;
size_t mLastPyBytes;
int mBeNiceEvery;
};
class TmpRowset
{
public:
TmpRowset(NSession *s, SimplePoolAllocator &allocator, Store& store) :
mRD(s), mRC(DB_COUNTUNAVAILABLE), mAllocator(allocator), mStore(store), mRows(rows_a(allocator))
{}
typedef CAccessorRowset<ACCESSOR, CBulkRowset> rowset_t;
DelayedException *Get(DBLENGTH &recvLen, rowset_t &a);
~TmpRowset();
//dissolve and change to python;
PyObject *ToPython(ToPythonCtxt &ctxt);
DBROWCOUNT mRC;
private:
//typedef std::vector<Row*> rows_t;
typedef StlPoolAllocator<Row*> rows_a;
typedef std::list<Row*, rows_a> rows_t;
typedef rows_t::iterator rows_i;
RowDescriptor mRD;
rows_t mRows;
SimplePoolAllocator &mAllocator;
Store& mStore;
};
class TmpRowsetList
{
public:
TmpRowsetList() : mProcResult(0) , mAllocator(8*1024), mStore(mAllocator){}
~TmpRowsetList();
typedef CCommand<ACCESSOR, CBulkRowset, CMultipleResults> command_t;
DelayedException *Get(DBLENGTH &recvLen, NSession *sess, command_t &cmd, DBROWCOUNT rc);
//dissolve and change to python.
PyObject *ToPython(ToPythonCtxt &ctxt);
size_t GetMemSaved() const { return mStore.GetMemSaved(); }
private:
typedef std::vector<TmpRowset*> rowsets_t;
typedef rowsets_t::iterator rowsets_i;
rowsets_t mRowsets;
int mProcResult; //used when list is empty
SimplePoolAllocator mAllocator;
Store mStore;
};
#endif //_TMPROWSET_H_