~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Brian Aker
  • Date: 2009-11-18 06:24:48 UTC
  • mfrom: (1220.1.15 staging)
  • Revision ID: brian@gaz-20091118062448-o36lo3yv81sc6u9z
Merge Brian + Stewart

Show diffs side-by-side

added added

removed removed

Lines of Context:
1542
1542
            statement->comment= null_lex_str;
1543
1543
            lex->charset=NULL;
1544
1544
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
 
1545
 
 
1546
            message::AlterTable &alter_proto=
 
1547
              ((statement::CreateTable *)Lex->statement)->alter_info.alter_proto;
 
1548
            statement->current_proto_field= alter_proto.add_added_field();
1545
1549
          }
1546
1550
          field_def
1547
1551
          {
1548
1552
            LEX *lex=Lex;
1549
1553
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1554
 
 
1555
            if (statement->current_proto_field)
 
1556
              statement->current_proto_field->set_name($1.str);
 
1557
 
1550
1558
            if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
1551
1559
                                  lex->length,lex->dec,lex->type,
1552
1560
                                  statement->column_format,
1554
1562
                                  &statement->comment,
1555
1563
                                  statement->change, &lex->interval_list, lex->charset))
1556
1564
              DRIZZLE_YYABORT;
 
1565
 
 
1566
            statement->current_proto_field= NULL;
1557
1567
          }
1558
1568
        ;
1559
1569
field_def:
1562
1572
 
1563
1573
type:
1564
1574
        int_type
1565
 
        { 
1566
 
          $$=$1; 
 
1575
        {
 
1576
          $$=$1;
1567
1577
          Lex->length=(char*) 0; /* use default length */
1568
 
        }
1569
 
        | real_type opt_precision { $$=$1; }
1570
 
        | char '(' NUM ')'
1571
 
          {
1572
 
            Lex->length=$3.str;
1573
 
            $$=DRIZZLE_TYPE_VARCHAR;
1574
 
          }
1575
 
        | char
1576
 
          {
1577
 
            Lex->length=(char*) "1";
1578
 
            $$=DRIZZLE_TYPE_VARCHAR;
1579
 
          }
1580
 
        | varchar '(' NUM ')'
1581
 
          {
1582
 
            Lex->length=$3.str;
1583
 
            $$= DRIZZLE_TYPE_VARCHAR;
1584
 
          }
1585
 
        | VARBINARY '(' NUM ')'
1586
 
          {
1587
 
            Lex->length=$3.str;
1588
 
            Lex->charset=&my_charset_bin;
1589
 
            $$= DRIZZLE_TYPE_VARCHAR;
1590
 
          }
1591
 
        | DATE_SYM
1592
 
          { $$=DRIZZLE_TYPE_DATE; }
1593
 
        | TIMESTAMP_SYM
1594
 
          { $$=DRIZZLE_TYPE_TIMESTAMP; }
1595
 
        | DATETIME_SYM
1596
 
          { $$=DRIZZLE_TYPE_DATETIME; }
1597
 
        | BLOB_SYM
1598
 
          {
1599
 
            Lex->charset=&my_charset_bin;
1600
 
            $$=DRIZZLE_TYPE_BLOB;
1601
 
            Lex->length=(char*) 0; /* use default length */
1602
 
          }
1603
 
        | TEXT_SYM
1604
 
          { 
1605
 
            $$=DRIZZLE_TYPE_BLOB; 
1606
 
            Lex->length=(char*) 0; /* use default length */
1607
 
          }
1608
 
        | DECIMAL_SYM float_options
1609
 
          { $$=DRIZZLE_TYPE_DECIMAL;}
1610
 
        | NUMERIC_SYM float_options
1611
 
          { $$=DRIZZLE_TYPE_DECIMAL;}
1612
 
        | FIXED_SYM float_options
1613
 
          { $$=DRIZZLE_TYPE_DECIMAL;}
1614
 
        | ENUM_SYM
1615
 
          {Lex->interval_list.empty();}
1616
 
          '(' string_list ')'
1617
 
          { $$=DRIZZLE_TYPE_ENUM; }
 
1578
          statement::CreateTable *statement=
 
1579
            (statement::CreateTable *)Lex->statement;
 
1580
 
 
1581
          if (statement->current_proto_field)
 
1582
          {
 
1583
            if ($1 == DRIZZLE_TYPE_LONG)
 
1584
              statement->current_proto_field->set_type(message::Table::Field::INTEGER);
 
1585
            else if ($1 == DRIZZLE_TYPE_LONGLONG)
 
1586
              statement->current_proto_field->set_type(message::Table::Field::BIGINT);
 
1587
            else
 
1588
              abort();
 
1589
          }
 
1590
          }
 
