104
140
This function is not for use in semantic actions and is internal to
105
141
the parser, as it performs some pre-return cleanup.
106
In semantic actions, please use parser::my_parse_error or my_error to
142
In semantic actions, please use my_parse_error or my_error to
107
143
push an error into the error stack and DRIZZLE_YYABORT
108
144
to abort from the parser.
111
147
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());
116
335
} /* namespace drizzled; */
828
1046
/* create a table */
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);
1049
CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
1051
Session *session= YYSession;
1052
LEX *lex= session->lex;
1053
lex->sql_command= SQLCOM_CREATE_TABLE;
1054
statement::CreateTable *statement= new(std::nothrow) statement::CreateTable(YYSession);
1055
lex->statement= statement;
1056
if (lex->statement == NULL)
1058
if (!lex->select_lex.add_table_to_list(session, $5, NULL,
1062
lex->col_list.empty();
1063
statement->change=NULL;
1064
statement->is_if_not_exists= $4;
1065
statement->create_info.db_type= NULL;
1066
statement->create_info.default_table_charset= NULL;
839
if (not Lex->select_lex.add_table_to_list(YYSession, $5, NULL,
843
Lex->col_list.empty();
1069
message::Table &proto= statement->create_table_message;
1071
proto.set_name($5->table.str);
1073
proto.set_type(message::Table::TEMPORARY);
1075
proto.set_type(message::Table::STANDARD);
845
create_table_definition
847
Lex->current_select= &Lex->select_lex;
1079
LEX *lex= YYSession->lex;
1080
lex->current_select= &lex->select_lex;
849
1082
| CREATE build_method
851
Lex->statement= new statement::CreateIndex(YYSession, $2);
1085
lex->sql_command= SQLCOM_CREATE_INDEX;
1086
statement::CreateIndex *statement= new(std::nothrow) statement::CreateIndex(YYSession);
1087
lex->statement= statement;
1088
if (lex->statement == NULL)
1090
statement->alter_info.flags.set(ALTER_ADD_INDEX);
1091
statement->alter_info.build_method= $2;
1092
lex->col_list.empty();
1093
statement->change=NULL;
853
1095
opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
855
if (not Lex->current_select->add_table_to_list(Lex->session, $9,
1098
statement::CreateIndex *statement= (statement::CreateIndex *)Lex->statement;
1100
if (!lex->current_select->add_table_to_list(lex->session, $9,
1102
TL_OPTION_UPDATING))
858
1103
DRIZZLE_YYABORT;
860
parser::buildKey(Lex, $4, $6);
1105
key= new Key($4, $6, &statement->key_create_info, 0, lex->col_list);
1106
statement->alter_info.key_list.push_back(key);
1107
lex->col_list.empty();
862
| CREATE DATABASE opt_if_not_exists schema_name
1109
| CREATE DATABASE opt_if_not_exists ident
864
Lex->statement= new statement::CreateSchema(YYSession);
1113
lex->sql_command=SQLCOM_CREATE_DB;
1114
statement::CreateSchema *statement= new(std::nothrow) statement::CreateSchema(YYSession);
1115
lex->statement= statement;
1116
if (lex->statement == NULL)
1118
statement->is_if_not_exists= $3;
866
1120
opt_create_database_options
872
create_table_definition:
873
'(' field_list ')' opt_create_table_options create_select_as
875
| '(' create_select ')'
877
Lex->current_select->set_braces(1);
1128
| opt_create_table_options
1130
| LIKE table_ident opt_create_table_options
1132
Session *session= YYSession;
1133
LEX *lex= session->lex;
1134
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1136
statement->is_create_table_like= true;
1137
if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
1140
| '(' LIKE table_ident ')'
1142
Session *session= YYSession;
1143
LEX *lex= session->lex;
1144
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1146
statement->is_create_table_like= true;
1147
if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
1153
field_list ')' opt_create_table_options
1156
{ 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
890
| opt_duplicate_as create_select
892
Lex->current_select->set_braces(0);
1162
| opt_duplicate opt_as create_select
1163
{ Lex->current_select->set_braces(0);}
895
| opt_duplicate_as '(' create_select ')'
897
Lex->current_select->set_braces(1);
1165
| opt_duplicate opt_as '(' create_select ')'
1166
{ 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
924
Lex->lock_option= TL_READ;
925
if (Lex->sql_command == SQLCOM_INSERT)
1174
lex->lock_option= TL_READ;
1175
if (lex->sql_command == SQLCOM_INSERT)
927
delete Lex->statement;
928
Lex->statement= new statement::InsertSelect(YYSession);
1177
lex->sql_command= SQLCOM_INSERT_SELECT;
1178
delete lex->statement;
1180
new(std::nothrow) statement::InsertSelect(YYSession);
1181
if (lex->statement == NULL)
930
else if (Lex->sql_command == SQLCOM_REPLACE)
1184
else if (lex->sql_command == SQLCOM_REPLACE)
932
delete Lex->statement;
933
Lex->statement= new statement::ReplaceSelect(YYSession);
1186
lex->sql_command= SQLCOM_REPLACE_SELECT;
1187
delete lex->statement;
1189
new(std::nothrow) statement::ReplaceSelect(YYSession);
1190
if (lex->statement == NULL)
936
1194
The following work only with the local list, the global list
937
1195
is created correctly in this case
939
Lex->current_select->table_list.save_and_clear(&Lex->save_list);
941
Lex->current_select->parsing_place= SELECT_LIST;
1197
lex->current_select->table_list.save_and_clear(&lex->save_list);
1198
mysql_init_select(lex);
1199
lex->current_select->parsing_place= SELECT_LIST;
943
1201
select_options select_item_list
1146
parser::buildCreateFieldIdent(Lex);
1465
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1466
lex->length=lex->dec=0;
1468
statement->default_value= statement->on_update_value= 0;
1469
statement->comment= null_lex_str;
1471
statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1473
message::AlterTable &alter_proto=
1474
((statement::CreateTable *)Lex->statement)->alter_info.alter_proto;
1475
statement->current_proto_field= alter_proto.add_added_field();
1150
1480
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1154
Lex->field()->set_name($1.str);
1482
if (statement->current_proto_field)
1483
statement->current_proto_field->set_name($1.str);
1157
if (add_field_to_list(Lex->session, &$1, (enum enum_field_types) $3,
1158
Lex->length, Lex->dec, Lex->type,
1485
if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
1486
lex->length,lex->dec,lex->type,
1159
1487
statement->column_format,
1160
1488
statement->default_value, statement->on_update_value,
1161
1489
&statement->comment,
1162
statement->change, &Lex->interval_list, Lex->charset))
1490
statement->change, &lex->interval_list, lex->charset))
1163
1491
DRIZZLE_YYABORT;
1165
Lex->setField(NULL);
1493
statement->current_proto_field= NULL;
1170
field_definition opt_attribute {}
1497
type opt_attribute {}
1174
1501
int_type ignored_field_number_length opt_field_number_signed opt_zerofill
1176
$$= parser::buildIntegerColumn(Lex, $1, ($3 or $4));
1504
Lex->length=(char*) 0; /* use default length */
1505
statement::CreateTable *statement=
1506
(statement::CreateTable *)Lex->statement;
1510
$1= DRIZZLE_TYPE_LONGLONG;
1513
if (statement->current_proto_field)
1515
assert ($1 == DRIZZLE_TYPE_LONG or $1 == DRIZZLE_TYPE_LONGLONG);
1516
// We update the type for unsigned types
1519
statement->current_proto_field->set_type(message::Table::Field::BIGINT);
1520
statement->current_proto_field->mutable_constraints()->set_is_unsigned(true);
1522
if ($1 == DRIZZLE_TYPE_LONG)
1524
statement->current_proto_field->set_type(message::Table::Field::INTEGER);
1526
else if ($1 == DRIZZLE_TYPE_LONGLONG)
1528
statement->current_proto_field->set_type(message::Table::Field::BIGINT);
1178
1532
| real_type opt_precision
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);
1536
statement::CreateTable *statement=
1537
(statement::CreateTable *)Lex->statement;
1539
if (statement->current_proto_field)
1541
assert ($1 == DRIZZLE_TYPE_DOUBLE);
1542
statement->current_proto_field->set_type(message::Table::Field::DOUBLE);
1548
$$=DRIZZLE_TYPE_VARCHAR;
1550
statement::CreateTable *statement=
1551
(statement::CreateTable *)Lex->statement;
1553
if (statement->current_proto_field)
1555
statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1556
message::Table::Field::StringFieldOptions *string_field_options;
1558
string_field_options= statement->current_proto_field->mutable_string_options();
1560
string_field_options->set_length(atoi($3.str));
1565
Lex->length=(char*) "1";
1566
$$=DRIZZLE_TYPE_VARCHAR;
1568
statement::CreateTable *statement=
1569
(statement::CreateTable *)Lex->statement;
1571
if (statement->current_proto_field)
1572
statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1574
| varchar '(' NUM ')'
1577
$$= DRIZZLE_TYPE_VARCHAR;
1579
statement::CreateTable *statement=
1580
(statement::CreateTable *)Lex->statement;
1582
if (statement->current_proto_field)
1584
statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1586
message::Table::Field::StringFieldOptions *string_field_options;
1588
string_field_options= statement->current_proto_field->mutable_string_options();
1590
string_field_options->set_length(atoi($3.str));
1593
| VARBINARY '(' NUM ')'
1596
Lex->charset=&my_charset_bin;
1597
$$= DRIZZLE_TYPE_VARCHAR;
1599
statement::CreateTable *statement=
1600
(statement::CreateTable *)Lex->statement;
1602
if (statement->current_proto_field)
1604
statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1605
message::Table::Field::StringFieldOptions *string_field_options;
1607
string_field_options= statement->current_proto_field->mutable_string_options();
1609
string_field_options->set_length(atoi($3.str));
1610
string_field_options->set_collation_id(my_charset_bin.number);
1611
string_field_options->set_collation(my_charset_bin.name);
1201
1616
$$=DRIZZLE_TYPE_DATE;
1204
Lex->field()->set_type(message::Table::Field::DATE);
1618
statement::CreateTable *statement=
1619
(statement::CreateTable *)Lex->statement;
1621
if (statement->current_proto_field)
1622
statement->current_proto_field->set_type(message::Table::Field::DATE);
1208
1626
$$=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);
1628
statement::CreateTable *statement=
1629
(statement::CreateTable *)Lex->statement;
1631
if (statement->current_proto_field)
1632
statement->current_proto_field->set_type(message::Table::Field::TIME);
1636
$$=DRIZZLE_TYPE_TIMESTAMP;
1638
statement::CreateTable *statement=
1639
(statement::CreateTable *)Lex->statement;
1641
if (statement->current_proto_field)
1642
statement->current_proto_field->set_type(message::Table::Field::EPOCH);
1223
1646
$$=DRIZZLE_TYPE_DATETIME;
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();
1648
statement::CreateTable *statement=
1649
(statement::CreateTable *)Lex->statement;
1651
if (statement->current_proto_field)
1652
statement->current_proto_field->set_type(message::Table::Field::DATETIME);
1656
Lex->charset=&my_charset_bin;
1657
$$=DRIZZLE_TYPE_BLOB;
1658
Lex->length=(char*) 0; /* use default length */
1660
statement::CreateTable *statement=
1661
(statement::CreateTable *)Lex->statement;
1663
if (statement->current_proto_field)
1665
statement->current_proto_field->set_type(message::Table::Field::BLOB);
1666
message::Table::Field::StringFieldOptions *string_field_options;
1668
string_field_options= statement->current_proto_field->mutable_string_options();
1669
string_field_options->set_collation_id(my_charset_bin.number);
1670
string_field_options->set_collation(my_charset_bin.name);
1675
$$=DRIZZLE_TYPE_BLOB;
1676
Lex->length=(char*) 0; /* use default length */
1678
statement::CreateTable *statement=
1679
(statement::CreateTable *)Lex->statement;
1681
if (statement->current_proto_field)
1682
statement->current_proto_field->set_type(message::Table::Field::BLOB);
1684
| DECIMAL_SYM float_options
1686
$$=DRIZZLE_TYPE_DECIMAL;
1688
statement::CreateTable *statement=
1689
(statement::CreateTable *)Lex->statement;
1691
if (statement->current_proto_field)
1692
statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1694
| NUMERIC_SYM float_options
1696
$$=DRIZZLE_TYPE_DECIMAL;
1698
statement::CreateTable *statement=
1699
(statement::CreateTable *)Lex->statement;
1701
if (statement->current_proto_field)
1702
statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1704
| FIXED_SYM float_options
1706
$$=DRIZZLE_TYPE_DECIMAL;
1708
statement::CreateTable *statement=
1709
(statement::CreateTable *)Lex->statement;
1711
if (statement->current_proto_field)
1712
statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1715
{Lex->interval_list.empty();}
1258
1718
$$=DRIZZLE_TYPE_ENUM;
1261
Lex->field()->set_type(message::Table::Field::ENUM);
1265
$$= parser::buildUuidColumn(Lex);
1269
$$= parser::buildBooleanColumn(Lex);
1720
statement::CreateTable *statement=
1721
(statement::CreateTable *)Lex->statement;
1723
if (statement->current_proto_field)
1724
statement->current_proto_field->set_type(message::Table::Field::ENUM);
1728
$$=DRIZZLE_TYPE_UUID;
1730
statement::CreateTable *statement=
1731
(statement::CreateTable *)Lex->statement;
1733
if (statement->current_proto_field)
1734
statement->current_proto_field->set_type(message::Table::Field::UUID);
1273
$$= parser::buildSerialColumn(Lex);
1738
$$=DRIZZLE_TYPE_LONGLONG;
1739
Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
1741
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1742
if (statement->current_proto_field)
1744
message::Table::Field::FieldConstraints *constraints;
1745
constraints= statement->current_proto_field->mutable_constraints();
1746
constraints->set_is_nullable(false);
1748
statement->current_proto_field->set_type(message::Table::Field::BIGINT);
4356
4962
DATABASES show_wild
4358
if (not show::buildScemas(YYSession))
4965
Session *session= YYSession;
4967
lex->sql_command= SQLCOM_SELECT;
4969
new(std::nothrow) statement::Show(session);
4970
if (lex->statement == NULL)
4973
std::string column_name= "Database";
4976
column_name.append(" (");
4977
column_name.append(Lex->wild->ptr());
4978
column_name.append(")");
4981
if (Lex->current_select->where)
4983
if (prepare_new_schema_table(session, lex, "SCHEMAS"))
4988
if (prepare_new_schema_table(session, lex, "SHOW_SCHEMAS"))
4992
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
4993
my_field->is_autogenerated_name= false;
4994
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
4996
if (session->add_item_to_list(my_field))
4999
if (session->add_order_to_list(my_field, true))
4361
5002
/* SHOW TABLES */
4362
5003
| TABLES opt_db show_wild
4364
if (not show::buildTables(YYSession, $2))
5006
Session *session= YYSession;
5008
lex->sql_command= SQLCOM_SELECT;
5010
statement::Show *select=
5011
new(std::nothrow) statement::Show(YYSession);
5013
lex->statement= select;
5015
if (lex->statement == NULL)
5019
std::string column_name= "Tables_in_";
5021
util::string::const_shared_ptr schema(session->schema());
5024
SchemaIdentifier identifier($2);
5025
column_name.append($2);
5026
lex->select_lex.db= $2;
5027
if (not plugin::StorageEngine::doesSchemaExist(identifier))
5029
my_error(ER_BAD_DB_ERROR, MYF(0), $2);
5031
select->setShowPredicate($2, "");
5033
else if (schema and not schema->empty())
5035
column_name.append(*schema);
5036
select->setShowPredicate(*schema, "");
5040
my_error(ER_NO_DB_ERROR, MYF(0));
5047
column_name.append(" (");
5048
column_name.append(Lex->wild->ptr());
5049
column_name.append(")");
5052
if (prepare_new_schema_table(YYSession, lex, "SHOW_TABLES"))
5055
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
5056
my_field->is_autogenerated_name= false;
5057
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
5059
if (session->add_item_to_list(my_field))
5062
if (session->add_order_to_list(my_field, true))
4367
5065
/* SHOW TEMPORARY TABLES */
4368
5066
| TEMPORARY_SYM TABLES show_wild
4370
if (not show::buildTemporaryTables(YYSession))
5069
Session *session= YYSession;
5071
lex->sql_command= SQLCOM_SELECT;
5073
statement::Show *select=
5074
new(std::nothrow) statement::Show(YYSession);
5076
lex->statement= select;
5078
if (lex->statement == NULL)
5082
if (prepare_new_schema_table(YYSession, lex, "SHOW_TEMPORARY_TABLES"))
5085
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5089
(session->lex->current_select->with_wild)++;
4373
5092
/* SHOW TABLE STATUS */
4374
5093
| TABLE_SYM STATUS_SYM opt_db show_wild
4376
if (not show::buildTableStatus(YYSession, $3))
5096
lex->sql_command= SQLCOM_SELECT;
5097
statement::Show *select=
5098
new(std::nothrow) statement::Show(YYSession);
5100
lex->statement= select;
5102
if (lex->statement == NULL)
5105
Session *session= YYSession;
5107
std::string column_name= "Tables_in_";
5109
util::string::const_shared_ptr schema(session->schema());
5112
lex->select_lex.db= $3;
5114
SchemaIdentifier identifier($3);
5115
if (not plugin::StorageEngine::doesSchemaExist(identifier))
5117
my_error(ER_BAD_DB_ERROR, MYF(0), $3);
5120
select->setShowPredicate($3, "");
5124
select->setShowPredicate(*schema, "");
5128
my_error(ER_NO_DB_ERROR, MYF(0));
5132
if (prepare_new_schema_table(session, lex, "SHOW_TABLE_STATUS"))
5135
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5139
(session->lex->current_select->with_wild)++;
4379
5141
/* SHOW COLUMNS FROM table_name */
4380
5142
| COLUMNS from_or_in table_ident opt_db show_wild
4382
if (not show::buildColumns(YYSession, $4, $3))
5145
Session *session= YYSession;
5146
statement::Show *select;
5148
lex->sql_command= SQLCOM_SELECT;
5150
select= new(std::nothrow) statement::Show(session);
5152
lex->statement= select;
5154
if (lex->statement == NULL)
5157
util::string::const_shared_ptr schema(session->schema());
5160
select->setShowPredicate($4, $3->table.str);
5162
else if ($3->db.str)
5164
select->setShowPredicate($3->db.str, $3->table.str);
5168
select->setShowPredicate(*schema, $3->table.str);
5172
my_error(ER_NO_DB_ERROR, MYF(0));
5177
drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
5178
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
5180
my_error(ER_NO_SUCH_TABLE, MYF(0),
5181
select->getShowSchema().c_str(),
5186
if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
5189
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5193
(session->lex->current_select->with_wild)++;
4385
5196
/* SHOW INDEXES from table */
4386
5197
| keys_or_index from_or_in table_ident opt_db where_clause
4388
if (not show::buildIndex(YYSession, $4, $3))
5200
Session *session= YYSession;
5201
statement::Show *select;
5203
lex->sql_command= SQLCOM_SELECT;
5205
select= new(std::nothrow) statement::Show(session);
5207
lex->statement= select;
5209
if (lex->statement == NULL)
5212
util::string::const_shared_ptr schema(session->schema());
5215
select->setShowPredicate($4, $3->table.str);
5217
else if ($3->db.str)
5219
select->setShowPredicate($3->db.str, $3->table.str);
5223
select->setShowPredicate(*schema, $3->table.str);
5227
my_error(ER_NO_DB_ERROR, MYF(0));
5232
drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
5233
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
5235
my_error(ER_NO_SUCH_TABLE, MYF(0),
5236
select->getShowSchema().c_str(),
5241
if (prepare_new_schema_table(session, lex, "SHOW_INDEXES"))
5244
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5248
(session->lex->current_select->with_wild)++;
4391
5250
| COUNT_SYM '(' '*' ')' WARNINGS
4393
show::buildSelectWarning(YYSession);
5252
(void) create_select_for_variable("warning_count");
5254
lex->statement= new(std::nothrow) statement::Show(YYSession);
5255
if (lex->statement == NULL)
4395
5258
| COUNT_SYM '(' '*' ')' ERRORS
4397
show::buildSelectError(YYSession);
5260
(void) create_select_for_variable("error_count");
5262
lex->statement= new(std::nothrow) statement::Show(YYSession);
5263
if (lex->statement == NULL)
4399
5266
| WARNINGS opt_limit_clause_init
4401
show::buildWarnings(YYSession);
5268
Lex->sql_command = SQLCOM_SHOW_WARNS;
5269
Lex->statement= new(std::nothrow) statement::ShowWarnings(YYSession);
5270
if (Lex->statement == NULL)
4403
5273
| ERRORS opt_limit_clause_init
4405
show::buildErrors(YYSession);
5275
Lex->sql_command = SQLCOM_SHOW_ERRORS;
5276
Lex->statement= new(std::nothrow) statement::ShowErrors(YYSession);
5277
if (Lex->statement == NULL)
4407
5280
| opt_var_type STATUS_SYM show_wild
4409
if (not show::buildStatus(YYSession, $1))
4412
| engine_option_value STATUS_SYM
4414
if (not show::buildEngineStatus(YYSession, $1))
5283
lex->sql_command= SQLCOM_SELECT;
5285
new(std::nothrow) statement::Show(YYSession);
5286
if (lex->statement == NULL)
5289
Session *session= YYSession;
5291
if ($1 == OPT_GLOBAL)
5293
if (prepare_new_schema_table(session, lex, "GLOBAL_STATUS"))
5298
if (prepare_new_schema_table(session, lex, "SESSION_STATUS"))
5302
std::string key("Variable_name");
5303
std::string value("Value");
5305
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5306
my_field->is_autogenerated_name= false;
5307
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5309
if (session->add_item_to_list(my_field))
5312
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5313
my_field->is_autogenerated_name= false;
5314
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5316
if (session->add_item_to_list(my_field))
4417
5319
| CREATE TABLE_SYM table_ident
4419
if (not show::buildCreateTable(YYSession, $3))
5322
lex->sql_command= SQLCOM_SELECT;
5323
statement::Show *select=
5324
new(std::nothrow) statement::Show(YYSession);
5326
lex->statement= select;
5328
if (lex->statement == NULL)
5331
Session *session= YYSession;
5333
if (prepare_new_schema_table(session, lex, "TABLE_SQL_DEFINITION"))
5336
util::string::const_shared_ptr schema(session->schema());
5339
select->setShowPredicate($3->db.str, $3->table.str);
5343
select->setShowPredicate(*schema, $3->table.str);
5347
my_error(ER_NO_DB_ERROR, MYF(0));
5351
std::string key("Table");
5352
std::string value("Create Table");
5354
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
5355
my_field->is_autogenerated_name= false;
5356
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5358
if (session->add_item_to_list(my_field))
5361
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
5362
my_field->is_autogenerated_name= false;
5363
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5365
if (session->add_item_to_list(my_field))
4422
5368
| PROCESSLIST_SYM
4424
if (not show::buildProcesslist(YYSession))
5372
lex->sql_command= SQLCOM_SELECT;
5374
new(std::nothrow) statement::Show(YYSession);
5375
if (lex->statement == NULL)
5378
Session *session= YYSession;
5380
if (prepare_new_schema_table(session, lex, "PROCESSLIST"))
5383
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5387
(session->lex->current_select->with_wild)++;
4427
5390
| opt_var_type VARIABLES show_wild
4429
if (not show::buildVariables(YYSession, $1))
5393
lex->sql_command= SQLCOM_SELECT;
5395
new(std::nothrow) statement::Show(YYSession);
5396
if (lex->statement == NULL)
5399
Session *session= YYSession;
5401
if ($1 == OPT_GLOBAL)
5403
if (prepare_new_schema_table(session, lex, "GLOBAL_VARIABLES"))
5408
if (prepare_new_schema_table(session, lex, "SESSION_VARIABLES"))
5412
std::string key("Variable_name");
5413
std::string value("Value");
5415
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5416
my_field->is_autogenerated_name= false;
5417
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5419
if (session->add_item_to_list(my_field))
5422
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5423
my_field->is_autogenerated_name= false;
5424
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5426
if (session->add_item_to_list(my_field))
4432
5429
| CREATE DATABASE opt_if_not_exists ident
4434
if (not show::buildCreateSchema(YYSession, $4))
5432
lex->sql_command= SQLCOM_SELECT;
5433
statement::Show *select=
5434
new(std::nothrow) statement::Show(YYSession);
5436
lex->statement= select;
5438
if (lex->statement == NULL)
5441
Session *session= YYSession;
5443
if (prepare_new_schema_table(session, lex, "SCHEMA_SQL_DEFINITION"))
5446
util::string::const_shared_ptr schema(session->schema());
5449
select->setShowPredicate($4.str);
5453
select->setShowPredicate(*schema);
5457
my_error(ER_NO_DB_ERROR, MYF(0));
5461
std::string key("Database");
5462
std::string value("Create Database");
5464
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
5465
my_field->is_autogenerated_name= false;
5466
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5468
if (session->add_item_to_list(my_field))
5471
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
5472
my_field->is_autogenerated_name= false;
5473
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5475
if (session->add_item_to_list(my_field))
4439
5480
/* empty */ { $$= 0; }
4872
6012
simple_ident_q:
4873
6013
ident '.' ident
4875
$$= parser::buildIdent(Lex, NULL_LEX_STRING, $1, $3);
6015
Session *session= YYSession;
6016
LEX *lex= session->lex;
6019
Select_Lex *sel= lex->current_select;
6020
if (sel->no_table_names_allowed)
6022
my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
6023
MYF(0), $1.str, session->where);
6025
$$= (sel->parsing_place != IN_HAVING ||
6026
sel->get_in_sum_expr() > 0) ?
6027
(Item*) new Item_field(Lex->current_context(),
6028
(const char *)NULL, $1.str, $3.str) :
6029
(Item*) new Item_ref(Lex->current_context(),
6030
(const char *)NULL, $1.str, $3.str);
4877
6033
| '.' ident '.' ident
4879
$$= parser::buildIdent(Lex, NULL_LEX_STRING, $2, $4);
6035
Session *session= YYSession;
6036
LEX *lex= session->lex;
6037
Select_Lex *sel= lex->current_select;
6038
if (sel->no_table_names_allowed)
6040
my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
6041
MYF(0), $2.str, session->where);
6043
$$= (sel->parsing_place != IN_HAVING ||
6044
sel->get_in_sum_expr() > 0) ?
6045
(Item*) new Item_field(Lex->current_context(), NULL, $2.str, $4.str) :
6046
(Item*) new Item_ref(Lex->current_context(),
6047
(const char *)NULL, $2.str, $4.str);
4881
6049
| ident '.' ident '.' ident
4883
$$= parser::buildIdent(Lex, $1, $3, $5);
6051
Session *session= YYSession;
6052
LEX *lex= session->lex;
6053
Select_Lex *sel= lex->current_select;
6054
if (sel->no_table_names_allowed)
6056
my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
6057
MYF(0), $3.str, session->where);
6059
$$= (sel->parsing_place != IN_HAVING ||
6060
sel->get_in_sum_expr() > 0) ?
6061
(Item*) new Item_field(Lex->current_context(), $1.str, $3.str,
6063
(Item*) new Item_ref(Lex->current_context(), $1.str, $3.str,
4892
6070
| ident '.' ident '.' ident
4894
if (not parser::checkFieldIdent(Lex, $1, $3))
6073
reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
6074
if (my_strcasecmp(table_alias_charset, $1.str, table->getSchemaName()))
6076
my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
6079
if (my_strcasecmp(table_alias_charset, $3.str,
6080
table->getTableName()))
6082
my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
4899
6087
| ident '.' ident
4901
if (not parser::checkFieldIdent(Lex, NULL_LEX_STRING, $1))
6090
reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
6091
if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
6093
my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
4902
6094
DRIZZLE_YYABORT;
6098
| '.' ident { $$=$2;} /* For Delphi */
4915
$$= new Table_ident($1);
4917
| schema_name '.' ident
4919
$$=new Table_ident($1,$3);
4923
$$= new Table_ident($2);
6102
ident { $$=new Table_ident($1); }
6103
| ident '.' ident { $$=new Table_ident($1,$3);}
6104
| '.' ident { $$=new Table_ident($2);} /* For Delphi */
4942
6111
const CHARSET_INFO * const cs= system_charset_info;