~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/parser.cc

  • Committer: Lee Bieber
  • Date: 2011-02-10 01:09:23 UTC
  • mfrom: (2152.2.1 alter-table)
  • Revision ID: kalebral@gmail.com-20110210010923-mbwuwow0nudk7ryh
Merge Brian - more parser rework

Show diffs side-by-side

added added

removed removed

Lines of Context:
405
405
  statement->alter_info.flags.set(ALTER_COLUMN_ORDER);
406
406
}
407
407
 
 
408
bool buildCollation(LEX *lex, const CHARSET_INFO *arg)
 
409
{
 
410
  statement::CreateTable *statement= (statement::CreateTable *)lex->statement;
 
411
 
 
412
  HA_CREATE_INFO *cinfo= &statement->create_info();
 
413
  if ((cinfo->used_fields & HA_CREATE_USED_DEFAULT_CHARSET) &&
 
414
      cinfo->default_table_charset && arg &&
 
415
      !my_charset_same(cinfo->default_table_charset, arg))
 
416
  {
 
417
    my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
 
418
             arg->name, cinfo->default_table_charset->csname);
 
419
    return false;
 
420
  }
 
421
  statement->create_info().default_table_charset= arg;
 
422
  statement->create_info().used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
 
423
 
 
424
  return true;
 
425
}
 
426
 
 
427
void buildKey(LEX *lex, Key::Keytype type_par, const lex_string_t &name_arg)
 
428
{
 
429
  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);
 
432
  statement->alter_info.key_list.push_back(key);
 
433
  lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
434
}
 
435
 
 
436
void buildForeignKey(LEX *lex, const lex_string_t &name_arg, drizzled::Table_ident *table)
 
437
{
 
438
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
 
439
  Key *key= new Foreign_key(name_arg, lex->col_list,
 
440
                            table,
 
441
                            lex->ref_list,
 
442
                            statement->fk_delete_opt,
 
443
                            statement->fk_update_opt,
 
444
                            statement->fk_match_option);
 
445
 
 
446
  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);
 
450
  statement->alter_info.key_list.push_back(key);
 
451
  lex->col_list.empty(); /* Alloced by memory::sql_alloc */
 
452
  /* Only used for ALTER TABLE. Ignored otherwise. */
 
453
  statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
 
454
}
 
455
 
 
456
drizzled::enum_field_types buildIntegerColumn(LEX *lex, drizzled::enum_field_types final_type, const bool is_unsigned)
 
457
 
458
  lex->length=(char*) 0; /* use default length */
 
459
 
 
460
  if (is_unsigned)
 
461
  {
 
462
    final_type= DRIZZLE_TYPE_LONGLONG;
 
463
  }
 
464
 
 
465
  if (lex->field())
 
466
  {
 
467
    assert (final_type == DRIZZLE_TYPE_LONG or final_type == DRIZZLE_TYPE_LONGLONG);
 
468
    // We update the type for unsigned types
 
469
    if (is_unsigned)
 
470
    {
 
471
      lex->field()->set_type(message::Table::Field::BIGINT);
 
472
      lex->field()->mutable_constraints()->set_is_unsigned(true);
 
473
    }
 
474
    else if (final_type == DRIZZLE_TYPE_LONG)
 
475
    {
 
476
      lex->field()->set_type(message::Table::Field::INTEGER);
 
477
    }
 
478
    else if (final_type == DRIZZLE_TYPE_LONGLONG)
 
479
    {
 
480
      lex->field()->set_type(message::Table::Field::BIGINT);
 
481
    }
 
482
  }
 
483
 
 
484
  return final_type;
 
485
}
 
486
 
 
487
drizzled::enum_field_types buildSerialColumn(LEX *lex)
 
488
{
 
489
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
 
490
  statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
491
 
 
492
  lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG | UNSIGNED_FLAG);
 
493
 
 
494
  if (lex->field())
 
495
  {
 
496
    lex->field()->mutable_constraints()->set_is_notnull(true);
 
497
    lex->field()->mutable_constraints()->set_is_unsigned(true);
 
498
 
 
499
    lex->field()->set_type(message::Table::Field::BIGINT);
 
500
  }
 
501
 
 
502
  return DRIZZLE_TYPE_LONGLONG;
 
503
}
 
504
 
 
505
drizzled::enum_field_types buildVarcharColumn(LEX *lex, const char *length)
 
506
{
 
507
  lex->length= const_cast<char *>(length);
 
508
 
 
509
  if (lex->field())
 
510
  {
 
511
    lex->field()->set_type(message::Table::Field::VARCHAR);
 
512
 
 
513
    message::Table::Field::StringFieldOptions *string_field_options;
 
514
 
 
515
    string_field_options= lex->field()->mutable_string_options();
 
516
 
 
517
    string_field_options->set_length(atoi(length));
 
518
  }
 
519
 
 
520
  return DRIZZLE_TYPE_VARCHAR;
 
521
}
 
