~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/parser.cc

  • Committer: Mark Atwood
  • Date: 2011-12-11 22:56:39 UTC
  • mfrom: (2465.1.1 drizzle)
  • Revision ID: me@mark.atwood.name-20111211225639-3d8ype7g2y82dci5
mergeĀ lp:~brianaker/drizzle/libdrizzle-breakout

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
 
 
72
70
  if (expr->type() == Item::SUBSELECT_ITEM)
73
71
  {
74
72
    Item_subselect *expr2 = (Item_subselect*) expr;
76
74
    if (expr2->substype() == Item_subselect::SINGLEROW_SUBS)
77
75
    {
78
76
      Item_singlerow_subselect *expr3 = (Item_singlerow_subselect*) expr2;
79
 
      Select_Lex *subselect;
80
77
 
81
78
      /*
82
79
        Implement the mandated change, by altering the semantic tree:
86
83
        which is represented as
87
84
          Item_in_subselect(left, subselect)
88
85
      */
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);
 
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);
96
89
    }
97
90
  }
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);
 
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);
105
94
}
106
95
 
107
96
/**
221
210
  my_printf_error(ER_PARSE_ERROR_UNKNOWN, ER(ER_PARSE_ERROR_UNKNOWN), MYF(0), message);
222
211
}
223
212
 
224
 
bool check_reserved_words(lex_string_t *name)
 
213
bool check_reserved_words(str_ref name)
225
214
{
226
 
  if (!my_strcasecmp(system_charset_info, name->str, "GLOBAL") ||
227
 
      !my_strcasecmp(system_charset_info, name->str, "LOCAL") ||
228
 
      !my_strcasecmp(system_charset_info, name->str, "SESSION"))
229
 
    return true;
230
 
 
231
 
  return false;
 
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");
232
218
}
233
219
 
234
220
 
301
287
  return true;
302
288
}
303
289
 
304
 
void buildEngineOption(LEX *lex, const char *key, const lex_string_t &value)
 
290
void buildEngineOption(LEX *lex, const char *key, str_ref value)
305
291
{
306
292
  message::Engine::Option *opt= lex->table()->mutable_engine()->add_options();
307
293
  opt->set_name(key);
308
 
  opt->set_state(value.str, value.length);
 
294
  opt->set_state(value.data(), value.size());
309
295
}
310
296
 
311
297
void buildEngineOption(LEX *lex, const char *key, uint64_t value)
315
301
  opt->set_state(boost::lexical_cast<std::string>(value));
316
302
}
317
303
 
318
 
void buildSchemaOption(LEX *lex, const char *key, const lex_string_t &value)
 
304
void buildSchemaOption(LEX *lex, const char *key, str_ref value)
319
305
{
320
 
  statement::CreateSchema *statement= (statement::CreateSchema *)lex->statement;
 
306
  statement::CreateSchema *statement= static_cast<statement::CreateSchema*>(lex->statement);
321
307
  message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
322
308
  opt->set_name(key);
323
 
  opt->set_state(value.str, value.length);
324
 
}
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.str);
330
 
  message::set_definer(statement->schema_message, user);
 
309
  opt->set_state(value.data(), value.size());
331
310
}
332
311
 
333
312
void buildSchemaDefiner(LEX *lex, const identifier::User &user)
334
313
{
335
 
  statement::CreateSchema *statement= (statement::CreateSchema *)lex->statement;
 
314
  statement::CreateSchema *statement= static_cast<statement::CreateSchema*>(lex->statement);
336
315
  message::set_definer(statement->schema_message, user);
337
316
}
338
317
 
339
318
void buildSchemaOption(LEX *lex, const char *key, uint64_t value)
340
319
{
341
 
  statement::CreateSchema *statement= (statement::CreateSchema *)lex->statement;
 
320
  statement::CreateSchema *statement= static_cast<statement::CreateSchema*>(lex->statement);
342
321
  message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
343
322
  opt->set_name(key);
344
323
  opt->set_state(boost::lexical_cast<std::string>(value));
345
324
}
346
325
 
347
 
bool checkFieldIdent(LEX *lex, const lex_string_t &schema_name, const lex_string_t &table_name)
 
326
bool checkFieldIdent(LEX *lex, str_ref schema_name, str_ref table_name)
348
327
{
349
328
  TableList *table= reinterpret_cast<TableList*>(lex->current_select->table_list.first);
350
329
 
351
 
  if (schema_name.length)
 
330
  if (schema_name.size() && table_alias_charset->strcasecmp(schema_name.data(), table->getSchemaName()))
352
331
  {
353
 
    if (my_strcasecmp(table_alias_charset, schema_name.str, table->getSchemaName()))
354
 
    {
355
 
      my_error(ER_WRONG_DB_NAME, MYF(0), schema_name.str);
356
 
      return false;
357
 
    }
 
332
    my_error(ER_WRONG_DB_NAME, MYF(0), schema_name.data());
 
333
    return false;
358
334
  }
359
335
 
360
 
  if (my_strcasecmp(table_alias_charset, table_name.str,
361
 
                    table->getTableName()))
 
336
  if (table_alias_charset->strcasecmp(table_name.data(), table->getTableName()))
362
337
  {
363
 
    my_error(ER_WRONG_TABLE_NAME, MYF(0), table_name.str);
 
338
    my_error(ER_WRONG_TABLE_NAME, MYF(0), table_name.data());
364
339
    return false;
365
340
  }
366
341
 
367
342
  return true;
368
343
}
369
344
 
370
 
Item *buildIdent(LEX *lex,
371
 
                 const lex_string_t &schema_name,
372
 
                 const lex_string_t &table_name,
373
 
                 const lex_string_t &field_name)
 
345
Item *buildIdent(LEX *lex, str_ref schema_name, str_ref table_name, str_ref field_name)
374
346
{
375
347
  Select_Lex *sel= lex->current_select;
376
348
 
377
 
  if (table_name.length and sel->no_table_names_allowed)
 
349
  if (table_name.size() and sel->no_table_names_allowed)
378
350
  {
379
 
    my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
380
 
             MYF(0), table_name.str, lex->session->where());
 
351
    my_error(ER_TABLENAME_NOT_ALLOWED_HERE, MYF(0), table_name.data(), lex->session->where());
381
352
  }
382
353
 
383
 
  Item *item= (sel->parsing_place != IN_HAVING or
384
 
               sel->get_in_sum_expr() > 0) ?
385
 
    (Item*) new Item_field(lex->current_context(), schema_name.str, table_name.str, field_name.str) :
386
 
    (Item*) new Item_ref(lex->current_context(), schema_name.str, table_name.str, field_name.str);
387
 
 
388
 
  return item;
 
354
  return sel->parsing_place != IN_HAVING || sel->get_in_sum_expr() > 0
 
355
    ? (Item*) new Item_field(lex->current_context(), schema_name.data(), table_name.data(), field_name.data()) 
 
356
    : (Item*) new Item_ref(lex->current_context(), schema_name.data(), table_name.data(), field_name.data());
389
357
}
390
358
 
391
 
Item *buildTableWild(LEX *lex, const lex_string_t &schema_name, const lex_string_t &table_name)
 
359
Item *buildTableWild(LEX *lex, str_ref schema_name, str_ref table_name)
392
360
{
393
361
  Select_Lex *sel= lex->current_select;
394
 
  Item *item= new Item_field(lex->current_context(), schema_name.str, table_name.str, "*");
 
362
  Item *item= new Item_field(lex->current_context(), schema_name.data(), table_name.data(), "*");
395
363
  sel->with_wild++;
396
 
 
397
364
  return item;
398
365
}
399
366
 
438
405
  return true;
439
406
}
440
407
 
441
 
void buildKey(LEX *lex, Key::Keytype type_par, const lex_string_t &name_arg)
 
408
void buildKey(LEX *lex, Key::Keytype type_par, str_ref name_arg)
442
409
{
443
410
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
444
411
  Key *key= new Key(type_par, name_arg, &statement->key_create_info, 0, lex->col_list);
446
413
  lex->col_list.clear(); /* Alloced by memory::sql_alloc */
