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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
/* Copyright (C) 2003 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#ifndef ODBC_COMMON_DescArea_hpp
#define ODBC_COMMON_DescArea_hpp
#include <map>
#include <vector>
#include <common/common.hpp>
#include "OdbcData.hpp"
/**
* Descriptor records. Contains:
* -# header, not called a "record" in this context
* -# bookmark record at index position 0
* -# descriptor records at index positions starting from 1
*
* These classes are in common/ since the code is general.
* However each area is associated with a HandleDesc.
*
* DescField - field identified by an SQL_DESC_* constant
* DescRec - header or record, a list of fields
* DescArea - header and all records
*/
class HandleBase;
class DescField;
class DescRec;
class DescArea;
enum DescPos {
Desc_pos_undef = 0,
Desc_pos_header,
Desc_pos_record,
Desc_pos_end
};
enum DescMode {
Desc_mode_undef = 0,
Desc_mode_readonly,
Desc_mode_writeonly,
Desc_mode_readwrite,
Desc_mode_unused
};
struct DescSpec {
DescPos m_pos; // header or record
int m_id; // SQL_DESC_ identifier
OdbcData::Type m_type; // data type
DescMode m_mode[1+4]; // access mode IPD APD IRD ARD
// called before setting value
typedef void CallbackSet(Ctx& ctx, HandleBase* self, const OdbcData& data);
CallbackSet* m_set;
// called to get default value
typedef void CallbackDefault(Ctx& ctx, HandleBase* self, OdbcData& data);
CallbackDefault* m_default;
};
enum DescAlloc {
Desc_alloc_undef = 0,
Desc_alloc_auto,
Desc_alloc_user
};
enum DescUsage {
Desc_usage_undef = 0,
Desc_usage_IPD = 1, // these must be 1-4
Desc_usage_IRD = 2,
Desc_usage_APD = 3,
Desc_usage_ARD = 4
};
/**
* @class DescField
* @brief Field identified by an SQL_DESC_* constant
*/
class DescField {
public:
DescField(const DescSpec& spec, const OdbcData& data);
DescField(const DescField& field);
~DescField();
private:
friend class DescRec;
void setData(const OdbcData& data);
const OdbcData& getData();
const DescSpec& m_spec;
OdbcData m_data;
};
inline
DescField::DescField(const DescSpec& spec, const OdbcData& data) :
m_spec(spec),
m_data(data)
{
}
inline
DescField::DescField(const DescField& field) :
m_spec(field.m_spec),
m_data(field.m_data)
{
}
inline
DescField::~DescField()
{
}
inline void
DescField::setData(const OdbcData& data)
{
ctx_assert(m_spec.m_type == data.type());
m_data.setValue(data);
}
inline const OdbcData&
DescField::getData()
{
ctx_assert(m_data.type() != OdbcData::Undef);
return m_data;
}
/**
* @class DescRec
* @brief Descriptor record, a list of fields
*/
class DescRec {
friend class DescArea;
public:
DescRec();
~DescRec();
void setField(int id, const OdbcData& data);
void getField(int id, OdbcData& data);
void setField(Ctx& ctx, int id, const OdbcData& data);
void getField(Ctx& ctx, int id, OdbcData& data);
private:
DescArea* m_area;
int m_num; // for logging only -1 = header 0 = bookmark
typedef std::map<int, DescField> Fields;
Fields m_fields;
};
inline
DescRec::DescRec() :
m_area(0)
{
}
inline
DescRec::~DescRec()
{
}
/**
* @class DescArea
* @brief All records, including header (record 0)
*
* Descriptor area includes a header (record 0)
* and zero or more records at position >= 1.
* Each of these describes one parameter or one column.
*
* - DescArea : Collection of records
* - DescRec : Collection of fields
* - DescField : Contains data of type OdbcData
*/
class DescArea {
public:
DescArea(HandleBase* handle, const DescSpec* specList);
~DescArea();
void setAlloc(DescAlloc alloc);
DescAlloc getAlloc() const;
void setUsage(DescUsage usage);
DescUsage getUsage() const;
static const char* nameUsage(DescUsage u);
// find specifier
const DescSpec& findSpec(int id);
// get or set number of records (record 0 not counted)
unsigned getCount() const;
void setCount(Ctx& ctx, unsigned count);
// paush new record (record 0 exists always)
DescRec& pushRecord();
// get ref to header or to any record
DescRec& getHeader();
DescRec& getRecord(unsigned num);
// modified since last bind
void setBound(bool bound);
bool isBound() const;
private:
HandleBase* m_handle;
const DescSpec* const m_specList;
DescRec m_header;
typedef std::vector<DescRec> Recs;
Recs m_recs;
DescAlloc m_alloc;
DescUsage m_usage;
bool m_bound;
};
inline void
DescArea::setAlloc(DescAlloc alloc)
{
m_alloc = alloc;
}
inline DescAlloc
DescArea::getAlloc() const
{
return m_alloc;
}
inline void
DescArea::setUsage(DescUsage usage)
{
m_usage = usage;
}
inline DescUsage
DescArea::getUsage() const
{
return m_usage;
}
inline const char*
DescArea::nameUsage(DescUsage u)
{
switch (u) {
case Desc_usage_undef:
break;
case Desc_usage_IPD:
return "IPD";
case Desc_usage_IRD:
return "IRD";
case Desc_usage_APD:
return "APD";
case Desc_usage_ARD:
return "ARD";
}
return "?";
}
inline void
DescArea::setBound(bool bound)
{
m_bound = bound;
}
inline bool
DescArea::isBound() const
{
return m_bound;
}
#endif
|