~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzle.cc

  • Committer: Monty Taylor
  • Date: 2010-06-02 17:55:52 UTC
  • mto: (1596.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1597.
  • Revision ID: mordred@inaugust.com-20100602175552-mxj2z7o12bvueuge
Removed the need for drizzled::internal usage in drizzle.cc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
#include <algorithm>
43
43
#include <limits.h>
44
44
#include <cassert>
45
 
#include "drizzled/charset_info.h"
46
45
#include <stdarg.h>
47
46
#include <math.h>
48
47
#include "client/linebuffer.h"
49
48
#include <signal.h>
50
49
#include <sys/ioctl.h>
51
50
#include <drizzled/configmake.h>
 
51
#include "drizzled/internal/utf8.h"
52
52
#include "drizzled/charset.h"
53
53
 
54
54
#if defined(HAVE_CURSES_H) && defined(HAVE_TERM_H)
318
318
static uint32_t delimiter_length= 1;
319
319
unsigned short terminal_width= 80;
320
320
 
321
 
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
322
 
 
323
321
int drizzleclient_real_query_for_lazy(const char *buf, int length,
324
322
                                      drizzle_result_st *result,
325
323
                                      uint32_t *error_code);
1658
1656
      status.setLineBuff(opt_max_input_line,NULL);
1659
1657
    if (status.getLineBuff() == NULL)
1660
1658
    {
1661
 
      internal::my_end();
1662
1659
      exit(1);
1663
1660
    }
1664
1661
    status.getLineBuff()->addString(vm["execute"].as<string>().c_str());
1725
1722
  }
1726
1723
  if(vm.count("version"))
1727
1724
  {
1728
 
    printf(_("%s  Ver %s Distrib %s, for %s-%s (%s) using readline %s\n"),
1729
 
    internal::my_progname, VER.c_str(), drizzle_version(),
1730
 
    HOST_VENDOR, HOST_OS, HOST_CPU,
1731
 
    rl_library_version);
 
1725
    printf(_("drizzle  Ver %s Distrib %s, for %s-%s (%s) using readline %s\n"),
 
1726
           VER.c_str(), drizzle_version(),
 
1727
           HOST_VENDOR, HOST_OS, HOST_CPU,
 
1728
           rl_library_version);
1732
1729
 
1733
1730
    exit(0);
1734
1731
  }
1735
1732
  
1736
1733
  if(vm.count("help"))
1737
1734
  {
1738
 
    printf(_("%s  Ver %s Distrib %s, for %s-%s (%s) using readline %s\n"),
1739
 
    internal::my_progname, VER.c_str(), drizzle_version(),
1740
 
    HOST_VENDOR, HOST_OS, HOST_CPU,
1741
 
    rl_library_version);
 
1735
    printf(_("drizzle  Ver %s Distrib %s, for %s-%s (%s) using readline %s\n"),
 
1736
           VER.c_str(), drizzle_version(),
 
1737
           HOST_VENDOR, HOST_OS, HOST_CPU,
 
1738
           rl_library_version);
1742
1739
    printf(_("Copyright (C) 2008 Sun Microsystems\n"
1743
1740
           "This software comes with ABSOLUTELY NO WARRANTY. "
1744
1741
           "This is free software,\n"
1745
1742
           "and you are welcome to modify and redistribute it "
1746
1743
           "under the GPL license\n"));
1747
 
    printf(_("Usage: %s [OPTIONS] [database]\n"), internal::my_progname);
 
1744
    printf(_("Usage: drizzle [OPTIONS] [database]\n"));
1748
1745
    cout<<long_options;
1749
1746
    exit(0);
1750
1747
  }
1879
1876
    if (verbose)
1880
1877
      tee_fprintf(stdout, _("Writing history-file %s\n"),histfile);
1881
1878
    if (!write_history(histfile_tmp))
1882
 
      internal::my_rename(histfile_tmp, histfile, MYF(MY_WME));
 
1879
      rename(histfile_tmp, histfile);
1883
1880
  }
1884
1881
  delete status.getLineBuff();
1885
1882
  status.setLineBuff(0);
2102
2099
  }
2103
2100
  else