1591
        | real_type opt_precision
 
1592
          {
 
1593
            $$=$1;
 
1594
 
 
1595
            statement::CreateTable *statement=
 
1596
              (statement::CreateTable *)Lex->statement;
 
1597
 
 
1598
            if (statement->current_proto_field)
 
1599
            {
 
1600
              assert ($1 == DRIZZLE_TYPE_DOUBLE);
 
1601
              statement->current_proto_field->set_type(message::Table::Field::DOUBLE);
 
1602
            }
 
1603
          }
 
1604
          | char '(' NUM ')'
 
1605
            {
 
1606
              Lex->length=$3.str;
 
1607
              $$=DRIZZLE_TYPE_VARCHAR;
 
1608
 
 
1609
            statement::CreateTable *statement=
 
1610
              (statement::CreateTable *)Lex->statement;
 
1611
 
 
1612
            if (statement->current_proto_field)
 
1613
            {
 
1614
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1615
              message::Table::Field::StringFieldOptions *string_field_options;
 
1616
 
 
1617
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1618
 
 
1619
              string_field_options->set_length(atoi($3.str));
 
1620
            }
 
1621
            }
 
1622
          | char
 
1623
            {
 
1624
              Lex->length=(char*) "1";
 
1625
              $$=DRIZZLE_TYPE_VARCHAR;
 
1626
 
 
1627
            statement::CreateTable *statement=
 
1628
              (statement::CreateTable *)Lex->statement;
 
1629
 
 
1630
            if (statement->current_proto_field)
 
1631
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1632
            }
 
1633
          | varchar '(' NUM ')'
 
1634
            {
 
1635
              Lex->length=$3.str;
 
1636
              $$= DRIZZLE_TYPE_VARCHAR;
 
1637
 
 
1638
            statement::CreateTable *statement=
 
1639
              (statement::CreateTable *)Lex->statement;
 
1640
 
 
1641
            if (statement->current_proto_field)
 
1642
            {
 
1643
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1644
 
 
1645
              message::Table::Field::StringFieldOptions *string_field_options;
 
1646
 
 
1647
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1648
 
 
1649
              string_field_options->set_length(atoi($3.str));
 
1650
            }
 
1651
            }
 
1652
          | VARBINARY '(' NUM ')'
 
1653
            {
 
1654
              Lex->length=$3.str;
 
1655
              Lex->charset=&my_charset_bin;
 
1656
              $$= DRIZZLE_TYPE_VARCHAR;
 
1657
 
 
1658
            statement::CreateTable *statement=
 
1659
              (statement::CreateTable *)Lex->statement;
 
1660
 
 
1661
            if (statement->current_proto_field)
 
1662
            {
 
1663
              statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
 
1664
              message::Table::Field::StringFieldOptions *string_field_options;
 
1665
 
 
1666
              string_field_options= statement->current_proto_field->mutable_string_options();
 
1667
 
 
1668
              string_field_options->set_length(atoi($3.str));
 
1669
              string_field_options->set_collation_id(my_charset_bin.number);
 
1670
              string_field_options->set_collation(my_charset_bin.name);
 
1671
            }
 
1672
            }
 
1673
          | DATE_SYM
 
1674
          {
 
1675
            $$=DRIZZLE_TYPE_DATE;
 
1676
 
 
1677
            statement::CreateTable *statement=
 
1678
              (statement::CreateTable *)Lex->statement;
 
1679
 
 
1680
            if (statement->current_proto_field)
 
1681
              statement->current_proto_field->set_type(message::Table::Field::DATE);
 
1682
          }
 
1683
          | TIMESTAMP_SYM
 
