~drizzle-trunk/drizzle/development

390.1.4 by Monty Taylor
More copyright header file fixes.
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
1 by brian
clean slate
19
383.1.44 by Monty Taylor
Renamed drizzle.h to libdrizzle.h.
20
#include "libdrizzle.h"
390.1.5 by Monty Taylor
Moved more functions into drizzle.c as part of the split of code.
21
#include "libdrizzle_priv.h"
542 by Monty Taylor
Cleaned up the last commit.
22
#include <libdrizzle/pack.h>
1 by brian
clean slate
23
#include "errmsg.h"
24
#include <sys/stat.h>
25
#include <signal.h>
26
#include <time.h>
206.3.1 by Patrick Galbraith
Most everything working with client rename
27
#ifdef   HAVE_PWD_H
1 by brian
clean slate
28
#include <pwd.h>
29
#endif
94 by Brian Aker
DOS removal. DOS... hard to believe aye?
30
1 by brian
clean slate
31
#include <sys/socket.h>
32
#include <netinet/in.h>
33
#include <arpa/inet.h>
34
#include <netdb.h>
35
#ifdef HAVE_SELECT_H
36
#include <select.h>
37
#endif
38
#ifdef HAVE_SYS_SELECT_H
39
#include <sys/select.h>
40
#endif
94 by Brian Aker
DOS removal. DOS... hard to believe aye?
41
1 by brian
clean slate
42
#ifdef HAVE_POLL
43
#include <sys/poll.h>
44
#endif
45
#ifdef HAVE_SYS_UN_H
46
#include <sys/un.h>
47
#endif
48
#ifndef INADDR_NONE
206.3.1 by Patrick Galbraith
Most everything working with client rename
49
#define INADDR_NONE  -1
1 by brian
clean slate
50
#endif
51
390.1.6 by Monty Taylor
Oh dear god the changes. The changes. I'd tell you what they are, but I'd just be making stuff up. Suffice it to day it's mostly all around splitting files in libdrizzle into different files and removing interdepends. And whatever else I happened to see...
52
#include <stdlib.h>
53
#include <string.h>
54
1 by brian
clean slate
55
#include <sql_common.h>
264.1.9 by Monty Taylor
Removed version.h (non-public header) from drizzle.h (public header)
56
#include <drizzled/version.h>
1 by brian
clean slate
57
383.1.38 by Monty Taylor
Reworked drizzle_escape_string.
58
/* Borrowed from libicu header */
59
60
#define U8_IS_SINGLE(c) (((c)&0x80)==0)
61
#define U8_LENGTH(c) \
62
    ((uint32_t)(c)<=0x7f ? 1 : \
63
        ((uint32_t)(c)<=0x7ff ? 2 : \
64
            ((uint32_t)(c)<=0xd7ff ? 3 : \
65
                ((uint32_t)(c)<=0xdfff || (uint32_t)(c)>0x10ffff ? 0 : \
66
                    ((uint32_t)(c)<=0xffff ? 3 : 4)\
67
                ) \
68
            ) \
69
        ) \
70
    )
71
72
1 by brian
clean slate
73
#undef net_buffer_length
74
#undef max_allowed_packet
75
206.3.1 by Patrick Galbraith
Most everything working with client rename
76
uint32_t     net_buffer_length= 8192;
77
uint32_t    max_allowed_packet= 1024L*1024L*1024L;
1 by brian
clean slate
78
390.1.5 by Monty Taylor
Moved more functions into drizzle.c as part of the split of code.
79
unsigned int drizzle_port=0;
80
1 by brian
clean slate
81
#include <errno.h>
82
202.2.2 by Monty Taylor
Merged mysql_server_init into drizzle_create()
83
206.3.1 by Patrick Galbraith
Most everything working with client rename
84
static DRIZZLE_PARAMETERS drizzle_internal_parameters=
1 by brian
clean slate
85
{&max_allowed_packet, &net_buffer_length, 0};
86
287.3.6 by Monty Taylor
Eeek. Final cleanups.
87
const DRIZZLE_PARAMETERS * drizzle_get_parameters(void)
1 by brian
clean slate
88
{
206.3.1 by Patrick Galbraith
Most everything working with client rename
89
  return &drizzle_internal_parameters;
1 by brian
clean slate
90
}
91
390.1.5 by Monty Taylor
Moved more functions into drizzle.c as part of the split of code.
92
unsigned int drizzle_get_default_port(void)
93
{
94
  return drizzle_port;
95
}
96
97
void drizzle_set_default_port(unsigned int port)
98
{
99
  drizzle_port= port;
100
}
101
1 by brian
clean slate
102
/*
103
  Expand wildcard to a sql string
104
*/
105
106
static void
107
append_wild(char *to, char *end, const char *wild)
108
{
206.3.1 by Patrick Galbraith
Most everything working with client rename
109
  end-=5;          /* Some extra */
1 by brian
clean slate
110
  if (wild && wild[0])
111
  {
240.1.2 by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c
112
    to= strcpy(to," like '");
113
    to+= 7; /* strlen(" like '"); */
114
1 by brian
clean slate
115
    while (*wild && to < end)
116
    {
117
      if (*wild == '\\' || *wild == '\'')
206.3.1 by Patrick Galbraith
Most everything working with client rename
118
  *to++='\\';
1 by brian
clean slate
119
      *to++= *wild++;
120
    }
206.3.1 by Patrick Galbraith
Most everything working with client rename
121
    if (*wild)          /* Too small buffer */
122
      *to++='%';        /* Nicer this way */
1 by brian
clean slate
123
    to[0]='\'';
124
    to[1]=0;
125
  }
126
}
127
128
/**************************************************************************
129
  Change user and database
130
**************************************************************************/
131
236.3.6 by Andrey Hristov
read_change_user_result doesn't neet buffer and password. They were needed to handle 3.23 authentication, which is no more.
132
int cli_read_change_user_result(DRIZZLE *drizzle)
1 by brian
clean slate
133
{
294 by Brian Aker
libdrizzle has ulong removed.
134
  uint32_t pkt_length;
1 by brian
clean slate
135
206.3.1 by Patrick Galbraith
Most everything working with client rename
136
  pkt_length= cli_safe_read(drizzle);
1 by brian
clean slate
137
  
138
  if (pkt_length == packet_error)
139
    return 1;
140
141
  return 0;
142
}
143
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
144
bool drizzle_change_user(DRIZZLE *drizzle, const char *user,
261.1.2 by Brian Aker
Cleanup/removal of more of the dead protocols.
145
                                 const char *passwd, const char *db)
