93
static bool check_reserved_words(LEX_STRING *name)
95
if (!my_strcasecmp(system_charset_info, name->str, "GLOBAL") ||
96
!my_strcasecmp(system_charset_info, name->str, "LOCAL") ||
97
!my_strcasecmp(system_charset_info, name->str, "SESSION"))
103
@brief Push an error message into MySQL error stack with line
104
and position information.
106
This function provides semantic action implementers with a way
107
to push the famous "You have a syntax error near..." error
108
message into the error stack, which is normally produced only if
109
a parse error is discovered internally by the Bison generated
113
struct my_parse_error_st {
118
static void my_parse_error(void *arg)
120
struct my_parse_error_st *ptr= (struct my_parse_error_st *)arg;
122
const char *s= ptr->s;
123
Session *session= ptr->session;
125
Lex_input_stream *lip= session->m_lip;
127
const char *yytext= lip->get_tok_start();
128
/* Push an error into the error stack */
129
my_printf_error(ER_PARSE_ERROR, ER(ER_PARSE_ERROR), MYF(0), s,
130
(yytext ? yytext : ""),
135
94
@brief Bison callback to report a syntax/OOM error
166
125
if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
167
126
s= ER(ER_SYNTAX_ERROR);
169
struct my_parse_error_st pass= { s, session };
170
my_parse_error(&pass);
174
Helper to resolve the SQL:2003 Syntax exception 1) in <in predicate>.
175
See SQL:2003, Part 2, section 8.4 <in predicate>, Note 184, page 383.
176
This function returns the proper item for the SQL expression
177
<code>left [NOT] IN ( expr )</code>
178
@param session the current thread
179
@param left the in predicand
180
@param equal true for IN predicates, false for NOT IN predicates
181
@param expr first and only expression of the in value list
182
@return an expression representing the IN predicate.
184
static Item* handle_sql2003_note184_exception(Session *session,
185
Item* left, bool equal,
189
Relevant references for this issue:
190
- SQL:2003, Part 2, section 8.4 <in predicate>, page 383,
191
- SQL:2003, Part 2, section 7.2 <row value expression>, page 296,
192
- SQL:2003, Part 2, section 6.3 <value expression primary>, page 174,
193
- SQL:2003, Part 2, section 7.15 <subquery>, page 370,
194
- SQL:2003 Feature F561, "Full value expressions".
196
The exception in SQL:2003 Note 184 means:
197
Item_singlerow_subselect, which corresponds to a <scalar subquery>,
198
should be re-interpreted as an Item_in_subselect, which corresponds
199
to a <table subquery> when used inside an <in predicate>.
201
Our reading of Note 184 is reccursive, so that all:
202
- IN (( <subquery> ))
203
- IN ((( <subquery> )))
204
- IN '('^N <subquery> ')'^N
206
should be interpreted as a <table subquery>, no matter how deep in the
207
expression the <subquery> is.
212
if (expr->type() == Item::SUBSELECT_ITEM)
214
Item_subselect *expr2 = (Item_subselect*) expr;
216
if (expr2->substype() == Item_subselect::SINGLEROW_SUBS)
218
Item_singlerow_subselect *expr3 = (Item_singlerow_subselect*) expr2;
219
Select_Lex *subselect;
222
Implement the mandated change, by altering the semantic tree:
223
left IN Item_singlerow_subselect(subselect)
226
which is represented as
227
Item_in_subselect(left, subselect)
229
subselect= expr3->invalidate_and_restore_select_lex();
230
result= new (session->mem_root) Item_in_subselect(left, subselect);
233
result = negate_expression(session, result);
240
result= new (session->mem_root) Item_func_eq(left, expr);
242
result= new (session->mem_root) Item_func_ne(left, expr);
248
@brief Creates a new Select_Lex for a UNION branch.
250
Sets up and initializes a Select_Lex structure for a query once the parser
251
discovers a UNION token. The current Select_Lex is pushed on the stack and
252
the new Select_Lex becomes the current one..=
254
@lex The parser state.
256
@is_union_distinct True if the union preceding the new select statement
259
@return <code>false</code> if successful, <code>true</code> if an error was
260
reported. In the latter case parsing should stop.
262
static bool add_select_to_union_list(Session *session, LEX *lex, bool is_union_distinct)
266
/* Only the last SELECT can have INTO...... */
267
my_error(ER_WRONG_USAGE, MYF(0), "UNION", "INTO");
270
if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
272
struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
273
my_parse_error(&pass);
276
/* This counter shouldn't be incremented for UNION parts */
278
if (new_select(lex, 0))
281
lex->current_select->linkage=UNION_TYPE;
282
if (is_union_distinct) /* UNION DISTINCT - remember position */
283
lex->current_select->master_unit()->union_distinct=
289
@brief Initializes a Select_Lex for a query within parentheses (aka
292
@return false if successful, true if an error was reported. In the latter
293
case parsing should stop.
295
static bool setup_select_in_parentheses(Session *session, LEX *lex)
297
Select_Lex * sel= lex->current_select;
298
if (sel->set_braces(1))
300
struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
301
my_parse_error(&pass);
304
if (sel->linkage == UNION_TYPE &&
305
!sel->master_unit()->first_select()->braces &&
306
sel->master_unit()->first_select()->linkage ==
309
struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
310
my_parse_error(&pass);
313
if (sel->linkage == UNION_TYPE &&
314
sel->olap != UNSPECIFIED_OLAP_TYPE &&
315
sel->master_unit()->fake_select_lex)
317
my_error(ER_WRONG_USAGE, MYF(0), "CUBE/ROLLUP", "ORDER BY");
320
/* select in braces, can't contain global parameters */
321
if (sel->master_unit()->fake_select_lex)
322
sel->master_unit()->global_parameters=
323
sel->master_unit()->fake_select_lex;
327
static Item* reserved_keyword_function(Session *session, const std::string &name, List<Item> *item_list)
329
const plugin::Function *udf= plugin::Function::get(name.c_str(), name.length());
334
item= Create_udf_func::s_singleton.create(session, udf, item_list);
336
my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", name.c_str());
128
parser::error_t pass= { s, session };
129
parser::my_parse_error(pass);
342
132
} /* namespace drizzled; */
362
152
drizzled::Key_part_spec *key_part;
363
153
const drizzled::plugin::Function *udf;
364
154
drizzled::TableList *table_list;
365
enum drizzled::enum_field_types field_val;
366
struct drizzled::sys_var_with_base variable;
367
enum drizzled::sql_var_t var_type;
155
drizzled::enum_field_types field_val;
156
drizzled::sys_var_with_base variable;
157
drizzled::sql_var_t var_type;
368
158
drizzled::Key::Keytype key_type;
369
enum drizzled::ha_key_alg key_alg;
370
enum drizzled::ha_rkey_function ha_rkey_mode;
371
enum drizzled::enum_tx_isolation tx_isolation;
372
enum drizzled::Cast_target cast_type;
159
drizzled::ha_key_alg key_alg;
160
drizzled::ha_rkey_function ha_rkey_mode;
161
drizzled::enum_tx_isolation tx_isolation;
162
drizzled::Cast_target cast_type;
373
163
const drizzled::CHARSET_INFO *charset;
374
164
drizzled::thr_lock_type lock_type;
375
165
drizzled::interval_type interval, interval_time_st;
376
166
drizzled::type::timestamp_t date_time_type;
377
167
drizzled::Select_Lex *select_lex;
378
168
drizzled::chooser_compare_func_creator boolfunc2creator;
379
struct drizzled::st_lex *lex;
380
enum drizzled::index_hint_type index_hint;
381
enum drizzled::enum_filetype filetype;
382
enum drizzled::ha_build_method build_method;
169
drizzled::st_lex *lex;
170
drizzled::index_hint_type index_hint;
171
drizzled::enum_filetype filetype;
172
drizzled::ha_build_method build_method;
383
173
drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption m_fk_option;
384
174
drizzled::execute_string_t execute_string;
4859
4636
DATABASES show_wild
4861
Lex->sql_command= SQLCOM_SELECT;
4862
Lex->statement= new statement::Show(YYSession);
4864
std::string column_name= "Database";
4867
column_name.append(" (");
4868
column_name.append(Lex->wild->ptr());
4869
column_name.append(")");
4872
if (Lex->current_select->where)
4874
if (prepare_new_schema_table(YYSession, Lex, "SCHEMAS"))
4879
if (prepare_new_schema_table(YYSession, Lex, "SHOW_SCHEMAS"))
4883
Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
4884
my_field->is_autogenerated_name= false;
4885
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
4887
if (YYSession->add_item_to_list(my_field))
4638
if (not show::buildScemas(YYSession))
4888
4639
DRIZZLE_YYABORT;
4890
if (YYSession->add_order_to_list(my_field, true))
4893
4641
/* SHOW TABLES */
4894
4642
| TABLES opt_db show_wild
4896
Lex->sql_command= SQLCOM_SELECT;
4898
drizzled::statement::Show *select= new statement::Show(YYSession);
4899
Lex->statement= select;
4901
std::string column_name= "Tables_in_";
4903
util::string::const_shared_ptr schema(YYSession->schema());
4906
identifier::Schema identifier($2);
4907
column_name.append($2);
4908
Lex->select_lex.db= $2;
4909
if (not plugin::StorageEngine::doesSchemaExist(identifier))
4911
my_error(ER_BAD_DB_ERROR, MYF(0), $2);
4913
select->setShowPredicate($2, "");
4915
else if (schema and not schema->empty())
4917
column_name.append(*schema);
4918
select->setShowPredicate(*schema, "");
4922
my_error(ER_NO_DB_ERROR, MYF(0));
4929
column_name.append(" (");
4930
column_name.append(Lex->wild->ptr());
4931
column_name.append(")");
4934
if (prepare_new_schema_table(YYSession, Lex, "SHOW_TABLES"))
4937
Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "TABLE_NAME");
4938
my_field->is_autogenerated_name= false;
4939
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
4941
if (YYSession->add_item_to_list(my_field))
4944
if (YYSession->add_order_to_list(my_field, true))
4644
if (not show::buildTables(YYSession, $2))
4947
4647
/* SHOW TEMPORARY TABLES */
4948
4648
| TEMPORARY_SYM TABLES show_wild
4950
Lex->sql_command= SQLCOM_SELECT;
4952
Lex->statement= new statement::Show(YYSession);
4955
if (prepare_new_schema_table(YYSession, Lex, "SHOW_TEMPORARY_TABLES"))
4958
if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
4962
(YYSession->lex->current_select->with_wild)++;
4650
if (not show::buildTemporaryTables(YYSession))
4965
4653
/* SHOW TABLE STATUS */
4966
4654
| TABLE_SYM STATUS_SYM opt_db show_wild
4968
Lex->sql_command= SQLCOM_SELECT;
4969
drizzled::statement::Show *select= new statement::Show(YYSession);
4970
Lex->statement= select;
4972
std::string column_name= "Tables_in_";
4974
util::string::const_shared_ptr schema(YYSession->schema());
4977
Lex->select_lex.db= $3;
4979
identifier::Schema identifier($3);
4980
if (not plugin::StorageEngine::doesSchemaExist(identifier))
4982
my_error(ER_BAD_DB_ERROR, MYF(0), $3);
4985
select->setShowPredicate($3, "");
4989
select->setShowPredicate(*schema, "");
4993
my_error(ER_NO_DB_ERROR, MYF(0));
4997
if (prepare_new_schema_table(YYSession, Lex, "SHOW_TABLE_STATUS"))
5000
if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
5004
(YYSession->lex->current_select->with_wild)++;
4656
if (not show::buildTableStatus(YYSession, $3))
5006
4659
/* SHOW COLUMNS FROM table_name */
5007
4660
| COLUMNS from_or_in table_ident opt_db show_wild
5009
Lex->sql_command= SQLCOM_SELECT;
5011
drizzled::statement::Show *select= new statement::Show(YYSession);
5012
Lex->statement= select;
5014
util::string::const_shared_ptr schema(YYSession->schema());
5017
select->setShowPredicate($4, $3->table.str);
5019
else if ($3->db.str)
5021
select->setShowPredicate($3->db.str, $3->table.str);
5025
select->setShowPredicate(*schema, $3->table.str);
5029
my_error(ER_NO_DB_ERROR, MYF(0));
5034
drizzled::identifier::Table identifier(select->getShowSchema().c_str(), $3->table.str);
5035
if (not plugin::StorageEngine::doesTableExist(*YYSession, identifier))
5037
my_error(ER_NO_SUCH_TABLE, MYF(0),
5038
select->getShowSchema().c_str(),
5043
if (prepare_new_schema_table(YYSession, Lex, "SHOW_COLUMNS"))
5046
if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
5050
(YYSession->lex->current_select->with_wild)++;
4662
if (not show::buildColumns(YYSession, $4, $3))
5053
4665
/* SHOW INDEXES from table */
5054
4666
| keys_or_index from_or_in table_ident opt_db where_clause
5056
Lex->sql_command= SQLCOM_SELECT;
5057
drizzled::statement::Show *select= new statement::Show(YYSession);
5058
Lex->statement= select;
5060
util::string::const_shared_ptr schema(YYSession->schema());
5063
select->setShowPredicate($4, $3->table.str);
5065
else if ($3->db.str)
5067
select->setShowPredicate($3->db.str, $3->table.str);
5071
select->setShowPredicate(*schema, $3->table.str);
5075
my_error(ER_NO_DB_ERROR, MYF(0));
5080
drizzled::identifier::Table identifier(select->getShowSchema().c_str(), $3->table.str);
5081
if (not plugin::StorageEngine::doesTableExist(*YYSession, identifier))
5083
my_error(ER_NO_SUCH_TABLE, MYF(0),
5084
select->getShowSchema().c_str(),
5089
if (prepare_new_schema_table(YYSession, Lex, "SHOW_INDEXES"))
5092
if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
5096
(YYSession->lex->current_select->with_wild)++;
4668
if (not show::buildIndex(YYSession, $4, $3))
5098
4671
| COUNT_SYM '(' '*' ')' WARNINGS
5100
4673
(void) create_select_for_variable("warning_count");
5108
4681
| WARNINGS opt_limit_clause_init
5110
Lex->sql_command = SQLCOM_SHOW_WARNS;
5111
Lex->statement= new statement::ShowWarnings(YYSession);
4683
if (not show::buildWarnings(YYSession))
5113
4686
| ERRORS opt_limit_clause_init
5115
Lex->sql_command = SQLCOM_SHOW_ERRORS;
5116
Lex->statement= new statement::ShowErrors(YYSession);
4688
if (not show::buildErrors(YYSession))
5118
4691
| opt_var_type STATUS_SYM show_wild
5120
Lex->sql_command= SQLCOM_SELECT;
5121
Lex->statement= new statement::Show(YYSession);
5123
if ($1 == OPT_GLOBAL)
5125
if (prepare_new_schema_table(YYSession, Lex, "GLOBAL_STATUS"))
5130
if (prepare_new_schema_table(YYSession, Lex, "SESSION_STATUS"))
5134
std::string key("Variable_name");
5135
std::string value("Value");
5137
Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5138
my_field->is_autogenerated_name= false;
5139
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5141
if (YYSession->add_item_to_list(my_field))
5144
my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5145
my_field->is_autogenerated_name= false;
5146
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5148
if (YYSession->add_item_to_list(my_field))
4693
if (not show::buildStatus(YYSession, $1))
5151
4696
| CREATE TABLE_SYM table_ident
5153
Lex->sql_command= SQLCOM_SELECT;
5154
statement::Show *select= new statement::Show(YYSession);
5155
Lex->statement= select;
5157
if (Lex->statement == NULL)
5160
if (prepare_new_schema_table(YYSession, Lex, "TABLE_SQL_DEFINITION"))
5163
util::string::const_shared_ptr schema(YYSession->schema());
5166
select->setShowPredicate($3->db.str, $3->table.str);
5170
select->setShowPredicate(*schema, $3->table.str);
5174
my_error(ER_NO_DB_ERROR, MYF(0));
5178
std::string key("Table");
5179
std::string value("Create Table");
5181
Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "TABLE_NAME");
5182
my_field->is_autogenerated_name= false;
5183
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5185
if (YYSession->add_item_to_list(my_field))
5188
my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
5189
my_field->is_autogenerated_name= false;
5190
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5192
if (YYSession->add_item_to_list(my_field))
4698
if (not show::buildCreateTable(YYSession, $3))
5195
4701
| PROCESSLIST_SYM
5198
Lex->sql_command= SQLCOM_SELECT;
5199
Lex->statement= new statement::Show(YYSession);
5201
if (prepare_new_schema_table(YYSession, Lex, "PROCESSLIST"))
5204
if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
5208
(YYSession->lex->current_select->with_wild)++;
4703
if (not show::buildProcesslist(YYSession))
5211
4706
| opt_var_type VARIABLES show_wild
5213
Lex->sql_command= SQLCOM_SELECT;
5214
Lex->statement= new statement::Show(YYSession);
5216
if ($1 == OPT_GLOBAL)
5218
if (prepare_new_schema_table(YYSession, Lex, "GLOBAL_VARIABLES"))
5223
if (prepare_new_schema_table(YYSession, Lex, "SESSION_VARIABLES"))
5227
std::string key("Variable_name");
5228
std::string value("Value");
5230
Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5231
my_field->is_autogenerated_name= false;
5232
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5234
if (YYSession->add_item_to_list(my_field))
5237
my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5238
my_field->is_autogenerated_name= false;
5239
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5241
if (YYSession->add_item_to_list(my_field))
4708
if (not show::buildVariables(YYSession, $1))
5244
4711
| CREATE DATABASE opt_if_not_exists ident
5246
Lex->sql_command= SQLCOM_SELECT;
5247
drizzled::statement::Show *select= new statement::Show(YYSession);
5248
Lex->statement= select;
5250
if (prepare_new_schema_table(YYSession, Lex, "SCHEMA_SQL_DEFINITION"))
5253
util::string::const_shared_ptr schema(YYSession->schema());
5256
select->setShowPredicate($4.str);
5260
select->setShowPredicate(*schema);
5264
my_error(ER_NO_DB_ERROR, MYF(0));
5268
std::string key("Database");
5269
std::string value("Create Database");
5271
Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
5272
my_field->is_autogenerated_name= false;
5273
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5275
if (YYSession->add_item_to_list(my_field))
5278
my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
5279
my_field->is_autogenerated_name= false;
5280
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5282
if (YYSession->add_item_to_list(my_field))
4713
if (not show::buildCreateSchema(YYSession, $4))
5287
4718
/* empty */ { $$= 0; }
5315
4746
describe_command table_ident
5317
Lex->lock_option= TL_READ;
5319
Lex->current_select->parsing_place= SELECT_LIST;
5320
Lex->sql_command= SQLCOM_SELECT;
5321
drizzled::statement::Show *select= new statement::Show(YYSession);
5322
Lex->statement= select;
5323
Lex->select_lex.db= 0;
5325
util::string::const_shared_ptr schema(YYSession->schema());
5328
select->setShowPredicate($2->db.str, $2->table.str);
5332
select->setShowPredicate(*schema, $2->table.str);
5336
my_error(ER_NO_DB_ERROR, MYF(0));
5341
drizzled::identifier::Table identifier(select->getShowSchema().c_str(), $2->table.str);
5342
if (not plugin::StorageEngine::doesTableExist(*YYSession, identifier))
5344
my_error(ER_NO_SUCH_TABLE, MYF(0),
5345
select->getShowSchema().c_str(),
5350
if (prepare_new_schema_table(YYSession, Lex, "SHOW_COLUMNS"))
5353
if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
5359
(YYSession->lex->current_select->with_wild)++;
4748
if (not show::buildDescribe(YYSession, $2))
5362
4753
opt_describe_column {}
5363
4754
| describe_command opt_extended_describe