1684
          {
 
1685
            $$=DRIZZLE_TYPE_TIMESTAMP;
 
1686
 
 
1687
            statement::CreateTable *statement=
 
1688
              (statement::CreateTable *)Lex->statement;
 
1689
 
 
1690
            if (statement->current_proto_field)
 
1691
              statement->current_proto_field->set_type(message::Table::Field::TIMESTAMP);
 
1692
          }
 
1693
          | DATETIME_SYM
 
1694
          {
 
1695
            $$=DRIZZLE_TYPE_DATETIME;
 
1696
 
 
1697
            statement::CreateTable *statement=
 
1698
              (statement::CreateTable *)Lex->statement;
 
1699
 
 
1700
            if (statement->current_proto_field)
 
1701
              statement->current_proto_field->set_type(message::Table::Field::DATETIME);
 
1702
          }
 
1703
          | BLOB_SYM
 
1704
            {
 
1705
              Lex->charset=&my_charset_bin;
 
1706
              $$=DRIZZLE_TYPE_BLOB;
 
1707
              Lex->length=(char*) 0; /* use default length */
 
1708
 
 
1709
            statement::CreateTable *statement=
 
1710
              (statement::CreateTable *)Lex->statement;
 
1711
 
 
1712
            if (statement->current_proto_field)
 
1713
              statement->current_proto_field->set_type(message::Table::Field::BLOB);
 
1714
            }
 
1715
          | TEXT_SYM
 
1716
            {
 
1717
              $$=DRIZZLE_TYPE_BLOB;
 
1718
              Lex->length=(char*) 0; /* use default length */
 
1719
 
 
1720
            statement::CreateTable *statement=
 
1721
              (statement::CreateTable *)Lex->statement;
 
1722
 
 
1723
            if (statement->current_proto_field)
 
1724
              statement->current_proto_field->set_type(message::Table::Field::BLOB);
 
1725
            }
 
1726
          | DECIMAL_SYM float_options
 
1727
          {
 
1728
            $$=DRIZZLE_TYPE_DECIMAL;
 
1729
 
 
1730
            statement::CreateTable *statement=
 
1731
              (statement::CreateTable *)Lex->statement;
 
1732
 
 
1733
            if (statement->current_proto_field)
 
1734
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1735
          }
 
1736
          | NUMERIC_SYM float_options
 
1737
          {
 
1738
            $$=DRIZZLE_TYPE_DECIMAL;
 
1739
 
 
1740
            statement::CreateTable *statement=
 
1741
              (statement::CreateTable *)Lex->statement;
 
1742
 
 
1743
            if (statement->current_proto_field)
 
1744
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1745
          }
 
1746
          | FIXED_SYM float_options
 
1747
          {
 
1748
            $$=DRIZZLE_TYPE_DECIMAL;
 
1749
 
 
1750
            statement::CreateTable *statement=
 
1751
              (statement::CreateTable *)Lex->statement;
 
1752
 
 
1753
            if (statement->current_proto_field)
 
1754
              statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
 
1755
          }
 
1756
          | ENUM_SYM
 
1757
            {Lex->interval_list.empty();}
 
1758
            '(' string_list ')'
 
1759
          {
 
1760
            $$=DRIZZLE_TYPE_ENUM;
 
1761
 
 
1762
            statement::CreateTable *statement=
 
1763
              (statement::CreateTable *)Lex->statement;
 
1764
 
 
1765
            if (statement->current_proto_field)
 
1766
              statement->current_proto_field->set_type(message::Table::Field::ENUM);
 
1767
          }
1618
1768
        | SERIAL_SYM
1619
1769
          {
1620
1770
            $$=DRIZZLE_TYPE_LONGLONG;
1621
1771
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
 
1772
 
 
1773
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
 
1774
            if (statement->current_proto_field)
 
1775
            {
 
1776
              message::Table::Field::FieldConstraints *constraints;
 
1777
              constraints= statement->current_proto_field->mutable_constraints();
 
1778
              constraints->set_is_nullable(false);
 
1779
 
 
1780
              statement->current_proto_field->set_type(message::Table::Field::BIGINT);
 
1781
            }
1622
1782
          }
1623
1783
        ;
1624
1784
 
1686
1846
        ;
1687
1847
 
