~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

  • Committer: Stewart Smith
  • Date: 2009-07-02 17:18:18 UTC
  • mfrom: (1085 staging)
  • mto: This revision was merged to the branch mainline in revision 1089.
  • Revision ID: stewart@flamingspork.com-20090702171818-qrp4d403iw8tazlg
mergeĀ mainline

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include <drizzled/lock.h>
38
38
#include <drizzled/select_send.h>
39
39
#include <bitset>
 
40
#include <algorithm>
40
41
 
41
42
using namespace std;
42
43
 
317
318
    It prepares a Select_Lex and a TableList object to represent the
318
319
    given command as a SELECT parse tree.
319
320
 
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
 
321
  @param session           thread handle
 
322
  @param lex               current lex
 
323
  @param table_ident       table alias if it's used
 
324
  @param schema_table_name the name of the INFORMATION_SCHEMA table to be
 
325
                           created
325
326
 
326
327
  @note
327
328
    Due to the way this function works with memory and LEX it cannot
336
337
*/
337
338
 
338
339
int prepare_schema_table(Session *session, LEX *lex, Table_ident *table_ident,
339
 
                         enum enum_schema_tables schema_table_idx)
 
340
                         const string& schema_table_name)
340
341
{
341
342
  Select_Lex *schema_select_lex= NULL;
342
343
 
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:
 
344
 
 
345
  if (schema_table_name.compare("TABLES") == 0 ||
 
346
      schema_table_name.compare("TABLE_NAMES") == 0)
 
347
  {
 
348
    LEX_STRING db;
 
349
    size_t dummy;
 
350
    if (lex->select_lex.db == NULL &&
 
351
        lex->copy_db_to(&lex->select_lex.db, &dummy))
 
352
    {
 
353
      return (1);
 
354
    }
 
355
    schema_select_lex= new Select_Lex();
 
356
    db.str= schema_select_lex->db= lex->select_lex.db;
 
357
    schema_select_lex->table_list.first= NULL;
 
358
    db.length= strlen(db.str);
 
359
 
 
360
    if (check_db_name(&db))
 
361
    {
 
362
      my_error(ER_WRONG_DB_NAME, MYF(0), db.str);
 
363
      return (1);
 
364
    }
 
365
  }
 
366
  else if (schema_table_name.compare("COLUMNS") == 0 ||
 
367
           schema_table_name.compare("STATISTICS") == 0)
370
368
  {
371
369
    assert(table_ident);
372
370
    TableList **query_tables_last= lex->query_tables_last;
374
372
    /* 'parent_lex' is used in init_query() so it must be before it. */
375
373
    schema_select_lex->parent_lex= lex;
376
374
    schema_select_lex->init_query();
377
 
    if (!schema_select_lex->add_table_to_list(session, table_ident, 0, 0, TL_READ))
378
 
      return(1);
 
375
    if (! schema_select_lex->add_table_to_list(session, table_ident, 0, 0, TL_READ))
 
376
    {
 
377
      return (1);
 
378
    }
379
379
    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_TABLE_CONSTRAINTS:
386
 
  case SCH_KEY_COLUMN_USAGE:
387
 
  default:
388
 
    break;
389
380
  }
390
381
 
391
382
  Select_Lex *select_lex= lex->current_select;
392
383
  assert(select_lex);
393
 
  if (make_schema_select(session, select_lex, schema_table_idx))
 
384
  if (make_schema_select(session, select_lex, schema_table_name))
394
385
  {
395
386
    return(1);
396
387
  }
2517
2508
    char command[80];
2518
2509
    Lex_input_stream *lip= session->m_lip;
2519
2510
    strncpy(command, lip->yylval->symbol.str,
2520
 
            cmin(lip->yylval->symbol.length, sizeof(command)-1));
2521
 
    command[cmin(lip->yylval->symbol.length, sizeof(command)-1)]=0;
 
2511
            min(lip->yylval->symbol.length, (uint32_t)(sizeof(command)-1)));
 
2512
    command[min(lip->yylval->symbol.length, (uint32_t)(sizeof(command)-1))]=0;
2522
2513
    my_error(ER_CANT_USE_OPTION_HERE, MYF(0), command);
2523
2514
    return 1;
2524
2515
  }