~mathiaz/ubuntu/lucid/mysql-dfsg-5.1/zap-bug-552053

« back to all changes in this revision

Viewing changes to client/mysql.cc

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug
  • Date: 2009-06-25 12:55:45 UTC
  • mfrom: (1.1.2 upstream) (0.1.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20090625125545-m8ogs96zzsri74xe
Tags: 5.1.34-1ubuntu1
* Merge from debian experimental (and 5.0 from main), remaining changes:
  - debian/mysql-server-5.1.config:
    + ask for MySQL root password at priority high instead of medium so
      that the password prompt is seen on a default install. (LP: #319843)
    + don't ask for root password when upgrading from a 5.0 install.
  - debian/control:
    + Make libmysqlclient16-dev a transitional package depending on
      libmysqlclient-dev.
    + Make libmysqlclient-dev conflict with libmysqlclient15-dev.
    + Don't build mysql-server, mysql-client, mysql-common and
      libmysqlclient15-dev binary packages since they're still provided
      by mysql-dfsg-5.0.
    + Make mysql-{client,server}-5.1 packages conflict and
      replace mysql-{client,server}-5.0, but not provide
      mysql-{client,server}.
    + Depend on a specific version of mysql-common rather than the src
      version of mysql-dfsg-5.1 since mysql-common is currently part of
      mysql-dfsg-5.0.
    + Lower mailx from a Recommends to a Suggests to avoid pulling in
      a full MTA on all installs of mysql-server. (LP: #259477)
  - debian/rules:
    + added -fno-strict-aliasing to CFLAGS to get around mysql testsuite
      build failures.
    + install mysql-test and sql-bench to /usr/share/mysql/ rather than
      /usr/.
  - debian/additions/debian-start.inc.sh: support ANSI mode (LP: #310211)
  - Add AppArmor profile:
    - debian/apparmor-profile: apparmor profile.
    - debian/rules, debian/mysql-server-5.0.files: install apparmor profile.
    - debian/mysql-server-5.0.dirs: add etc/apparmor.d/force-complain
    - debian/mysql-server-5.0.postrm: remove symlink in force-complain/ on
      purge.
    - debian/mysql-server-5.1.README.Debian: add apparmor documentation.
    - debian/additions/my.cnf: Add warning about apparmor. (LP: #201799)
    - debian/mysql-server-5.1.postinst: reload apparmor profiles.
  - debian/additions/my.cnf: remove language option. Error message files are
    located in a different directory in MySQL 5.0. Setting the language
    option to use /usr/share/mysql/english breaks 5.0. Both 5.0 and 5.1
    use a default value that works. (LP: #316974)
  - debian/mysql-server-5.1.mysql.init:
    + Clearly indicate that we do not support running multiple instances
      of mysqld by duplicating the init script.
      (closes: #314785, #324834, #435165, #444216)
    + Properly parameterize all existing references to the mysql config
      file (/etc/mysql/my.cnf).
  - debian/mysql-server-5.0.postinst: Clear out the second password
    when setting up mysql. (LP: #344816)
  - mysql-server-core-5.1 package for files needed by Akonadi:
    + debian/control: create mysql-server-core-5.1 package.
    + debian/mysql-server-core-5.1.files, debian/mysql-server-5.1.files:
      move core mysqld files to mysql-server-core-5.1 package.
  - Don't package sql-bench and mysql-test file.
* Dropped changes:
  - debian/patches/92_ssl_test_cert.dpatch: certificate expiration in
    test suite (LP: #323755). Included upstream.
* Dropped from 5.0:
  - apparmor profile:
    - debian/control: Recommends apparmor >= 2.1+1075-0ubuntu6. All version
      of apparmor-profile (>hardy) are higher than this version.
    - debian/mysql-server-5.0.preinst: create symlink for force-complain/
      on pre-feisty upgrades, upgrades where apparmor-profiles profile is
      unchanged (ie non-enforcing) and upgrades where the profile
      doesn't exist. Support for pre-hardy upgrades is no longer needed.
* debian/mysql-server-5.1.postinst: fix debian-sys-maint user creation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
#define MAX_COLUMN_LENGTH            1024
50
50
 
51
51
/* Buffer to hold 'version' and 'version_comment' */
52
 
#define MAX_SERVER_VERSION_LENGTH     128
 
52
static char *server_version= NULL;
53
53
 
54
54
/* Array of options to pass to libemysqld */
55
55
#define MAX_SERVER_ARGS               64
115
115
#define PROMPT_CHAR '\\'
116
116
#define DEFAULT_DELIMITER ";"
117
117
 
 
118
#define MAX_BATCH_BUFFER_SIZE (1024L * 1024L)
 
119
 
118
120
typedef struct st_status
119
121
{
120
122
  int exit_status;
250
252
  { "connect",'r', com_connect,1,
251
253
    "Reconnect to the server. Optional arguments are db and host." },
252
254
  { "delimiter", 'd', com_delimiter,    1,
253
 
    "Set statement delimiter. NOTE: Takes the rest of the line as new delimiter." },
 
255
    "Set statement delimiter." },
254
256
#ifdef USE_POPEN
255
257
  { "edit",   'e', com_edit,   0, "Edit command with $EDITOR."},
256
258
#endif
1045
1047
 
1046
1048
static COMMANDS *find_command(char *name,char cmd_name);
1047
1049
static bool add_line(String &buffer,char *line,char *in_string,
1048
 
                     bool *ml_comment);
 
1050
                     bool *ml_comment, bool truncated);
1049
1051
static void remove_cntrl(String &buffer);
1050
1052
static void print_table_data(MYSQL_RES *result);
1051
1053
static void print_table_data_html(MYSQL_RES *result);
1117
1119
    exit(1);
1118
1120
  }
1119
1121
  if (status.batch && !status.line_buff &&
1120
 
      !(status.line_buff=batch_readline_init(opt_max_allowed_packet+512,stdin)))
 
1122
      !(status.line_buff= batch_readline_init(MAX_BATCH_BUFFER_SIZE, stdin)))
1121
1123
  {
1122
1124
    free_defaults(defaults_argv);
1123
1125
    my_end(0);
1198
1200
#endif
1199
1201
  sprintf(buff, "%s",
1200
1202
#ifndef NOT_YET
1201
 
          "Type 'help;' or '\\h' for help. Type '\\c' to clear the buffer.\n");
 
1203
          "Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\n");
1202
1204
#else
1203
1205
          "Type 'help [[%]function name[%]]' to get help on usage of function.\n");
1204
1206
#endif
1234
1236
  glob_buffer.free();
1235
1237
  old_buffer.free();
1236
1238
  processed_prompt.free();
 
1239
  my_free(server_version,MYF(MY_ALLOW_ZERO_PTR));
1237
1240
  my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
1238
1241
  my_free(opt_mysql_unix_port,MYF(MY_ALLOW_ZERO_PTR));
1239
1242
  my_free(histfile,MYF(MY_ALLOW_ZERO_PTR));
1810
1813
  ulong line_number=0;
1811
1814
  bool ml_comment= 0;  
1812
1815
  COMMANDS *com;
 
1816
  bool truncated= 0;
1813
1817
  status.exit_status=1;
1814
1818
  
1815
1819
  for (;;)
1816
1820
  {
1817
1821
    if (!interactive)
1818
1822
    {
1819
 
      line=batch_readline(status.line_buff);
 
1823
      line=batch_readline(status.line_buff, &truncated);
1820
1824
      /*
1821
1825
        Skip UTF8 Byte Order Marker (BOM) 0xEFBBBF.
1822
1826
        Editors like "notepad" put this marker in
1913
1917
#endif
1914
1918
      continue;
1915
1919
    }
1916
 
    if (add_line(glob_buffer,line,&in_string,&ml_comment))
 
1920
    if (add_line(glob_buffer,line,&in_string,&ml_comment, truncated))
1917
1921
      break;
1918
1922
  }
1919
1923
  /* if in batch mode, send last query even if it doesn't end with \g or go */
1999
2003
 
2000
2004
 
2001
2005
static bool add_line(String &buffer,char *line,char *in_string,
2002
 
                     bool *ml_comment)
 
2006
                     bool *ml_comment, bool truncated)
2003
2007
{
2004
2008
  uchar inchar;
2005
2009
  char buff[80], *pos, *out;
2044
2048
    }
2045
2049
#endif
2046
2050
    if (!*ml_comment && inchar == '\\' &&
2047
 
        !(mysql.server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES))
 
2051
        !(*in_string && 
 
2052
          (mysql.server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)))
2048
2053
    {
2049
2054
      // Found possbile one character command like \c
2050
2055
 
2244
2249
  }
2245
2250
  if (out != line || !buffer.is_empty())
2246
2251
  {
2247
 
    *out++='\n';
2248
2252
    uint length=(uint) (out-line);
 
2253
 
 
2254
    if (!truncated &&
 
2255
        (length < 9 || 
 
2256
         my_strnncoll (charset_info, 
 
2257
                       (uchar *)line, 9, (const uchar *) "delimiter", 9)))
 
2258
    {
 
2259
      /* 
 
2260
        Don't add a new line in case there's a DELIMITER command to be 
 
2261
        added to the glob buffer (e.g. on processing a line like 
 
2262
        "<command>;DELIMITER <non-eof>") : similar to how a new line is 
 
2263
        not added in the case when the DELIMITER is the first command 
 
2264
        entered with an empty glob buffer. 
 
2265
      */
 
2266
      *out++='\n';
 
2267
      length++;
 
2268
    }
2249
2269
    if (buffer.length() + length >= buffer.alloced_length())
2250
2270
      buffer.realloc(buffer.length()+length+IO_SIZE);
2251
2271
    if ((!*ml_comment || preserve_comments) && buffer.append(line, length))
2269
2289
  if not.
2270
2290
*/
2271
2291
 
2272
 
#if defined(USE_NEW_READLINE_INTERFACE) || defined(USE_LIBEDIT_INTERFACE)
 
2292
#if defined(USE_NEW_READLINE_INTERFACE) 
2273
2293
extern "C" char *no_completion(const char*,int)
 
2294
#elif defined(USE_LIBEDIT_INTERFACE)
 
2295
extern "C" int no_completion(const char*,int)
2274
2296
#else
2275
2297
extern "C" char *no_completion()
2276
2298
#endif
2645
2667
      (res= mysql_use_result(&mysql)))
2646
2668
  {
2647
2669
    MYSQL_ROW row= mysql_fetch_row(res);
2648
 
    if (row[0])
 
2670
    if (row && row[0])
2649
2671
      current_db= my_strdup(row[0], MYF(MY_WME));
2650
2672
    mysql_free_result(res);
2651
2673
  }
2852
2874
  param= get_arg(buff, 0);
2853
2875
  if (!param || !*param)
2854
2876
  {
2855
 
    return put_info("Usage: \\C char_setname | charset charset_name", 
 
2877
    return put_info("Usage: \\C charset_name | charset charset_name", 
2856
2878
                    INFO_ERROR, 0);
2857
2879
  }
2858
2880
  new_cs= get_charset_by_csname(param, MY_CS_PRIMARY, MYF(MY_WME));
3904
3926
    return put_info(buff, INFO_ERROR, 0);
3905
3927
  }
3906
3928
 
3907
 
  if (!(line_buff=batch_readline_init(opt_max_allowed_packet+512,sql_file)))
 
3929
  if (!(line_buff= batch_readline_init(MAX_BATCH_BUFFER_SIZE, sql_file)))
3908
3930
  {
3909
3931
    my_fclose(sql_file,MYF(0));
3910
3932
    return put_info("Can't initialize batch_readline", INFO_ERROR, 0);
4344
4366
static const char *
4345
4367
server_version_string(MYSQL *con)
4346
4368
{
4347
 
  static char buf[MAX_SERVER_VERSION_LENGTH] = "";
4348
 
 
4349
4369
  /* Only one thread calls this, so no synchronization is needed */
4350
 
  if (buf[0] == '\0')
 
4370
  if (server_version == NULL)
4351
4371
  {
4352
 
    char *bufp = buf;
4353
4372
    MYSQL_RES *result;
4354
4373
 
4355
 
    bufp= strnmov(buf, mysql_get_server_info(con), sizeof buf);
4356
 
 
4357
4374
    /* "limit 1" is protection against SQL_SELECT_LIMIT=0 */
4358
4375
    if (!mysql_query(con, "select @@version_comment limit 1") &&
4359
4376
        (result = mysql_use_result(con)))
4361
4378
      MYSQL_ROW cur = mysql_fetch_row(result);
4362
4379
      if (cur && cur[0])
4363
4380
      {
4364
 
        bufp = strxnmov(bufp, sizeof buf - (bufp - buf), " ", cur[0], NullS);
 
4381
        /* version, space, comment, \0 */
 
4382
        size_t len= strlen(mysql_get_server_info(con)) + strlen(cur[0]) + 2;
 
4383
 
 
4384
        if ((server_version= (char *) my_malloc(len, MYF(MY_WME))))
 
4385
        {
 
4386
          char *bufp;
 
4387
          bufp = strmov(server_version, mysql_get_server_info(con));
 
4388
          bufp = strmov(bufp, " ");
 
4389
          (void) strmov(bufp, cur[0]);
 
4390
        }
4365
4391
      }
4366
4392
      mysql_free_result(result);
4367
4393
    }
4368
4394
 
4369
 
    /* str*nmov doesn't guarantee NUL-termination */
4370
 
    if (bufp == buf + sizeof buf)
4371
 
      buf[sizeof buf - 1] = '\0';
 
4395
    /*
 
4396
      If for some reason we didn't get a version_comment, we'll
 
4397
      keep things simple.
 
4398
    */
 
4399
 
 
4400
    if (server_version == NULL)
 
4401
    {
 
4402
      server_version= strdup(mysql_get_server_info(con));
 
4403
    }
4372
4404
  }
4373
4405
 
4374
 
  return buf;
 
4406
  return server_version ? server_version : "";
4375
4407
}
4376
4408
 
4377
4409
static int