~drizzle-trunk/drizzle/development

2244.1.1 by Monty Taylor
Split libdrizzle into 1.0 and 2.0. Applied the C++ changes to 2.0 branch.
1
/*
2
 * Drizzle Client & Protocol Library
3
 *
4
 * Copyright (C) 2008 Eric Day (eday@oddments.org)
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions are
9
 * met:
10
 *
11
 *     * Redistributions of source code must retain the above copyright
12
 * notice, this list of conditions and the following disclaimer.
13
 *
14
 *     * Redistributions in binary form must reproduce the above
15
 * copyright notice, this list of conditions and the following disclaimer
16
 * in the documentation and/or other materials provided with the
17
 * distribution.
18
 *
19
 *     * The names of its contributors may not be used to endorse or
20
 * promote products derived from this software without specific prior
21
 * written permission.
22
 *
23
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
 *
35
 */
36
2449.1.4 by Brian Aker
Complete update of libdrizzle
37
#pragma once
38
2244.1.1 by Monty Taylor
Split libdrizzle into 1.0 and 2.0. Applied the C++ changes to 2.0 branch.
39
/**
40
 * @file
41
 * @brief Struct Definitions
42
 */
43
44
#include <sys/types.h>
45
46
#ifndef NI_MAXHOST
47
# define NI_MAXHOST 1025
48
#endif
49
50
#ifdef __cplusplus
51
extern "C" {
52
#endif
53
54
#ifndef __cplusplus
55
struct drizzle_st;
56
struct drizzle_con_tcp_st;
57
struct drizzle_con_uds_st;
58
struct drizzle_con_st;
59
struct drizzle_query_st;
60
struct drizzle_result_st;
61
struct drizzle_column_st;
62
#else
63
64
65
/**
66
 * @ingroup drizzle
67
 */
68
class drizzle_st
69
{
70
public:
71
  uint16_t error_code;
2461.1.2 by Brian Aker
Pass through refactoring.
72
  struct options_t {
73
    bool is_allocated;
74
    bool is_non_blocking;
75
    bool is_free_objects;
76
    bool is_assert_dangling;
77
78
    options_t() :
79
      is_allocated(false),
80
      is_non_blocking(false),
81
      is_free_objects(false),
82
      is_assert_dangling(false)
83
    { }
84
  } options;
2244.1.1 by Monty Taylor
Split libdrizzle into 1.0 and 2.0. Applied the C++ changes to 2.0 branch.
85
  drizzle_verbose_t verbose;
86
  uint32_t con_count;
87
  uint32_t pfds_size;
88
  uint32_t query_count;
89
  uint32_t query_new;
90
  uint32_t query_running;
91
  int last_errno;
92
  int timeout;
93
  drizzle_con_st *con_list;
94
  void *context;
95
  drizzle_context_free_fn *context_free_fn;
96
  drizzle_event_watch_fn *event_watch_fn;
97
  void *event_watch_context;
98
  drizzle_log_fn *log_fn;
99
  void *log_context;
100
  struct pollfd *pfds;
101
  drizzle_query_st *query_list;
102
  char sqlstate[DRIZZLE_MAX_SQLSTATE_SIZE + 1];
103
  char last_error[DRIZZLE_MAX_ERROR_SIZE];
104
105
  drizzle_st() :
106
    error_code(0),
2461.1.2 by Brian Aker
Pass through refactoring.
107
    options(),
2244.1.1 by Monty Taylor
Split libdrizzle into 1.0 and 2.0. Applied the C++ changes to 2.0 branch.
108
    verbose(DRIZZLE_VERBOSE_ERROR),
109
    con_count(0),
110
    pfds_size(0),
111
    query_count(0),
112
    query_new(0),
113
    query_running(0),
114
    last_errno(0),
115
    timeout(-1),
116
    con_list(NULL),
117
    context(NULL),
118
    context_free_fn(NULL),
119
    event_watch_fn(NULL),
120
    event_watch_context(NULL),
121
    log_fn(NULL),
122
    log_context(NULL),
123
    pfds(NULL),
124
    query_list(NULL)
125
  { }
126
};
127
128
/**
129
 * @ingroup drizzle_con
130
 */
131
class drizzle_con_tcp_st
132
{
133
public:
134
  in_port_t port;
135
  struct addrinfo *addrinfo;
136
  char *host;
137
  char host_buffer[NI_MAXHOST];
138
};
139
140
/**
141
 * @ingroup drizzle_con
142
 */
143
class drizzle_con_uds_st
144
{
145
public:
146
  struct addrinfo addrinfo;
147
  struct sockaddr_un sockaddr;
148
};
149
150
/**
151
 * @ingroup drizzle_con
152
 */
153
class drizzle_con_st
154
{
155
public:
156
  uint8_t packet_number;
157
  uint8_t protocol_version;
158
  uint8_t state_current;
159
  short events;
160
  short revents;
161
  int capabilities;
162
  drizzle_charset_t charset;
163
  drizzle_command_t command;
2461.1.4 by Brian Aker
More updates to libdrizzle-2.0
164
  struct option_t {
165
    bool is_allocated;
166
167
    option_t() :
168
      is_allocated(false)
169
    { }
170
  } _options;
2244.1.1 by Monty Taylor
Split libdrizzle into 1.0 and 2.0. Applied the C++ changes to 2.0 branch.
171
  int options;
172
  drizzle_con_socket_t socket_type;
173
  drizzle_con_status_t status;
174
  uint32_t max_packet_size;
175
  uint32_t result_count;
176
  uint32_t thread_id;
177
  int backlog;
178
  int fd;
179
  size_t buffer_size;
180
  size_t command_offset;
181
  size_t command_size;
182
  size_t command_total;
183
  size_t packet_size;
184
  struct addrinfo *addrinfo_next;
185
  uint8_t *buffer_ptr;
186
  uint8_t *command_buffer;
187
  uint8_t *command_data;
188
  void *context;
189
  drizzle_con_context_free_fn *context_free_fn;
190
  drizzle_st *drizzle;
191
  drizzle_con_st *next;
192
  drizzle_con_st *prev;
193
  drizzle_query_st *query;
194
  drizzle_result_st *result;
195
  drizzle_result_st *result_list;
196
  uint8_t *scramble;
197
  union
198
  {
199
    drizzle_con_tcp_st tcp;
200
    drizzle_con_uds_st uds;
201
  } socket;
202
  uint8_t buffer[DRIZZLE_MAX_BUFFER_SIZE];
2461.1.1 by Brian Aker
Fix safety issues around calling API with no check for NULL
203
  char schema[DRIZZLE_MAX_DB_SIZE];
2244.1.1 by Monty Taylor
Split libdrizzle into 1.0 and 2.0. Applied the C++ changes to 2.0 branch.
204
  char password[DRIZZLE_MAX_PASSWORD_SIZE];
205
  uint8_t scramble_buffer[DRIZZLE_MAX_SCRAMBLE_SIZE];
206
  char server_version[DRIZZLE_MAX_SERVER_VERSION_SIZE];
207
  char server_extra[DRIZZLE_MAX_SERVER_EXTRA_SIZE];
208
  drizzle_state_fn *state_stack[DRIZZLE_STATE_STACK_SIZE];
209
  char user[DRIZZLE_MAX_USER_SIZE];
210
211
  drizzle_con_st() :
212
    packet_number(0),
213
    protocol_version(0),
214
    state_current(0),
215
    events(0),
216
    revents(0),
217
    capabilities(DRIZZLE_CAPABILITIES_NONE),
218
    options(DRIZZLE_CON_NONE),
219
    max_packet_size(0),
220
    result_count(0),
221
    thread_id(0),
222
    backlog(0),
223
    fd(0),
224
    buffer_size(0),
225
    command_offset(0),
226
    command_size(0),
227
    command_total(0),
228
    packet_size(0),
229
    addrinfo_next(NULL),
230
    buffer_ptr(NULL),
231
    command_buffer(NULL),
232
    command_data(NULL),
233
    context(NULL),
234
    context_free_fn(NULL),
235
    drizzle(NULL),
236
    next(NULL),
237
    prev(NULL),
238
    query(NULL),
239
    result(NULL),
240
    result_list(NULL),
241
    scramble(NULL)
242
  { }
243
};
244
245
/**
246
 * @ingroup drizzle_query
247
 */
248
class drizzle_query_st
249
{
2461.1.2 by Brian Aker
Pass through refactoring.
250
private:
2244.1.1 by Monty Taylor
Split libdrizzle into 1.0 and 2.0. Applied the C++ changes to 2.0 branch.
251
public:
252
  drizzle_st *drizzle;
253
  drizzle_query_st *next;
254
  drizzle_query_st *prev;
2461.1.4 by Brian Aker
More updates to libdrizzle-2.0
255
  struct option_t {
256
    bool is_allocated;
257
258
    option_t() :
259
      is_allocated(false)
260
    { }
261
  } options;
2244.1.1 by Monty Taylor
Split libdrizzle into 1.0 and 2.0. Applied the C++ changes to 2.0 branch.
262
  drizzle_query_state_t state;
263
  drizzle_con_st *con;
264
  drizzle_result_st *result;
265
  const char *string;
266
  size_t size;
267
  void *context;
268
  drizzle_query_context_free_fn *context_free_fn;
269
270
  drizzle_query_st() :
271
    drizzle(NULL),
272
    next(NULL),
273
    prev(NULL),
274
    con(NULL),
275
    result(NULL),
276
    string(NULL),
277
    size(0),
278
    context(NULL),
279
    context_free_fn(NULL)
280
  { }
281
};
282
283
/**
284
 * @ingroup drizzle_result
285
 */
286
class drizzle_result_st
287
{
288
public:
289
  drizzle_con_st *con;
290
  drizzle_result_st *next;
291
  drizzle_result_st *prev;
2461.1.4 by Brian Aker
More updates to libdrizzle-2.0
292
  struct option_t {
293
    bool is_allocated;
294
295
    option_t() :
296
      is_allocated(false)
297
    { }
298
  } _options;
2244.1.1 by Monty Taylor
Split libdrizzle into 1.0 and 2.0. Applied the C++ changes to 2.0 branch.
299
  int options;
300
301
  char info[DRIZZLE_MAX_INFO_SIZE];
302
  uint16_t error_code;
303
  char sqlstate[DRIZZLE_MAX_SQLSTATE_SIZE + 1];
304
  uint64_t insert_id;
305
  uint16_t warning_count;
306
  uint64_t affected_rows;
307
308
  uint16_t column_count;
309
  uint16_t column_current;
310
  drizzle_column_st *column_list;
311
  drizzle_column_st *column;
312
  drizzle_column_st *column_buffer;
313
314
  uint64_t row_count;
315
  uint64_t row_current;
316
317
  uint16_t field_current;
318
  size_t field_total;
319
  size_t field_offset;
320
  size_t field_size;
321
  drizzle_field_t field;
322
  drizzle_field_t field_buffer;
323
324
  uint64_t row_list_size;
325
  drizzle_row_t row;
326
  drizzle_row_list_t *row_list;
327
  size_t *field_sizes;
328
  drizzle_field_sizes_list_t *field_sizes_list;
329
330
  drizzle_result_st() :
331
    con(NULL),
332
    next(NULL),
333
    prev(NULL),
334
    options(DRIZZLE_RESULT_NONE),
335
    error_code(0),
336
    insert_id(0),
337
    warning_count(0),
338
    affected_rows(0),
339
    column_count(0),
340
    column_current(0),
341
    column_list(NULL),
342
    column(NULL),
343
    column_buffer(NULL),
344
    row_count(0),
345
    row_current(0),
346
    field_current(0),
347
    field_total(0),
348
    field_offset(0),
349
    field_size(0),
350
    row_list_size(0),
351
    row_list(NULL),
352
    field_sizes(NULL),
353
    field_sizes_list(NULL)
354
  { }
355
};
356
357
/**
358
 * @ingroup drizzle_column
359
 */
360
class drizzle_column_st
361
{
362
public:
363
  drizzle_result_st *result;
364
  drizzle_column_st *next;
365
  drizzle_column_st *prev;
2461.1.4 by Brian Aker
More updates to libdrizzle-2.0
366
  struct options_t {
367
    bool is_allocated;
368
369
    options_t() :
370
      is_allocated(false)
371
    { }
372
  } options;
2244.1.1 by Monty Taylor
Split libdrizzle into 1.0 and 2.0. Applied the C++ changes to 2.0 branch.
373
  char catalog[DRIZZLE_MAX_CATALOG_SIZE];
2461.1.1 by Brian Aker
Fix safety issues around calling API with no check for NULL
374
  char schema[DRIZZLE_MAX_DB_SIZE];
2244.1.1 by Monty Taylor
Split libdrizzle into 1.0 and 2.0. Applied the C++ changes to 2.0 branch.
375
  char table[DRIZZLE_MAX_TABLE_SIZE];
376
  char orig_table[DRIZZLE_MAX_TABLE_SIZE];
377
  char name[DRIZZLE_MAX_COLUMN_NAME_SIZE];
378
  char orig_name[DRIZZLE_MAX_COLUMN_NAME_SIZE];
379
  drizzle_charset_t charset;
380
  uint32_t size;
381
  size_t max_size;
382
  drizzle_column_type_t type;
383
  int flags;
384
  uint8_t decimals;
385
  uint8_t default_value[DRIZZLE_MAX_DEFAULT_VALUE_SIZE];
386
  size_t default_value_size;
387
388
  drizzle_column_st() :
389
    result(NULL),
390
    next(NULL),
391
    prev(NULL),
392
    size(0),
393
    max_size(0),
394
    flags(DRIZZLE_COLUMN_FLAGS_NONE),
395
    decimals(0),
396
    default_value_size(0)
397
  { }
398
};
399
#endif
400
401
#ifdef __cplusplus
402
}
403
#endif