summaryrefslogtreecommitdiff
path: root/storage/ndb/src/old_files/client/odbc/common/OdbcData.hpp
blob: c1884507cfeaf2e1fab296e45b0329dc0d9ac813 (plain)
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/* 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_OdbcData_hpp
#define ODBC_COMMON_OdbcData_hpp

#include <ndb_types.h>
#include <common/common.hpp>

/**
 * @class OdbcData
 * @brief Odbc data types and storage
 *
 * Stores diagnostics, attributes, and descriptors.  Also used
 * for converting to and from driver function arguments.
 */
class OdbcData {
public:
    enum Type {
	Undef = 0,
	Smallint,
	Usmallint,
	Integer,
	Uinteger,
	Pointer,
	SmallintPtr,
	UsmallintPtr,
	IntegerPtr,
	UintegerPtr,
	PointerPtr,
	Sqlchar,
	Sqlstate
    };
    OdbcData();
    OdbcData(Type type);
    OdbcData(const OdbcData& odbcData);
    OdbcData(SQLSMALLINT smallint);
    OdbcData(SQLUSMALLINT usmallint);
    OdbcData(SQLINTEGER integer);
    OdbcData(SQLUINTEGER uinteger);
    OdbcData(SQLPOINTER pointer);
    OdbcData(SQLSMALLINT* smallintPtr);
    OdbcData(SQLUSMALLINT* usmallintPtr);
    OdbcData(SQLINTEGER* integerPtr);
    OdbcData(SQLUINTEGER* uintegerPtr);
    OdbcData(SQLPOINTER* pointerPtr);
    OdbcData(const char* sqlchar);
    OdbcData(const ::Sqlstate& sqlstate);
    ~OdbcData();
    Type type() const;
    void setValue();
    void setValue(Type type);
    void setValue(const OdbcData odbcData);
    // get value
    SQLSMALLINT smallint() const;
    SQLUSMALLINT usmallint() const;
    SQLINTEGER integer() const;
    SQLUINTEGER uinteger() const;
    SQLPOINTER pointer() const;
    SQLSMALLINT* smallintPtr() const;
    SQLUSMALLINT* usmallintPtr() const;
    SQLINTEGER* integerPtr() const;
    SQLUINTEGER* uintegerPtr() const;
    SQLPOINTER* pointerPtr() const;
    const char* sqlchar() const;
    const ::Sqlstate& sqlstate() const;
    // copy in from user buffer
    void copyin(Ctx& ctx, Type type, SQLPOINTER buf, SQLINTEGER length);
    // copy out to user buffer
    void copyout(Ctx& ctx, SQLPOINTER buf, SQLINTEGER length, SQLINTEGER* total, SQLSMALLINT* total2 = 0);
    // logging
    void print(char* buf, unsigned size) const;
private:
    OdbcData& operator=(const OdbcData& odbcData);	// disallowed
    Type m_type;
    union {
	SQLSMALLINT m_smallint;
	SQLUSMALLINT m_usmallint;
	SQLINTEGER m_integer;
	SQLUINTEGER m_uinteger;
	SQLPOINTER m_pointer;
	SQLSMALLINT* m_smallintPtr;
	SQLUSMALLINT* m_usmallintPtr;
	SQLINTEGER* m_integerPtr;
	SQLUINTEGER* m_uintegerPtr;
	SQLPOINTER* m_pointerPtr;
	char* m_sqlchar;
	const ::Sqlstate* m_sqlstate;
    };
};

inline OdbcData::Type
OdbcData::type() const
{
    return m_type;
}

inline
OdbcData::OdbcData(SQLSMALLINT smallint) :
    m_type(Smallint),
    m_smallint(smallint)
{
}

inline
OdbcData::OdbcData(SQLUSMALLINT usmallint) :
    m_type(Usmallint),
    m_usmallint(usmallint)
{
}

inline
OdbcData::OdbcData(SQLINTEGER integer) :
    m_type(Integer),
    m_integer(integer)
{
}

inline
OdbcData::OdbcData(SQLUINTEGER uinteger) :
    m_type(Uinteger),
    m_uinteger(uinteger)
{
}

inline
OdbcData::OdbcData(SQLPOINTER pointer) :
    m_type(Pointer),
    m_pointer(pointer)
{
}

inline
OdbcData::OdbcData(SQLSMALLINT* smallintPtr) :
    m_type(SmallintPtr),
    m_smallintPtr(smallintPtr)
{
}

inline
OdbcData::OdbcData(SQLUSMALLINT* usmallintPtr) :
    m_type(UsmallintPtr),
    m_usmallintPtr(usmallintPtr)
{
}

inline
OdbcData::OdbcData(SQLINTEGER* integerPtr) :
    m_type(IntegerPtr),
    m_integerPtr(integerPtr)
{
}

inline
OdbcData::OdbcData(SQLUINTEGER* uintegerPtr) :
    m_type(UintegerPtr),
    m_uintegerPtr(uintegerPtr)
{
}

inline
OdbcData::OdbcData(SQLPOINTER* pointerPtr) :
    m_type(PointerPtr),
    m_pointerPtr(pointerPtr)
{
}

inline
OdbcData::OdbcData(const char* sqlchar) :
    m_type(Sqlchar)
{
    unsigned n = strlen(sqlchar);
    m_sqlchar = new char[n + 1];
    strcpy(m_sqlchar, sqlchar);
}

inline
OdbcData::OdbcData(const ::Sqlstate& sqlstate) :
    m_type(Sqlstate),
    m_sqlstate(&sqlstate)
{
}

// get value

inline SQLSMALLINT
OdbcData::smallint() const
{
    ctx_assert(m_type == Smallint);
    return m_smallint;
}

inline SQLUSMALLINT
OdbcData::usmallint() const
{
    ctx_assert(m_type == Usmallint);
    return m_usmallint;
}

inline SQLINTEGER
OdbcData::integer() const
{
    ctx_assert(m_type == Integer);
    return m_integer;
}

inline SQLUINTEGER
OdbcData::uinteger() const
{
    ctx_assert(m_type == Uinteger);
    return m_uinteger;
}

inline SQLPOINTER
OdbcData::pointer() const
{
    ctx_assert(m_type == Pointer);
    return m_pointer;
}

inline SQLSMALLINT*
OdbcData::smallintPtr() const
{
    ctx_assert(m_type == SmallintPtr);
    return m_smallintPtr;
}

inline SQLUSMALLINT*
OdbcData::usmallintPtr() const
{
    ctx_assert(m_type == UsmallintPtr);
    return m_usmallintPtr;
}

inline SQLINTEGER*
OdbcData::integerPtr() const
{
    ctx_assert(m_type == IntegerPtr);
    return m_integerPtr;
}

inline SQLUINTEGER*
OdbcData::uintegerPtr() const
{
    ctx_assert(m_type == UintegerPtr);
    return m_uintegerPtr;
}

inline SQLPOINTER*
OdbcData::pointerPtr() const
{
    ctx_assert(m_type == PointerPtr);
    return m_pointerPtr;
}

inline const char*
OdbcData::sqlchar() const
{
    ctx_assert(m_type == Sqlchar);
    return m_sqlchar;
}

inline const ::Sqlstate&
OdbcData::sqlstate() const
{
    ctx_assert(m_type == Sqlstate);
    return *m_sqlstate;
}

#endif