~skinny.moey/drizzle/innodb-replication

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Brian Aker
  • Date: 2010-11-08 22:35:57 UTC
  • mfrom: (1802.1.114 trunk)
  • Revision ID: brian@tangent.org-20101108223557-w3xzwp9hjjtjhtc1
MergeĀ inĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
16
/* sql_yacc.yy */
17
17
 
521
521
%token  ESCAPED
522
522
%token  ESCAPE_SYM                    /* SQL-2003-R */
523
523
%token  EXCLUSIVE_SYM
 
524
%token  EXECUTE_SYM
524
525
%token  EXISTS                        /* SQL-2003-R */
525
526
%token  EXTENDED_SYM
526
527
%token  EXTRACT_SYM                   /* SQL-2003-N */
802
803
        IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
803
804
        opt_component
804
805
        BIN_NUM TEXT_STRING_filesystem ident_or_empty
 
806
        execute_var_or_string
805
807
        opt_constraint constraint opt_ident
806
808
 
807
809
%type <lex_str_ptr>
933
935
        subselect_end select_var_list select_var_list_init opt_len
934
936
        opt_extended_describe
935
937
        statement
 
938
        execute
936
939
        opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
937
940
        init_key_options key_options key_opts key_opt key_using_alg
938
941
END_OF_INPUT
1004
1007
        | delete
1005
1008
        | describe
1006
1009
        | drop
 
1010
        | execute
1007
1011
        | flush
1008
1012
        | insert
1009
1013
        | kill
1989
1993
        | CASCADE       { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_CASCADE; }
1990
1994
        | SET NULL_SYM  { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_NULL; }
1991
1995
        | NO_SYM ACTION { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_NO_ACTION; }
1992
 
        | SET DEFAULT   { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_DEFAULT;  }
 
1996
        | SET DEFAULT   { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT;  }
1993
1997
        ;
1994
1998
 
1995
1999
key_type:
2121
2125
              DRIZZLE_YYABORT;
2122
2126
            lex->col_list.empty();
2123
2127
            lex->select_lex.init_order();
2124
 
            lex->select_lex.db=
2125
 
              ((TableList*) lex->select_lex.table_list.first)->db;
 
2128
            lex->select_lex.db= const_cast<char *>(((TableList*) lex->select_lex.table_list.first)->getSchemaName());
2126
2129
            statement->alter_info.build_method= $2;
2127
2130
          }
2128
2131
          alter_commands
3719
3722
/* Warning - may return NULL in case of incomplete SELECT */
3720
3723
table_factor:
3721
3724
          {
3722
 
            Select_Lex *sel= Lex->current_select;
3723
 
            sel->table_join_options= 0;
3724
3725
          }
3725
3726
          table_ident opt_table_alias opt_key_definition
