~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/parser.cc

  • Committer: Olaf van der Spek
  • Date: 2011-10-17 22:46:16 UTC
  • mto: This revision was merged to the branch mainline in revision 2442.
  • Revision ID: olafvdspek@gmail.com-20111017224616-gcj9z1sjpauwsp14
Refactor

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
    expression the <subquery> is.
68
68
  */
69
69
 
 
70
  Item *result;
 
71
 
70
72
  if (expr->type() == Item::SUBSELECT_ITEM)
71
73
  {
72
74
    Item_subselect *expr2 = (Item_subselect*) expr;
74
76
    if (expr2->substype() == Item_subselect::SINGLEROW_SUBS)
75
77
    {
76
78
      Item_singlerow_subselect *expr3 = (Item_singlerow_subselect*) expr2;
 
79
      Select_Lex *subselect;
77
80
 
78
81
      /*
79
82
        Implement the mandated change, by altering the semantic tree:
83
86
        which is represented as
84
87
          Item_in_subselect(left, subselect)
85
88
      */
86
 
      Select_Lex* subselect= expr3->invalidate_and_restore_select_lex();
87
 
      Item* result= new (session->mem_root) Item_in_subselect(left, subselect);
88
 
      return equal ? result : negate_expression(session, result);
 
89
      subselect= expr3->invalidate_and_restore_select_lex();
 
90
      result= new (session->mem_root) Item_in_subselect(left, subselect);
 
91
 
 
92
      if (! equal)
 
93
        result = negate_expression(session, result);
 
94
 
 
95
      return(result);
89
96
    }
90
97
  }
91
 
  return equal
92
 
    ? (Item*) new (session->mem_root) Item_func_eq(left, expr)
93
 
    : (Item*) new (session->mem_root) Item_func_ne(left, expr);
 
98
 
 
99
  if (equal)
 
100
    result= new (session->mem_root) Item_func_eq(left, expr);
 
101
  else
 
102
    result= new (session->mem_root) Item_func_ne(left, expr);
 
103
 
 
104
  return(result);
94
105
}
95
106
 