447
414
}
448
415
 
449
 
void buildForeignKey(LEX *lex, const lex_string_t &name_arg, drizzled::Table_ident *table)
 
416
void buildForeignKey(LEX *lex, str_ref name_arg, drizzled::Table_ident *table)
450
417
{
451
418
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
452
 
  Key *key= new Foreign_key(name_arg, lex->col_list,
453
 
                            table,
454
 
                            lex->ref_list,
455
 
                            statement->fk_delete_opt,
456
 
                            statement->fk_update_opt,
457
 
                            statement->fk_match_option);
 
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));
458
421
 
459
 
  statement->alter_info.key_list.push_back(key);
460
 
  key= new Key(Key::MULTIPLE, name_arg, &default_key_create_info, 1, lex->col_list);
461
 
  statement->alter_info.key_list.push_back(key);
 
422
  statement->alter_info.key_list.push_back(new Key(Key::MULTIPLE, name_arg, &default_key_create_info, 1, lex->col_list));
462
423
  lex->col_list.clear(); /* Alloced by memory::sql_alloc */
463
424
  /* Only used for ALTER TABLE. Ignored otherwise. */
464
425
  statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
668
629
 
669
630
void buildReplicationOption(LEX *lex, bool arg)
670
631
{
671
 
  statement::CreateSchema *statement= (statement::CreateSchema *)lex->statement;
 
632
  statement::CreateSchema *statement= static_cast<statement::CreateSchema*>(lex->statement);
672
633
  message::set_is_replicated(statement->schema_message, arg);
673
634
}
674
635