~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/parser.cc

  • Committer: Andrew Hutchings
  • Date: 2011-02-02 12:51:57 UTC
  • mto: (2157.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2158.
  • Revision ID: andrew@linuxjedi.co.uk-20110202125157-r6thh7ox4g9l90ec
Make transaction_message_threshold a read-only global variable instead of a per-session variable
Make replication_dictionary column lengths use transation_message_threshold

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>
 
21
#include "config.h"
22
22
 
23
23
#include <drizzled/parser.h>
24
24
 
248
248
  push an error into the error stack and DRIZZLE_YYABORT
249
249
  to abort from the parser.
250
250
*/
251
 
void errorOn(drizzled::Session *session, const char *s)
 
251
void errorOn(const char *s)
252
252
{
 
253
  Session *session= current_session;
 
254
 
253
255
  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
254
256
  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
255
257
  {
395
397
  lex->setField(alter_proto.add_added_field());
396
398
}
397
399
 
398
 
void storeAlterColumnPosition(LEX *lex, const char *position)
399
 
{
400
 
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
401
 
 
402
 
  lex->last_field->after=const_cast<char*> (position);
403
 
  statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
404
 
}
405
 
 
406
 
bool buildCollation(LEX *lex, const CHARSET_INFO *arg)
407
 
{
408
 
  statement::CreateTable *statement= (statement::CreateTable *)lex->statement;
409
 
 
410
 
  HA_CREATE_INFO *cinfo= &statement->create_info();
411
 
  if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
412
 
      cinfo->default_table_charset && arg &&
413
 
      !my_charset_same(cinfo->default_table_charset, arg))
414
 
  {
415
 
    my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
416
 
             arg->name, cinfo->default_table_charset->csname);
417
 
    return false;
418
 
  }
419
 
  statement->create_info().default_table_charset= arg;
420
 
  statement->create_info().used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
421
 
 
422
 
  return true;
423
 
}
424
 
 
425
 
void buildKey(LEX *lex, Key::Keytype type_par, const lex_string_t &name_arg)
426
 
{
427
 
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
428
 
  Key *key= new Key(type_par, name_arg, &statement->key_create_info, 0,
429
 
                    lex->col_list);
430
 
  statement->alter_info.key_list.push_back(key);
431
 
  lex->col_list.clear(); /* Alloced by memory::sql_alloc */
432
 
}
433
 
 
434
 
void buildForeignKey(LEX *lex, const lex_string_t &name_arg, drizzled::Table_ident *table)
435
 
{
436
 
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
437
 
  Key *key= new Foreign_key(name_arg, lex->col_list,
438
 
                            table,
439
 
                            lex->ref_list,
440
 
                            statement->fk_delete_opt,
441
 
                            statement->fk_update_opt,
442
 
                            statement->fk_match_option);
443
 
 
444
 
  statement->alter_info.key_list.push_back(key);
445
 
  key= new Key(Key::MULTIPLE, name_arg,
446
 
               &default_key_create_info, 1,
447
 
               lex->col_list);
448
 
  statement->alter_info.key_list.push_back(key);
449
 
  lex->col_list.clear(); /* Alloced by memory::sql_alloc */
450
 
  /* Only used for ALTER TABLE. Ignored otherwise. */
451
 
  statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
452
 
}
453
 
 
454
 
drizzled::enum_field_types buildIntegerColumn(LEX *lex, drizzled::enum_field_types final_type, const bool is_unsigned)
455
 
456
 
  lex->length=(char*) 0; /* use default length */
457
 
 
458
 
  if (is_unsigned)
459
 
  {
460
 
    final_type= DRIZZLE_TYPE_LONGLONG;
461
 
  }
462
 
 
463
 
  if (lex->field())