2104
2101
  {
2105
 
    while (my_isspace(charset_info,*name))
 
2102
    while (isspace(*name))
2106
2103
      name++;
2107
2104
    /*
2108
2105
      If there is an \\g in the row or if the row has a delimiter but
2111
2108
    */
2112
2109
    if (strstr(name, "\\g") || (strstr(name, delimiter) &&
2113
2110
                                !(strlen(name) >= 9 &&
2114
 
                                  !my_strnncoll(charset_info,
2115
 
                                                (unsigned char*) name, 9,
2116
 
                                                (const unsigned char*) "delimiter",
2117
 
                                                9))))
 
2111
                                  !strcmp(name, "delimiter"))))
2118
2112
      return(NULL);
2119
2113
    if ((end=strcont(name," \t")))
2120
2114
    {
2121
2115
      len=(uint32_t) (end - name);
2122
 
      while (my_isspace(charset_info,*end))
 
2116
      while (isspace(*end))
2123
2117
        end++;
2124
2118
      if (!*end)
2125
2119
        end=0;          // no arguments to function
2131
2125
  for (uint32_t i= 0; commands[i].getName(); i++)
2132
2126
  {
2133
2127
    if (commands[i].func &&
2134
 
        ((name && !my_strnncoll(charset_info,(const unsigned char*)name,len, (const unsigned char*)commands[i].getName(),len) && !commands[i].getName()[len] && (!end || (end && commands[i].getTakesParams()))) || (!name && commands[i].getCmdChar() == cmd_char)))
 
2128
        ((name && !strncmp(name, commands[i].getName(), len)
 
2129
          && !commands[i].getName()[len] && (!end || (end && commands[i].getTakesParams()))) || (!name && commands[i].getCmdChar() == cmd_char)))
2135
2130
    {
2136
2131
      return(&commands[i]);
2137
2132
    }
2161
2156
    if (!preserve_comments)
2162
2157
    {
2163
2158
      // Skip spaces at the beggining of a statement
2164
 
      if (my_isspace(charset_info,inchar) && (out == line) &&
 
2159
      if (isspace(inchar) && (out == line) &&
2165
2160
          (buffer->empty()))
2166
2161
        continue;
2167
2162
    }
2168
2163
 
2169
2164
    // Accept multi-byte characters as-is
2170
2165
    int length;
2171
 
    if (use_mb(charset_info) &&
2172
 
        (length= my_ismbchar(charset_info, pos, end_of_line)))
 
2166
    if ((length= U8_LENGTH(*pos)))
2173
2167
    {
2174
2168
      if (!*ml_comment || preserve_comments)
2175
2169
      {
2248
2242
    }
2249
2243
    else if (!*ml_comment && !*in_string &&
2250
2244
             (end_of_line - pos) >= 10 &&
2251
 
             !my_strnncoll(charset_info, (unsigned char*) pos, 10,
2252
 
                           (const unsigned char*) "delimiter ", 10))
 
2245
             !strncmp(pos, "delimiter ", 10))
2253
2246
    {
2254
2247
      // Flush previously accepted characters
2255
2248
      if (out != line)
2286
2279
 
2287
2280
      if (preserve_comments)
2288
2281
      {
2289
 
        while (my_isspace(charset_info, *pos))
 
2282
        while (isspace(*pos))
2290
2283
          *out++= *pos++;
2291
2284
      }
2292
2285
      // Flush previously accepted characters
2299
2292
      if (preserve_comments && ((*pos == '#') ||
2300
2293
                                ((*pos == '-') &&
2301
2294
                                 (pos[1] == '-') &&
2302
 
                                 my_isspace(charset_info, pos[2]))))
 
2295
                                 isspace(pos[2]))))
2303
2296
      {
2304
2297
        // Add trailing single line comments to this statement
2305
2298
        buffer->append(pos);
2326
2319
                 && (inchar == '#'
2327
2320
                     || (inchar == '-'
2328
2321
                         && pos[1] == '-'
2329
 
                         && my_isspace(charset_info,pos[2])))))
 
2322
                         && isspace(pos[2])))))