1688
1848
attribute:
1689
 
          NULL_SYM { Lex->type&= ~ NOT_NULL_FLAG; }
 
1849
          NULL_SYM
 
1850
          {
 
1851
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1852
            Lex->type&= ~ NOT_NULL_FLAG;
 
1853
 
 
1854
            if (statement->current_proto_field)
 
1855
            {
 
1856
              message::Table::Field::FieldConstraints *constraints;
 
1857
              constraints= statement->current_proto_field->mutable_constraints();
 
1858
              constraints->set_is_nullable(true);
 
1859
            }
 
1860
          }
1690
1861
        | COLUMN_FORMAT_SYM column_format_types
1691
1862
          {
1692
1863
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1694
1865
            statement->column_format= $2;
1695
1866
            statement->alter_info.flags.set(ALTER_COLUMN_FORMAT);
1696
1867
          }
1697
 
        | not NULL_SYM { Lex->type|= NOT_NULL_FLAG; }
 
1868
        | not NULL_SYM
 
1869
          {
 
1870
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1871
            Lex->type|= NOT_NULL_FLAG;
 
1872
 
 
1873
            if (statement->current_proto_field)
 
1874
            {
 
1875
              message::Table::Field::FieldConstraints *constraints;
 
1876
              constraints= statement->current_proto_field->mutable_constraints();
 
1877
              constraints->set_is_nullable(false);
 
1878
            }
 
1879
          }
1698
1880
        | DEFAULT now_or_signed_literal 
1699
1881
          { 
1700
1882
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1704
1886
          }
1705
1887
        | ON UPDATE_SYM NOW_SYM optional_braces 
1706
1888
          { ((statement::AlterTable *)Lex->statement)->on_update_value= new Item_func_now_local(); }
1707
 
        | AUTO_INC { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG; }
 
1889
        | AUTO_INC
 
1890
          {
 
1891
            Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG;
 
1892
 
 
1893
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1894
            if (statement->current_proto_field)
 
1895
            {
 
1896
              message::Table::Field::FieldConstraints *constraints;
 
1897
 
 
1898
              constraints= statement->current_proto_field->mutable_constraints();
 
1899
              constraints->set_is_nullable(false);
 
1900
            }
 
1901
          }
1708
1902
        | SERIAL_SYM DEFAULT VALUE_SYM
1709
1903
          { 
1710
1904
            LEX *lex=Lex;
1712
1906
 
1713
1907
            lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
1714
1908
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1909
 
 
1910
            if (statement->current_proto_field)
 
1911
            {
 
1912
              message::Table::Field::FieldConstraints *constraints;
 
1913
              constraints= statement->current_proto_field->mutable_constraints();
 
1914
              constraints->set_is_nullable(false);
 
1915
            }
1715
1916
          }
1716
1917
        | opt_primary KEY_SYM
1717
1918
          {
1720
1921
 
1721
1922
            lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
1722
1923
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1924
 
 
1925
            if (statement->current_proto_field)
 
1926
            {
 
1927
              message::Table::Field::FieldConstraints *constraints;
 
1928
              constraints= statement->current_proto_field->mutable_constraints();
 
1929
              constraints->set_is_nullable(false);
 
1930
            }
1723
1931
          }
1724
1932
        | UNIQUE_SYM
1725
1933
          {
1737
1945
            lex->type|= UNIQUE_KEY_FLAG; 
1738
1946
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1739
1947
          }
1740
 
        | COMMENT_SYM TEXT_STRING_sys { ((statement::AlterTable *)Lex->statement)->comment= $2; }
 
1948
        | COMMENT_SYM TEXT_STRING_sys
 
1949
          {
 
1950
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
 
1951
            statement->comment= $2;
 
1952
 
 
1953
            if (statement->current_proto_field)
 
1954
              statement->current_proto_field->set_comment($2.str);
 
1955
          }
1741
1956
        | COLLATE_SYM collation_name
1742
1957
          {
1743
1958
            if (Lex->charset && !my_charset_same(Lex->charset,$2))
2169
2384
            lex->charset= NULL;
2170
2385
            statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
2171
2386
            statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
 
2387
 
 
2388
            statement->current_proto_field= NULL;
2172
2389
          }
2173
2390
          field_def
2174
2391
          {