~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

Merged up with brian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
121
121
#include <drizzled/statement/set_option.h>
122
122
#include <drizzled/statement/show_create.h>
123
123
#include <drizzled/statement/show_create_schema.h>
124
 
#include <drizzled/statement/show_engine_status.h>
125
124
#include <drizzled/statement/show_errors.h>
126
125
#include <drizzled/statement/show_processlist.h>
127
126
#include <drizzled/statement/show_status.h>
4828
4827
           DATABASES show_wild
4829
4828
           {
4830
4829
             LEX *lex= Lex;
4831
 
             lex->sql_command= SQLCOM_SHOW_DATABASES;
 
4830
             lex->sql_command= SQLCOM_SELECT;
4832
4831
             lex->statement=
4833
4832
               new(std::nothrow) statement::Select(YYSession);
4834
4833
             if (lex->statement == NULL)
4835
4834
               DRIZZLE_YYABORT;
4836
 
             if (prepare_schema_table(YYSession, lex, 0, "SCHEMATA"))
 
4835
 
 
4836
             Session *session= YYSession;
 
4837
 
 
4838
             std::string column_name= "Database";
 
4839
             if (Lex->wild)
 
4840
             {
 
4841
               column_name.append(" (");
 
4842
               column_name.append(Lex->wild->c_str());
 
4843
               column_name.append(")");
 
4844
             }
 
4845
 
 
4846
             if (Lex->current_select->where)
 
4847
             {
 
4848
               if (prepare_new_schema_table(YYSession, lex, "SCHEMAS"))
 
4849
                 DRIZZLE_YYABORT;
 
4850
             }
 
4851
             else
 
4852
             {
 
4853
               if (prepare_new_schema_table(YYSession, lex, "SCHEMA_NAMES"))
 
4854
                 DRIZZLE_YYABORT;
 
4855
             }
 
4856
 
 
4857
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
 
4858
             my_field->is_autogenerated_name= false;
 
4859
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
 
4860
 
 
4861
             if (session->add_item_to_list(my_field))
4837
4862
               DRIZZLE_YYABORT;
4838
4863
           }
4839
 
         | opt_full TABLES opt_db show_wild
 
4864
         | TABLES opt_db show_wild
4840
4865
           {
4841
4866
             LEX *lex= Lex;
4842
 
             lex->sql_command= SQLCOM_SHOW_TABLES;
 
4867
             lex->sql_command= SQLCOM_SELECT;
4843
4868
             lex->statement=
4844
4869
               new(std::nothrow) statement::Select(YYSession);
4845
4870
             if (lex->statement == NULL)
4846
4871
               DRIZZLE_YYABORT;
4847
 
             lex->select_lex.db= $3;
4848
 
             if (prepare_schema_table(YYSession, lex, 0, "TABLE_NAMES"))
 
4872
 
 
4873
              Session *session= YYSession;
 
4874
 
 
4875
              std::string column_name= "Tables_in_";
 
4876
 
 
4877
              if ($2)
 
4878
              {
 
4879
                message::Schema schema_message;
 
4880
                column_name.append($2);
 
4881
                lex->select_lex.db= $2;
 
4882
                if (not plugin::StorageEngine::getSchemaDefinition($2, schema_message))
 
4883
                {
 
4884
                  my_error(ER_BAD_DB_ERROR, MYF(0), $2);
 
4885
                }
 
4886
              }
 
4887
              else
 
4888
              {
 
4889
                column_name.append(session->db);
 
4890
              }
 
4891
 
 
4892
             if (Lex->wild)
 
4893
             {
 
4894
               column_name.append(" (");
 
4895
               column_name.append(Lex->wild->c_str());
 
4896
               column_name.append(")");
 
4897
             }
 
4898
 
 
4899
             if (Lex->current_select->where)
 
4900
             {
 
4901
               if (prepare_new_schema_table(YYSession, lex, "TABLES"))
 
4902
                 DRIZZLE_YYABORT;
 
4903
             }
 
4904
             else
 
4905
             {
 
4906
               if (prepare_new_schema_table(YYSession, lex, "LOCAL_TABLE_NAMES"))
 
4907
                 DRIZZLE_YYABORT;
 
4908
             }
 
4909
 
 
4910
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
 
4911
             my_field->is_autogenerated_name= false;
 
4912
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
 
4913
 
 
4914
             if (session->add_item_to_list(my_field))
4849
4915
               DRIZZLE_YYABORT;
4850
4916
           }
4851
4917
         | TABLE_SYM STATUS_SYM opt_db show_wild
4852
4918
           {
4853
4919
             LEX *lex= Lex;
4854
 
             lex->sql_command= SQLCOM_SHOW_TABLE_STATUS;
 
4920
             lex->sql_command= SQLCOM_SELECT;
4855
4921
             lex->statement=
4856
4922
               new(std::nothrow) statement::Select(YYSession);
4857
4923
             if (lex->statement == NULL)
4858
4924
               DRIZZLE_YYABORT;
4859
 
             lex->select_lex.db= $3;
4860
 
             if (prepare_schema_table(YYSession, lex, 0, "TABLES"))
4861
 
               DRIZZLE_YYABORT;
 
4925
 
 
4926
             Session *session= YYSession;
 
4927
 
 
4928
             std::string column_name= "Tables_in_";
 
4929
 
 
4930
             if ($3)
 
4931
             {
 
4932
               message::Schema schema_message;
 
4933
               lex->select_lex.db= $3;
 
4934
 
 
4935
               if (not plugin::StorageEngine::getSchemaDefinition($3, schema_message))
 
4936
               {
 
4937
                 my_error(ER_BAD_DB_ERROR, MYF(0), $3);
 
4938
               }
 
4939
             }
 
4940
 
 
4941
             if (prepare_new_schema_table(session, lex, "LOCAL_TABLE_STATUS"))
 
4942
               DRIZZLE_YYABORT;
 
4943
 
 
4944
             if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
4945
                                                           context,
 
4946
                                                           NULL, NULL, "*")))
 
