~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzle.cc

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 *
35
35
 **/
36
36
 
37
 
#include <config.h>
 
37
#include "config.h"
38
38
#include <libdrizzle/drizzle_client.h>
39
39
 
40
 
#include "server_detect.h"
41
 
#include "get_password.h"
 
40
#include "client/get_password.h"
42
41
 
43
 
#include <boost/date_time/posix_time/posix_time.hpp>
 
42
#include "boost/date_time/posix_time/posix_time.hpp"
44
43
 
45
44
#include <cerrno>
46
45
#include <string>
54
53
#include <stdarg.h>
55
54
#include <math.h>
56
55
#include <memory>
57
 
#include <client/linebuffer.h>
 
56
#include "client/linebuffer.h"
58
57
#include <signal.h>
59
58
#include <sys/ioctl.h>
60
59
#include <drizzled/configmake.h>
61
 
#include <drizzled/utf8/utf8.h>
 
60
#include "drizzled/utf8/utf8.h"
62
61
#include <cstdlib>
63
62
 
64
63
#if defined(HAVE_CURSES_H) && defined(HAVE_TERM_H)
152
151
#endif
153
152
#include <boost/program_options.hpp>
154
153
#include <boost/scoped_ptr.hpp>
155
 
#include <drizzled/program_options/config_file.h>
 
154
#include "drizzled/program_options/config_file.h"
156
155
 
157
156
using namespace std;
158
157
namespace po=boost::program_options;
308
307
static uint32_t select_limit;
309
308
static uint32_t max_join_size;
310
309
static uint32_t opt_connect_timeout= 0;
311
 
static ServerDetect::server_type server_type= ServerDetect::SERVER_UNKNOWN_FOUND;
312
310
std::string current_db,
313
311
  delimiter_str,  
314
312
  current_host,
430
428
static void add_int_to_prompt(int toadd);
431
429
static int get_result_width(drizzle_result_st *res);
432
430
static int get_field_disp_length(drizzle_column_st * field);
433
 
static const char * strcont(const char *str, const char *set);
 
431
static const char * strcont(register const char *str, register const char *set);
434
432
 
435
433
/* A class which contains information on the commands this program
436
434
   can understand. */
2762
2760
static int
2763
2761
com_help(string *buffer, const char *)
2764
2762
{
2765
 
  int i, j;
 
2763
  register int i, j;
2766
2764
  char buff[32], *end;
2767
2765
  std::vector<char> output_buff;
2768
2766
  output_buff.resize(512);
3130
3128
  drizzle_return_t ret;
3131
3129
  drizzle_column_st *field;
3132
3130
  std::vector<bool> num_flag;
3133
 
  std::vector<bool> boolean_flag;
3134
 
  std::vector<bool> ansi_boolean_flag;
3135
3131
  string separator;
3136
3132
 
3137
3133
  separator.reserve(256);
3138
3134
 
3139
3135
  num_flag.resize(drizzle_result_column_count(result));
3140
 
  boolean_flag.resize(drizzle_result_column_count(result));
3141
 
  ansi_boolean_flag.resize(drizzle_result_column_count(result));
3142
3136
  if (column_types_flag)
3143
3137
  {
3144
3138
    print_field_types(result);
3181
3175
      // Room for "NULL"
3182
3176
      length=4;
3183
3177
    }
3184
 
    if ((length < 5) and 
3185
 
      (server_type == ServerDetect::SERVER_DRIZZLE_FOUND) and
3186
 
      (drizzle_column_type(field) == DRIZZLE_COLUMN_TYPE_TINY) and
3187
 
      (drizzle_column_type(field) & DRIZZLE_COLUMN_FLAGS_UNSIGNED))
3188
 
    {
3189
 
      // Room for "FALSE"
3190
 
      length= 5;
3191
 
    }
3192
3178
    drizzle_column_set_max_size(field, length);
3193
3179
 
3194
3180
    for (x=0; x< (length+2); x++)
3212
3198
                  drizzle_column_name(field));
3213
3199
      num_flag[off]= ((drizzle_column_type(field) <= DRIZZLE_COLUMN_TYPE_LONGLONG) ||
3214
3200
                      (drizzle_column_type(field) == DRIZZLE_COLUMN_TYPE_NEWDECIMAL));
3215
 
      if ((server_type == ServerDetect::SERVER_DRIZZLE_FOUND) and
3216
 
        (drizzle_column_type(field) == DRIZZLE_COLUMN_TYPE_TINY))
3217
 
      {
3218
 
        if ((drizzle_column_flags(field) & DRIZZLE_COLUMN_FLAGS_UNSIGNED))
3219
 
        {
3220
 
          ansi_boolean_flag[off]= true;
3221
 
        }
3222
 
        else
3223
 
        {
3224
 
          ansi_boolean_flag[off]= false;
3225
 
        }
3226
 
        boolean_flag[off]= true;
3227
 
        num_flag[off]= false;
3228
 
      }
3229
 
      else
3230
 
      {
3231
 
        boolean_flag[off]= false;
3232
 
      }
3233
3201
    }
3234
3202
    (void) tee_fputs("\n", PAGER);
3235
3203
    tee_puts((char*) separator.c_str(), PAGER);
3268
3236
        buffer= "NULL";
3269
3237
        data_length= 4;
3270
3238
      }
3271
 
      else if (boolean_flag[off])
