~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/parser.cc

  • Committer: Mark Atwood
  • Date: 2011-08-11 03:05:03 UTC
  • mfrom: (2385.1.12 refactor4)
  • Revision ID: me@mark.atwood.name-20110811030503-rp9xjihc5x3y0x4q
merge lp:~olafvdspek/drizzle/refactor4

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include "config.h"
22
 
 
 
21
#include <config.h>
23
22
#include <drizzled/parser.h>
 
23
#include <drizzled/alter_info.h>
 
24
#include <drizzled/create_field.h>
 
25
#include <drizzled/item/subselect.h>
 
26
#include <drizzled/lex_input_stream.h>
 
27
#include <drizzled/message/alter_table.pb.h>
 
28
#include <drizzled/session.h>
 
29
#include <drizzled/sql_lex.h>
24
30
 
25
 
namespace drizzled
26
 
{
27
 
namespace parser
28
 
{
 
31
namespace drizzled {
 
32
namespace parser {
29
33
 
30
34
/**
31
35
  Helper to resolve the SQL:2003 Syntax exception 1) in <in predicate>.
179
183
 
180
184
Item* reserved_keyword_function(Session *session, const std::string &name, List<Item> *item_list)
181
185
{
182
 
  const plugin::Function *udf= plugin::Function::get(name.c_str(), name.length());
183
 
  Item *item= NULL;
 
186
  const plugin::Function *udf= plugin::Function::get(name);
184
187
 
185
188
  if (udf)
186
189
  {
187
 
    item= Create_udf_func::s_singleton.create(session, udf, item_list);
188
 
  } else {
189
 
    my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", name.c_str());
 
190
    return Create_udf_func::s_singleton.create(session, udf, item_list);
190
191
  }
191
192
 
192
 
  return item;
 
193
  my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", name.c_str());
 
194
 
 
195
  return NULL;
193
196
}
194
197
 
195
198
/**
218
221
  my_printf_error(ER_PARSE_ERROR_UNKNOWN, ER(ER_PARSE_ERROR_UNKNOWN), MYF(0), message);
219
222
}
220
223
 
221
 
bool check_reserved_words(LEX_STRING *name)
 
224
bool check_reserved_words(lex_string_t *name)
222
225
{
223
226
  if (!my_strcasecmp(system_charset_info, name->str, "GLOBAL") ||
224
227
      !my_strcasecmp(system_charset_info, name->str, "LOCAL") ||
248
251
  push an error into the error stack and DRIZZLE_YYABORT
249
252
  to abort from the parser.
250
253
*/
251
 
void errorOn(const char *s)
 
254
void errorOn(drizzled::Session *session, const char *s)
252
255
{
253
 
  Session *session= current_session;
254
 
 
255
256
  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
256
257
  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
257
258
  {
300
301
  return true;
301
302
}
302
303
 
303
 
void buildEngineOption(LEX *lex, const char *key, const LEX_STRING &value)
 
304
void buildEngineOption(LEX *lex, const char *key, const lex_string_t &value)
304
305
{
305
306
  message::Engine::Option *opt= lex->table()->mutable_engine()->add_options();
306
307
  opt->set_name(key);
314
315
  opt->set_state(boost::lexical_cast<std::string>(value));
315
316
}
316
317
 
317
 
void buildSchemaOption(LEX *lex, const char *key, const LEX_STRING &value)
 
318
void buildSchemaOption(LEX *lex, const char *key, const lex_string_t &value)
318
319
{
319
320
  statement::CreateSchema *statement= (statement::CreateSchema *)lex->statement;
320
321
  message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
322
323
  opt->set_state(value.str, value.length);
323
324
}
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);
 
331
}
 
332
 
 
333
void buildSchemaDefiner(LEX *lex, const identifier::User &user)
 
334
{
 
335
  statement::CreateSchema *statement= (statement::CreateSchema *)lex->statement;
 
336
  message::set_definer(statement->schema_message, user);
 
337
}
 
338
 
325
339
void buildSchemaOption(LEX *lex, const char *key, uint64_t value)
326
340
{
327
341
  statement::CreateSchema *statement= (statement::CreateSchema *)lex->statement;
330
344
  opt->set_state(boost::lexical_cast<std::string>(value));
331
345
}
332
346
 
333
 
bool checkFieldIdent(LEX *lex, const LEX_STRING &schema_name, const LEX_STRING &table_name)
 
347
bool checkFieldIdent(LEX *lex, const lex_string_t &schema_name, const lex_string_t &table_name)
334
348
{
335
349
  TableList *table= reinterpret_cast<TableList*>(lex->current_select->table_list.first);
336
350
 
354
368
}
355
369
 
356
370
Item *buildIdent(LEX *lex,
357
 
                 const LEX_STRING &schema_name,
358
 
                 const LEX_STRING &table_name,
359
 
                 const LEX_STRING &field_name)
 
371
                 const lex_string_t &schema_name,
 
372
                 const lex_string_t &table_name,
 
373
                 const lex_string_t &field_name)
360
374
{
361
375
  Select_Lex *sel= lex->current_select;
362
376
 
374
388
  return item;
375
389
}
376
390
 
377
 
Item *buildTableWild(LEX *lex, const LEX_STRING &schema_name, const LEX_STRING &table_name)
 
391
Item *buildTableWild(LEX *lex, const lex_string_t &schema_name, const lex_string_t &table_name)
378
392
{
379
393
  Select_Lex *sel= lex->current_select;
380
394
  Item *item= new Item_field(lex->current_context(), schema_name.str, table_name.str, "*");
389
403
  lex->length= lex->dec=0;
390
404
  lex->type=0;
391
405
  statement->default_value= statement->on_update_value= 0;
392
 
  statement->comment= null_lex_str;
 
406
  statement->comment= null_lex_string();
393
407
  lex->charset= NULL;
394
408
  statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
395
409
 
396
 
  message::AlterTable &alter_proto= ((statement::CreateTable *)lex->statement)->alter_info.alter_proto;
397
 
  lex->setField(alter_proto.add_added_field());
 
410
  message::AddedFields &added_fields_proto= ((statement::CreateTable *)lex->statement)->alter_info.added_fields_proto;
 
411
  lex->setField(added_fields_proto.add_added_field());
398
412
}
399
413
 
400
414
void storeAlterColumnPosition(LEX *lex, const char *position)
401
415
{
402
416
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
403
417
 
404
 
  lex->last_field->after=const_cast<char*> (position);
 
418
  lex->last_field->after= position;
405
419
  statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
406
420
}
407
421
 
408
 
bool buildCollation(LEX *lex, const CHARSET_INFO *arg)
 
422
bool buildCollation(LEX *lex, const charset_info_st *arg)
409
423
{
410
424
  statement::CreateTable *statement= (statement::CreateTable *)lex->statement;
411
425
 
427
441
void buildKey(LEX *lex, Key::Keytype type_par, const lex_string_t &name_arg)
428
442
{
429
443
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
430
 
  Key *key= new Key(type_par, name_arg, &statement->key_create_info, 0,
431
 
                    lex->col_list);
 
444
  Key *key= new Key(type_par, name_arg, &statement->key_create_info, 0, lex->col_list);
432
445
  statement->alter_info.key_list.push_back(key);
433
 
  lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
446
  lex->col_list.clear(); /* Alloced by memory::sql_alloc */
434
447
}
435
448
 
436
449
void buildForeignKey(LEX *lex, const lex_string_t &name_arg, drizzled::Table_ident *table)
444
457
                            statement->fk_match_option);
445
458
 
446
459
  statement->alter_info.key_list.push_back(key);
447
 
  key= new Key(Key::MULTIPLE, name_arg,
448
 
               &default_key_create_info, 1,
449
 
               lex->col_list);
 
460
  key= new Key(Key::MULTIPLE, name_arg, &default_key_create_info, 1, lex->col_list);
450
461
  statement->alter_info.key_list.push_back(key);
451
 
  lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
462
  lex->col_list.clear(); /* Alloced by memory::sql_alloc */
452
463
  /* Only used for ALTER TABLE. Ignored otherwise. */
453
464
  statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
454
465
}
455
466
 
456
467
drizzled::enum_field_types buildIntegerColumn(LEX *lex, drizzled::enum_field_types final_type, const bool is_unsigned)
457
468
458
 
  lex->length=(char*) 0; /* use default length */
 
469
  lex->length= NULL; /* use default length */
459
470
 
460
471
  if (is_unsigned)
461
472
  {
504
515
 
505
516
drizzled::enum_field_types buildVarcharColumn(LEX *lex, const char *length)
506
517
{
507
 
  lex->length= const_cast<char *>(length);
 
518
  lex->length= length;
508
519
 
509
520
  if (lex->field())
510
521
  {
530
541
 
531
542
drizzled::enum_field_types buildVarbinaryColumn(LEX *lex, const char *length)
532
543
{
533
 
  lex->length= const_cast<char *>(length);
 
544
  lex->length= length;
534
545
  lex->charset= &my_charset_bin;
535
546
 
536
547
  if (lex->field())
602
613
 
603
614
  if (length)
604
615
  {
605
 
    lex->length= const_cast<char *>(length);
 
616
    lex->length= length;
606
617
    return DRIZZLE_TYPE_MICROTIME;
607
618
  }
608
619
 
647
658
  }
648
659
}
649
660
 
 
661
void buildReplicationOption(LEX *lex, bool arg)
 
662
{
 
663
  statement::CreateSchema *statement= (statement::CreateSchema *)lex->statement;
 
664
  message::set_is_replicated(statement->schema_message, arg);
 
665
}
 
666
 
 
667
void buildAddAlterDropIndex(LEX *lex, const char *name, bool is_foreign_key)
 
668
{
 
669
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
 
670
 
 
671
  message::AlterTable::AlterTableOperation *operation;
 
672
  operation= lex->alter_table()->add_operations();
 
673
  operation->set_drop_name(name);
 
674
 
 
675
  statement->alter_info.flags.set(ALTER_DROP_INDEX);
 
676
  if (is_foreign_key)
 
677
  {
 
678
    statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
 
679
    operation->set_operation(message::AlterTable::AlterTableOperation::DROP_FOREIGN_KEY);
 
680
  }
 
681
  else
 
682
  {
 
683
    operation->set_operation(message::AlterTable::AlterTableOperation::DROP_KEY);
 
684
  }
 
685
}
 
686
 
650
687
} // namespace parser
651
688
} // namespace drizzled