~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/libdrizzle.c

  • Committer: Monty Taylor
  • Date: 2008-09-16 06:40:44 UTC
  • mfrom: (390.1.7 client-split)
  • Revision ID: monty@inaugust.com-20080916064044-vbgmaf36cvm8jufx
Merged in from client-split.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2004 DRIZZLE AB
2
 
 
3
 
   This program is free software; you can redistribute it and/or modify
4
 
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation.
6
 
 
7
 
   There are special exceptions to the terms and conditions of the GPL as it
8
 
   is applied to this software. View the full text of the exception in file
9
 
   EXCEPTIONS-CLIENT in the directory of this software distribution.
10
 
 
11
 
   This program is distributed in the hope that it will be useful,
12
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
   GNU General Public License for more details.
15
 
 
16
 
   You should have received a copy of the GNU General Public License
17
 
   along with this program; if not, write to the Free Software
18
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
19
 
 
20
 
#include <drizzled/global.h>
 
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
 */
 
19
 
21
20
#include "libdrizzle.h"
 
21
#include "libdrizzle_priv.h"
22
22
#include "errmsg.h"
23
23
#include <sys/stat.h>
24
24
#include <signal.h>
48
48
#define INADDR_NONE  -1
49
49
#endif
50
50
 
 
51
#include <stdlib.h>
 
52
#include <string.h>
 
53
 
51
54
#include <sql_common.h>
52
55
#include <drizzled/version.h>
53
56
 
72
75
uint32_t     net_buffer_length= 8192;
73
76
uint32_t    max_allowed_packet= 1024L*1024L*1024L;
74
77
 
 
78
unsigned int drizzle_port=0;
 
79
 
75
80
#include <errno.h>
76
81
#define SOCKET_ERROR -1
77
82
 
91
96
  return &drizzle_internal_parameters;
92
97
}
93
98
 
 
99
unsigned int drizzle_get_default_port(void)
 
100
{
 
101
  return drizzle_port;
 
102
}
 
103
 
 
104
void drizzle_set_default_port(unsigned int port)
 
105
{
 
106
  drizzle_port= port;
 
107
}
 
108
 
94
109
/*
95
110
  Expand wildcard to a sql string
96
111
*/
171
186
  }
172
187
 
173
188
  /* Write authentication package */
174
 
  (void)simple_command(drizzle,COM_CHANGE_USER, (uchar*) buff, (uint32_t) (end-buff), 1);
 
189
  (void)simple_command(drizzle,COM_CHANGE_USER, (unsigned char*) buff, (uint32_t) (end-buff), 1);
175
190
 
176
191
  rc= (*drizzle->methods->read_change_user_result)(drizzle);
177
192
 
312
327
  end= strncpy(end+1, wild ? wild : "", 128) + 128;
313
328
 
314
329
  free_old_query(drizzle);
315
 
  if (simple_command(drizzle, COM_FIELD_LIST, (uchar*) buff,
 
330
  if (simple_command(drizzle, COM_FIELD_LIST, (unsigned char*) buff,
316
331
                     (uint32_t) (end-buff), 1) ||
317
332
      !(fields= (*drizzle->methods->list_fields)(drizzle)))
318
333
    return(NULL);
337
352
{
338
353
  DRIZZLE_DATA *fields;
339
354
  uint field_count;
340
 
  uchar *pos;
 
355
  unsigned char *pos;
341
356
 
342
357
  if (simple_command(drizzle,COM_PROCESS_INFO,0,0,0))
343
358
    return(0);
344
359
  free_old_query(drizzle);
345
 
  pos=(uchar*) drizzle->net.read_pos;
 
360
  pos=(unsigned char*) drizzle->net.read_pos;
346
361
  field_count=(uint) net_field_length(&pos);
347
362
  if (!(fields = (*drizzle->methods->read_rows)(drizzle,(DRIZZLE_FIELD*) 0, 7)))
348
363
    return(NULL);
357
372
int
358
373
drizzle_shutdown(DRIZZLE *drizzle, enum drizzle_enum_shutdown_level shutdown_level)
359
374
{
360
 
  uchar level[1];
361
 
  level[0]= (uchar) shutdown_level;
 
375
  unsigned char level[1];
 
376
  level[0]= (unsigned char) shutdown_level;
362
377
  return(simple_command(drizzle, COM_SHUTDOWN, level, 1, 0));
363
378
}
364
379
 
366
381
int
367
382
drizzle_refresh(DRIZZLE *drizzle,uint options)
368
383
{
369
 
  uchar bits[1];
370
 
  bits[0]= (uchar) options;
 
384
  unsigned char bits[1];
 
385
  bits[0]= (unsigned char) options;
371
386
  return(simple_command(drizzle, COM_REFRESH, bits, 1, 0));
372
387
}
373
388
 
375
390
int32_t
376
391
drizzle_kill(DRIZZLE *drizzle, uint32_t pid)
377
392
{
378
 
  uchar buff[4];
 
393
  unsigned char buff[4];
379
394
  int4store(buff,pid);
380
395
  return(simple_command(drizzle,COM_PROCESS_KILL,buff,sizeof(buff),0));
381
396
}
384
399
int
385
400
drizzle_set_server_option(DRIZZLE *drizzle, enum enum_drizzle_set_option option)
386
401
{
387
 
  uchar buff[2];
 
402
  unsigned char buff[2];
388
403
  int2store(buff, (uint) option);
389
404
  return(simple_command(drizzle, COM_SET_OPTION, buff, sizeof(buff), 0));
390
405
}
395
410
  drizzle->net.read_pos[drizzle->packet_length]=0;  /* End of stat string */
396
411
  if (!drizzle->net.read_pos[0])
397
412
  {
398
 
    set_drizzle_error(drizzle, CR_WRONG_HOST_INFO, unknown_sqlstate);
 
413
    drizzle_set_error(drizzle, CR_WRONG_HOST_INFO, sqlstate_get_unknown());
399
414
    return drizzle->net.last_error;
400
415
  }
401
416
  return (char*) drizzle->net.read_pos;
488
503
 
489
504
const char * drizzle_sqlstate(const DRIZZLE *drizzle)
490
505
{
491
 
  return drizzle ? drizzle->net.sqlstate : cant_connect_sqlstate;
 
506
  return drizzle ? drizzle->net.sqlstate : sqlstate_get_cant_connect();
492
507
}
493
508
 
494
509
uint32_t drizzle_warning_count(const DRIZZLE *drizzle)
520
535
  my_net_set_read_timeout(net, CLIENT_NET_READ_TIMEOUT);
521
536
  my_net_set_write_timeout(net, CLIENT_NET_WRITE_TIMEOUT);
522
537
  net->retry_count=  1;
523
 
  net->max_packet_size= max(net_buffer_length, max_allowed_packet);
 
538
  net->max_packet_size= (net_buffer_length > max_allowed_packet) ?
 
539
    net_buffer_length : max_allowed_packet;
524
540
}
525
541
 
526
542
/*
699
715
{
700
716
  if (drizzle->status != DRIZZLE_STATUS_READY)
701
717
  {
702
 
    set_drizzle_error(drizzle, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
 
718
    drizzle_set_error(drizzle, CR_COMMANDS_OUT_OF_SYNC, sqlstate_get_unknown());
703
719
    return(1);
704
720
  }
705
721