1 by brian
clean slate
146
{
147
  char buff[USERNAME_LENGTH+SCRAMBLED_PASSWORD_CHAR_LENGTH+NAME_LEN+2];
148
  char *end= buff;
149
  int rc;
150
151
  /* Use an empty string instead of NULL. */
152
153
  if (!user)
154
    user="";
155
  if (!passwd)
156
    passwd="";
157
158
  /* Store user into the buffer */
240.1.2 by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c
159
  end= strncpy(end, user, USERNAME_LENGTH) + USERNAME_LENGTH + 1;
1 by brian
clean slate
160
161
  /* write scrambled password according to server capabilities */
162
  if (passwd[0])
163
  {
164
    {
165
      *end++= SCRAMBLE_LENGTH;
166
      end+= SCRAMBLE_LENGTH;
167
    }
168
  }
169
  else
170
    *end++= '\0';                               /* empty password */
171
  /* Add database if needed */
240.1.2 by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c
172
  end= strncpy(end, db ? db : "", NAME_LEN) + NAME_LEN + 1;
1 by brian
clean slate
173
174
  /* Add character set number. */
206.3.1 by Patrick Galbraith
Most everything working with client rename
175
  if (drizzle->server_capabilities & CLIENT_SECURE_CONNECTION)
1 by brian
clean slate
176
  {
395 by Brian Aker
Fixed uint/ushort issue in libdrizzle
177
    int2store(end, (uint16_t) 45); // utf8mb4 number from mystrings/ctype-utf8.c
1 by brian
clean slate
178
    end+= 2;
179
  }
180
181
  /* Write authentication package */
390.1.6 by Monty Taylor
Oh dear god the changes. The changes. I'd tell you what they are, but I'd just be making stuff up. Suffice it to day it's mostly all around splitting files in libdrizzle into different files and removing interdepends. And whatever else I happened to see...
182
  (void)simple_command(drizzle,COM_CHANGE_USER, (unsigned char*) buff, (uint32_t) (end-buff), 1);
1 by brian
clean slate
183
236.3.6 by Andrey Hristov
read_change_user_result doesn't neet buffer and password. They were needed to handle 3.23 authentication, which is no more.
184
  rc= (*drizzle->methods->read_change_user_result)(drizzle);
1 by brian
clean slate
185
186
  if (rc == 0)
187
  {
188
    /* Free old connect information */
207.2.3 by Toru Maesaka
Merge from trunk and conflicts resolved
189
    if(drizzle->user)
190
      free(drizzle->user);
191
    if(drizzle->passwd)
192
      free(drizzle->passwd);
193
    if(drizzle->db)
194
      free(drizzle->db);
1 by brian
clean slate
195
196
    /* alloc new connect information */
240.1.1 by Toru Maesaka
removed my_strdup and dead code from libdrizzle
197
    drizzle->user= strdup(user);
198
    drizzle->passwd= strdup(passwd);
199
    drizzle->db= db ? strdup(db) : 0;
1 by brian
clean slate
200
  }
201
51.3.5 by Jay Pipes
Merged in from trunk.
202
  return(rc);
1 by brian
clean slate
203
}
204
205
#if defined(HAVE_GETPWUID) && defined(NO_GETPWUID_DECL)
206
struct passwd *getpwuid(uid_t);
207
char* getlogin(void);
208
#endif
209
210
/**************************************************************************
211
  Do a query. If query returned rows, free old rows.
206.3.1 by Patrick Galbraith
Most everything working with client rename
212
  Read data by drizzle_store_result or by repeat call of drizzle_fetch_row
1 by brian
clean slate
213
**************************************************************************/
214
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
215
int
206.3.1 by Patrick Galbraith
Most everything working with client rename
216
drizzle_query(DRIZZLE *drizzle, const char *query)
1 by brian
clean slate
217
{
395 by Brian Aker
Fixed uint/ushort issue in libdrizzle
218
  return drizzle_real_query(drizzle,query, (uint32_t) strlen(query));
1 by brian
clean slate
219
}
220
221
222
/**************************************************************************
223
  Return next field of the query results
224
**************************************************************************/
225
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
226
DRIZZLE_FIELD *
206.3.1 by Patrick Galbraith
Most everything working with client rename
227
drizzle_fetch_field(DRIZZLE_RES *result)
1 by brian
clean slate
228
{
229
  if (result->current_field >= result->field_count)
230
    return(NULL);
231
  return &result->fields[result->current_field++];
232
}
233
234
235
/**************************************************************************
236
  Move to a specific row and column
237
**************************************************************************/
238
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
239
void
206.3.1 by Patrick Galbraith
Most everything working with client rename
240
drizzle_data_seek(DRIZZLE_RES *result, uint64_t row)
1 by brian
clean slate
241
{
206.3.1 by Patrick Galbraith
Most everything working with client rename
242
  DRIZZLE_ROWS  *tmp=0;
1 by brian
clean slate
243
  if (result->data)
244
    for (tmp=result->data->data; row-- && tmp ; tmp = tmp->next) ;
245
  result->current_row=0;
246
  result->data_cursor = tmp;
247
}
248
249
250
/*************************************************************************
206.3.1 by Patrick Galbraith
Most everything working with client rename
251
  put the row or field cursor one a position one got from DRIZZLE_ROW_tell()
252
  This doesn't restore any data. The next drizzle_fetch_row or
253
  drizzle_fetch_field will return the next row or field after the last used
1 by brian
clean slate
254
*************************************************************************/
255
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
256
DRIZZLE_ROW_OFFSET
206.3.1 by Patrick Galbraith
Most everything working with client rename
257
drizzle_row_seek(DRIZZLE_RES *result, DRIZZLE_ROW_OFFSET row)
1 by brian
clean slate
258
{
206.3.1 by Patrick Galbraith
Most everything working with client rename
259
  DRIZZLE_ROW_OFFSET return_value=result->data_cursor;
1 by brian
clean slate
260
  result->current_row= 0;
261
  result->data_cursor= row;
262
  return return_value;
263
}
264
265
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
266
DRIZZLE_FIELD_OFFSET
206.3.1 by Patrick Galbraith
Most everything working with client rename
267
drizzle_field_seek(DRIZZLE_RES *result, DRIZZLE_FIELD_OFFSET field_offset)
1 by brian
clean slate
268
{
206.3.1 by Patrick Galbraith
Most everything working with client rename
269
  DRIZZLE_FIELD_OFFSET return_value=result->current_field;
1 by brian
clean slate
270
  result->current_field=field_offset;
271
  return return_value;
272
}
273
274
275
/*****************************************************************************
276
  List all tables in a database
277
  If wild is given then only the tables matching wild is returned
278
*****************************************************************************/
279
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
280
DRIZZLE_RES *
206.3.1 by Patrick Galbraith
Most everything working with client rename
281
drizzle_list_tables(DRIZZLE *drizzle, const char *wild)
1 by brian
clean slate
282
{
283
  char buff[255];
240.1.2 by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c
284
  char *ptr= strcpy(buff, "show tables");
285
  ptr+= 11; /* strlen("show tables"); */
1 by brian
clean slate
286
240.1.2 by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c
287
  append_wild(ptr,buff+sizeof(buff),wild);
206.3.1 by Patrick Galbraith
Most everything working with client rename
288
  if (drizzle_query(drizzle,buff))
51.3.5 by Jay Pipes
Merged in from trunk.
289
    return(0);
206.3.1 by Patrick Galbraith
Most everything working with client rename
290
  return (drizzle_store_result(drizzle));
1 by brian
clean slate
291
}
292
293
206.3.1 by Patrick Galbraith
Most everything working with client rename
294
DRIZZLE_FIELD *cli_list_fields(DRIZZLE *drizzle)
1 by brian
clean slate
295
{
206.3.1 by Patrick Galbraith
Most everything working with client rename
296
  DRIZZLE_DATA *query;
264.2.4 by Andrey Hristov
Remove support for the old, pre-4.1, protocol
297
  if (!(query= cli_read_rows(drizzle,(DRIZZLE_FIELD*) 0, 8)))
1 by brian
clean slate
298
    return NULL;
299
395 by Brian Aker
Fixed uint/ushort issue in libdrizzle
300
  drizzle->field_count= (uint32_t) query->rows;
383.1.40 by Monty Taylor
More mysys removal from libdrizzle. Got rid of MEM_ROOT related stuff.
301
  return unpack_fields(query, drizzle->field_count, 1);
1 by brian
clean slate
302
}
303
304
305
/**************************************************************************
306
  List all fields in a table
307
  If wild is given then only the fields matching wild is returned
308
  Instead of this use query:
309
  show fields in 'table' like "wild"
310
**************************************************************************/
311
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
312
DRIZZLE_RES *
206.3.1 by Patrick Galbraith
Most everything working with client rename
313
drizzle_list_fields(DRIZZLE *drizzle, const char *table, const char *wild)
1 by brian
clean slate
314
{
206.3.1 by Patrick Galbraith
Most everything working with client rename
315
  DRIZZLE_RES   *result;
316
  DRIZZLE_FIELD *fields;
240.1.2 by Toru Maesaka
str(mov|make) replaced with standard C calls in libdrizzle.c
317
  char buff[257], *end;
318
319
  end= strncpy(buff, table, 128) + 128;
320
  end= strncpy(end+1, wild ? wild : "", 128) + 128;
321
206.3.1 by Patrick Galbraith
Most everything working with client rename
322
  free_old_query(drizzle);
390.1.6 by Monty Taylor
Oh dear god the changes. The changes. I'd tell you what they are, but I'd just be making stuff up. Suffice it to day it's mostly all around splitting files in libdrizzle into different files and removing interdepends. And whatever else I happened to see...
323
  if (simple_command(drizzle, COM_FIELD_LIST, (unsigned char*) buff,
294 by Brian Aker
libdrizzle has ulong removed.
324
                     (uint32_t) (end-buff), 1) ||
206.3.1 by Patrick Galbraith
Most everything working with client rename
325
      !(fields= (*drizzle->methods->list_fields)(drizzle)))
326
    return(NULL);
327
207.2.3 by Toru Maesaka
Merge from trunk and conflicts resolved
328
  if (!(result = (DRIZZLE_RES *) malloc(sizeof(DRIZZLE_RES))))
206.3.1 by Patrick Galbraith
Most everything working with client rename
329
    return(NULL);
330
266.3.2 by Andrew Garner
memory was not initialized for new results in drizzle_list_fields
331
  memset(result, 0, sizeof(DRIZZLE_RES));
332
206.3.1 by Patrick Galbraith
Most everything working with client rename
333
  result->methods= drizzle->methods;
334
  drizzle->fields=0;
335
  result->field_count = drizzle->field_count;
1 by brian
clean slate
336
  result->fields= fields;
337
  result->eof=1;
51.3.5 by Jay Pipes
Merged in from trunk.
338
  return(result);
1 by brian
clean slate
339
}
340
341
/* List all running processes (threads) in server */
342
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
343
DRIZZLE_RES *
206.3.1 by Patrick Galbraith
Most everything working with client rename
344
drizzle_list_processes(DRIZZLE *drizzle)
1 by brian
clean slate
345
{
206.3.1 by Patrick Galbraith
Most everything working with client rename
346
  DRIZZLE_DATA *fields;
395 by Brian Aker
Fixed uint/ushort issue in libdrizzle
347
  uint32_t field_count;
390.1.6 by Monty Taylor
Oh dear god the changes. The changes. I'd tell you what they are, but I'd just be making stuff up. Suffice it to day it's mostly all around splitting files in libdrizzle into different files and removing interdepends. And whatever else I happened to see...
348
  unsigned char *pos;
1 by brian
clean slate
349
206.3.1 by Patrick Galbraith
Most everything working with client rename
350
  if (simple_command(drizzle,COM_PROCESS_INFO,0,0,0))
51.3.5 by Jay Pipes
Merged in from trunk.
351
    return(0);
206.3.1 by Patrick Galbraith
Most everything working with client rename
352
  free_old_query(drizzle);
390.1.6 by Monty Taylor
Oh dear god the changes. The changes. I'd tell you what they are, but I'd just be making stuff up. Suffice it to day it's mostly all around splitting files in libdrizzle into different files and removing interdepends. And whatever else I happened to see...
353
  pos=(unsigned char*) drizzle->net.read_pos;
395 by Brian Aker
Fixed uint/ushort issue in libdrizzle
354
  field_count=(uint32_t) net_field_length(&pos);
264.2.4 by Andrey Hristov
Remove support for the old, pre-4.1, protocol
355
  if (!(fields = (*drizzle->methods->read_rows)(drizzle,(DRIZZLE_FIELD*) 0, 7)))
51.3.5 by Jay Pipes
Merged in from trunk.
356
    return(NULL);
383.1.40 by Monty Taylor
More mysys removal from libdrizzle. Got rid of MEM_ROOT related stuff.
357
  if (!(drizzle->fields=unpack_fields(fields, field_count, 0)))
51.3.5 by Jay Pipes
Merged in from trunk.
358
    return(0);
206.3.1 by Patrick Galbraith
Most everything working with client rename
359
  drizzle->status=DRIZZLE_STATUS_GET_RESULT;
360
  drizzle->field_count=field_count;
361
  return(drizzle_store_result(drizzle));
1 by brian
clean slate
362
}
363
364
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
365
int
438.1.9 by Brian Aker
Removed dead shutdown code.
366
drizzle_shutdown(DRIZZLE *drizzle)
1 by brian
clean slate
367
{
480 by Brian Aker
Two regression fixes.
368
  return(simple_command(drizzle, COM_SHUTDOWN, 0, 0, 0));
1 by brian
clean slate
369
}
370
371
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
372
int
438.1.9 by Brian Aker
Removed dead shutdown code.
373
drizzle_refresh(DRIZZLE *drizzle, uint32_t options)
1 by brian
clean slate
374
{
390.1.6 by Monty Taylor
Oh dear god the changes. The changes. I'd tell you what they are, but I'd just be making stuff up. Suffice it to day it's mostly all around splitting files in libdrizzle into different files and removing interdepends. And whatever else I happened to see...
375
  unsigned char bits[1];
376
  bits[0]= (unsigned char) options;
206.3.1 by Patrick Galbraith
Most everything working with client rename
377
  return(simple_command(drizzle, COM_REFRESH, bits, 1, 0));
1 by brian
clean slate
378
}
379
380
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
381
int32_t
206.3.1 by Patrick Galbraith
Most everything working with client rename
382
drizzle_kill(DRIZZLE *drizzle, uint32_t pid)
1 by brian
clean slate
383
{
390.1.6 by Monty Taylor
Oh dear god the changes. The changes. I'd tell you what they are, but I'd just be making stuff up. Suffice it to day it's mostly all around splitting files in libdrizzle into different files and removing interdepends. And whatever else I happened to see...
384
  unsigned char buff[4];
1 by brian
clean slate
385
  int4store(buff,pid);
206.3.1 by Patrick Galbraith
Most everything working with client rename
386
  return(simple_command(drizzle,COM_PROCESS_KILL,buff,sizeof(buff),0));
1 by brian
clean slate
387
}
388
389
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
390
int
206.3.1 by Patrick Galbraith
Most everything working with client rename
391
drizzle_set_server_option(DRIZZLE *drizzle, enum enum_drizzle_set_option option)
1 by brian
clean slate
392
{
390.1.6 by Monty Taylor
Oh dear god the changes. The changes. I'd tell you what they are, but I'd just be making stuff up. Suffice it to day it's mostly all around splitting files in libdrizzle into different files and removing interdepends. And whatever else I happened to see...
393
  unsigned char buff[2];
395 by Brian Aker
Fixed uint/ushort issue in libdrizzle
394
  int2store(buff, (uint32_t) option);
206.3.1 by Patrick Galbraith
Most everything working with client rename
395
  return(simple_command(drizzle, COM_SET_OPTION, buff, sizeof(buff), 0));
1 by brian
clean slate
396
}
397
398
206.3.1 by Patrick Galbraith
Most everything working with client rename
399
const char *cli_read_statistics(DRIZZLE *drizzle)
1 by brian
clean slate
400
{
206.3.1 by Patrick Galbraith
Most everything working with client rename
401
  drizzle->net.read_pos[drizzle->packet_length]=0;  /* End of stat string */
402
  if (!drizzle->net.read_pos[0])
1 by brian
clean slate
403
  {
390.1.6 by Monty Taylor
Oh dear god the changes. The changes. I'd tell you what they are, but I'd just be making stuff up. Suffice it to day it's mostly all around splitting files in libdrizzle into different files and removing interdepends. And whatever else I happened to see...
404
    drizzle_set_error(drizzle, CR_WRONG_HOST_INFO, sqlstate_get_unknown());
206.3.1 by Patrick Galbraith
Most everything working with client rename
405
    return drizzle->net.last_error;
1 by brian
clean slate
406
  }
206.3.1 by Patrick Galbraith
Most everything working with client rename
407
  return (char*) drizzle->net.read_pos;
1 by brian
clean slate
408
}
409
410
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
411
int
206.3.1 by Patrick Galbraith
Most everything working with client rename
412
drizzle_ping(DRIZZLE *drizzle)
1 by brian
clean slate
413
{
414
  int res;
206.3.1 by Patrick Galbraith
Most everything working with client rename
415
  res= simple_command(drizzle,COM_PING,0,0,0);
416
  if (res == CR_SERVER_LOST && drizzle->reconnect)
417
    res= simple_command(drizzle,COM_PING,0,0,0);
51.3.5 by Jay Pipes
Merged in from trunk.
418
  return(res);
1 by brian
clean slate
419
}
420
421
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
422
const char *
236.3.5 by Andrey Hristov
Constify libdrizzle functions
423
drizzle_get_server_info(const DRIZZLE *drizzle)
1 by brian
clean slate
424
{
206.3.1 by Patrick Galbraith
Most everything working with client rename
425
  return((char*) drizzle->server_version);
1 by brian
clean slate
426
}
427
428
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
429
const char *
236.3.5 by Andrey Hristov
Constify libdrizzle functions
430
drizzle_get_host_info(const DRIZZLE *drizzle)
1 by brian
clean slate
431
{
206.3.1 by Patrick Galbraith
Most everything working with client rename
432
  return(drizzle->host_info);
1 by brian
clean slate
433
}
434
435
395 by Brian Aker
Fixed uint/ushort issue in libdrizzle
436
uint32_t
236.3.5 by Andrey Hristov
Constify libdrizzle functions
437
drizzle_get_proto_info(const DRIZZLE *drizzle)
1 by brian
clean slate
438
{
206.3.1 by Patrick Galbraith
Most everything working with client rename
439
  return (drizzle->protocol_version);
1 by brian
clean slate
440
}
441
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
442
const char *
206.3.1 by Patrick Galbraith
Most everything working with client rename
443
drizzle_get_client_info(void)
1 by brian
clean slate
444
{
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
445
  return (char*) DRIZZLE_SERVER_VERSION;
1 by brian
clean slate
446
}
447
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
448
uint32_t drizzle_get_client_version(void)
1 by brian
clean slate
449
{
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
450
  return DRIZZLE_VERSION_ID;
1 by brian
clean slate
451
}
452
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
453
bool drizzle_eof(const DRIZZLE_RES *res)
1 by brian
clean slate
454
{
455
  return res->eof;
456
}
457
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
458
const DRIZZLE_FIELD * drizzle_fetch_field_direct(const DRIZZLE_RES *res, unsigned int fieldnr)
1 by brian
clean slate
459
{
460
  return &(res)->fields[fieldnr];
461
}
462
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
463
const DRIZZLE_FIELD * drizzle_fetch_fields(const DRIZZLE_RES *res)
1 by brian
clean slate
464
{
236.3.5 by Andrey Hristov
Constify libdrizzle functions
465
  return res->fields;
1 by brian
clean slate
466
}
467
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
468
DRIZZLE_ROW_OFFSET drizzle_row_tell(const DRIZZLE_RES *res)
1 by brian
clean slate
469
{
470
  return res->data_cursor;
471
}
472
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
473
DRIZZLE_FIELD_OFFSET drizzle_field_tell(const DRIZZLE_RES *res)
1 by brian
clean slate
474
{
236.3.5 by Andrey Hristov
Constify libdrizzle functions
475
  return res->current_field;
1 by brian
clean slate
476
}
477
206.3.1 by Patrick Galbraith
Most everything working with client rename
478
/* DRIZZLE */
479
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
480
unsigned int drizzle_field_count(const DRIZZLE *drizzle)
206.3.1 by Patrick Galbraith
Most everything working with client rename
481
{
482
  return drizzle->field_count;
483
}
484
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
485
uint64_t drizzle_affected_rows(const DRIZZLE *drizzle)
206.3.1 by Patrick Galbraith
Most everything working with client rename
486
{
487
  return drizzle->affected_rows;
488
}
489
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
490
uint64_t drizzle_insert_id(const DRIZZLE *drizzle)
206.3.1 by Patrick Galbraith
Most everything working with client rename
491
{
492
  return drizzle->insert_id;
493
}
494
287.3.6 by Monty Taylor
Eeek. Final cleanups.
495
const char * drizzle_sqlstate(const DRIZZLE *drizzle)
206.3.1 by Patrick Galbraith
Most everything working with client rename
496
{
390.1.6 by Monty Taylor
Oh dear god the changes. The changes. I'd tell you what they are, but I'd just be making stuff up. Suffice it to day it's mostly all around splitting files in libdrizzle into different files and removing interdepends. And whatever else I happened to see...
497
  return drizzle ? drizzle->net.sqlstate : sqlstate_get_cant_connect();
206.3.1 by Patrick Galbraith
Most everything working with client rename
498
}
499
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
500
uint32_t drizzle_warning_count(const DRIZZLE *drizzle)
206.3.1 by Patrick Galbraith
Most everything working with client rename
501
{
502
  return drizzle->warning_count;
503
}
504
287.3.6 by Monty Taylor
Eeek. Final cleanups.
505
const char * drizzle_info(const DRIZZLE *drizzle)
206.3.1 by Patrick Galbraith
Most everything working with client rename
506
{
507
  return drizzle->info;
508
}
509
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
510
uint32_t drizzle_thread_id(const DRIZZLE *drizzle)
206.3.1 by Patrick Galbraith
Most everything working with client rename
511
{
236.3.5 by Andrey Hristov
Constify libdrizzle functions
512
  return drizzle->thread_id;
206.3.1 by Patrick Galbraith
Most everything working with client rename
513
}
514
1 by brian
clean slate
515
/****************************************************************************
516
  Some support functions
517
****************************************************************************/
518
519
/*
520
  Functions called my my_net_init() to set some application specific variables
521
*/
522
523
void my_net_local_init(NET *net)
524
{
395 by Brian Aker
Fixed uint/ushort issue in libdrizzle
525
  net->max_packet=   (uint32_t) net_buffer_length;
1 by brian
clean slate
526
  my_net_set_read_timeout(net, CLIENT_NET_READ_TIMEOUT);
527
  my_net_set_write_timeout(net, CLIENT_NET_WRITE_TIMEOUT);
528
  net->retry_count=  1;
390.1.6 by Monty Taylor
Oh dear god the changes. The changes. I'd tell you what they are, but I'd just be making stuff up. Suffice it to day it's mostly all around splitting files in libdrizzle into different files and removing interdepends. And whatever else I happened to see...
529
  net->max_packet_size= (net_buffer_length > max_allowed_packet) ?
530
    net_buffer_length : max_allowed_packet;
1 by brian
clean slate
531
}
532
533
/*
534
  This function is used to create HEX string that you
535
  can use in a SQL statement in of the either ways:
206.3.1 by Patrick Galbraith
Most everything working with client rename
536
    INSERT INTO blob_column VALUES (0xAABBCC);  (any DRIZZLE version)
264.2.4 by Andrey Hristov
Remove support for the old, pre-4.1, protocol
537
    INSERT INTO blob_column VALUES (X'AABBCC'); 
1 by brian
clean slate
538
  
539
  The string in "from" is encoded to a HEX string.
540
  The result is placed in "to" and a terminating null byte is appended.
541
  
542
  The string pointed to by "from" must be "length" bytes long.
543
  You must allocate the "to" buffer to be at least length*2+1 bytes long.
544
  Each character needs two bytes, and you need room for the terminating
206.3.1 by Patrick Galbraith
Most everything working with client rename
545
  null byte. When drizzle_hex_string() returns, the contents of "to" will
1 by brian
clean slate
546
  be a null-terminated string. The return value is the length of the
383.1.38 by Monty Taylor
Reworked drizzle_escape_string.
547
  encoded string, not including the terminating null character.  The return value does not contain any leading 0x or a leading X' and
1 by brian
clean slate
548
  trailing '. The caller must supply whichever of those is desired.
549
*/
550
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
551
uint32_t
206.3.1 by Patrick Galbraith
Most everything working with client rename
552
drizzle_hex_string(char *to, const char *from, uint32_t length)
1 by brian
clean slate
553
{
554
  char *to0= to;
555
  const char *end;
556
            
557
  for (end= from + length; from < end; from++)
558
  {
559
    *to++= _dig_vec_upper[((unsigned char) *from) >> 4];
560
    *to++= _dig_vec_upper[((unsigned char) *from) & 0x0F];
561
  }
562
  *to= '\0';
164 by Brian Aker
Commit cleanup of export types.
563
  return (uint32_t) (to-to0);
1 by brian
clean slate
564
}
565
566
/*
567
  Add escape characters to a string (blob?) to make it suitable for a insert
568
  to should at least have place for length*2+1 chars
569
  Returns the length of the to string
570
*/
571
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
572
uint32_t
206.3.1 by Patrick Galbraith
Most everything working with client rename
573
drizzle_escape_string(char *to,const char *from, uint32_t length)
1 by brian
clean slate
574
{
383.1.38 by Monty Taylor
Reworked drizzle_escape_string.
575
  const char *to_start= to;
576
  const char *end, *to_end=to_start + 2*length;
577
  bool overflow= false;
578
  for (end= from + length; from < end; from++)
579
  {
580
    uint32_t tmp_length;
581
    char escape= 0;
582
    if (!U8_IS_SINGLE(*from))
583
    {
584
      tmp_length= U8_LENGTH(*from);
585
      if (to + tmp_length > to_end)
586
      {
587
        overflow= true;
588
        break;
589
      }
590
      while (tmp_length--)
591
        *to++= *from++;
592
      from--;
593
      continue;
594
    }
595
    switch (*from) {
596
    case 0:                             /* Must be escaped for 'mysql' */
597
      escape= '0';
598
      break;
599
    case '\n':                          /* Must be escaped for logs */
600
      escape= 'n';
601
      break;
602
    case '\r':
603
      escape= 'r';
604
      break;
605
    case '\\':
606
      escape= '\\';
607
      break;
608
    case '\'':
609
      escape= '\'';
610
      break;
611
    case '"':                           /* Better safe than sorry */
612
      escape= '"';
613
      break;
614
    case '\032':                        /* This gives problems on Win32 */
615
      escape= 'Z';
616
      break;
617
    }
618
    if (escape)
619
    {
620
      if (to + 2 > to_end)
621
      {
622
        overflow= true;
623
        break;
624
      }
625
      *to++= '\\';
626
      *to++= escape;
627
    }
628
    else
629
    {
630
      if (to + 1 > to_end)
631
      {
632
        overflow= true;
633
        break;
634
      }
635
      *to++= *from;
636
    }
637
  }
638
  *to= 0;
639
  return overflow ? (size_t) -1 : (size_t) (to - to_start);
1 by brian
clean slate
640
}
641
206.3.1 by Patrick Galbraith
Most everything working with client rename
642
int cli_unbuffered_fetch(DRIZZLE *drizzle, char **row)
1 by brian
clean slate
643
{
206.3.1 by Patrick Galbraith
Most everything working with client rename
644
  if (packet_error == cli_safe_read(drizzle))
1 by brian
clean slate
645
    return 1;
646
236.3.3 by Andrey Hristov
Define a constant, instead of a magic number
647
  *row= ((drizzle->net.read_pos[0] == DRIZZLE_PROTOCOL_NO_MORE_DATA) ? NULL :
206.3.1 by Patrick Galbraith
Most everything working with client rename
648
   (char*) (drizzle->net.read_pos+1));
1 by brian
clean slate
649
  return 0;
650
}
651
652
/********************************************************************
653
 Transactional APIs
654
*********************************************************************/
655
656
/*
657
  Commit the current transaction
658
*/
659
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
660
bool drizzle_commit(DRIZZLE *drizzle)
1 by brian
clean slate
661
{
207.2.3 by Toru Maesaka
Merge from trunk and conflicts resolved
662
  return((bool) drizzle_real_query(drizzle, "commit", 6));
1 by brian
clean slate
663
}
664
665
/*
666
  Rollback the current transaction
667
*/
668
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
669
bool drizzle_rollback(DRIZZLE *drizzle)
1 by brian
clean slate
670
{
207.2.3 by Toru Maesaka
Merge from trunk and conflicts resolved
671
  return((bool) drizzle_real_query(drizzle, "rollback", 8));
1 by brian
clean slate
672
}
673
674
675
/*
676
  Set autocommit to either true or false
677
*/
678
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
679
bool drizzle_autocommit(DRIZZLE *drizzle, bool auto_mode)
1 by brian
clean slate
680
{
207.2.3 by Toru Maesaka
Merge from trunk and conflicts resolved
681
  return((bool) drizzle_real_query(drizzle, auto_mode ?
1 by brian
clean slate
682
                                         "set autocommit=1":"set autocommit=0",
683
                                         16));
684
}
685
686
687
/********************************************************************
688
 Multi query execution + SPs APIs
689
*********************************************************************/
690
691
/*
692
  Returns true/false to indicate whether any more query results exist
206.3.1 by Patrick Galbraith
Most everything working with client rename
693
  to be read using drizzle_next_result()
1 by brian
clean slate
694
*/
695
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
696
bool drizzle_more_results(const DRIZZLE *drizzle)
1 by brian
clean slate
697
{
236.3.3 by Andrey Hristov
Define a constant, instead of a magic number
698
  return (drizzle->server_status & SERVER_MORE_RESULTS_EXISTS) ? true:false;
1 by brian
clean slate
699
}
700
701
702
/*
703
  Reads and returns the next query results
704
*/
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
705
int drizzle_next_result(DRIZZLE *drizzle)
1 by brian
clean slate
706
{
206.3.1 by Patrick Galbraith
Most everything working with client rename
707
  if (drizzle->status != DRIZZLE_STATUS_READY)
1 by brian
clean slate
708
  {
390.1.6 by Monty Taylor
Oh dear god the changes. The changes. I'd tell you what they are, but I'd just be making stuff up. Suffice it to day it's mostly all around splitting files in libdrizzle into different files and removing interdepends. And whatever else I happened to see...
709
    drizzle_set_error(drizzle, CR_COMMANDS_OUT_OF_SYNC, sqlstate_get_unknown());
51.3.5 by Jay Pipes
Merged in from trunk.
710
    return(1);
1 by brian
clean slate
711
  }
712
206.3.1 by Patrick Galbraith
Most everything working with client rename
713
  net_clear_error(&drizzle->net);
714
  drizzle->affected_rows= ~(uint64_t) 0;
715
716
  if (drizzle->server_status & SERVER_MORE_RESULTS_EXISTS)
717
    return((*drizzle->methods->next_result)(drizzle));
718
719
  return(-1);        /* No more results */
720
}
721
722
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
723
DRIZZLE_RES * drizzle_use_result(DRIZZLE *drizzle)
206.3.1 by Patrick Galbraith
Most everything working with client rename
724
{
725
  return (*drizzle->methods->use_result)(drizzle);
726
}
727
287.3.3 by Monty Taylor
Removed STDCALL macros calls.
728
bool drizzle_read_query_result(DRIZZLE *drizzle)
206.3.1 by Patrick Galbraith
Most everything working with client rename
729
{
730
  return (*drizzle->methods->read_query_result)(drizzle);
1 by brian
clean slate
731
}
732