~ubuntu-branches/ubuntu/gutsy/mysql-dfsg-5.0/gutsy

« back to all changes in this revision

Viewing changes to libmysqld/examples/mysql.cc

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2007-04-03 09:43:01 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20070403094301-fnjhfr59hu72pvtg
Tags: 5.0.38-0ubuntu1
* Package the Enterprise version again (.37 was a community version), since
  Debian and we have always done so. This brings in a few more bug fixes and
  makes functional derivations less likely.
* debian/README.Maintainer: Add pointer to upstream download URL, since it
  is very hard to find the Enterprise versions.
* Disable 33_scripts__mysql_create_system_tables__no_test.dpatch, since that
  script was removed upstream.
* debian/patches/41_scripts__mysql_install_db.sh__no_test.dpatch: Adapted to
  changed formatting in new upstream version.
* Remove debian/patches/86_PATH_MAX.dpatch, fixed upstream.
* Add debian/patches/90_org_tables_definition.dpatch: Fix local variable
  declaration in libmysqld/sql_parse.cc to fix compilation with
  EMBEDDED_LIBRARY.

Show diffs side-by-side

added added

removed removed

Lines of Context:
131
131
static MYSQL mysql;                     /* The connection */
132
132
static my_bool info_flag=0,ignore_errors=0,wait_flag=0,quick=0,
133
133
               connected=0,opt_raw_data=0,unbuffered=0,output_tables=0,
134
 
               rehash=1,skip_updates=0,safe_updates=0,one_database=0,
 
134
               opt_rehash=1,skip_updates=0,safe_updates=0,one_database=0,
135
135
               opt_compress=0, using_opt_local_infile=0,
136
136
               vertical=0, line_numbers=1, column_names=1,opt_html=0,
137
137
               opt_xml=0,opt_nopager=1, opt_outfile=0, named_cmds= 0,
443
443
    signal(SIGINT, mysql_sigint);               // Catch SIGINT to clean up
444
444
  signal(SIGQUIT, mysql_end);                   // Catch SIGQUIT to clean up
445
445
 
446
 
  /*
447
 
    Run in interactive mode like the ingres/postgres monitor
448
 
  */
449
 
 
450
446
  put_info("Welcome to the MySQL monitor.  Commands end with ; or \\g.",
451
447
           INFO_INFO);
452
448
  sprintf((char*) glob_buffer.ptr(),
585
581
#endif
586
582
  {"auto-rehash", OPT_AUTO_REHASH,
587
583
   "Enable automatic rehashing. One doesn't need to use 'rehash' to get table and field completion, but startup and reconnecting may take a longer time. Disable with --disable-auto-rehash.",
588
 
   (gptr*) &rehash, (gptr*) &rehash, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
 
584
   (gptr*) &opt_rehash, (gptr*) &opt_rehash, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
 
585
   0, 0},
589
586
  {"no-auto-rehash", 'A',
590
587
   "No automatic rehashing. One has to use 'rehash' to get table and field completion. This gives a quicker start of mysql and disables rehashing on reconnect. WARNING: options deprecated; use --disable-auto-rehash instead.",
591
588
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
888
885
  }
889
886
  break;
890
887
  case 'A':
891
 
    rehash= 0;
 
888
    opt_rehash= 0;
892
889
    break;
893
890
  case 'N':
894
891
    column_names= 0;
1768
1765
 
1769
1766
static int reconnect(void)
1770
1767
{
 
1768
  /* purecov: begin tested */
1771
1769
  if (opt_reconnect)
1772
1770
  {
1773
1771
    put_info("No connection. Trying to reconnect...",INFO_INFO);
1774
1772
    (void) com_connect((String *) 0, 0);
1775
 
    if (rehash)
 
1773
    if (opt_rehash)
1776
1774
      com_rehash(NULL, NULL);
1777
1775
  }
1778
1776
  if (!connected)
1779
1777
    return put_info("Can't connect to the server\n",INFO_ERROR);
 
1778
  /* purecov: end */
1780
1779
  return 0;
1781
1780
}
1782
1781
 
2941
2940
com_connect(String *buffer, char *line)
2942
2941
{
2943
2942
  char *tmp, buff[256];
2944
 
  bool save_rehash= rehash;
 
2943
  bool save_rehash= opt_rehash;
2945
2944
  int error;
2946
2945
 
2947
2946
  bzero(buff, sizeof(buff));
2965
2964
      }
2966
2965
    }
2967
2966
    else
2968
 
      rehash= 0;                                // Quick re-connect
 
2967
    {
 
2968
      /* Quick re-connect */
 
2969
      opt_rehash= 0;                            /* purecov: tested */
 
2970
    }
2969
2971
    buffer->length(0);                          // command used
2970
2972
  }
2971
2973
  else
2972
 
    rehash= 0;
 
2974
    opt_rehash= 0;
2973
2975
  error=sql_connect(current_host,current_db,current_user,opt_password,0);
2974
 
  rehash= save_rehash;
 
2976
  opt_rehash= save_rehash;
2975
2977
 
2976
2978
  if (connected)