4947
               DRIZZLE_YYABORT;
 
4948
             (session->lex->current_select->with_wild)++;
4862
4949
           }
4863
 
        | OPEN_SYM TABLES opt_db show_wild
4864
 
          {
4865
 
            LEX *lex= Lex;
4866
 
            lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
4867
 
            lex->statement=
4868
 
              new(std::nothrow) statement::Select(YYSession);
4869
 
            if (lex->statement == NULL)
4870
 
              DRIZZLE_YYABORT;
4871
 
            lex->select_lex.db= $3;
4872
 
            if (prepare_schema_table(YYSession, lex, 0, "OPEN_TABLES"))
4873
 
              DRIZZLE_YYABORT;
4874
 
          }
4875
 
        | ENGINE_SYM ident_or_text STATUS_SYM /* This should either go... well it should go */
4876
 
          {
4877
 
            Lex->sql_command= SQLCOM_SHOW_ENGINE_STATUS;
4878
 
            Lex->statement=
4879
 
              new(std::nothrow) statement::ShowEngineStatus(YYSession, $2.str);
4880
 
            if (Lex->statement == NULL)
4881
 
              DRIZZLE_YYABORT;
4882
 
          }
4883
 
        | opt_full COLUMNS from_or_in table_ident opt_db show_wild
 
4950
        | COLUMNS from_or_in table_ident opt_db show_wild
4884
4951
          {
4885
4952
            LEX *lex= Lex;
4886
4953
            lex->sql_command= SQLCOM_SHOW_FIELDS;
4888
4955
              new(std::nothrow) statement::Select(YYSession);
4889
4956
            if (lex->statement == NULL)
4890
4957
              DRIZZLE_YYABORT;
4891
 
            if ($5)
4892
 
              $4->change_db($5);
4893
 
            if (prepare_schema_table(YYSession, lex, $4, "COLUMNS"))
 
4958
            if ($4)
 
4959
              $3->change_db($4);
 
4960
            if (prepare_schema_table(YYSession, lex, $3, "OLD_COLUMNS"))
4894
4961
              DRIZZLE_YYABORT;
4895
4962
          }
4896
4963
        | keys_or_index from_or_in table_ident opt_db where_clause
4902
4969
              DRIZZLE_YYABORT;
4903
4970
            if ($4)
4904
4971
              $3->change_db($4);
4905
 
            if (prepare_schema_table(YYSession, lex, $3, "STATISTICS"))
 
4972
            if (prepare_schema_table(YYSession, lex, $3, "OLD_STATISTICS"))
4906
4973
              DRIZZLE_YYABORT;
4907
4974
          }
4908
4975
        | COUNT_SYM '(' '*' ')' WARNINGS
4945
5012
            if (lex->statement == NULL)
4946
5013
              DRIZZLE_YYABORT;
4947
5014
            lex->option_type= $1;
4948
 
            if (prepare_schema_table(YYSession, lex, 0, "STATUS"))
 
5015
            if (prepare_schema_table(YYSession, lex, 0, "OLD_STATUS"))
4949
5016
              DRIZZLE_YYABORT;
4950
5017
          }
4951
 
        | opt_full PROCESSLIST_SYM
 
5018
        | PROCESSLIST_SYM
4952
5019
          {
4953
5020
            Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;
4954
5021
            Lex->statement=
4965
5032
            if (lex->statement == NULL)
4966
5033
              DRIZZLE_YYABORT;
4967
5034
            lex->option_type= $1;
4968
 
            if (prepare_schema_table(YYSession, lex, 0, "VARIABLES"))
 
5035
            if (prepare_schema_table(YYSession, lex, 0, "OLD_VARIABLES"))
4969
5036
              DRIZZLE_YYABORT;
4970
5037
          }
4971
5038
        | CREATE DATABASE opt_if_not_exists ident
4994
5061
        | from_or_in ident { $$= $2.str; }
4995
5062
        ;
4996
5063
 
4997
 
opt_full:
4998
 
          /* empty */ { Lex->verbose= false; }
4999
 
        | FULL        { Lex->verbose= true; }
5000
 
        ;
5001
 
 
5002
5064
from_or_in:
5003
5065
          FROM
5004
5066
        | IN_SYM
5034
5096
            if (lex->statement == NULL)
5035
5097
              DRIZZLE_YYABORT;
5036
5098
            lex->select_lex.db= 0;
5037
 
            lex->verbose= 0;
5038
 
            if (prepare_schema_table(YYSession, lex, $2, "COLUMNS"))
 
5099
            if (prepare_schema_table(YYSession, lex, $2, "OLD_COLUMNS"))
5039
5100
              DRIZZLE_YYABORT;
5040
5101
          }
5041
5102
          opt_describe_column {}