3726
3727
          {
3727
3728
            if (!($$= Lex->current_select->add_table_to_list(YYSession, $2, $3,
3728
 
                             Lex->current_select->get_table_join_options(),
 
3729
                             0,
3729
3730
                             Lex->lock_option,
3730
3731
                             Lex->current_select->pop_index_hints())))
3731
3732
              DRIZZLE_YYABORT;
4462
4463
          /* empty */ { $$= 0; }
4463
4464
        | TEMPORARY_SYM { $$= 1; }
4464
4465
        ;
 
4466
 
 
4467
/*
 
4468
  Execute a string as dynamic SQL.
 
4469
  */
 
4470
 
 
4471
execute:
 
4472
       EXECUTE_SYM execute_var_or_string
 
4473
       {
 
4474
       }
 
4475
 
 
4476
 
 
4477
execute_var_or_string:
 
4478
         ident_or_text
 
4479
         {
 
4480
            LEX *lex= Lex;
 
4481
            statement::Execute *statement= new(std::nothrow) statement::Execute(YYSession);
 
4482
            lex->statement= statement;
 
4483
            if (lex->statement == NULL)
 
4484
              DRIZZLE_YYABORT;
 
4485
 
 
4486
            statement->setQuery($1);
 
4487
         }
 
4488
        | '@' ident_or_text
 
4489
        {
 
4490
          LEX *lex= Lex;
 
4491
          statement::Execute *statement= new(std::nothrow) statement::Execute(YYSession);
 
4492
          lex->statement= statement;
 
4493
          if (lex->statement == NULL)
 
4494
            DRIZZLE_YYABORT;
 
4495
 
 
4496
          statement->setVar();
 
4497
          statement->setQuery($2);
 
4498
        }
 
4499
 
4465
4500
/*
4466
4501
** Insert : add new data to table
4467
4502
*/
4760
4795
          {}
4761
4796
        ;
4762
4797
 
 
4798
/* SHOW SCHEMAS */
4763
4799
show_param:
4764
4800
           DATABASES show_wild
4765
4801
           {
4768
4804
 
4769
4805
             lex->sql_command= SQLCOM_SELECT;
4770
4806
             lex->statement=
4771
 
               new(std::nothrow) statement::Select(session);
 
4807
               new(std::nothrow) statement::Show(session);
4772
4808
             if (lex->statement == NULL)
4773
4809
               DRIZZLE_YYABORT;
4774
4810
 
4801
4837
              if (session->add_order_to_list(my_field, true))
4802
4838
                DRIZZLE_YYABORT;
4803
4839
           }
 
4840
           /* SHOW TABLES */
4804
4841
         | TABLES opt_db show_wild
4805
4842
           {
4806
4843
             LEX *lex= Lex;
4808
4845
 
4809
4846
             lex->sql_command= SQLCOM_SELECT;
4810
4847
 
4811
 
             statement::Select *select=
4812
 
               new(std::nothrow) statement::Select(YYSession);
 
4848
             statement::Show *select=
 
4849
               new(std::nothrow) statement::Show(YYSession);
4813
4850
 
4814
4851
             lex->statement= select;
4815
4852
 
4861
4898
              if (session->add_order_to_list(my_field, true))
4862
4899
                DRIZZLE_YYABORT;
4863
4900
           }
 
4901
           /* SHOW TEMPORARY TABLES */
4864
4902
         | TEMPORARY_SYM TABLES show_wild
4865
4903
           {
4866
4904
             LEX *lex= Lex;
4868
4906
 
4869
4907
             lex->sql_command= SQLCOM_SELECT;
4870
4908
 
4871
 
             statement::Select *select=
4872
 
               new(std::nothrow) statement::Select(YYSession);
 
4909
             statement::Show *select=
 
4910
               new(std::nothrow) statement::Show(YYSession);
4873
4911
 
4874
4912
             lex->statement= select;
4875
4913
 
4887
4925
             (session->lex->current_select->with_wild)++;
4888
4926
 
4889
4927
           }
 
4928
           /* SHOW TABLE STATUS */
4890
4929
         | TABLE_SYM STATUS_SYM opt_db show_wild
4891
4930
           {
4892
4931
             LEX *lex= Lex;
4893
4932
             lex->sql_command= SQLCOM_SELECT;
4894
 
             statement::Select *select=
4895
 
               new(std::nothrow) statement::Select(YYSession);
 
4933
             statement::Show *select=
 
4934
               new(std::nothrow) statement::Show(YYSession);
4896
4935
 
4897
4936
             lex->statement= select;
4898
4937
 
4929
4968
               DRIZZLE_YYABORT;
4930
4969
             (session->lex->current_select->with_wild)++;
4931
4970
           }
 
4971
           /* SHOW COLUMNS FROM table_name */
4932
4972
        | COLUMNS from_or_in table_ident opt_db show_wild
4933
4973
          {
4934
4974
             LEX *lex= Lex;
4935
4975
             Session *session= YYSession;
4936
 
             statement::Select *select;
 
4976
             statement::Show *select;
4937
4977
 
4938
4978
             lex->sql_command= SQLCOM_SELECT;
4939
4979
 
4940
 
             select= new(std::nothrow) statement::Select(session);
 
4980
             select= new(std::nothrow) statement::Show(session);
4941
4981
 
4942
4982
             lex->statement= select;
4943
4983
 
4971
5011
             (session->lex->current_select->with_wild)++;
4972
5012
 
4973
5013
          }
 
5014
          /* SHOW INDEXES from table */
4974
5015
        | keys_or_index from_or_in table_ident opt_db where_clause
4975
5016
          {
4976
5017
             LEX *lex= Lex;
4977
5018
             Session *session= YYSession;
4978
 
             statement::Select *select;
 
5019
             statement::Show *select;
4979
5020
 
4980
5021
             lex->sql_command= SQLCOM_SELECT;
4981
5022
 
4982
 
             select= new(std::nothrow) statement::Select(session);
 
5023
             select= new(std::nothrow) statement::Show(session);
4983
5024
 
4984
5025
             lex->statement= select;
4985
5026
 
5016
5057
          {
5017
5058
            (void) create_select_for_variable("warning_count");
5018
5059
            LEX *lex= Lex;
5019
 
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
5060
            lex->statement= new(std::nothrow) statement::Show(YYSession);
5020
5061
            if (lex->statement == NULL)
5021
5062
              DRIZZLE_YYABORT;
5022
5063
          }
5024
5065
          {
5025
5066
            (void) create_select_for_variable("error_count");
5026
5067
            LEX *lex= Lex;
5027
 
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
5068
            lex->statement= new(std::nothrow) statement::Show(YYSession);
5028
5069
            if (lex->statement == NULL)
5029
5070
              DRIZZLE_YYABORT;
5030
5071
          }
5047
5088
             LEX *lex= Lex;
5048
5089
             lex->sql_command= SQLCOM_SELECT;
5049
5090
             lex->statement=
5050
 
               new(std::nothrow) statement::Select(YYSession);
 
5091
               new(std::nothrow) statement::Show(YYSession);
5051
5092
             if (lex->statement == NULL)
5052
5093
               DRIZZLE_YYABORT;
5053
5094
 
5081
5122
             if (session->add_item_to_list(my_field))
5082
5123
               DRIZZLE_YYABORT;
5083
5124
           }
 
5125
        | CREATE TABLE_SYM table_ident
 
5126
           {
 
5127
             LEX *lex= Lex;
 
5128
             lex->sql_command= SQLCOM_SELECT;
 
5129
             statement::Show *select=
 
5130
               new(std::nothrow) statement::Show(YYSession);
 
5131
 
 
5132
             lex->statement= select;
 
5133
 
 
5134
             if (lex->statement == NULL)
 
5135
               DRIZZLE_YYABORT;
 
5136
 
 
5137
             Session *session= YYSession;
 
5138
 
 
5139
             if (prepare_new_schema_table(session, lex, "TABLE_SQL_DEFINITION"))
 
5140
               DRIZZLE_YYABORT;
 
5141
 
 
5142
             if ($3->db.str)
 
5143
              select->setShowPredicate($3->db.str, $3->table.str);
 
5144
             else
 
5145
              select->setShowPredicate(session->db, $3->table.str);
 
5146
 
 
5147
             std::string key("Table");
 
5148
             std::string value("Create Table");
 
5149
 
 
5150
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
 
5151
             my_field->is_autogenerated_name= false;
 
5152
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5153
 
 
5154
             if (session->add_item_to_list(my_field))
 
5155
               DRIZZLE_YYABORT;
 
5156
 
 
5157
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
 
5158
             my_field->is_autogenerated_name= false;
 
5159
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5160
 
 
5161
             if (session->add_item_to_list(my_field))
 
5162
               DRIZZLE_YYABORT;
 
5163
           }
5084
5164
        | PROCESSLIST_SYM
5085
5165
          {
5086
5166
           {
5087
5167
             LEX *lex= Lex;
5088
5168
             lex->sql_command= SQLCOM_SELECT;
5089
5169
             lex->statement=
5090
 
               new(std::nothrow) statement::Select(YYSession);
 
5170
               new(std::nothrow) statement::Show(YYSession);
5091
5171
             if (lex->statement == NULL)
5092
5172
               DRIZZLE_YYABORT;
5093
5173
 
5108
5188
             LEX *lex= Lex;
5109
5189
             lex->sql_command= SQLCOM_SELECT;
5110
5190
             lex->statement=
5111
 
               new(std::nothrow) statement::Select(YYSession);
 
5191
               new(std::nothrow) statement::Show(YYSession);
5112
5192
             if (lex->statement == NULL)
5113
5193
               DRIZZLE_YYABORT;
5114
5194
 
5143
5223
               DRIZZLE_YYABORT;
5144
5224
           }
5145
5225
        | CREATE DATABASE opt_if_not_exists ident
5146
 
          {
5147
 
            Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
5148
 
            statement::ShowCreateSchema *statement= new(std::nothrow) statement::ShowCreateSchema(YYSession);
5149
 
            Lex->statement= statement;
5150
 
            if (Lex->statement == NULL)
5151
 
              DRIZZLE_YYABORT;
5152
 
            statement->is_if_not_exists= $3;
5153
 
            Lex->name= $4;
5154
 
          }
5155
 
        | CREATE TABLE_SYM table_ident
5156
 
          {
5157
 
            LEX *lex= Lex;
5158
 
            lex->sql_command = SQLCOM_SHOW_CREATE;
5159
 
            lex->statement= new(std::nothrow) statement::ShowCreate(YYSession);
5160
 
            if (lex->statement == NULL)
5161
 
              DRIZZLE_YYABORT;
5162
 
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
5163
 
              DRIZZLE_YYABORT;
5164
 
          }
 
5226
           {
 
5227
             LEX *lex= Lex;
 
5228
             lex->sql_command= SQLCOM_SELECT;
 
5229
             statement::Show *select=
 
5230
               new(std::nothrow) statement::Show(YYSession);
 
5231
 
 
5232
             lex->statement= select;
 
5233
 
 
5234
             if (lex->statement == NULL)
 
5235
               DRIZZLE_YYABORT;
 
5236
 
 
5237
             Session *session= YYSession;
 
5238
 
 
5239
             if (prepare_new_schema_table(session, lex, "SCHEMA_SQL_DEFINITION"))
 
5240
               DRIZZLE_YYABORT;
 
5241
 
 
5242
             if ($4.str)
 
5243
              select->setShowPredicate($4.str);
 
5244
             else
 
5245
              select->setShowPredicate(session->db);
 
5246
 
 
5247
             std::string key("Database");
 
5248
             std::string value("Create Database");
 
5249
 
 
5250
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
 
5251
             my_field->is_autogenerated_name= false;
 
5252
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5253
 
 
5254
             if (session->add_item_to_list(my_field))
 
5255
               DRIZZLE_YYABORT;
 
5256
 
 
5257
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
 
5258
             my_field->is_autogenerated_name= false;
 
5259
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5260
 
 
5261
             if (session->add_item_to_list(my_field))
 
5262
               DRIZZLE_YYABORT;
 
5263
           }
5165
5264
 
5166
5265
opt_db:
5167
5266
          /* empty */  { $$= 0; }
5195
5294
          describe_command table_ident
5196
5295
          {
5197
5296
            Session *session= YYSession;
5198
 
            statement::Select *select;
 
5297
            statement::Show *select;
5199
5298
            LEX *lex= Lex;
5200
5299
            lex->lock_option= TL_READ;
5201
5300
            mysql_init_select(lex);
5202
5301
            lex->current_select->parsing_place= SELECT_LIST;
5203
5302
            lex->sql_command= SQLCOM_SELECT;
5204
 
            select= new(std::nothrow) statement::Select(session);
 
5303
            select= new(std::nothrow) statement::Show(session);
5205
5304
            lex->statement= select;
5206
5305
            if (lex->statement == NULL)
5207
5306
              DRIZZLE_YYABORT;
5731
5830
          {
5732
5831
            TableList *table=
5733
5832
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
5734
 
            if (my_strcasecmp(table_alias_charset, $1.str, table->db))
 
5833
            if (my_strcasecmp(table_alias_charset, $1.str, table->getSchemaName()))
5735
5834
            {
5736
5835
              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
5737
5836
              DRIZZLE_YYABORT;
5738
5837
            }
5739
5838
            if (my_strcasecmp(table_alias_charset, $3.str,
5740
 
                              table->table_name))
 
5839
                              table->getTableName()))
5741
5840
            {
5742
5841
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
5743
5842
              DRIZZLE_YYABORT;