96
107
/**
210
221
  my_printf_error(ER_PARSE_ERROR_UNKNOWN, ER(ER_PARSE_ERROR_UNKNOWN), MYF(0), message);
211
222
}
212
223
 
213
 
bool check_reserved_words(str_ref name)
 
224
bool check_reserved_words(lex_string_t *name)
214
225
{
215
 
  return not system_charset_info->strcasecmp(name.data(), "GLOBAL") 
216
 
    || not system_charset_info->strcasecmp(name.data(), "LOCAL")
217
 
    || not system_charset_info->strcasecmp(name.data(), "SESSION");
 
226
  if (!my_strcasecmp(system_charset_info, name->data(), "GLOBAL") ||
 
227
      !my_strcasecmp(system_charset_info, name->data(), "LOCAL") ||
 
228
      !my_strcasecmp(system_charset_info, name->data(), "SESSION"))
 
229
    return true;
 
230
 
 
231
  return false;
218
232
}
219
233
 
220
234
 
303
317
 
304
318
void buildSchemaOption(LEX *lex, const char *key, str_ref value)
305
319
{
306
 
  statement::CreateSchema *statement= static_cast<statement::CreateSchema*>(lex->statement);
 
320
  statement::CreateSchema *statement= (statement::CreateSchema *)lex->statement;
307
321
  message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
308
322
  opt->set_name(key);
309
323
  opt->set_state(value.data(), value.size());
310
324
}
311
325
 
 
326
void buildSchemaDefiner(LEX *lex, const lex_string_t &value)
 
327
{
 
328
  statement::CreateSchema *statement= (statement::CreateSchema *)lex->statement;
 
329
  identifier::User user(value.data());
 
330
  message::set_definer(statement->schema_message, user);
 
331
}
 
332
 
312
333
void buildSchemaDefiner(LEX *lex, const identifier::User &user)
313
334
{
314
 
  statement::CreateSchema *statement= static_cast<statement::CreateSchema*>(lex->statement);
 
335
  statement::CreateSchema *statement= (statement::CreateSchema *)lex->statement;
315
336
  message::set_definer(statement->schema_message, user);
316
337
}
317
338
 
318
339
void buildSchemaOption(LEX *lex, const char *key, uint64_t value)
319
340
{
320
 
  statement::CreateSchema *statement= static_cast<statement::CreateSchema*>(lex->statement);
 
341
  statement::CreateSchema *statement= (statement::CreateSchema *)lex->statement;
321
342
  message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
322
343
  opt->set_name(key);
323
344
  opt->set_state(boost::lexical_cast<std::string>(value));
324
345
}
325
346
 
326
 
bool checkFieldIdent(LEX *lex, str_ref schema_name, str_ref table_name)
 
347
bool checkFieldIdent(LEX *lex, const lex_string_t &schema_name, const lex_string_t &table_name)
327
348
{
328
349
  TableList *table= reinterpret_cast<TableList*>(lex->current_select->table_list.first);
329
350
 
330
 
  if (schema_name.size() && table_alias_charset->strcasecmp(schema_name.data(), table->getSchemaName()))
 
351
  if (schema_name.size())
331
352
  {
332
 
    my_error(ER_WRONG_DB_NAME, MYF(0), schema_name.data());
333
 
    return false;
 
353
    if (my_strcasecmp(table_alias_charset, schema_name.data(), table->getSchemaName()))
 
354
    {
 
355
      my_error(ER_WRONG_DB_NAME, MYF(0), schema_name.data());
 
356
      return false;
 
357
    }
334
358
  }
335
359
 
336
 
  if (table_alias_charset->strcasecmp(table_name.data(), table->getTableName()))
 
360
  if (my_strcasecmp(table_alias_charset, table_name.data(),
 
361
                    table->getTableName()))
337
362
  {
338
363
    my_error(ER_WRONG_TABLE_NAME, MYF(0), table_name.data());
339
364
    return false;
342
367
  return true;
343
368
}
344
369
 
345
 
Item *buildIdent(LEX *lex, str_ref schema_name, str_ref table_name, str_ref field_name)
 
370
Item *buildIdent(LEX *lex, const lex_string_t &schema_name, const lex_string_t &table_name, const lex_string_t &field_name)
346
371
{
347
372
  Select_Lex *sel= lex->current_select;
348
373
 
356
381
    : (Item*) new Item_ref(lex->current_context(), schema_name.data(), table_name.data(), field_name.data());
357
382
}
358
383
 
359
 
Item *buildTableWild(LEX *lex, str_ref schema_name, str_ref table_name)
 
384
Item *buildTableWild(LEX *lex, const lex_string_t &schema_name, const lex_string_t &table_name)
360
385
{
361
386
  Select_Lex *sel= lex->current_select;
362
387
  Item *item= new Item_field(lex->current_context(), schema_name.data(), table_name.data(), "*");
405
430
  return true;
406
431
}
407
432
 
408
 
void buildKey(LEX *lex, Key::Keytype type_par, str_ref name_arg)
 
433
void buildKey(LEX *lex, Key::Keytype type_par, const lex_string_t &name_arg)
409
434
{
410
435
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
411
436
  Key *key= new Key(type_par, name_arg, &statement->key_create_info, 0, lex->col_list);
413
438
  lex->col_list.clear(); /* Alloced by memory::sql_alloc */
414
439
}
415
440
 
416
 
void buildForeignKey(LEX *lex, str_ref name_arg, drizzled::Table_ident *table)
 
441
void buildForeignKey(LEX *lex, const lex_string_t &name_arg, drizzled::Table_ident *table)
417
442
{
418
443
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
419
 
  statement->alter_info.key_list.push_back(new Foreign_key(name_arg, lex->col_list, table, lex->ref_list, 
420
 
    statement->fk_delete_opt, statement->fk_update_opt, statement->fk_match_option));
 
444
  Key *key= new Foreign_key(name_arg, lex->col_list,
 
445
                            table,
 
446
                            lex->ref_list,
 
447
                            statement->fk_delete_opt,
 
448
                            statement->fk_update_opt,
 
449
                            statement->fk_match_option);
421
450
 
422
 
  statement->alter_info.key_list.push_back(new Key(Key::MULTIPLE, name_arg, &default_key_create_info, 1, lex->col_list));
 
451
  statement->alter_info.key_list.push_back(key);
 
452
  key= new Key(Key::MULTIPLE, name_arg, &default_key_create_info, 1, lex->col_list);
 
453
  statement->alter_info.key_list.push_back(key);
423
454
  lex->col_list.clear(); /* Alloced by memory::sql_alloc */
424
455
  /* Only used for ALTER TABLE. Ignored otherwise. */
425
456
  statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
629
660
 
630
661
void buildReplicationOption(LEX *lex, bool arg)
631
662
{
632
 
  statement::CreateSchema *statement= static_cast<statement::CreateSchema*>(lex->statement);
 
663
  statement::CreateSchema *statement= (statement::CreateSchema *)lex->statement;
633
664
  message::set_is_replicated(statement->schema_message, arg);
634
665
}
635
666