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 (new_select(lex, 0))
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);
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);
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);
1265
$$= parser::buildUuidColumn(Lex);
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);
1738
$$=DRIZZLE_TYPE_BOOLEAN;
1740
statement::CreateTable *statement=
1741
(statement::CreateTable *)Lex->statement;
1743
if (statement->current_proto_field)
1744
statement->current_proto_field->set_type(message::Table::Field::BOOLEAN);
1269
$$= parser::buildBooleanColumn(Lex);
1748
$$=DRIZZLE_TYPE_BOOLEAN;
1750
statement::CreateTable *statement=
1751
(statement::CreateTable *)Lex->statement;
1753
if (statement->current_proto_field)
1754
statement->current_proto_field->set_type(message::Table::Field::BOOLEAN);
1273
$$= parser::buildSerialColumn(Lex);
1758
$$=DRIZZLE_TYPE_LONGLONG;
1759
Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
1761
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1762
if (statement->current_proto_field)
1764
message::Table::Field::FieldConstraints *constraints;
1765
constraints= statement->current_proto_field->mutable_constraints();
1766
constraints->set_is_nullable(false);
1768
statement->current_proto_field->set_type(message::Table::Field::BIGINT);
4356
4990
DATABASES show_wild
4358
if (not show::buildScemas(YYSession))
4993
Session *session= YYSession;
4995
lex->sql_command= SQLCOM_SELECT;
4997
new(std::nothrow) statement::Show(session);
4998
if (lex->statement == NULL)
5001
std::string column_name= "Database";
5004
column_name.append(" (");
5005
column_name.append(Lex->wild->ptr());
5006
column_name.append(")");
5009
if (Lex->current_select->where)
5011
if (prepare_new_schema_table(session, lex, "SCHEMAS"))
5016
if (prepare_new_schema_table(session, lex, "SHOW_SCHEMAS"))
5020
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
5021
my_field->is_autogenerated_name= false;
5022
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
5024
if (session->add_item_to_list(my_field))
5027
if (session->add_order_to_list(my_field, true))
4361
5030
/* SHOW TABLES */
4362
5031
| TABLES opt_db show_wild
4364
if (not show::buildTables(YYSession, $2))
5034
Session *session= YYSession;
5036
lex->sql_command= SQLCOM_SELECT;
5038
statement::Show *select=
5039
new(std::nothrow) statement::Show(YYSession);
5041
lex->statement= select;
5043
if (lex->statement == NULL)
5047
std::string column_name= "Tables_in_";
5049
util::string::const_shared_ptr schema(session->schema());
5052
SchemaIdentifier identifier($2);
5053
column_name.append($2);
5054
lex->select_lex.db= $2;
5055
if (not plugin::StorageEngine::doesSchemaExist(identifier))
5057
my_error(ER_BAD_DB_ERROR, MYF(0), $2);
5059
select->setShowPredicate($2, "");
5061
else if (schema and not schema->empty())
5063
column_name.append(*schema);
5064
select->setShowPredicate(*schema, "");
5068
my_error(ER_NO_DB_ERROR, MYF(0));
5075
column_name.append(" (");
5076
column_name.append(Lex->wild->ptr());
5077
column_name.append(")");
5080
if (prepare_new_schema_table(YYSession, lex, "SHOW_TABLES"))
5083
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
5084
my_field->is_autogenerated_name= false;
5085
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
5087
if (session->add_item_to_list(my_field))
5090
if (session->add_order_to_list(my_field, true))
4367
5093
/* SHOW TEMPORARY TABLES */
4368
5094
| TEMPORARY_SYM TABLES show_wild
4370
if (not show::buildTemporaryTables(YYSession))
5097
Session *session= YYSession;
5099
lex->sql_command= SQLCOM_SELECT;
5101
statement::Show *select=
5102
new(std::nothrow) statement::Show(YYSession);
5104
lex->statement= select;
5106
if (lex->statement == NULL)
5110
if (prepare_new_schema_table(YYSession, lex, "SHOW_TEMPORARY_TABLES"))
5113
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5117
(session->lex->current_select->with_wild)++;
4373
5120
/* SHOW TABLE STATUS */
4374
5121
| TABLE_SYM STATUS_SYM opt_db show_wild
4376
if (not show::buildTableStatus(YYSession, $3))
5124
lex->sql_command= SQLCOM_SELECT;
5125
statement::Show *select=
5126
new(std::nothrow) statement::Show(YYSession);
5128
lex->statement= select;
5130
if (lex->statement == NULL)
5133
Session *session= YYSession;
5135
std::string column_name= "Tables_in_";
5137
util::string::const_shared_ptr schema(session->schema());
5140
lex->select_lex.db= $3;
5142
SchemaIdentifier identifier($3);
5143
if (not plugin::StorageEngine::doesSchemaExist(identifier))
5145
my_error(ER_BAD_DB_ERROR, MYF(0), $3);
5148
select->setShowPredicate($3, "");
5152
select->setShowPredicate(*schema, "");
5156
my_error(ER_NO_DB_ERROR, MYF(0));
5160
if (prepare_new_schema_table(session, lex, "SHOW_TABLE_STATUS"))
5163
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5167
(session->lex->current_select->with_wild)++;
4379
5169
/* SHOW COLUMNS FROM table_name */
4380
5170
| COLUMNS from_or_in table_ident opt_db show_wild
4382
if (not show::buildColumns(YYSession, $4, $3))
5173
Session *session= YYSession;
5174
statement::Show *select;
5176
lex->sql_command= SQLCOM_SELECT;
5178
select= new(std::nothrow) statement::Show(session);
5180
lex->statement= select;
5182
if (lex->statement == NULL)
5185
util::string::const_shared_ptr schema(session->schema());
5188
select->setShowPredicate($4, $3->table.str);
5190
else if ($3->db.str)
5192
select->setShowPredicate($3->db.str, $3->table.str);
5196
select->setShowPredicate(*schema, $3->table.str);
5200
my_error(ER_NO_DB_ERROR, MYF(0));
5205
drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
5206
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
5208
my_error(ER_NO_SUCH_TABLE, MYF(0),
5209
select->getShowSchema().c_str(),
5214
if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
5217
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5221
(session->lex->current_select->with_wild)++;
4385
5224
/* SHOW INDEXES from table */
4386
5225
| keys_or_index from_or_in table_ident opt_db where_clause
4388
if (not show::buildIndex(YYSession, $4, $3))
5228
Session *session= YYSession;
5229
statement::Show *select;
5231
lex->sql_command= SQLCOM_SELECT;
5233
select= new(std::nothrow) statement::Show(session);
5235
lex->statement= select;
5237
if (lex->statement == NULL)
5240
util::string::const_shared_ptr schema(session->schema());
5243
select->setShowPredicate($4, $3->table.str);
5245
else if ($3->db.str)
5247
select->setShowPredicate($3->db.str, $3->table.str);
5251
select->setShowPredicate(*schema, $3->table.str);
5255
my_error(ER_NO_DB_ERROR, MYF(0));
5260
drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
5261
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
5263
my_error(ER_NO_SUCH_TABLE, MYF(0),
5264
select->getShowSchema().c_str(),
5269
if (prepare_new_schema_table(session, lex, "SHOW_INDEXES"))
5272
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5276
(session->lex->current_select->with_wild)++;
4391
5278
| COUNT_SYM '(' '*' ')' WARNINGS
4393
show::buildSelectWarning(YYSession);
5280
(void) create_select_for_variable("warning_count");
5282
lex->statement= new(std::nothrow) statement::Show(YYSession);
5283
if (lex->statement == NULL)
4395
5286
| COUNT_SYM '(' '*' ')' ERRORS
4397
show::buildSelectError(YYSession);
5288
(void) create_select_for_variable("error_count");
5290
lex->statement= new(std::nothrow) statement::Show(YYSession);
5291
if (lex->statement == NULL)
4399
5294
| WARNINGS opt_limit_clause_init
4401
show::buildWarnings(YYSession);
5296
Lex->sql_command = SQLCOM_SHOW_WARNS;
5297
Lex->statement= new(std::nothrow) statement::ShowWarnings(YYSession);
5298
if (Lex->statement == NULL)
4403
5301
| ERRORS opt_limit_clause_init
4405
show::buildErrors(YYSession);
5303
Lex->sql_command = SQLCOM_SHOW_ERRORS;
5304
Lex->statement= new(std::nothrow) statement::ShowErrors(YYSession);
5305
if (Lex->statement == NULL)
4407
5308
| 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))
5311
lex->sql_command= SQLCOM_SELECT;
5313
new(std::nothrow) statement::Show(YYSession);
5314
if (lex->statement == NULL)
5317
Session *session= YYSession;
5319
if ($1 == OPT_GLOBAL)
5321
if (prepare_new_schema_table(session, lex, "GLOBAL_STATUS"))
5326
if (prepare_new_schema_table(session, lex, "SESSION_STATUS"))
5330
std::string key("Variable_name");
5331
std::string value("Value");
5333
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5334
my_field->is_autogenerated_name= false;
5335
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5337
if (session->add_item_to_list(my_field))
5340
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5341
my_field->is_autogenerated_name= false;
5342
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5344
if (session->add_item_to_list(my_field))
4417
5347
| CREATE TABLE_SYM table_ident
4419
if (not show::buildCreateTable(YYSession, $3))
5350
lex->sql_command= SQLCOM_SELECT;
5351
statement::Show *select=
5352
new(std::nothrow) statement::Show(YYSession);
5354
lex->statement= select;
5356
if (lex->statement == NULL)
5359
Session *session= YYSession;
5361
if (prepare_new_schema_table(session, lex, "TABLE_SQL_DEFINITION"))
5364
util::string::const_shared_ptr schema(session->schema());
5367
select->setShowPredicate($3->db.str, $3->table.str);
5371
select->setShowPredicate(*schema, $3->table.str);
5375
my_error(ER_NO_DB_ERROR, MYF(0));
5379
std::string key("Table");
5380
std::string value("Create Table");
5382
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
5383
my_field->is_autogenerated_name= false;
5384
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5386
if (session->add_item_to_list(my_field))
5389
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
5390
my_field->is_autogenerated_name= false;
5391
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5393
if (session->add_item_to_list(my_field))
4422
5396
| PROCESSLIST_SYM
4424
if (not show::buildProcesslist(YYSession))
5400
lex->sql_command= SQLCOM_SELECT;
5402
new(std::nothrow) statement::Show(YYSession);
5403
if (lex->statement == NULL)
5406
Session *session= YYSession;
5408
if (prepare_new_schema_table(session, lex, "PROCESSLIST"))
5411
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5415
(session->lex->current_select->with_wild)++;
4427
5418
| opt_var_type VARIABLES show_wild
4429
if (not show::buildVariables(YYSession, $1))
5421
lex->sql_command= SQLCOM_SELECT;
5423
new(std::nothrow) statement::Show(YYSession);
5424
if (lex->statement == NULL)
5427
Session *session= YYSession;
5429
if ($1 == OPT_GLOBAL)
5431
if (prepare_new_schema_table(session, lex, "GLOBAL_VARIABLES"))
5436
if (prepare_new_schema_table(session, lex, "SESSION_VARIABLES"))
5440
std::string key("Variable_name");
5441
std::string value("Value");
5443
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5444
my_field->is_autogenerated_name= false;
5445
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5447
if (session->add_item_to_list(my_field))
5450
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5451
my_field->is_autogenerated_name= false;
5452
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5454
if (session->add_item_to_list(my_field))
4432
5457
| CREATE DATABASE opt_if_not_exists ident
4434
if (not show::buildCreateSchema(YYSession, $4))
5460
lex->sql_command= SQLCOM_SELECT;
5461
statement::Show *select=
5462
new(std::nothrow) statement::Show(YYSession);
5464
lex->statement= select;
5466
if (lex->statement == NULL)
5469
Session *session= YYSession;
5471
if (prepare_new_schema_table(session, lex, "SCHEMA_SQL_DEFINITION"))
5474
util::string::const_shared_ptr schema(session->schema());
5477
select->setShowPredicate($4.str);
5481
select->setShowPredicate(*schema);
5485
my_error(ER_NO_DB_ERROR, MYF(0));
5489
std::string key("Database");
5490
std::string value("Create Database");
5492
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
5493
my_field->is_autogenerated_name= false;
5494
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5496
if (session->add_item_to_list(my_field))
5499
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
5500
my_field->is_autogenerated_name= false;
5501
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5503
if (session->add_item_to_list(my_field))
4439
5508
/* empty */ { $$= 0; }
4872
6040
simple_ident_q:
4873
6041
ident '.' ident
4875
$$= parser::buildIdent(Lex, NULL_LEX_STRING, $1, $3);
6043
Session *session= YYSession;
6044
LEX *lex= session->lex;
6047
Select_Lex *sel= lex->current_select;
6048
if (sel->no_table_names_allowed)
6050
my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
6051
MYF(0), $1.str, session->where);
6053
$$= (sel->parsing_place != IN_HAVING ||
6054
sel->get_in_sum_expr() > 0) ?
6055
(Item*) new Item_field(Lex->current_context(),
6056
(const char *)NULL, $1.str, $3.str) :
6057
(Item*) new Item_ref(Lex->current_context(),
6058
(const char *)NULL, $1.str, $3.str);
4877
6061
| '.' ident '.' ident
4879
$$= parser::buildIdent(Lex, NULL_LEX_STRING, $2, $4);
6063
Session *session= YYSession;
6064
LEX *lex= session->lex;
6065
Select_Lex *sel= lex->current_select;
6066
if (sel->no_table_names_allowed)
6068
my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
6069
MYF(0), $2.str, session->where);
6071
$$= (sel->parsing_place != IN_HAVING ||
6072
sel->get_in_sum_expr() > 0) ?
6073
(Item*) new Item_field(Lex->current_context(), NULL, $2.str, $4.str) :
6074
(Item*) new Item_ref(Lex->current_context(),
6075
(const char *)NULL, $2.str, $4.str);
4881
6077
| ident '.' ident '.' ident
4883
$$= parser::buildIdent(Lex, $1, $3, $5);
6079
Session *session= YYSession;
6080
LEX *lex= session->lex;
6081
Select_Lex *sel= lex->current_select;
6082
if (sel->no_table_names_allowed)
6084
my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
6085
MYF(0), $3.str, session->where);
6087
$$= (sel->parsing_place != IN_HAVING ||
6088
sel->get_in_sum_expr() > 0) ?
6089
(Item*) new Item_field(Lex->current_context(), $1.str, $3.str,
6091
(Item*) new Item_ref(Lex->current_context(), $1.str, $3.str,
4892
6098
| ident '.' ident '.' ident
4894
if (not parser::checkFieldIdent(Lex, $1, $3))
6101
reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
6102
if (my_strcasecmp(table_alias_charset, $1.str, table->getSchemaName()))
6104
my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
6107
if (my_strcasecmp(table_alias_charset, $3.str,
6108
table->getTableName()))
6110
my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
4899
6115
| ident '.' ident
4901
if (not parser::checkFieldIdent(Lex, NULL_LEX_STRING, $1))
6118
reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
6119
if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
6121
my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
4902
6122
DRIZZLE_YYABORT;
6126
| '.' ident { $$=$2;} /* For Delphi */
4915
$$= new Table_ident($1);
4917
| schema_name '.' ident
4919
$$=new Table_ident($1,$3);
4923
$$= new Table_ident($2);
6130
ident { $$=new Table_ident($1); }
6131
| ident '.' ident { $$=new Table_ident($1,$3);}
6132
| '.' ident { $$=new Table_ident($2);} /* For Delphi */
4942
6139
const CHARSET_INFO * const cs= system_charset_info;