464
 
  {
465
 
    assert (final_type == DRIZZLE_TYPE_LONG or final_type == DRIZZLE_TYPE_LONGLONG);
466
 
    // We update the type for unsigned types
467
 
    if (is_unsigned)
468
 
    {
469
 
      lex->field()->set_type(message::Table::Field::BIGINT);
470
 
      lex->field()->mutable_constraints()->set_is_unsigned(true);
471
 
    }
472
 
    else if (final_type == DRIZZLE_TYPE_LONG)
473
 
    {
474
 
      lex->field()->set_type(message::Table::Field::INTEGER);
475
 
    }
476
 
    else if (final_type == DRIZZLE_TYPE_LONGLONG)
477
 
    {
478
 
      lex->field()->set_type(message::Table::Field::BIGINT);
479
 
    }
480
 
  }
481
 
 
482
 
  return final_type;
483
 
}
484
 
 
485
 
drizzled::enum_field_types buildSerialColumn(LEX *lex)
486
 
{
487
 
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
488
 
  statement->alter_info.flags.set(ALTER_ADD_INDEX);
489
 
 
490
 
  lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG | UNSIGNED_FLAG);
491
 
 
492
 
  if (lex->field())
493
 
  {
494
 
    lex->field()->mutable_constraints()->set_is_notnull(true);
495
 
    lex->field()->mutable_constraints()->set_is_unsigned(true);
496
 
 
497
 
    lex->field()->set_type(message::Table::Field::BIGINT);
498
 
  }
499
 
 
500
 
  return DRIZZLE_TYPE_LONGLONG;
501
 
}
502
 
 
503
 
drizzled::enum_field_types buildVarcharColumn(LEX *lex, const char *length)
504
 
{
505
 
  lex->length= const_cast<char *>(length);
506
 
 
507
 
  if (lex->field())
508
 
  {
509
 
    lex->field()->set_type(message::Table::Field::VARCHAR);
510
 
 
511
 
    message::Table::Field::StringFieldOptions *string_field_options;
512
 
 
513
 
    string_field_options= lex->field()->mutable_string_options();
514
 
 
515
 
    string_field_options->set_length(atoi(length));
516
 
  }
517
 
 
518
 
  return DRIZZLE_TYPE_VARCHAR;
519
 
}
520
 
 
521
 
drizzled::enum_field_types buildDecimalColumn(LEX *lex)
522
 
{
523
 
  if (lex->field())
524
 
    lex->field()->set_type(message::Table::Field::DECIMAL);
525
 
 
526
 
  return DRIZZLE_TYPE_DECIMAL;
527
 
}
528
 
 
529
 
drizzled::enum_field_types buildVarbinaryColumn(LEX *lex, const char *length)
530
 
{
531
 
  lex->length= const_cast<char *>(length);
532
 
  lex->charset= &my_charset_bin;
533
 
 
534
 
  if (lex->field())
535
 
  {
536
 
    lex->field()->set_type(message::Table::Field::VARCHAR);
537
 
 
538
 
    message::Table::Field::StringFieldOptions *string_field_options;
539
 
 
540
 
    string_field_options= lex->field()->mutable_string_options();
541
 
 
542
 
    string_field_options->set_length(atoi(length));
543
 
    string_field_options->set_collation_id(my_charset_bin.number);
544
 
    string_field_options->set_collation(my_charset_bin.name);
545
 
  }
546
 
 
547
 
  return DRIZZLE_TYPE_VARCHAR;
548
 
}
549
 
 
550
 
drizzled::enum_field_types buildBlobColumn(LEX *lex)
551
 
{
552
 
  lex->charset=&my_charset_bin;
553
 
  lex->length=(char*) 0; /* use default length */
554
 
 
555
 
  if (lex->field())
556
 
  {
557
 
    lex->field()->set_type(message::Table::Field::BLOB);
558
 
    message::Table::Field::StringFieldOptions *string_field_options;
559
 
 
560
 
    string_field_options= lex->field()->mutable_string_options();
561
 
    string_field_options->set_collation_id(my_charset_bin.number);
562
 
    string_field_options->set_collation(my_charset_bin.name);
563
 
  }
564
 
 
565
 
  return DRIZZLE_TYPE_BLOB;
566
 
}
567
 
 
568
 
