104
147
This function is not for use in semantic actions and is internal to
105
148
the parser, as it performs some pre-return cleanup.
106
In semantic actions, please use parser::my_parse_error or my_error to
149
In semantic actions, please use my_parse_error or my_error to
107
150
push an error into the error stack and DRIZZLE_YYABORT
108
151
to abort from the parser.
111
154
static void DRIZZLEerror(const char *s)
156
Session *session= current_session;
159
Restore the original LEX if it was replaced when parsing
160
a stored procedure. We must ensure that a parsing error
161
does not leave any side effects in the Session.
163
LEX::cleanup_lex_after_parse_error(session);
165
/* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
166
if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
167
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());
116
342
} /* namespace drizzled; */
828
1053
/* 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);
1056
CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
1058
Session *session= YYSession;
1059
LEX *lex= session->lex;
1060
lex->sql_command= SQLCOM_CREATE_TABLE;
1061
statement::CreateTable *statement= new(std::nothrow) statement::CreateTable(YYSession);
1062
lex->statement= statement;
1063
if (lex->statement == NULL)
1065
if (!lex->select_lex.add_table_to_list(session, $5, NULL,
1069
lex->col_list.empty();
1070
statement->change=NULL;
1071
statement->is_if_not_exists= $4;
1072
statement->create_info.db_type= NULL;
1073
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();
1076
message::Table &proto= statement->create_table_message;
1078
proto.set_name($5->table.str);
1080
proto.set_type(message::Table::TEMPORARY);
1082
proto.set_type(message::Table::STANDARD);
845
create_table_definition
847
Lex->current_select= &Lex->select_lex;
1086
LEX *lex= YYSession->lex;
1087
lex->current_select= &lex->select_lex;
849
1089
| CREATE build_method
851
Lex->statement= new statement::CreateIndex(YYSession, $2);
1092
lex->sql_command= SQLCOM_CREATE_INDEX;
1093
statement::CreateIndex *statement= new(std::nothrow) statement::CreateIndex(YYSession);
1094
lex->statement= statement;
1095
if (lex->statement == NULL)
1097
statement->alter_info.flags.set(ALTER_ADD_INDEX);
1098
statement->alter_info.build_method= $2;
1099
lex->col_list.empty();
1100
statement->change=NULL;
853
1102
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,
1105
statement::CreateIndex *statement= (statement::CreateIndex *)Lex->statement;
1107
if (!lex->current_select->add_table_to_list(lex->session, $9,
1109
TL_OPTION_UPDATING))
858
1110
DRIZZLE_YYABORT;
860
parser::buildKey(Lex, $4, $6);
1112
key= new Key($4, $6, &statement->key_create_info, 0, lex->col_list);
1113
statement->alter_info.key_list.push_back(key);
1114
lex->col_list.empty();
862
| CREATE DATABASE opt_if_not_exists schema_name
1116
| CREATE DATABASE opt_if_not_exists ident
864
Lex->statement= new statement::CreateSchema(YYSession);
1120
lex->sql_command=SQLCOM_CREATE_DB;
1121
statement::CreateSchema *statement= new(std::nothrow) statement::CreateSchema(YYSession);
1122
lex->statement= statement;
1123
if (lex->statement == NULL)
1125
statement->is_if_not_exists= $3;
866
1127
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);
1135
| opt_create_table_options
1137
| LIKE table_ident opt_create_table_options
1139
Session *session= YYSession;
1140
LEX *lex= session->lex;
1141
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1143
statement->is_create_table_like= true;
1144
if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
1147
| '(' LIKE table_ident ')'
1149
Session *session= YYSession;
1150
LEX *lex= session->lex;
1151
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1153
statement->is_create_table_like= true;
1154
if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
1160
field_list ')' opt_create_table_options
1163
{ 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);
1169
| opt_duplicate opt_as create_select
1170
{ Lex->current_select->set_braces(0);}
895
| opt_duplicate_as '(' create_select ')'
897
Lex->current_select->set_braces(1);
1172
| opt_duplicate opt_as '(' create_select ')'
1173
{ 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)
1181
lex->lock_option= TL_READ;
1182
if (lex->sql_command == SQLCOM_INSERT)
927
delete Lex->statement;
928
Lex->statement= new statement::InsertSelect(YYSession);
1184
lex->sql_command= SQLCOM_INSERT_SELECT;
1185
delete lex->statement;
1187
new(std::nothrow) statement::InsertSelect(YYSession);
1188
if (lex->statement == NULL)
930
else if (Lex->sql_command == SQLCOM_REPLACE)
1191
else if (lex->sql_command == SQLCOM_REPLACE)
932
delete Lex->statement;
933
Lex->statement= new statement::ReplaceSelect(YYSession);
1193
lex->sql_command= SQLCOM_REPLACE_SELECT;
1194
delete lex->statement;
1196
new(std::nothrow) statement::ReplaceSelect(YYSession);
1197
if (lex->statement == NULL)
936
1201
The following work only with the local list, the global list
937
1202
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;
1204
lex->current_select->table_list.save_and_clear(&lex->save_list);
1206
lex->current_select->parsing_place= SELECT_LIST;
943
1208
select_options select_item_list
1146
parser::buildCreateFieldIdent(Lex);
1472
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1473
lex->length=lex->dec=0;
1475
statement->default_value= statement->on_update_value= 0;
1476
statement->comment= null_lex_str;
1478
statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1480
message::AlterTable &alter_proto=
1481
((statement::CreateTable *)Lex->statement)->alter_info.alter_proto;
1482
statement->current_proto_field= alter_proto.add_added_field();
1150
1487
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1154
Lex->field()->set_name($1.str);
1489
if (statement->current_proto_field)
1490
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,
1492
if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
1493
lex->length,lex->dec,lex->type,
1159
1494
statement->column_format,
1160
1495
statement->default_value, statement->on_update_value,
1161
1496
&statement->comment,
1162
statement->change, &Lex->interval_list, Lex->charset))
1497
statement->change, &lex->interval_list, lex->charset))
1163
1498
DRIZZLE_YYABORT;
1165
Lex->setField(NULL);
1500
statement->current_proto_field= NULL;
1170
field_definition opt_attribute {}
1504
type opt_attribute {}
1174
1508
int_type ignored_field_number_length opt_field_number_signed opt_zerofill
1176
$$= parser::buildIntegerColumn(Lex, $1, ($3 or $4));
1511
Lex->length=(char*) 0; /* use default length */
1512
statement::CreateTable *statement=
1513
(statement::CreateTable *)Lex->statement;
1517
$1= DRIZZLE_TYPE_LONGLONG;
1520
if (statement->current_proto_field)
1522
assert ($1 == DRIZZLE_TYPE_LONG or $1 == DRIZZLE_TYPE_LONGLONG);
1523
// We update the type for unsigned types
1526
statement->current_proto_field->set_type(message::Table::Field::BIGINT);
1527
statement->current_proto_field->mutable_constraints()->set_is_unsigned(true);
1529
if ($1 == DRIZZLE_TYPE_LONG)
1531
statement->current_proto_field->set_type(message::Table::Field::INTEGER);
1533
else if ($1 == DRIZZLE_TYPE_LONGLONG)
1535
statement->current_proto_field->set_type(message::Table::Field::BIGINT);
1178
1539
| 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);
1543
statement::CreateTable *statement=
1544
(statement::CreateTable *)Lex->statement;
1546
if (statement->current_proto_field)
1548
assert ($1 == DRIZZLE_TYPE_DOUBLE);
1549
statement->current_proto_field->set_type(message::Table::Field::DOUBLE);
1555
$$=DRIZZLE_TYPE_VARCHAR;
1557
statement::CreateTable *statement=
1558
(statement::CreateTable *)Lex->statement;
1560
if (statement->current_proto_field)
1562
statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1563
message::Table::Field::StringFieldOptions *string_field_options;
1565
string_field_options= statement->current_proto_field->mutable_string_options();
1567
string_field_options->set_length(atoi($3.str));
1572
Lex->length=(char*) "1";
1573
$$=DRIZZLE_TYPE_VARCHAR;
1575
statement::CreateTable *statement=
1576
(statement::CreateTable *)Lex->statement;
1578
if (statement->current_proto_field)
1579
statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1581
| varchar '(' NUM ')'
1584
$$= DRIZZLE_TYPE_VARCHAR;
1586
statement::CreateTable *statement=
1587
(statement::CreateTable *)Lex->statement;
1589
if (statement->current_proto_field)
1591
statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1593
message::Table::Field::StringFieldOptions *string_field_options;
1595
string_field_options= statement->current_proto_field->mutable_string_options();
1597
string_field_options->set_length(atoi($3.str));
1600
| VARBINARY '(' NUM ')'
1603
Lex->charset=&my_charset_bin;
1604
$$= DRIZZLE_TYPE_VARCHAR;
1606
statement::CreateTable *statement=
1607
(statement::CreateTable *)Lex->statement;
1609
if (statement->current_proto_field)
1611
statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1612
message::Table::Field::StringFieldOptions *string_field_options;
1614
string_field_options= statement->current_proto_field->mutable_string_options();
1616
string_field_options->set_length(atoi($3.str));
1617
string_field_options->set_collation_id(my_charset_bin.number);
1618
string_field_options->set_collation(my_charset_bin.name);
1201
1623
$$=DRIZZLE_TYPE_DATE;
1204
Lex->field()->set_type(message::Table::Field::DATE);
1625
statement::CreateTable *statement=
1626
(statement::CreateTable *)Lex->statement;
1628
if (statement->current_proto_field)
1629
statement->current_proto_field->set_type(message::Table::Field::DATE);
1208
1633
$$=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);
1635
statement::CreateTable *statement=
1636
(statement::CreateTable *)Lex->statement;
1638
if (statement->current_proto_field)
1639
statement->current_proto_field->set_type(message::Table::Field::TIME);
1643
$$=DRIZZLE_TYPE_TIMESTAMP;
1645
statement::CreateTable *statement=
1646
(statement::CreateTable *)Lex->statement;
1648
if (statement->current_proto_field)
1649
statement->current_proto_field->set_type(message::Table::Field::EPOCH);
1223
1653
$$=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();
1655
statement::CreateTable *statement=
1656
(statement::CreateTable *)Lex->statement;
1658
if (statement->current_proto_field)
1659
statement->current_proto_field->set_type(message::Table::Field::DATETIME);
1663
Lex->charset=&my_charset_bin;
1664
$$=DRIZZLE_TYPE_BLOB;
1665
Lex->length=(char*) 0; /* use default length */
1667
statement::CreateTable *statement=
1668
(statement::CreateTable *)Lex->statement;
1670
if (statement->current_proto_field)
1672
statement->current_proto_field->set_type(message::Table::Field::BLOB);
1673
message::Table::Field::StringFieldOptions *string_field_options;
1675
string_field_options= statement->current_proto_field->mutable_string_options();
1676
string_field_options->set_collation_id(my_charset_bin.number);
1677
string_field_options->set_collation(my_charset_bin.name);
1682
$$=DRIZZLE_TYPE_BLOB;
1683
Lex->length=(char*) 0; /* use default length */
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::BLOB);
1691
| DECIMAL_SYM float_options
1693
$$=DRIZZLE_TYPE_DECIMAL;
1695
statement::CreateTable *statement=
1696
(statement::CreateTable *)Lex->statement;
1698
if (statement->current_proto_field)
1699
statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1701
| NUMERIC_SYM float_options
1703
$$=DRIZZLE_TYPE_DECIMAL;
1705
statement::CreateTable *statement=
1706
(statement::CreateTable *)Lex->statement;
1708
if (statement->current_proto_field)
1709
statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1711
| FIXED_SYM float_options
1713
$$=DRIZZLE_TYPE_DECIMAL;
1715
statement::CreateTable *statement=
1716
(statement::CreateTable *)Lex->statement;
1718
if (statement->current_proto_field)
1719
statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1722
{Lex->interval_list.empty();}
1258
1725
$$=DRIZZLE_TYPE_ENUM;
1261
Lex->field()->set_type(message::Table::Field::ENUM);
1727
statement::CreateTable *statement=
1728
(statement::CreateTable *)Lex->statement;
1730
if (statement->current_proto_field)
1731
statement->current_proto_field->set_type(message::Table::Field::ENUM);
1265
$$= parser::buildUuidColumn(Lex);
1735
$$=DRIZZLE_TYPE_UUID;
1737
statement::CreateTable *statement=
1738
(statement::CreateTable *)Lex->statement;
1740
if (statement->current_proto_field)
1741
statement->current_proto_field->set_type(message::Table::Field::UUID);
1745
$$=DRIZZLE_TYPE_BOOLEAN;
1747
statement::CreateTable *statement=
1748
(statement::CreateTable *)Lex->statement;
1750
if (statement->current_proto_field)
1751
statement->current_proto_field->set_type(message::Table::Field::BOOLEAN);
1269
$$= parser::buildBooleanColumn(Lex);
1755
$$=DRIZZLE_TYPE_BOOLEAN;
1757
statement::CreateTable *statement=
1758
(statement::CreateTable *)Lex->statement;
1760
if (statement->current_proto_field)
1761
statement->current_proto_field->set_type(message::Table::Field::BOOLEAN);
1273
$$= parser::buildSerialColumn(Lex);
1765
$$=DRIZZLE_TYPE_LONGLONG;
1766
Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
1768
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1769
if (statement->current_proto_field)
1771
message::Table::Field::FieldConstraints *constraints;
1772
constraints= statement->current_proto_field->mutable_constraints();
1773
constraints->set_is_nullable(false);
1775
statement->current_proto_field->set_type(message::Table::Field::BIGINT);
4356
4999
DATABASES show_wild
4358
if (not show::buildScemas(YYSession))
5002
Session *session= YYSession;
5004
lex->sql_command= SQLCOM_SELECT;
5006
new(std::nothrow) statement::Show(session);
5007
if (lex->statement == NULL)
5010
std::string column_name= "Database";
5013
column_name.append(" (");
5014
column_name.append(Lex->wild->ptr());
5015
column_name.append(")");
5018
if (Lex->current_select->where)
5020
if (prepare_new_schema_table(session, lex, "SCHEMAS"))
5025
if (prepare_new_schema_table(session, lex, "SHOW_SCHEMAS"))
5029
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
5030
my_field->is_autogenerated_name= false;
5031
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
5033
if (session->add_item_to_list(my_field))
5036
if (session->add_order_to_list(my_field, true))
4361
5039
/* SHOW TABLES */
4362
5040
| TABLES opt_db show_wild
4364
if (not show::buildTables(YYSession, $2))
5043
Session *session= YYSession;
5045
lex->sql_command= SQLCOM_SELECT;
5047
statement::Show *select=
5048
new(std::nothrow) statement::Show(YYSession);
5050
lex->statement= select;
5052
if (lex->statement == NULL)
5056
std::string column_name= "Tables_in_";
5058
util::string::const_shared_ptr schema(session->schema());
5061
SchemaIdentifier identifier($2);
5062
column_name.append($2);
5063
lex->select_lex.db= $2;
5064
if (not plugin::StorageEngine::doesSchemaExist(identifier))
5066
my_error(ER_BAD_DB_ERROR, MYF(0), $2);
5068
select->setShowPredicate($2, "");
5070
else if (schema and not schema->empty())
5072
column_name.append(*schema);
5073
select->setShowPredicate(*schema, "");
5077
my_error(ER_NO_DB_ERROR, MYF(0));
5084
column_name.append(" (");
5085
column_name.append(Lex->wild->ptr());
5086
column_name.append(")");
5089
if (prepare_new_schema_table(YYSession, lex, "SHOW_TABLES"))
5092
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
5093
my_field->is_autogenerated_name= false;
5094
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
5096
if (session->add_item_to_list(my_field))
5099
if (session->add_order_to_list(my_field, true))
4367
5102
/* SHOW TEMPORARY TABLES */
4368
5103
| TEMPORARY_SYM TABLES show_wild
4370
if (not show::buildTemporaryTables(YYSession))
5106
Session *session= YYSession;
5108
lex->sql_command= SQLCOM_SELECT;
5110
statement::Show *select=
5111
new(std::nothrow) statement::Show(YYSession);
5113
lex->statement= select;
5115
if (lex->statement == NULL)
5119
if (prepare_new_schema_table(YYSession, lex, "SHOW_TEMPORARY_TABLES"))
5122
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5126
(session->lex->current_select->with_wild)++;
4373
5129
/* SHOW TABLE STATUS */
4374
5130
| TABLE_SYM STATUS_SYM opt_db show_wild
4376
if (not show::buildTableStatus(YYSession, $3))
5133
lex->sql_command= SQLCOM_SELECT;
5134
statement::Show *select=
5135
new(std::nothrow) statement::Show(YYSession);
5137
lex->statement= select;
5139
if (lex->statement == NULL)
5142
Session *session= YYSession;
5144
std::string column_name= "Tables_in_";
5146
util::string::const_shared_ptr schema(session->schema());
5149
lex->select_lex.db= $3;
5151
SchemaIdentifier identifier($3);
5152
if (not plugin::StorageEngine::doesSchemaExist(identifier))
5154
my_error(ER_BAD_DB_ERROR, MYF(0), $3);
5157
select->setShowPredicate($3, "");
5161
select->setShowPredicate(*schema, "");
5165
my_error(ER_NO_DB_ERROR, MYF(0));
5169
if (prepare_new_schema_table(session, lex, "SHOW_TABLE_STATUS"))
5172
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5176
(session->lex->current_select->with_wild)++;
4379
5178
/* SHOW COLUMNS FROM table_name */
4380
5179
| COLUMNS from_or_in table_ident opt_db show_wild
4382
if (not show::buildColumns(YYSession, $4, $3))
5182
Session *session= YYSession;
5183
statement::Show *select;
5185
lex->sql_command= SQLCOM_SELECT;
5187
select= new(std::nothrow) statement::Show(session);
5189
lex->statement= select;
5191
if (lex->statement == NULL)
5194
util::string::const_shared_ptr schema(session->schema());
5197
select->setShowPredicate($4, $3->table.str);
5199
else if ($3->db.str)
5201
select->setShowPredicate($3->db.str, $3->table.str);
5205
select->setShowPredicate(*schema, $3->table.str);
5209
my_error(ER_NO_DB_ERROR, MYF(0));
5214
drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
5215
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
5217
my_error(ER_NO_SUCH_TABLE, MYF(0),
5218
select->getShowSchema().c_str(),
5223
if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
5226
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5230
(session->lex->current_select->with_wild)++;
4385
5233
/* SHOW INDEXES from table */
4386
5234
| keys_or_index from_or_in table_ident opt_db where_clause
4388
if (not show::buildIndex(YYSession, $4, $3))
5237
Session *session= YYSession;
5238
statement::Show *select;
5240
lex->sql_command= SQLCOM_SELECT;
5242
select= new(std::nothrow) statement::Show(session);
5244
lex->statement= select;
5246
if (lex->statement == NULL)
5249
util::string::const_shared_ptr schema(session->schema());
5252
select->setShowPredicate($4, $3->table.str);
5254
else if ($3->db.str)
5256
select->setShowPredicate($3->db.str, $3->table.str);
5260
select->setShowPredicate(*schema, $3->table.str);
5264
my_error(ER_NO_DB_ERROR, MYF(0));
5269
drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
5270
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
5272
my_error(ER_NO_SUCH_TABLE, MYF(0),
5273
select->getShowSchema().c_str(),
5278
if (prepare_new_schema_table(session, lex, "SHOW_INDEXES"))
5281
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5285
(session->lex->current_select->with_wild)++;
4391
5287
| COUNT_SYM '(' '*' ')' WARNINGS
4393
show::buildSelectWarning(YYSession);
5289
(void) create_select_for_variable("warning_count");
5291
lex->statement= new(std::nothrow) statement::Show(YYSession);
5292
if (lex->statement == NULL)
4395
5295
| COUNT_SYM '(' '*' ')' ERRORS
4397
show::buildSelectError(YYSession);
5297
(void) create_select_for_variable("error_count");
5299
lex->statement= new(std::nothrow) statement::Show(YYSession);
5300
if (lex->statement == NULL)
4399
5303
| WARNINGS opt_limit_clause_init
4401
show::buildWarnings(YYSession);
5305
Lex->sql_command = SQLCOM_SHOW_WARNS;
5306
Lex->statement= new(std::nothrow) statement::ShowWarnings(YYSession);
5307
if (Lex->statement == NULL)
4403
5310
| ERRORS opt_limit_clause_init
4405
show::buildErrors(YYSession);
5312
Lex->sql_command = SQLCOM_SHOW_ERRORS;
5313
Lex->statement= new(std::nothrow) statement::ShowErrors(YYSession);
5314
if (Lex->statement == NULL)
4407
5317
| 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))
5320
lex->sql_command= SQLCOM_SELECT;
5322
new(std::nothrow) statement::Show(YYSession);
5323
if (lex->statement == NULL)
5326
Session *session= YYSession;
5328
if ($1 == OPT_GLOBAL)
5330
if (prepare_new_schema_table(session, lex, "GLOBAL_STATUS"))
5335
if (prepare_new_schema_table(session, lex, "SESSION_STATUS"))
5339
std::string key("Variable_name");
5340
std::string value("Value");
5342
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5343
my_field->is_autogenerated_name= false;
5344
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5346
if (session->add_item_to_list(my_field))
5349
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5350
my_field->is_autogenerated_name= false;
5351
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5353
if (session->add_item_to_list(my_field))
4417
5356
| CREATE TABLE_SYM table_ident
4419
if (not show::buildCreateTable(YYSession, $3))
5359
lex->sql_command= SQLCOM_SELECT;
5360
statement::Show *select=
5361
new(std::nothrow) statement::Show(YYSession);
5363
lex->statement= select;
5365
if (lex->statement == NULL)
5368
Session *session= YYSession;
5370
if (prepare_new_schema_table(session, lex, "TABLE_SQL_DEFINITION"))
5373
util::string::const_shared_ptr schema(session->schema());
5376
select->setShowPredicate($3->db.str, $3->table.str);
5380
select->setShowPredicate(*schema, $3->table.str);
5384
my_error(ER_NO_DB_ERROR, MYF(0));
5388
std::string key("Table");
5389
std::string value("Create Table");
5391
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
5392
my_field->is_autogenerated_name= false;
5393
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5395
if (session->add_item_to_list(my_field))
5398
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
5399
my_field->is_autogenerated_name= false;
5400
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5402
if (session->add_item_to_list(my_field))
4422
5405
| PROCESSLIST_SYM
4424
if (not show::buildProcesslist(YYSession))
5409
lex->sql_command= SQLCOM_SELECT;
5411
new(std::nothrow) statement::Show(YYSession);
5412
if (lex->statement == NULL)
5415
Session *session= YYSession;
5417
if (prepare_new_schema_table(session, lex, "PROCESSLIST"))
5420
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5424
(session->lex->current_select->with_wild)++;
4427
5427
| opt_var_type VARIABLES show_wild
4429
if (not show::buildVariables(YYSession, $1))
5430
lex->sql_command= SQLCOM_SELECT;
5432
new(std::nothrow) statement::Show(YYSession);
5433
if (lex->statement == NULL)
5436
Session *session= YYSession;
5438
if ($1 == OPT_GLOBAL)
5440
if (prepare_new_schema_table(session, lex, "GLOBAL_VARIABLES"))
5445
if (prepare_new_schema_table(session, lex, "SESSION_VARIABLES"))
5449
std::string key("Variable_name");
5450
std::string value("Value");
5452
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5453
my_field->is_autogenerated_name= false;
5454
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5456
if (session->add_item_to_list(my_field))
5459
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5460
my_field->is_autogenerated_name= false;
5461
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5463
if (session->add_item_to_list(my_field))
4432
5466
| CREATE DATABASE opt_if_not_exists ident
4434
if (not show::buildCreateSchema(YYSession, $4))
5469
lex->sql_command= SQLCOM_SELECT;
5470
statement::Show *select=
5471
new(std::nothrow) statement::Show(YYSession);
5473
lex->statement= select;
5475
if (lex->statement == NULL)
5478
Session *session= YYSession;
5480
if (prepare_new_schema_table(session, lex, "SCHEMA_SQL_DEFINITION"))
5483
util::string::const_shared_ptr schema(session->schema());
5486
select->setShowPredicate($4.str);
5490
select->setShowPredicate(*schema);
5494
my_error(ER_NO_DB_ERROR, MYF(0));
5498
std::string key("Database");
5499
std::string value("Create Database");
5501
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
5502
my_field->is_autogenerated_name= false;
5503
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5505
if (session->add_item_to_list(my_field))
5508
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
5509
my_field->is_autogenerated_name= false;
5510
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5512
if (session->add_item_to_list(my_field))
4439
5517
/* empty */ { $$= 0; }
4872
6049
simple_ident_q:
4873
6050
ident '.' ident
4875
$$= parser::buildIdent(Lex, NULL_LEX_STRING, $1, $3);
6052
Session *session= YYSession;
6053
LEX *lex= session->lex;
6056
Select_Lex *sel= lex->current_select;
6057
if (sel->no_table_names_allowed)
6059
my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
6060
MYF(0), $1.str, session->where);
6062
$$= (sel->parsing_place != IN_HAVING ||
6063
sel->get_in_sum_expr() > 0) ?
6064
(Item*) new Item_field(Lex->current_context(),
6065
(const char *)NULL, $1.str, $3.str) :
6066
(Item*) new Item_ref(Lex->current_context(),
6067
(const char *)NULL, $1.str, $3.str);
4877
6070
| '.' ident '.' ident
4879
$$= parser::buildIdent(Lex, NULL_LEX_STRING, $2, $4);
6072
Session *session= YYSession;
6073
LEX *lex= session->lex;
6074
Select_Lex *sel= lex->current_select;
6075
if (sel->no_table_names_allowed)
6077
my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
6078
MYF(0), $2.str, session->where);
6080
$$= (sel->parsing_place != IN_HAVING ||
6081
sel->get_in_sum_expr() > 0) ?
6082
(Item*) new Item_field(Lex->current_context(), NULL, $2.str, $4.str) :
6083
(Item*) new Item_ref(Lex->current_context(),
6084
(const char *)NULL, $2.str, $4.str);
4881
6086
| ident '.' ident '.' ident
4883
$$= parser::buildIdent(Lex, $1, $3, $5);
6088
Session *session= YYSession;
6089
LEX *lex= session->lex;
6090
Select_Lex *sel= lex->current_select;
6091
if (sel->no_table_names_allowed)
6093
my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
6094
MYF(0), $3.str, session->where);
6096
$$= (sel->parsing_place != IN_HAVING ||
6097
sel->get_in_sum_expr() > 0) ?
6098
(Item*) new Item_field(Lex->current_context(), $1.str, $3.str,
6100
(Item*) new Item_ref(Lex->current_context(), $1.str, $3.str,
4892
6107
| ident '.' ident '.' ident
4894
if (not parser::checkFieldIdent(Lex, $1, $3))
6110
reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
6111
if (my_strcasecmp(table_alias_charset, $1.str, table->getSchemaName()))
6113
my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
6116
if (my_strcasecmp(table_alias_charset, $3.str,
6117
table->getTableName()))
6119
my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
4899
6124
| ident '.' ident
4901
if (not parser::checkFieldIdent(Lex, NULL_LEX_STRING, $1))
6127
reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
6128
if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
6130
my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
4902
6131
DRIZZLE_YYABORT;
6135
| '.' ident { $$=$2;} /* For Delphi */
4915
$$= new Table_ident($1);
4917
| schema_name '.' ident
4919
$$=new Table_ident($1,$3);
4923
$$= new Table_ident($2);
6139
ident { $$=new Table_ident($1); }
6140
| ident '.' ident { $$=new Table_ident($1,$3);}
6141
| '.' ident { $$=new Table_ident($2);} /* For Delphi */
4942
6148
const CHARSET_INFO * const cs= system_charset_info;