2330
2323
    {
2331
2324
      // Flush previously accepted characters
2332
2325
      if (out != line)
2392
2385
        *in_string= (char) inchar;
2393
2386
      if (!*ml_comment || preserve_comments)
2394
2387
      {
2395
 
        if (need_space && !my_isspace(charset_info, (char)inchar))
 
2388
        if (need_space && !isspace((char)inchar))
2396
2389
          *out++= ' ';
2397
2390
        need_space= 0;
2398
2391
        *out++= (char) inchar;
3133
3126
                "Database:   `%s`\n"
3134
3127
                "Table:      `%s`\n"
3135
3128
                "Org_table:  `%s`\n"
3136
 
                "Type:       %s\n"
 
3129
                "Type:       UTF-8\n"
3137
3130
                "Collation:  %s (%u)\n"
3138
3131
                "Length:     %lu\n"
3139
3132
                "Max_length: %lu\n"
3144
3137
                drizzle_column_db(field), drizzle_column_table(field),
3145
3138
                drizzle_column_orig_table(field),
3146
3139
                fieldtype2str(drizzle_column_type(field)),
3147
 
                get_charset_name(drizzle_column_charset(field)),
3148
3140
                drizzle_column_charset(field), drizzle_column_size(field),
3149
3141
                drizzle_column_max_size(field), drizzle_column_decimals(field),
3150
3142
                fieldflags2str(drizzle_column_flags(field)));
3184
3176
      /* Check if the max_byte value is really the maximum in terms
3185
3177
         of visual length since multibyte characters can affect the
3186
3178
         length of the separator. */
3187
 
      length= charset_info->cset->numcells(charset_info,
3188
 
                                           drizzle_column_name(field),
3189
 
                                           drizzle_column_name(field) +
3190
 
                                           name_length);
 
3179
      length= U8_LENGTH(*(drizzle_column_name(field)));
3191
3180
 
3192
3181
      if (name_length == drizzle_column_max_size(field))
3193
3182
      {
3225
3214
    for (uint32_t off=0; (field = drizzle_column_next(result)) ; off++)
3226
3215
    {
3227
3216
      uint32_t name_length= (uint32_t) strlen(drizzle_column_name(field));
3228
 
      uint32_t numcells= charset_info->cset->numcells(charset_info,
3229
 
                                                  drizzle_column_name(field),
3230
 
                                                  drizzle_column_name(field) +
3231
 
                                                  name_length);
 
3217
      uint32_t numcells= U8_LENGTH(*drizzle_column_name(field));
3232
3218
      uint32_t display_length= drizzle_column_max_size(field) + name_length -
3233
3219
                               numcells;
3234
3220
      tee_fprintf(PAGER, " %-*s |",(int) min(display_length,
3291
3277
        We need to find how much screen real-estate we will occupy to know how
3292
3278
        many extra padding-characters we should send with the printing function.
3293
3279
      */
3294
 
      visible_length= charset_info->cset->numcells(charset_info, buffer, buffer + data_length);
 
3280
      visible_length= U8_LENGTH(*buffer);
3295
3281
      extra_padding= data_length - visible_length;
3296
3282
 
3297
3283
      if (field_max_length > MAX_COLUMN_LENGTH)
3519
3505
    else for (const char *end=pos+length ; pos != end ; pos++)
3520
3506
    {
3521
3507
      int l;
3522
 
      if (use_mb(charset_info) &&
3523
 
          (l = my_ismbchar(charset_info, pos, end)))
 
3508
      if ((l = U8_LENGTH(*pos)))
3524
3509
      {
3525
3510
        while (l--)
3526
3511
          tee_putc(*pos++, PAGER);
3599
3584
 
3600
3585
  if (status.getBatch())
3601
3586
    return 0;
3602
 
  while (my_isspace(charset_info,*line))
 
3587
  while (isspace(*line))
3603
3588
    line++;
3604
3589
  if (!(param = strchr(line, ' '))) // if outfile wasn't given, use the default
3605
3590
  {
3618
3603
  }
3619
3604
 
3620
3605
  /* eliminate the spaces before the parameters */
3621
 
  while (my_isspace(charset_info,*param))
 
3606
  while (isspace(*param))
3622
3607
    param++;
3623
3608
  strncpy(file_name, param, sizeof(file_name) - 1);
3624
3609
  end= file_name + strlen(file_name);
3625
3610
  /* remove end space from command line */
3626
 
  while (end > file_name && (my_isspace(charset_info,end[-1]) ||
3627
 
                             my_iscntrl(charset_info,end[-1])))
 
3611
  while (end > file_name && (isspace(end[-1]) ||
 
3612
                             iscntrl(end[-1])))
3628
3613
    end--;
3629
3614
  end[0]= 0;
3630
3615
  if (end == file_name)
3659
3644
  if (status.getBatch())
3660
3645
    return 0;
3661
3646
  /* Skip spaces in front of the pager command */
3662
 
  while (my_isspace(charset_info, *line))
 
3647
  while (isspace(*line))
3663
3648
    line++;
3664
3649
  /* Skip the pager command */
3665
3650
  param= strchr(line, ' ');
3666
3651
  /* Skip the spaces between the command and the argument */
3667
 
  while (param && my_isspace(charset_info, *param))
 
3652
  while (param && isspace(*param))
3668
3653
    param++;
3669
3654
  if (!param || !strlen(param)) // if pager was not given, use the default
3670
3655
  {
3682
3667
  {
3683
3668
    end= strncpy(pager_name, param, sizeof(pager_name)-1);
3684
3669
    end+= strlen(pager_name);
3685
 
    while (end > pager_name && (my_isspace(charset_info,end[-1]) ||
3686
 
                                my_iscntrl(charset_info,end[-1])))
 
3670
    while (end > pager_name && (isspace(end[-1]) ||
 
3671
                                iscntrl(end[-1])))
3687
3672
      end--;
3688
3673
    end[0]=0;
3689
3674
    strcpy(pager, pager_name);
3804
3789
  FILE *sql_file;
3805
3790
 
3806
3791
  /* Skip space from file name */
3807
 
  while (my_isspace(charset_info,*line))
 
3792
  while (isspace(*line))
3808
3793
    line++;
3809
3794
  if (!(param = strchr(line, ' ')))    // Skip command name
3810
3795
    return put_info("Usage: \\. <filename> | source <filename>",
3811
3796
                    INFO_ERROR, 0,0);
3812
 
  while (my_isspace(charset_info,*param))
 
3797
  while (isspace(*param))
3813
3798
    param++;
3814
3799
  end= strncpy(source_name,param,sizeof(source_name)-1);
3815
3800
  end+= strlen(source_name);
3816
 
  while (end > source_name && (my_isspace(charset_info,end[-1]) ||
3817
 
                               my_iscntrl(charset_info,end[-1])))
 
3801
  while (end > source_name && (isspace(end[-1]) ||
 
3802
                               iscntrl(end[-1])))
3818
3803
    end--;
3819
3804
  end[0]=0;
3820
 
  internal::unpack_filename(source_name,source_name);
 
3805
 
3821
3806
  /* open file name */
3822
3807
  if (!(sql_file = fopen(source_name, "r")))
3823
3808
  {
4013
3998
  else
4014
3999
  {
4015
4000
    /* skip leading white spaces */
4016
 
    while (my_isspace(charset_info, *ptr))
 
4001
    while (isspace(*ptr))
4017
4002
      ptr++;
4018
4003
    if (*ptr == '\\') // short command was used
4019
4004
      ptr+= 2;
4020
4005
    else
4021
 
      while (*ptr &&!my_isspace(charset_info, *ptr)) // skip command
 
4006
      while (*ptr &&!isspace(*ptr)) // skip command
4022
4007
        ptr++;
4023
4008
  }
4024
4009
  if (!*ptr)
4025
4010
    return NULL;
4026
 
  while (my_isspace(charset_info, *ptr))
 
4011
  while (isspace(*ptr))
4027
4012
    ptr++;
4028
4013
  if (*ptr == '\'' || *ptr == '\"' || *ptr == '`')
4029
4014
  {
4118
4103
  drizzle_return_t ret;
4119
4104
 
4120
4105
  tee_puts("--------------", stdout);
4121
 
  printf(_("%s  Ver %s Distrib %s, for %s-%s (%s) using readline %s\n"),
4122
 
  internal::my_progname, VER.c_str(), drizzle_version(),
 
4106
  printf(_("drizzle  Ver %s Distrib %s, for %s-%s (%s) using readline %s\n"),
 
4107
  VER.c_str(), drizzle_version(),
4123
4108
  HOST_VENDOR, HOST_OS, HOST_CPU,
4124
4109
  rl_library_version);          /* Print version */
4125
4110
 
4330
4315
{
4331
4316
  const char *start=  buffer->c_str();
4332
4317
  const char *end= start + (buffer->length());
4333
 
  while (start < end && !my_isgraph(charset_info,end[-1]))
 
4318
  while (start < end && !isgraph(end[-1]))
4334
4319
    end--;
4335
4320
  uint32_t pos_to_truncate= (end-start);
4336
4321
  if (buffer->length() > pos_to_truncate)