~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

  • Committer: devananda
  • Date: 2009-06-30 14:27:54 UTC
  • mfrom: (1030.2.4 trunk)
  • mto: (1093.1.7 captain)
  • mto: This revision was merged to the branch mainline in revision 1095.
  • Revision ID: devananda.vdv@gmail.com-20090630142754-vm9w374yxkf1pikc
mergeĀ fromĀ lp

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <drizzled/data_home.h>
26
26
#include <drizzled/sql_base.h>
27
27
#include <drizzled/show.h>
 
28
#include <drizzled/info_schema.h>
28
29
#include <drizzled/rename.h>
29
30
#include <drizzled/function/time/unix_timestamp.h>
30
31
#include <drizzled/function/get_system_var.h>
129
130
    The following admin table operations are allowed
130
131
    on log tables.
131
132
  */
132
 
  sql_command_flags[SQLCOM_REPAIR]=           CF_WRITE_LOGS_COMMAND;
133
133
  sql_command_flags[SQLCOM_OPTIMIZE]=         CF_WRITE_LOGS_COMMAND;
134
134
  sql_command_flags[SQLCOM_ANALYZE]=          CF_WRITE_LOGS_COMMAND;
135
135
}
317
317
    It prepares a Select_Lex and a TableList object to represent the
318
318
    given command as a SELECT parse tree.
319
319
 
320
 
  @param session              thread handle
321
 
  @param lex              current lex
322
 
  @param table_ident      table alias if it's used
323
 
  @param schema_table_idx the type of the INFORMATION_SCHEMA table to be
324
 
                          created
 
320
  @param session           thread handle
 
321
  @param lex               current lex
 
322
  @param table_ident       table alias if it's used
 
323
  @param schema_table_name the name of the INFORMATION_SCHEMA table to be
 
324
                           created
325
325
 
326
326
  @note
327
327
    Due to the way this function works with memory and LEX it cannot
336
336
*/
337
337
 
338
338
int prepare_schema_table(Session *session, LEX *lex, Table_ident *table_ident,
339
 
                         enum enum_schema_tables schema_table_idx)
 
339
                         const string& schema_table_name)
340
340
{
341
341
  Select_Lex *schema_select_lex= NULL;
342
342
 
343
 
  switch (schema_table_idx) {
344
 
  case SCH_SCHEMATA:
345
 
    break;
346
 
  case SCH_TABLE_NAMES:
347
 
  case SCH_TABLES:
348
 
    {
349
 
      LEX_STRING db;
350
 
      size_t dummy;
351
 
      if (lex->select_lex.db == NULL &&
352
 
          lex->copy_db_to(&lex->select_lex.db, &dummy))
353
 
      {
354
 
        return(1);
355
 
      }
356
 
      schema_select_lex= new Select_Lex();
357
 
      db.str= schema_select_lex->db= lex->select_lex.db;
358
 
      schema_select_lex->table_list.first= NULL;
359
 
      db.length= strlen(db.str);
360
 
 
361
 
      if (check_db_name(&db))
362
 
      {
363
 
        my_error(ER_WRONG_DB_NAME, MYF(0), db.str);
364
 
        return(1);
365
 
      }
366
 
      break;
367
 
    }
368
 
  case SCH_COLUMNS:
369
 
  case SCH_STATISTICS:
 
343
 
 
344
  if (schema_table_name.compare("TABLES") == 0 ||
 
345
      schema_table_name.compare("TABLE_NAMES") == 0)
 
346
  {
 
347
    LEX_STRING db;
 
348
    size_t dummy;
 
349
    if (lex->select_lex.db == NULL &&
 
350
        lex->copy_db_to(&lex->select_lex.db, &dummy))
 
351
    {
 
352
      return (1);
 
353
    }
 
354
    schema_select_lex= new Select_Lex();
 
355
    db.str= schema_select_lex->db= lex->select_lex.db;
 
356
    schema_select_lex->table_list.first= NULL;
 
357
    db.length= strlen(db.str);
 
358
 
 
359
    if (check_db_name(&db))
 
360
    {
 
361
      my_error(ER_WRONG_DB_NAME, MYF(0), db.str);
 
362
      return (1);
 
363
    }
 
364
  }
 
365
  else if (schema_table_name.compare("COLUMNS") == 0 ||
 
366
           schema_table_name.compare("STATISTICS") == 0)
370
367
  {
371
368
    assert(table_ident);
372
369
    TableList **query_tables_last= lex->query_tables_last;
374
371
    /* 'parent_lex' is used in init_query() so it must be before it. */
375
372
    schema_select_lex->parent_lex= lex;
376
373
    schema_select_lex->init_query();
377
 
    if (!schema_select_lex->add_table_to_list(session, table_ident, 0, 0, TL_READ))
378
 
      return(1);
 
374
    if (! schema_select_lex->add_table_to_list(session, table_ident, 0, 0, TL_READ))
 
375
    {
 
376
      return (1);
 
377
    }
379
378
    lex->query_tables_last= query_tables_last;
380
 
    break;
381
 
  }
382
 
  case SCH_OPEN_TABLES:
383
 
  case SCH_VARIABLES:
384
 
  case SCH_STATUS:
385
 
  case SCH_CHARSETS:
386
 
  case SCH_COLLATIONS:
387
 
  case SCH_COLLATION_CHARACTER_SET_APPLICABILITY:
388
 
  case SCH_TABLE_CONSTRAINTS:
389
 
  case SCH_KEY_COLUMN_USAGE:
390
 
  default:
391
 
    break;
392
379
  }
393
380
 
394
381
  Select_Lex *select_lex= lex->current_select;
395
382
  assert(select_lex);
396
 
  if (make_schema_select(session, select_lex, schema_table_idx))
 
383
  if (make_schema_select(session, select_lex, schema_table_name))
397
384
  {
398
385
    return(1);
399
386
  }
552
539
  }
