140
104
This function is not for use in semantic actions and is internal to
141
105
the parser, as it performs some pre-return cleanup.
142
In semantic actions, please use my_parse_error or my_error to
106
In semantic actions, please use parser::my_parse_error or my_error to
143
107
push an error into the error stack and DRIZZLE_YYABORT
144
108
to abort from the parser.
147
111
static void DRIZZLEerror(const char *s)
149
Session *session= current_session;
152
Restore the original LEX if it was replaced when parsing
153
a stored procedure. We must ensure that a parsing error
154
does not leave any side effects in the Session.
156
LEX::cleanup_lex_after_parse_error(session);
158
/* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
159
if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
160
s= ER(ER_SYNTAX_ERROR);
162
struct my_parse_error_st pass= { s, session };
163
my_parse_error(&pass);
167
Helper to resolve the SQL:2003 Syntax exception 1) in <in predicate>.
168
See SQL:2003, Part 2, section 8.4 <in predicate>, Note 184, page 383.
169
This function returns the proper item for the SQL expression
170
<code>left [NOT] IN ( expr )</code>
171
@param session the current thread
172
@param left the in predicand
173
@param equal true for IN predicates, false for NOT IN predicates
174
@param expr first and only expression of the in value list
175
@return an expression representing the IN predicate.
177
static Item* handle_sql2003_note184_exception(Session *session,
178
Item* left, bool equal,
182
Relevant references for this issue:
183
- SQL:2003, Part 2, section 8.4 <in predicate>, page 383,
184
- SQL:2003, Part 2, section 7.2 <row value expression>, page 296,
185
- SQL:2003, Part 2, section 6.3 <value expression primary>, page 174,
186
- SQL:2003, Part 2, section 7.15 <subquery>, page 370,
187
- SQL:2003 Feature F561, "Full value expressions".
189
The exception in SQL:2003 Note 184 means:
190
Item_singlerow_subselect, which corresponds to a <scalar subquery>,
191
should be re-interpreted as an Item_in_subselect, which corresponds
192
to a <table subquery> when used inside an <in predicate>.
194
Our reading of Note 184 is reccursive, so that all:
195
- IN (( <subquery> ))
196
- IN ((( <subquery> )))
197
- IN '('^N <subquery> ')'^N
199
should be interpreted as a <table subquery>, no matter how deep in the
200
expression the <subquery> is.
205
if (expr->type() == Item::SUBSELECT_ITEM)
207
Item_subselect *expr2 = (Item_subselect*) expr;
209
if (expr2->substype() == Item_subselect::SINGLEROW_SUBS)
211
Item_singlerow_subselect *expr3 = (Item_singlerow_subselect*) expr2;
212
Select_Lex *subselect;
215
Implement the mandated change, by altering the semantic tree:
216
left IN Item_singlerow_subselect(subselect)
219
which is represented as
220
Item_in_subselect(left, subselect)
222
subselect= expr3->invalidate_and_restore_select_lex();
223
result= new (session->mem_root) Item_in_subselect(left, subselect);
226
result = negate_expression(session, result);
233
result= new (session->mem_root) Item_func_eq(left, expr);
235
result= new (session->mem_root) Item_func_ne(left, expr);
241
@brief Creates a new Select_Lex for a UNION branch.
243
Sets up and initializes a Select_Lex structure for a query once the parser
244
discovers a UNION token. The current Select_Lex is pushed on the stack and
245
the new Select_Lex becomes the current one..=
247
@lex The parser state.
249
@is_union_distinct True if the union preceding the new select statement
252
@return <code>false</code> if successful, <code>true</code> if an error was
253
reported. In the latter case parsing should stop.
255
static bool add_select_to_union_list(Session *session, LEX *lex, bool is_union_distinct)
259
/* Only the last SELECT can have INTO...... */
260
my_error(ER_WRONG_USAGE, MYF(0), "UNION", "INTO");
263
if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
265
struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
266
my_parse_error(&pass);
269
/* This counter shouldn't be incremented for UNION parts */
271
if (mysql_new_select(lex, 0))
273
mysql_init_select(lex);
274
lex->current_select->linkage=UNION_TYPE;
275
if (is_union_distinct) /* UNION DISTINCT - remember position */
276
lex->current_select->master_unit()->union_distinct=
282
@brief Initializes a Select_Lex for a query within parentheses (aka
285
@return false if successful, true if an error was reported. In the latter
286
case parsing should stop.
288
static bool setup_select_in_parentheses(Session *session, LEX *lex)
290
Select_Lex * sel= lex->current_select;
291
if (sel->set_braces(1))
293
struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
294
my_parse_error(&pass);
297
if (sel->linkage == UNION_TYPE &&
298
!sel->master_unit()->first_select()->braces &&
299
sel->master_unit()->first_select()->linkage ==
302
struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
303
my_parse_error(&pass);
306
if (sel->linkage == UNION_TYPE &&
307
sel->olap != UNSPECIFIED_OLAP_TYPE &&
308
sel->master_unit()->fake_select_lex)
310
my_error(ER_WRONG_USAGE, MYF(0), "CUBE/ROLLUP", "ORDER BY");
313
/* select in braces, can't contain global parameters */
314
if (sel->master_unit()->fake_select_lex)
315
sel->master_unit()->global_parameters=
316
sel->master_unit()->fake_select_lex;
320
static Item* reserved_keyword_function(Session *session, const std::string &name, List<Item> *item_list)
322
const plugin::Function *udf= plugin::Function::get(name.c_str(), name.length());
327
item= Create_udf_func::s_singleton.create(session, udf, item_list);
329
my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", name.c_str());
335
116
} /* namespace drizzled; */
1035
828
/* create a table */
1038
CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
1040
Session *session= YYSession;
1041
LEX *lex= session->lex;
1042
lex->sql_command= SQLCOM_CREATE_TABLE;
1043
statement::CreateTable *statement= new(std::nothrow) statement::CreateTable(YYSession);
1044
lex->statement= statement;
1045
if (lex->statement == NULL)
1047
if (!lex->select_lex.add_table_to_list(session, $5, NULL,
1051
lex->col_list.empty();
1052
statement->change=NULL;
1053
statement->is_if_not_exists= $4;
1054
statement->create_info.db_type= NULL;
1055
statement->create_info.default_table_charset= NULL;
831
CREATE CATALOG_SYM catalog_name
833
Lex->statement= new statement::catalog::Create(YYSession, $3);
835
| CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
837
Lex->statement= new statement::CreateTable(YYSession, $5, $2);
1058
message::Table &proto= statement->create_table_message;
1060
proto.set_name($5->table.str);
1062
proto.set_type(message::Table::TEMPORARY);
1064
proto.set_type(message::Table::STANDARD);
839
if (not Lex->select_lex.add_table_to_list(YYSession, $5, NULL,
843
Lex->col_list.empty();
845
create_table_definition
1068
LEX *lex= YYSession->lex;
1069
lex->current_select= &lex->select_lex;
847
Lex->current_select= &Lex->select_lex;
1071
849
| CREATE build_method
1074
lex->sql_command= SQLCOM_CREATE_INDEX;
1075
statement::CreateIndex *statement= new(std::nothrow) statement::CreateIndex(YYSession);
1076
lex->statement= statement;
1077
if (lex->statement == NULL)
1079
statement->alter_info.flags.set(ALTER_ADD_INDEX);
1080
statement->alter_info.build_method= $2;
1081
lex->col_list.empty();
1082
statement->change=NULL;
851
Lex->statement= new statement::CreateIndex(YYSession, $2);
1084
853
opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
1087
statement::CreateIndex *statement= (statement::CreateIndex *)Lex->statement;
855
if (not Lex->current_select->add_table_to_list(Lex->session, $9,
1089
if (!lex->current_select->add_table_to_list(lex->session, $9,
1091
TL_OPTION_UPDATING))
1094
key= new Key($4, $6, &statement->key_create_info, 0, lex->col_list);
1095
statement->alter_info.key_list.push_back(key);
1096
lex->col_list.empty();
860
parser::buildKey(Lex, $4, $6);
1098
| CREATE DATABASE opt_if_not_exists ident
862
| CREATE DATABASE opt_if_not_exists schema_name
1102
lex->sql_command=SQLCOM_CREATE_DB;
1103
statement::CreateSchema *statement= new(std::nothrow) statement::CreateSchema(YYSession);
1104
lex->statement= statement;
1105
if (lex->statement == NULL)
1107
statement->is_if_not_exists= $3;
864
Lex->statement= new statement::CreateSchema(YYSession);
1109
866
opt_create_database_options
1117
| opt_create_table_options
1119
| LIKE table_ident opt_create_table_options
1121
Session *session= YYSession;
1122
LEX *lex= session->lex;
1123
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1125
statement->is_create_table_like= true;
1126
if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
1129
| '(' LIKE table_ident ')'
1131
Session *session= YYSession;
1132
LEX *lex= session->lex;
1133
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1135
statement->is_create_table_like= true;
1136
if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
1142
field_list ')' opt_create_table_options
1145
{ Lex->current_select->set_braces(1);}
872
create_table_definition:
873
'(' field_list ')' opt_create_table_options create_select_as
875
| '(' create_select ')'
877
Lex->current_select->set_braces(1);
880
| '(' create_like ')' opt_create_table_options
882
| create_like opt_create_table_options
884
| opt_create_table_options create_select_as
1151
| opt_duplicate opt_as create_select
1152
{ Lex->current_select->set_braces(0);}
890
| opt_duplicate_as create_select
892
Lex->current_select->set_braces(0);
1154
| opt_duplicate opt_as '(' create_select ')'
1155
{ Lex->current_select->set_braces(1);}
895
| opt_duplicate_as '(' create_select ')'
897
Lex->current_select->set_braces(1);
905
((statement::CreateTable *)(YYSession->getLex()->statement))->is_create_table_like= true;
907
if (not YYSession->getLex()->select_lex.add_table_to_list(YYSession, $2, NULL, 0, TL_READ))
919
This rule is used for both CREATE TABLE .. SELECT, AND INSERT ... SELECT
1163
lex->lock_option= TL_READ;
1164
if (lex->sql_command == SQLCOM_INSERT)
924
Lex->lock_option= TL_READ;
925
if (Lex->sql_command == SQLCOM_INSERT)
1166
lex->sql_command= SQLCOM_INSERT_SELECT;
1167
delete lex->statement;
1169
new(std::nothrow) statement::InsertSelect(YYSession);
1170
if (lex->statement == NULL)
927
delete Lex->statement;
928
Lex->statement= new statement::InsertSelect(YYSession);
1173
else if (lex->sql_command == SQLCOM_REPLACE)
930
else if (Lex->sql_command == SQLCOM_REPLACE)
1175
lex->sql_command= SQLCOM_REPLACE_SELECT;
1176
delete lex->statement;
1178
new(std::nothrow) statement::ReplaceSelect(YYSession);
1179
if (lex->statement == NULL)
932
delete Lex->statement;
933
Lex->statement= new statement::ReplaceSelect(YYSession);
1183
936
The following work only with the local list, the global list
1184
937
is created correctly in this case
1186
lex->current_select->table_list.save_and_clear(&lex->save_list);
1187
mysql_init_select(lex);
1188
lex->current_select->parsing_place= SELECT_LIST;
939
Lex->current_select->table_list.save_and_clear(&Lex->save_list);
941
Lex->current_select->parsing_place= SELECT_LIST;
1190
943
select_options select_item_list
1454
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1455
lex->length=lex->dec=0;
1457
statement->default_value= statement->on_update_value= 0;
1458
statement->comment= null_lex_str;
1460
statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1462
message::AlterTable &alter_proto=
1463
((statement::CreateTable *)Lex->statement)->alter_info.alter_proto;
1464
statement->current_proto_field= alter_proto.add_added_field();
1146
parser::buildCreateFieldIdent(Lex);
1469
1150
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1471
if (statement->current_proto_field)
1472
statement->current_proto_field->set_name($1.str);
1154
Lex->field()->set_name($1.str);
1474
if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
1475
lex->length,lex->dec,lex->type,
1157
if (add_field_to_list(Lex->session, &$1, (enum enum_field_types) $3,
1158
Lex->length, Lex->dec, Lex->type,
1476
1159
statement->column_format,
1477
1160
statement->default_value, statement->on_update_value,
1478
1161
&statement->comment,
1479
statement->change, &lex->interval_list, lex->charset))
1162
statement->change, &Lex->interval_list, Lex->charset))
1480
1163
DRIZZLE_YYABORT;
1482
statement->current_proto_field= NULL;
1165
Lex->setField(NULL);
1486
type opt_attribute {}
1170
field_definition opt_attribute {}
1493
Lex->length=(char*) 0; /* use default length */
1494
statement::CreateTable *statement=
1495
(statement::CreateTable *)Lex->statement;
1497
if (statement->current_proto_field)
1499
if ($1 == DRIZZLE_TYPE_LONG)
1500
statement->current_proto_field->set_type(message::Table::Field::INTEGER);
1501
else if ($1 == DRIZZLE_TYPE_LONGLONG)
1502
statement->current_proto_field->set_type(message::Table::Field::BIGINT);
1174
int_type ignored_field_number_length opt_field_number_signed opt_zerofill
1176
$$= parser::buildIntegerColumn(Lex, $1, ($3 or $4));
1507
1178
| real_type opt_precision
1511
statement::CreateTable *statement=
1512
(statement::CreateTable *)Lex->statement;
1514
if (statement->current_proto_field)
1516
assert ($1 == DRIZZLE_TYPE_DOUBLE);
1517
statement->current_proto_field->set_type(message::Table::Field::DOUBLE);
1523
$$=DRIZZLE_TYPE_VARCHAR;
1525
statement::CreateTable *statement=
1526
(statement::CreateTable *)Lex->statement;
1528
if (statement->current_proto_field)
1530
statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1531
message::Table::Field::StringFieldOptions *string_field_options;
1533
string_field_options= statement->current_proto_field->mutable_string_options();
1535
string_field_options->set_length(atoi($3.str));
1540
Lex->length=(char*) "1";
1541
$$=DRIZZLE_TYPE_VARCHAR;
1543
statement::CreateTable *statement=
1544
(statement::CreateTable *)Lex->statement;
1546
if (statement->current_proto_field)
1547
statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1549
| varchar '(' NUM ')'
1552
$$= DRIZZLE_TYPE_VARCHAR;
1554
statement::CreateTable *statement=
1555
(statement::CreateTable *)Lex->statement;
1557
if (statement->current_proto_field)
1559
statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1561
message::Table::Field::StringFieldOptions *string_field_options;
1563
string_field_options= statement->current_proto_field->mutable_string_options();
1565
string_field_options->set_length(atoi($3.str));
1568
| VARBINARY '(' NUM ')'
1571
Lex->charset=&my_charset_bin;
1572
$$= DRIZZLE_TYPE_VARCHAR;
1574
statement::CreateTable *statement=
1575
(statement::CreateTable *)Lex->statement;
1577
if (statement->current_proto_field)
1579
statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1580
message::Table::Field::StringFieldOptions *string_field_options;
1582
string_field_options= statement->current_proto_field->mutable_string_options();
1584
string_field_options->set_length(atoi($3.str));
1585
string_field_options->set_collation_id(my_charset_bin.number);
1586
string_field_options->set_collation(my_charset_bin.name);
1180
assert ($1 == DRIZZLE_TYPE_DOUBLE);
1181
$$= parser::buildDoubleColumn(Lex);
1185
$$= parser::buildVarcharColumn(Lex, $3.str);
1189
$$= parser::buildVarcharColumn(Lex, "1");
1191
| varchar '(' NUM ')'
1193
$$= parser::buildVarcharColumn(Lex, $3.str);
1195
| VARBINARY '(' NUM ')'
1197
$$= parser::buildVarbinaryColumn(Lex, $3.str);
1591
1201
$$=DRIZZLE_TYPE_DATE;
1593
statement::CreateTable *statement=
1594
(statement::CreateTable *)Lex->statement;
1596
if (statement->current_proto_field)
1597
statement->current_proto_field->set_type(message::Table::Field::DATE);
1601
$$=DRIZZLE_TYPE_TIMESTAMP;
1603
statement::CreateTable *statement=
1604
(statement::CreateTable *)Lex->statement;
1606
if (statement->current_proto_field)
1607
statement->current_proto_field->set_type(message::Table::Field::TIMESTAMP);
1204
Lex->field()->set_type(message::Table::Field::DATE);
1208
$$=DRIZZLE_TYPE_TIME;
1211
Lex->field()->set_type(message::Table::Field::TIME);
1215
$$=parser::buildTimestampColumn(Lex, NULL);
1217
| TIMESTAMP_SYM '(' NUM ')'
1219
$$=parser::buildTimestampColumn(Lex, $3.str);
1611
1223
$$=DRIZZLE_TYPE_DATETIME;
1613
statement::CreateTable *statement=
1614
(statement::CreateTable *)Lex->statement;
1616
if (statement->current_proto_field)
1617
statement->current_proto_field->set_type(message::Table::Field::DATETIME);
1621
Lex->charset=&my_charset_bin;
1622
$$=DRIZZLE_TYPE_BLOB;
1623
Lex->length=(char*) 0; /* use default length */
1625
statement::CreateTable *statement=
1626
(statement::CreateTable *)Lex->statement;
1628
if (statement->current_proto_field)
1630
statement->current_proto_field->set_type(message::Table::Field::BLOB);
1631
message::Table::Field::StringFieldOptions *string_field_options;
1633
string_field_options= statement->current_proto_field->mutable_string_options();
1634
string_field_options->set_collation_id(my_charset_bin.number);
1635
string_field_options->set_collation(my_charset_bin.name);
1640
$$=DRIZZLE_TYPE_BLOB;
1641
Lex->length=(char*) 0; /* use default length */
1643
statement::CreateTable *statement=
1644
(statement::CreateTable *)Lex->statement;
1646
if (statement->current_proto_field)
1647
statement->current_proto_field->set_type(message::Table::Field::BLOB);
1649
| DECIMAL_SYM float_options
1651
$$=DRIZZLE_TYPE_DECIMAL;
1653
statement::CreateTable *statement=
1654
(statement::CreateTable *)Lex->statement;
1656
if (statement->current_proto_field)
1657
statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1659
| NUMERIC_SYM float_options
1661
$$=DRIZZLE_TYPE_DECIMAL;
1663
statement::CreateTable *statement=
1664
(statement::CreateTable *)Lex->statement;
1666
if (statement->current_proto_field)
1667
statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1669
| FIXED_SYM float_options
1671
$$=DRIZZLE_TYPE_DECIMAL;
1673
statement::CreateTable *statement=
1674
(statement::CreateTable *)Lex->statement;
1676
if (statement->current_proto_field)
1677
statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1680
{Lex->interval_list.empty();}
1226
Lex->field()->set_type(message::Table::Field::DATETIME);
1230
$$= parser::buildBlobColumn(Lex);
1234
$$=DRIZZLE_TYPE_BLOB;
1235
Lex->length=(char*) 0; /* use default length */
1238
Lex->field()->set_type(message::Table::Field::BLOB);
1240
| DECIMAL_SYM float_options
1242
$$= parser::buildDecimalColumn(Lex);
1244
| NUMERIC_SYM float_options
1246
$$= parser::buildDecimalColumn(Lex);
1248
| FIXED_SYM float_options
1250
$$= parser::buildDecimalColumn(Lex);
1254
Lex->interval_list.empty();
1683
1258
$$=DRIZZLE_TYPE_ENUM;
1685
statement::CreateTable *statement=
1686
(statement::CreateTable *)Lex->statement;
1688
if (statement->current_proto_field)
1689
statement->current_proto_field->set_type(message::Table::Field::ENUM);
1261
Lex->field()->set_type(message::Table::Field::ENUM);
1265
$$= parser::buildUuidColumn(Lex);
1269
$$= parser::buildBooleanColumn(Lex);
1693
$$=DRIZZLE_TYPE_LONGLONG;
1694
Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
1696
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1697
if (statement->current_proto_field)
1699
message::Table::Field::FieldConstraints *constraints;
1700
constraints= statement->current_proto_field->mutable_constraints();
1701
constraints->set_is_nullable(false);
1703
statement->current_proto_field->set_type(message::Table::Field::BIGINT);
1273
$$= parser::buildSerialColumn(Lex);
4807
4356
DATABASES show_wild
4810
Session *session= YYSession;
4812
lex->sql_command= SQLCOM_SELECT;
4814
new(std::nothrow) statement::Show(session);
4815
if (lex->statement == NULL)
4818
std::string column_name= "Database";
4821
column_name.append(" (");
4822
column_name.append(Lex->wild->ptr());
4823
column_name.append(")");
4826
if (Lex->current_select->where)
4828
if (prepare_new_schema_table(session, lex, "SCHEMAS"))
4833
if (prepare_new_schema_table(session, lex, "SHOW_SCHEMAS"))
4837
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
4838
my_field->is_autogenerated_name= false;
4839
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
4841
if (session->add_item_to_list(my_field))
4844
if (session->add_order_to_list(my_field, true))
4358
if (not show::buildScemas(YYSession))
4847
4361
/* SHOW TABLES */
4848
4362
| TABLES opt_db show_wild
4851
Session *session= YYSession;
4853
lex->sql_command= SQLCOM_SELECT;
4855
statement::Show *select=
4856
new(std::nothrow) statement::Show(YYSession);
4858
lex->statement= select;
4860
if (lex->statement == NULL)
4864
std::string column_name= "Tables_in_";
4868
SchemaIdentifier identifier($2);
4869
column_name.append($2);
4870
lex->select_lex.db= $2;
4871
if (not plugin::StorageEngine::doesSchemaExist(identifier))
4873
my_error(ER_BAD_DB_ERROR, MYF(0), $2);
4875
select->setShowPredicate($2, "");
4877
else if (not session->db.empty())
4879
column_name.append(session->db);
4880
select->setShowPredicate(session->db, "");
4884
my_error(ER_NO_DB_ERROR, MYF(0));
4890
column_name.append(" (");
4891
column_name.append(Lex->wild->ptr());
4892
column_name.append(")");
4895
if (prepare_new_schema_table(YYSession, lex, "SHOW_TABLES"))
4898
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
4899
my_field->is_autogenerated_name= false;
4900
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
4902
if (session->add_item_to_list(my_field))
4905
if (session->add_order_to_list(my_field, true))
4364
if (not show::buildTables(YYSession, $2))
4908
4367
/* SHOW TEMPORARY TABLES */
4909
4368
| TEMPORARY_SYM TABLES show_wild
4912
Session *session= YYSession;
4914
lex->sql_command= SQLCOM_SELECT;
4916
statement::Show *select=
4917
new(std::nothrow) statement::Show(YYSession);
4919
lex->statement= select;
4921
if (lex->statement == NULL)
4925
if (prepare_new_schema_table(YYSession, lex, "SHOW_TEMPORARY_TABLES"))
4928
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
4932
(session->lex->current_select->with_wild)++;
4370
if (not show::buildTemporaryTables(YYSession))
4935
4373
/* SHOW TABLE STATUS */
4936
4374
| TABLE_SYM STATUS_SYM opt_db show_wild
4939
lex->sql_command= SQLCOM_SELECT;
4940
statement::Show *select=
4941
new(std::nothrow) statement::Show(YYSession);
4943
lex->statement= select;
4945
if (lex->statement == NULL)
4948
Session *session= YYSession;
4950
std::string column_name= "Tables_in_";
4954
lex->select_lex.db= $3;
4956
SchemaIdentifier identifier($3);
4957
if (not plugin::StorageEngine::doesSchemaExist(identifier))
4959
my_error(ER_BAD_DB_ERROR, MYF(0), $3);
4962
select->setShowPredicate($3, "");
4966
select->setShowPredicate(session->db, "");
4969
if (prepare_new_schema_table(session, lex, "SHOW_TABLE_STATUS"))
4972
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
4976
(session->lex->current_select->with_wild)++;
4376
if (not show::buildTableStatus(YYSession, $3))
4978
4379
/* SHOW COLUMNS FROM table_name */
4979
4380
| COLUMNS from_or_in table_ident opt_db show_wild
4982
Session *session= YYSession;
4983
statement::Show *select;
4985
lex->sql_command= SQLCOM_SELECT;
4987
select= new(std::nothrow) statement::Show(session);
4989
lex->statement= select;
4991
if (lex->statement == NULL)
4995
select->setShowPredicate($4, $3->table.str);
4996
else if ($3->db.str)
4997
select->setShowPredicate($3->db.str, $3->table.str);
4999
select->setShowPredicate(session->db, $3->table.str);
5002
drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
5003
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
5005
my_error(ER_NO_SUCH_TABLE, MYF(0),
5006
select->getShowSchema().c_str(),
5011
if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
5014
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5018
(session->lex->current_select->with_wild)++;
4382
if (not show::buildColumns(YYSession, $4, $3))
5021
4385
/* SHOW INDEXES from table */
5022
4386
| keys_or_index from_or_in table_ident opt_db where_clause
5025
Session *session= YYSession;
5026
statement::Show *select;
5028
lex->sql_command= SQLCOM_SELECT;
5030
select= new(std::nothrow) statement::Show(session);
5032
lex->statement= select;
5034
if (lex->statement == NULL)
5038
select->setShowPredicate($4, $3->table.str);
5039
else if ($3->db.str)
5040
select->setShowPredicate($3->db.str, $3->table.str);
5042
select->setShowPredicate(session->db, $3->table.str);
5045
drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
5046
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
5048
my_error(ER_NO_SUCH_TABLE, MYF(0),
5049
select->getShowSchema().c_str(),
5054
if (prepare_new_schema_table(session, lex, "SHOW_INDEXES"))
5057
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5061
(session->lex->current_select->with_wild)++;
4388
if (not show::buildIndex(YYSession, $4, $3))
5063
4391
| COUNT_SYM '(' '*' ')' WARNINGS
5065
(void) create_select_for_variable("warning_count");
5067
lex->statement= new(std::nothrow) statement::Show(YYSession);
5068
if (lex->statement == NULL)
4393
show::buildSelectWarning(YYSession);
5071
4395
| COUNT_SYM '(' '*' ')' ERRORS
5073
(void) create_select_for_variable("error_count");
5075
lex->statement= new(std::nothrow) statement::Show(YYSession);
5076
if (lex->statement == NULL)
4397
show::buildSelectError(YYSession);
5079
4399
| WARNINGS opt_limit_clause_init
5081
Lex->sql_command = SQLCOM_SHOW_WARNS;
5082
Lex->statement= new(std::nothrow) statement::ShowWarnings(YYSession);
5083
if (Lex->statement == NULL)
4401
show::buildWarnings(YYSession);
5086
4403
| ERRORS opt_limit_clause_init
5088
Lex->sql_command = SQLCOM_SHOW_ERRORS;
5089
Lex->statement= new(std::nothrow) statement::ShowErrors(YYSession);
5090
if (Lex->statement == NULL)
4405
show::buildErrors(YYSession);
5093
4407
| opt_var_type STATUS_SYM show_wild
5096
lex->sql_command= SQLCOM_SELECT;
5098
new(std::nothrow) statement::Show(YYSession);
5099
if (lex->statement == NULL)
5102
Session *session= YYSession;
5104
if ($1 == OPT_GLOBAL)
5106
if (prepare_new_schema_table(session, lex, "GLOBAL_STATUS"))
5111
if (prepare_new_schema_table(session, lex, "SESSION_STATUS"))
5115
std::string key("Variable_name");
5116
std::string value("Value");
5118
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5119
my_field->is_autogenerated_name= false;
5120
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5122
if (session->add_item_to_list(my_field))
5125
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5126
my_field->is_autogenerated_name= false;
5127
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5129
if (session->add_item_to_list(my_field))
4409
if (not show::buildStatus(YYSession, $1))
4412
| engine_option_value STATUS_SYM
4414
if (not show::buildEngineStatus(YYSession, $1))
5132
4417
| CREATE TABLE_SYM table_ident
5135
lex->sql_command= SQLCOM_SELECT;
5136
statement::Show *select=
5137
new(std::nothrow) statement::Show(YYSession);
5139
lex->statement= select;
5141
if (lex->statement == NULL)
5144
Session *session= YYSession;
5146
if (prepare_new_schema_table(session, lex, "TABLE_SQL_DEFINITION"))
5150
select->setShowPredicate($3->db.str, $3->table.str);
5152
select->setShowPredicate(session->db, $3->table.str);
5154
std::string key("Table");
5155
std::string value("Create Table");
5157
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
5158
my_field->is_autogenerated_name= false;
5159
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5161
if (session->add_item_to_list(my_field))
5164
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
5165
my_field->is_autogenerated_name= false;
5166
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5168
if (session->add_item_to_list(my_field))
4419
if (not show::buildCreateTable(YYSession, $3))
5171
4422
| PROCESSLIST_SYM
5175
lex->sql_command= SQLCOM_SELECT;
5177
new(std::nothrow) statement::Show(YYSession);
5178
if (lex->statement == NULL)
5181
Session *session= YYSession;
5183
if (prepare_new_schema_table(session, lex, "PROCESSLIST"))
5186
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5190
(session->lex->current_select->with_wild)++;
4424
if (not show::buildProcesslist(YYSession))
5193
4427
| opt_var_type VARIABLES show_wild
5196
lex->sql_command= SQLCOM_SELECT;
5198
new(std::nothrow) statement::Show(YYSession);
5199
if (lex->statement == NULL)
5202
Session *session= YYSession;
5204
if ($1 == OPT_GLOBAL)
5206
if (prepare_new_schema_table(session, lex, "GLOBAL_VARIABLES"))
5211
if (prepare_new_schema_table(session, lex, "SESSION_VARIABLES"))
5215
std::string key("Variable_name");
5216
std::string value("Value");
5218
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5219
my_field->is_autogenerated_name= false;
5220
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5222
if (session->add_item_to_list(my_field))
5225
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5226
my_field->is_autogenerated_name= false;
5227
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5229
if (session->add_item_to_list(my_field))
4429
if (not show::buildVariables(YYSession, $1))
5232
4432
| CREATE DATABASE opt_if_not_exists ident
5235
lex->sql_command= SQLCOM_SELECT;
5236
statement::Show *select=
5237
new(std::nothrow) statement::Show(YYSession);
5239
lex->statement= select;
5241
if (lex->statement == NULL)
5244
Session *session= YYSession;
5246
if (prepare_new_schema_table(session, lex, "SCHEMA_SQL_DEFINITION"))
5250
select->setShowPredicate($4.str);
5252
select->setShowPredicate(session->db);
5254
std::string key("Database");
5255
std::string value("Create Database");
5257
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
5258
my_field->is_autogenerated_name= false;
5259
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5261
if (session->add_item_to_list(my_field))
5264
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
5265
my_field->is_autogenerated_name= false;
5266
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5268
if (session->add_item_to_list(my_field))
4434
if (not show::buildCreateSchema(YYSession, $4))
5273
4439
/* empty */ { $$= 0; }
5783
4872
simple_ident_q:
5784
4873
ident '.' ident
5786
Session *session= YYSession;
5787
LEX *lex= session->lex;
5790
Select_Lex *sel= lex->current_select;
5791
if (sel->no_table_names_allowed)
5793
my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5794
MYF(0), $1.str, session->where);
5796
$$= (sel->parsing_place != IN_HAVING ||
5797
sel->get_in_sum_expr() > 0) ?
5798
(Item*) new Item_field(Lex->current_context(),
5799
(const char *)NULL, $1.str, $3.str) :
5800
(Item*) new Item_ref(Lex->current_context(),
5801
(const char *)NULL, $1.str, $3.str);
4875
$$= parser::buildIdent(Lex, NULL_LEX_STRING, $1, $3);
5804
4877
| '.' ident '.' ident
5806
Session *session= YYSession;
5807
LEX *lex= session->lex;
5808
Select_Lex *sel= lex->current_select;
5809
if (sel->no_table_names_allowed)
5811
my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5812
MYF(0), $2.str, session->where);
5814
$$= (sel->parsing_place != IN_HAVING ||
5815
sel->get_in_sum_expr() > 0) ?
5816
(Item*) new Item_field(Lex->current_context(), NULL, $2.str, $4.str) :
5817
(Item*) new Item_ref(Lex->current_context(),
5818
(const char *)NULL, $2.str, $4.str);
4879
$$= parser::buildIdent(Lex, NULL_LEX_STRING, $2, $4);
5820
4881
| ident '.' ident '.' ident
5822
Session *session= YYSession;
5823
LEX *lex= session->lex;
5824
Select_Lex *sel= lex->current_select;
5825
if (sel->no_table_names_allowed)
5827
my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5828
MYF(0), $3.str, session->where);
5830
$$= (sel->parsing_place != IN_HAVING ||
5831
sel->get_in_sum_expr() > 0) ?
5832
(Item*) new Item_field(Lex->current_context(), $1.str, $3.str,
5834
(Item*) new Item_ref(Lex->current_context(), $1.str, $3.str,
4883
$$= parser::buildIdent(Lex, $1, $3, $5);
5841
4892
| ident '.' ident '.' ident
5844
reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
5845
if (my_strcasecmp(table_alias_charset, $1.str, table->getSchemaName()))
5847
my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
5850
if (my_strcasecmp(table_alias_charset, $3.str,
5851
table->getTableName()))
5853
my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
4894
if (not parser::checkFieldIdent(Lex, $1, $3))
5858
4899
| ident '.' ident
5861
reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
5862
if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
5864
my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
4901
if (not parser::checkFieldIdent(Lex, NULL_LEX_STRING, $1))
5865
4902
DRIZZLE_YYABORT;
5869
| '.' ident { $$=$2;} /* For Delphi */
5873
ident { $$=new Table_ident($1); }
5874
| ident '.' ident { $$=new Table_ident($1,$3);}
5875
| '.' ident { $$=new Table_ident($2);} /* For Delphi */
4915
$$= new Table_ident($1);
4917
| schema_name '.' ident
4919
$$=new Table_ident($1,$3);
4923
$$= new Table_ident($2);
5882
4942
const CHARSET_INFO * const cs= system_charset_info;