522
 
 
523
drizzled::enum_field_types buildDecimalColumn(LEX *lex)
 
524
{
 
525
  if (lex->field())
 
526
    lex->field()->set_type(message::Table::Field::DECIMAL);
 
527
 
 
528
  return DRIZZLE_TYPE_DECIMAL;
 
529
}
 
530
 
 
531
drizzled::enum_field_types buildVarbinaryColumn(LEX *lex, const char *length)
 
532
{
 
533
  lex->length= const_cast<char *>(length);
 
534
  lex->charset= &my_charset_bin;
 
535
 
 
536
  if (lex->field())
 
537
  {
 
538
    lex->field()->set_type(message::Table::Field::VARCHAR);
 
539
 
 
540
    message::Table::Field::StringFieldOptions *string_field_options;
 
541
 
 
542
    string_field_options= lex->field()->mutable_string_options();
 
543
 
 
544
    string_field_options->set_length(atoi(length));
 
545
    string_field_options->set_collation_id(my_charset_bin.number);
 
546
    string_field_options->set_collation(my_charset_bin.name);
 
547
  }
 
548
 
 
549
  return DRIZZLE_TYPE_VARCHAR;
 
550
}
 
551
 
 
552
drizzled::enum_field_types buildBlobColumn(LEX *lex)
 
553
{
 
554
  lex->charset=&my_charset_bin;
 
555
  lex->length=(char*) 0; /* use default length */
 
556
 
 
557
  if (lex->field())
 
558
  {
 
559
    lex->field()->set_type(message::Table::Field::BLOB);
 
560
    message::Table::Field::StringFieldOptions *string_field_options;
 
561
 
 
562
    string_field_options= lex->field()->mutable_string_options();
 
563
    string_field_options->set_collation_id(my_charset_bin.number);
 
564
    string_field_options->set_collation(my_charset_bin.name);
 
565
  }
 
566
 
 
567
  return DRIZZLE_TYPE_BLOB;
 
568
}
 
569
 
 
570
drizzled::enum_field_types buildBooleanColumn(LEX *lex)
 
571
{
 
572
  if (lex->field())
 
573
    lex->field()->set_type(message::Table::Field::BOOLEAN);
 
574
 
 
575
  return DRIZZLE_TYPE_BOOLEAN;
 
576
}
 
577
 
 
578
drizzled::enum_field_types buildUuidColumn(LEX *lex)
 
579
{
 
580
  if (lex->field())
 
581
    lex->field()->set_type(message::Table::Field::UUID);
 
582
 
 
583
  return DRIZZLE_TYPE_UUID;
 
584
}
 
585
 
 
586
drizzled::enum_field_types buildDoubleColumn(LEX *lex)
 
587
{
 
588
  if (lex->field())
 
589
  {
 
590
    lex->field()->set_type(message::Table::Field::DOUBLE);
 
591
  }
 
592
 
 
593
  return DRIZZLE_TYPE_DOUBLE;
 
594
}
 
595
 
 
596
drizzled::enum_field_types buildTimestampColumn(LEX *lex, const char *length)
 
597
{
 
598
  if (lex->field())
 
599
  {
 
600
    lex->field()->set_type(message::Table::Field::EPOCH);
 
601
  }
 
602
 
 
603
  if (length)
 
604
  {
 
605
    lex->length= const_cast<char *>(length);
 
606
    return DRIZZLE_TYPE_MICROTIME;
 
607
  }
 
608
 
 
609
  lex->length= NULL;
 
610
 
 
611
  return DRIZZLE_TYPE_TIMESTAMP;
 
612
}
 
613
 
 
614
void buildKeyOnColumn(LEX *lex)
 
615
{
 
616
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
 
617
 
 
618
  lex->type|= UNIQUE_KEY_FLAG;
 
619
  statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
620
 
 
621
  if (lex->field())
 
622
  {
 
623
    lex->field()->mutable_constraints()->set_is_unique(true);
 
624
  }
 
625
}
 
626
 
 
627
void buildAutoOnColumn(LEX *lex)
 
628
{
 
629
  lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG;
 
630
 
 
631
  if (lex->field())
 
632
  {
 
633
    lex->field()->mutable_constraints()->set_is_notnull(true);
 
634
  }
 
635
}
 
636
 
 
637
void buildPrimaryOnColumn(LEX *lex)
 
638
{
 
639
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
 
640
 
 
641
  lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
 
642
  statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
643
 
 
644
  if (lex->field())
 
645
  {
 
646
    lex->field()->mutable_constraints()->set_is_notnull(true);
 
647
  }
 
648
}
 
649
 
408
650
} // namespace parser
409
651
} // namespace drizzled