2977
2979
  {
3133
3135
    current_db=my_strdup(tmp,MYF(MY_WME));
3134
3136
#ifdef HAVE_READLINE
3135
3137
    if (select_db > 1)
3136
 
      build_completion_hash(rehash, 1);
 
3138
      build_completion_hash(opt_rehash, 1);
3137
3139
#endif
3138
3140
  }
3139
3141
 
3287
3289
  mysql.reconnect= 1;
3288
3290
#endif
3289
3291
#ifdef HAVE_READLINE
3290
 
  build_completion_hash(rehash, 1);
 
3292
  build_completion_hash(opt_rehash, 1);
3291
3293
#endif
3292
3294
  return 0;
3293
3295
}
3332
3334
com_status(String *buffer __attribute__((unused)),
3333
3335
           char *line __attribute__((unused)))
3334
3336
{
3335
 
  const char *status;
3336
 
  char buff[22];
 
3337
  const char *status_str;
 
3338
  char buff[40];
3337
3339
  ulonglong id;
3338
3340
  MYSQL_RES *result;
3339
3341
  LINT_INIT(result);
3359
3361
      mysql_free_result(result);
3360
3362
    } 
3361
3363
#ifdef HAVE_OPENSSL
3362
 
    if ((status= mysql_get_ssl_cipher(&mysql)))
 
3364
    if ((status_str= mysql_get_ssl_cipher(&mysql)))
3363
3365
      tee_fprintf(stdout, "SSL:\t\t\tCipher in use is %s\n",
3364
 
                  status);
 
3366
                  status_str);
3365
3367
    else
3366
3368
#endif /* HAVE_OPENSSL */
3367
3369
      tee_puts("SSL:\t\t\tNot in use", stdout);
3420
3422
    tee_fprintf(stdout, "Protocol:\t\tCompressed\n");
3421
3423
#endif
3422
3424
 
3423
 
  if ((status=mysql_stat(&mysql)) && !mysql_error(&mysql)[0])
 
3425
  if ((status_str= mysql_stat(&mysql)) && !mysql_error(&mysql)[0])
3424
3426
  {
3425
3427
    ulong sec;
3426
 
    char buff[40];
3427
 
    const char *pos= strchr(status,' ');
 
3428
    const char *pos= strchr(status_str,' ');
3428
3429
    /* print label */
3429
 
    tee_fprintf(stdout, "%.*s\t\t\t", (int) (pos-status), status);
3430
 
    if ((status=str2int(pos,10,0,LONG_MAX,(long*) &sec)))
 
3430
    tee_fprintf(stdout, "%.*s\t\t\t", (int) (pos-status_str), status_str);
 
3431
    if ((status_str= str2int(pos,10,0,LONG_MAX,(long*) &sec)))
3431
3432
    {
3432
3433
      nice_time((double) sec,buff,0);
3433
3434
      tee_puts(buff, stdout);                   /* print nice time */
3434
 
      while (*status == ' ') status++;          /* to next info */
3435
 
    }
3436
 
    if (status)
3437
 
    {
 
3435
      while (*status_str == ' ')
 
3436
        status_str++;  /* to next info */
3438
3437
      tee_putc('\n', stdout);
3439
 
      tee_puts(status, stdout);
 
3438
      tee_puts(status_str, stdout);
3440
3439
    }
3441
3440
  }
3442
3441
  if (safe_updates)
3456
3455
}
3457
3456
 
3458
3457
static const char *
3459
 
server_version_string(MYSQL *mysql)
 
3458
server_version_string(MYSQL *con)
3460
3459
{
3461
3460
  static char buf[MAX_SERVER_VERSION_LENGTH] = "";
3462
3461
 
3466
3465
    char *bufp = buf;
3467
3466
    MYSQL_RES *result;
3468
3467
 
3469
 
    bufp = strnmov(buf, mysql_get_server_info(mysql), sizeof buf);
 
3468
    bufp= strnmov(buf, mysql_get_server_info(con), sizeof buf);
3470
3469
 
3471
3470
    /* "limit 1" is protection against SQL_SELECT_LIMIT=0 */
3472
 
    if (!mysql_query(mysql, "select @@version_comment limit 1") &&
3473
 
        (result = mysql_use_result(mysql)))
 
3471
    if (!mysql_query(con, "select @@version_comment limit 1") &&
 
3472
        (result = mysql_use_result(con)))
3474
3473
    {
3475
3474
      MYSQL_ROW cur = mysql_fetch_row(result);
3476
3475
      if (cur && cur[0])
3560
3559
 
3561
3560
 
3562
3561
static int
3563
 
put_error(MYSQL *mysql)
 
3562
put_error(MYSQL *con)
3564
3563
{
3565
 
  return put_info(mysql_error(mysql), INFO_ERROR, mysql_errno(mysql),
3566
 
                  mysql_sqlstate(mysql));
 
3564
  return put_info(mysql_error(con), INFO_ERROR, mysql_errno(con),
 
3565
                  mysql_sqlstate(con));
3567
3566
}  
3568
3567
 
3569
3568
 
3822
3821
        break;
3823
3822
      case 'D':
3824
3823
        char* dateTime;
3825
 
        time_t lclock;
3826
 
        lclock = time(NULL);
3827
3824
        dateTime = ctime(&lclock);
3828
3825
        processed_prompt.append(strtok(dateTime,"\n"));
3829
3826
        break;