3272
 
      {
3273
 
        if (strncmp(cur[off],"1", 1) == 0)
3274
 
        {
3275
 
          if (ansi_boolean_flag[off])
3276
 
          {
3277
 
            buffer= "YES";
3278
 
            data_length= 3;
3279
 
          }
3280
 
          else
3281
 
          {
3282
 
            buffer= "TRUE";
3283
 
            data_length= 4;
3284
 
          }
3285
 
        }
3286
 
        else
3287
 
        {
3288
 
          if (ansi_boolean_flag[off])
3289
 
          {
3290
 
            buffer= "NO";
3291
 
            data_length= 2;
3292
 
          }
3293
 
          else
3294
 
          {
3295
 
            buffer= "FALSE";
3296
 
            data_length= 5;
3297
 
          }
3298
 
        }
3299
 
      }
3300
3239
      else
3301
3240
      {
3302
3241
        buffer= cur[off];
3570
3509
  drizzle_return_t ret;
3571
3510
  drizzle_column_st *field;
3572
3511
  size_t *lengths;
3573
 
  std::vector<bool> boolean_flag;
3574
 
  std::vector<bool> ansi_boolean_flag;
3575
 
 
3576
 
  boolean_flag.resize(drizzle_result_column_count(result));
3577
 
  ansi_boolean_flag.resize(drizzle_result_column_count(result));
3578
 
 
3579
 
  int first=0;
3580
 
  for (uint32_t off= 0; (field = drizzle_column_next(result)); off++)
 
3512
 
 
3513
  if (opt_silent < 2 && column_names)
3581
3514
  {
3582
 
    if (opt_silent < 2 && column_names)
 
3515
    int first=0;
 
3516
    while ((field = drizzle_column_next(result)))
3583
3517
    {
3584
3518
      if (first++)
3585
3519
        (void) tee_fputs("\t", PAGER);
3586
3520
      (void) tee_fputs(drizzle_column_name(field), PAGER);
3587
3521
    }
3588
 
    if ((server_type == ServerDetect::SERVER_DRIZZLE_FOUND) and
3589
 
      (drizzle_column_type(field) == DRIZZLE_COLUMN_TYPE_TINY))
3590
 
    {
3591
 
      if ((drizzle_column_flags(field) & DRIZZLE_COLUMN_FLAGS_UNSIGNED))
3592
 
      {
3593
 
        ansi_boolean_flag[off]= true;
3594
 
      }
3595
 
      else
3596
 
      {
3597
 
        ansi_boolean_flag[off]= false;
3598
 
      }
3599
 
      boolean_flag[off]= true;
3600
 
    }
3601
 
    else
3602
 
    {
3603
 
      boolean_flag[off]= false;
3604
 
    }
3605
 
  }
3606
 
  if (opt_silent < 2 && column_names)
3607
 
  {
3608
3522
    (void) tee_fputs("\n", PAGER);
3609
3523
  }
3610
3524
  while (1)
3625
3539
      break;
3626
3540
 
3627
3541
    lengths= drizzle_row_field_sizes(result);
3628
 
    drizzle_column_seek(result, 0);
3629
 
    for (uint32_t off=0 ; off < drizzle_result_column_count(result); off++)
 
3542
    safe_put_field(cur[0],lengths[0]);
 
3543
    for (uint32_t off=1 ; off < drizzle_result_column_count(result); off++)
3630
3544
    {
3631
 
      if (off != 0)
3632
 
        (void) tee_fputs("\t", PAGER);
3633
 
      if (boolean_flag[off])
3634
 
      {
3635
 
        if (strncmp(cur[off],"1", 1) == 0)
3636
 
        {
3637
 
          if (ansi_boolean_flag[off])
3638
 
          {
3639
 
            safe_put_field("YES", 3);
3640
 
          }
3641
 
          else
3642
 
          {
3643
 
            safe_put_field("TRUE", 4);
3644
 
          }
3645
 
        }
3646
 
        else
3647
 
        {
3648
 
          if (ansi_boolean_flag[off])
3649
 
          {
3650
 
            safe_put_field("NO", 2);
3651
 
          }
3652
 
          else
3653
 
          {
3654
 
            safe_put_field("FALSE", 5);
3655
 
          }
3656
 
        }
3657
 
      }
3658
 
      else
3659
 
      {
3660
 
        safe_put_field(cur[off], lengths[off]);
3661
 
      }
 
3545
      (void) tee_fputs("\t", PAGER);
 
3546
      safe_put_field(cur[off], lengths[off]);
3662
3547
    }
3663
3548
    (void) tee_fputs("\n", PAGER);
3664
3549
    if (quick)
4223
4108
  }
4224
4109
  connected=1;
4225
4110
 
4226
 
  ServerDetect server_detect(&con);
4227
 
  server_type= server_detect.getServerType();
4228
 
 
4229
4111
  build_completion_hash(opt_rehash, 1);
4230
4112
  return 0;
4231
4113
}
4779
4661
    if there isn't anything found.
4780
4662
*/
4781
4663
 
4782
 
static const char * strcont(const char *str, const char *set)
 
4664
static const char * strcont(register const char *str, register const char *set)
4783
4665
{
4784
 
  const char * start = (const char *) set;
 
4666
  register const char * start = (const char *) set;
4785
4667
 
4786
4668
  while (*str)
4787
4669
  {