553
540
  case SQLCOM_SHOW_ENGINE_STATUS:
554
541
    {
555
 
      res = ha_show_status(session, lex->create_info.db_type, HA_ENGINE_STATUS);
 
542
      res = ha_show_status(session, lex->show_engine, HA_ENGINE_STATUS);
556
543
      break;
557
544
    }
558
545
  case SQLCOM_CREATE_TABLE:
662
649
        */
663
650
        if ((result= new select_create(create_table,
664
651
                                       &create_info,
 
652
                                       lex->create_table_proto,
665
653
                                       &alter_info,
666
654
                                       select_lex->item_list,
667
655
                                       lex->duplicates,
825
813
    res = mysql_checksum_table(session, first_table, &lex->check_opt);
826
814
    break;
827
815
  }
828
 
  case SQLCOM_REPAIR:
829
 
  {
830
 
    assert(first_table == all_tables && first_table != 0);
831
 
    res= mysql_repair_table(session, first_table, &lex->check_opt);
832
 
    /* ! we write after unlocking the table */
833
 
    /*
834
 
      Presumably, REPAIR and binlog writing doesn't require synchronization
835
 
    */
836
 
    write_bin_log(session, true, session->query, session->query_length);
837
 
    select_lex->table_list.first= (unsigned char*) first_table;
838
 
    lex->query_tables=all_tables;
839
 
    break;
840
 
  }
841
816
  case SQLCOM_CHECK:
842
817
  {
843
818
    assert(first_table == all_tables && first_table != 0);
1083
1058
  case SQLCOM_SHOW_PROCESSLIST:
1084
1059
    mysqld_list_processes(session, NULL, lex->verbose);
1085
1060
    break;
1086
 
  case SQLCOM_SHOW_ENGINE_LOGS:
1087
 
    {
1088
 
      res= ha_show_status(session, lex->create_info.db_type, HA_ENGINE_LOGS);
1089
 
      break;
1090
 
    }
1091
1061
  case SQLCOM_CHANGE_DB:
1092
1062
  {
1093
1063
    LEX_STRING db_str= { (char *) select_lex->db, strlen(select_lex->db) };
1905
1875
  {
1906
1876
    InfoSchemaTable *schema_table= find_schema_table(ptr->table_name);
1907
1877
    if (!schema_table ||
1908
 
        (schema_table->hidden &&
 
1878
        (schema_table->isHidden() &&
1909
1879
         ((sql_command_flags[lex->sql_command].test(CF_BIT_STATUS_COMMAND)) == 0 ||
1910
1880
          /*
1911
1881
            this check is used for show columns|keys from I_S hidden table
2397
2367
bool reload_cache(Session *session, ulong options, TableList *tables)
2398
2368
{
2399
2369
  bool result=0;
2400
 
  select_errors=0;                              /* Write if more errors */
2401
2370
 
2402
2371
  if (options & REFRESH_LOG)
2403
2372
  {