drizzled::enum_field_types buildBooleanColumn(LEX *lex)
569
 
{
570
 
  if (lex->field())
571
 
    lex->field()->set_type(message::Table::Field::BOOLEAN);
572
 
 
573
 
  return DRIZZLE_TYPE_BOOLEAN;
574
 
}
575
 
 
576
 
drizzled::enum_field_types buildUuidColumn(LEX *lex)
577
 
{
578
 
  if (lex->field())
579
 
    lex->field()->set_type(message::Table::Field::UUID);
580
 
 
581
 
  return DRIZZLE_TYPE_UUID;
582
 
}
583
 
 
584
 
drizzled::enum_field_types buildDoubleColumn(LEX *lex)
585
 
{
586
 
  if (lex->field())
587
 
  {
588
 
    lex->field()->set_type(message::Table::Field::DOUBLE);
589
 
  }
590
 
 
591
 
  return DRIZZLE_TYPE_DOUBLE;
592
 
}
593
 
 
594
 
drizzled::enum_field_types buildTimestampColumn(LEX *lex, const char *length)
595
 
{
596
 
  if (lex->field())
597
 
  {
598
 
    lex->field()->set_type(message::Table::Field::EPOCH);
599
 
  }
600
 
 
601
 
  if (length)
602
 
  {
603
 
    lex->length= const_cast<char *>(length);
604
 
    return DRIZZLE_TYPE_MICROTIME;
605
 
  }
606
 
 
607
 
  lex->length= NULL;
608
 
 
609
 
  return DRIZZLE_TYPE_TIMESTAMP;
610
 
}
611
 
 
612
 
void buildKeyOnColumn(LEX *lex)
613
 
{
614
 
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
615
 
 
616
 
  lex->type|= UNIQUE_KEY_FLAG;
617
 
  statement->alter_info.flags.set(ALTER_ADD_INDEX);
618
 
 
619
 
  if (lex->field())
620
 
  {
621
 
    lex->field()->mutable_constraints()->set_is_unique(true);
622
 
  }
623
 
}
624
 
 
625
 
void buildAutoOnColumn(LEX *lex)
626
 
{
627
 
  lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG;
628
 
 
629
 
  if (lex->field())
630
 
  {
631
 
    lex->field()->mutable_constraints()->set_is_notnull(true);
632
 
  }
633
 
}
634
 
 
635
 
void buildPrimaryOnColumn(LEX *lex)
636
 
{
637
 
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
638
 
 
639
 
  lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
640
 
  statement->alter_info.flags.set(ALTER_ADD_INDEX);
641
 
 
642
 
  if (lex->field())
643
 
  {
644
 
    lex->field()->mutable_constraints()->set_is_notnull(true);
645
 
  }
646
 
}
647
 
 
648
 
void buildReplicationOption(LEX *lex, bool arg)
649
 
{
650
 
  statement::CreateSchema *statement= (statement::CreateSchema *)lex->statement;
651
 
  message::ReplicationOptions *options= statement->schema_message.mutable_replication_options();
652
 
  options->set_dont_replicate(arg);
653
 
}
654
 
 
655
 
void buildAddAlterDropIndex(LEX *lex, const char *name, bool is_foreign_key)
656
 
{
657
 
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
658
 
 
659
 
  statement->alter_info.flags.set(ALTER_DROP_INDEX);
660
 
  if (is_foreign_key)
661
 
  {
662
 
    statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
663
 
    statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::FOREIGN_KEY, name));
664
 
  }
665
 
  else
666
 
  {
667
 
    statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::KEY, name));
668
 
  }
669
 
}
670
 
 
671
400
} // namespace parser
672
401
} // namespace drizzled