99
140
This function is not for use in semantic actions and is internal to
100
141
the parser, as it performs some pre-return cleanup.
101
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
102
143
push an error into the error stack and DRIZZLE_YYABORT
103
144
to abort from the parser.
106
static void base_sql_error(drizzled::Session *session, const char *s)
108
parser::errorOn(session, s);
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());
111
335
} /* namespace drizzled; */
113
337
using namespace drizzled;
118
unsigned long ulong_num;
119
342
uint64_t ulonglong_number;
120
343
int64_t longlong_number;
121
344
drizzled::LEX_STRING lex_str;
827
1030
/* create a table */
830
CREATE CATALOG_SYM catalog_name
832
Lex->statement= new statement::catalog::Create(YYSession, $3);
834
| CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
836
Lex->statement= new statement::CreateTable(YYSession, $5, $2);
1033
CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
1035
Session *session= YYSession;
1036
LEX *lex= session->lex;
1037
lex->sql_command= SQLCOM_CREATE_TABLE;
1038
statement::CreateTable *statement= new(std::nothrow) statement::CreateTable(YYSession);
1039
lex->statement= statement;
1040
if (lex->statement == NULL)
1042
if (!lex->select_lex.add_table_to_list(session, $5, NULL,
1046
lex->col_list.empty();
1047
statement->change=NULL;
1048
statement->is_if_not_exists= $4;
1049
statement->create_info.db_type= NULL;
1050
statement->create_info.default_table_charset= NULL;
838
if (not Lex->select_lex.add_table_to_list(YYSession, $5, NULL,
842
Lex->col_list.clear();
1053
message::Table &proto= statement->create_table_message;
1055
proto.set_name($5->table.str);
1057
proto.set_type(message::Table::TEMPORARY);
1059
proto.set_type(message::Table::STANDARD);
844
create_table_definition
846
Lex->current_select= &Lex->select_lex;
1063
LEX *lex= YYSession->lex;
1064
lex->current_select= &lex->select_lex;
848
1066
| CREATE build_method
850
Lex->statement= new statement::CreateIndex(YYSession, $2);
1069
lex->sql_command= SQLCOM_CREATE_INDEX;
1070
statement::CreateIndex *statement= new(std::nothrow) statement::CreateIndex(YYSession);
1071
lex->statement= statement;
1072
if (lex->statement == NULL)
1074
statement->alter_info.flags.set(ALTER_ADD_INDEX);
1075
statement->alter_info.build_method= $2;
1076
lex->col_list.empty();
1077
statement->change=NULL;
852
1079
opt_unique INDEX_SYM ident key_alg ON table_ident '(' key_list ')' key_options
854
if (not Lex->current_select->add_table_to_list(Lex->session, $9,
1082
statement::CreateIndex *statement= (statement::CreateIndex *)Lex->statement;
1084
if (!lex->current_select->add_table_to_list(lex->session, $9,
1086
TL_OPTION_UPDATING))
857
1087
DRIZZLE_YYABORT;
859
parser::buildKey(Lex, $4, $6);
1089
key= new Key($4, $6, &statement->key_create_info, 0, lex->col_list);
1090
statement->alter_info.key_list.push_back(key);
1091
lex->col_list.empty();
861
| CREATE DATABASE opt_if_not_exists schema_name
1093
| CREATE DATABASE opt_if_not_exists ident
863
Lex->statement= new statement::CreateSchema(YYSession);
1097
lex->sql_command=SQLCOM_CREATE_DB;
1098
statement::CreateSchema *statement= new(std::nothrow) statement::CreateSchema(YYSession);
1099
lex->statement= statement;
1100
if (lex->statement == NULL)
1102
statement->is_if_not_exists= $3;
865
1104
opt_create_database_options
871
create_table_definition:
872
'(' field_list ')' opt_create_table_options create_select_as
874
| '(' create_select ')'
876
Lex->current_select->set_braces(1);
1112
| opt_create_table_options
1114
| LIKE table_ident opt_create_table_options
1116
Session *session= YYSession;
1117
LEX *lex= session->lex;
1118
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1120
statement->is_create_table_like= true;
1121
if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
1124
| '(' LIKE table_ident ')'
1126
Session *session= YYSession;
1127
LEX *lex= session->lex;
1128
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1130
statement->is_create_table_like= true;
1131
if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
1137
field_list ')' opt_create_table_options
1140
{ Lex->current_select->set_braces(1);}
879
| '(' create_like ')' opt_create_table_options
881
| create_like opt_create_table_options
883
| opt_create_table_options create_select_as
889
| opt_duplicate_as create_select
891
Lex->current_select->set_braces(0);
1146
| opt_duplicate opt_as create_select
1147
{ Lex->current_select->set_braces(0);}
894
| opt_duplicate_as '(' create_select ')'
896
Lex->current_select->set_braces(1);
1149
| opt_duplicate opt_as '(' create_select ')'
1150
{ Lex->current_select->set_braces(1);}
904
((statement::CreateTable *)(YYSession->getLex()->statement))->is_create_table_like= true;
906
if (not YYSession->getLex()->select_lex.add_table_to_list(YYSession, $2, NULL, 0, TL_READ))
918
This rule is used for both CREATE TABLE .. SELECT, AND INSERT ... SELECT
923
Lex->lock_option= TL_READ;
924
if (Lex->sql_command == SQLCOM_INSERT)
1158
lex->lock_option= TL_READ;
1159
if (lex->sql_command == SQLCOM_INSERT)
926
delete Lex->statement;
927
Lex->statement= new statement::InsertSelect(YYSession);
1161
lex->sql_command= SQLCOM_INSERT_SELECT;
1162
delete lex->statement;
1164
new(std::nothrow) statement::InsertSelect(YYSession);
1165
if (lex->statement == NULL)
929
else if (Lex->sql_command == SQLCOM_REPLACE)
1168
else if (lex->sql_command == SQLCOM_REPLACE)
931
delete Lex->statement;
932
Lex->statement= new statement::ReplaceSelect(YYSession);
1170
lex->sql_command= SQLCOM_REPLACE_SELECT;
1171
delete lex->statement;
1173
new(std::nothrow) statement::ReplaceSelect(YYSession);
1174
if (lex->statement == NULL)
935
1178
The following work only with the local list, the global list
936
1179
is created correctly in this case
938
Lex->current_select->table_list.save_and_clear(&Lex->save_list);
940
Lex->current_select->parsing_place= SELECT_LIST;
1181
lex->current_select->table_list.save_and_clear(&lex->save_list);
1182
mysql_init_select(lex);
1183
lex->current_select->parsing_place= SELECT_LIST;
942
1185
select_options select_item_list
1161
parser::buildCreateFieldIdent(Lex);
1449
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1450
lex->length=lex->dec=0;
1452
statement->default_value= statement->on_update_value= 0;
1453
statement->comment= null_lex_str;
1455
statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1457
message::AlterTable &alter_proto=
1458
((statement::CreateTable *)Lex->statement)->alter_info.alter_proto;
1459
statement->current_proto_field= alter_proto.add_added_field();
1165
1464
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1169
Lex->field()->set_name($1.str);
1466
if (statement->current_proto_field)
1467
statement->current_proto_field->set_name($1.str);
1172
if (add_field_to_list(Lex->session, &$1, (enum enum_field_types) $3,
1173
Lex->length, Lex->dec, Lex->type,
1469
if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
1470
lex->length,lex->dec,lex->type,
1174
1471
statement->column_format,
1175
1472
statement->default_value, statement->on_update_value,
1176
1473
&statement->comment,
1177
statement->change, &Lex->interval_list, Lex->charset))
1474
statement->change, &lex->interval_list, lex->charset))
1178
1475
DRIZZLE_YYABORT;
1180
Lex->setField(NULL);
1477
statement->current_proto_field= NULL;
1185
field_definition opt_attribute {}
1481
type opt_attribute {}
1189
int_type ignored_field_number_length opt_field_number_signed opt_zerofill
1191
$$= parser::buildIntegerColumn(Lex, $1, ($3 or $4));
1488
Lex->length=(char*) 0; /* use default length */
1489
statement::CreateTable *statement=
1490
(statement::CreateTable *)Lex->statement;
1492
if (statement->current_proto_field)
1494
if ($1 == DRIZZLE_TYPE_LONG)
1495
statement->current_proto_field->set_type(message::Table::Field::INTEGER);
1496
else if ($1 == DRIZZLE_TYPE_LONGLONG)
1497
statement->current_proto_field->set_type(message::Table::Field::BIGINT);
1193
1502
| real_type opt_precision
1195
assert ($1 == DRIZZLE_TYPE_DOUBLE);
1196
$$= parser::buildDoubleColumn(Lex);
1200
$$= parser::buildVarcharColumn(Lex, $3.str);
1204
$$= parser::buildVarcharColumn(Lex, "1");
1206
| varchar '(' NUM ')'
1208
$$= parser::buildVarcharColumn(Lex, $3.str);
1210
| VARBINARY '(' NUM ')'
1212
$$= parser::buildVarbinaryColumn(Lex, $3.str);
1506
statement::CreateTable *statement=
1507
(statement::CreateTable *)Lex->statement;
1509
if (statement->current_proto_field)
1511
assert ($1 == DRIZZLE_TYPE_DOUBLE);
1512
statement->current_proto_field->set_type(message::Table::Field::DOUBLE);
1518
$$=DRIZZLE_TYPE_VARCHAR;
1520
statement::CreateTable *statement=
1521
(statement::CreateTable *)Lex->statement;
1523
if (statement->current_proto_field)
1525
statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1526
message::Table::Field::StringFieldOptions *string_field_options;
1528
string_field_options= statement->current_proto_field->mutable_string_options();
1530
string_field_options->set_length(atoi($3.str));
1535
Lex->length=(char*) "1";
1536
$$=DRIZZLE_TYPE_VARCHAR;
1538
statement::CreateTable *statement=
1539
(statement::CreateTable *)Lex->statement;
1541
if (statement->current_proto_field)
1542
statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1544
| varchar '(' NUM ')'
1547
$$= DRIZZLE_TYPE_VARCHAR;
1549
statement::CreateTable *statement=
1550
(statement::CreateTable *)Lex->statement;
1552
if (statement->current_proto_field)
1554
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));
1563
| VARBINARY '(' NUM ')'
1566
Lex->charset=&my_charset_bin;
1567
$$= DRIZZLE_TYPE_VARCHAR;
1569
statement::CreateTable *statement=
1570
(statement::CreateTable *)Lex->statement;
1572
if (statement->current_proto_field)
1574
statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1575
message::Table::Field::StringFieldOptions *string_field_options;
1577
string_field_options= statement->current_proto_field->mutable_string_options();
1579
string_field_options->set_length(atoi($3.str));
1580
string_field_options->set_collation_id(my_charset_bin.number);
1581
string_field_options->set_collation(my_charset_bin.name);
1216
1586
$$=DRIZZLE_TYPE_DATE;
1219
Lex->field()->set_type(message::Table::Field::DATE);
1223
$$=DRIZZLE_TYPE_TIME;
1226
Lex->field()->set_type(message::Table::Field::TIME);
1230
$$=parser::buildTimestampColumn(Lex, NULL);
1232
| TIMESTAMP_SYM '(' NUM ')'
1234
$$=parser::buildTimestampColumn(Lex, $3.str);
1588
statement::CreateTable *statement=
1589
(statement::CreateTable *)Lex->statement;
1591
if (statement->current_proto_field)
1592
statement->current_proto_field->set_type(message::Table::Field::DATE);
1596
$$=DRIZZLE_TYPE_TIMESTAMP;
1598
statement::CreateTable *statement=
1599
(statement::CreateTable *)Lex->statement;
1601
if (statement->current_proto_field)
1602
statement->current_proto_field->set_type(message::Table::Field::TIMESTAMP);
1238
1606
$$=DRIZZLE_TYPE_DATETIME;
1241
Lex->field()->set_type(message::Table::Field::DATETIME);
1245
$$= parser::buildBlobColumn(Lex);
1249
$$=DRIZZLE_TYPE_BLOB;
1250
Lex->length=(char*) 0; /* use default length */
1253
Lex->field()->set_type(message::Table::Field::BLOB);
1255
| DECIMAL_SYM float_options
1257
$$= parser::buildDecimalColumn(Lex);
1259
| NUMERIC_SYM float_options
1261
$$= parser::buildDecimalColumn(Lex);
1263
| FIXED_SYM float_options
1265
$$= parser::buildDecimalColumn(Lex);
1269
Lex->interval_list.clear();
1608
statement::CreateTable *statement=
1609
(statement::CreateTable *)Lex->statement;
1611
if (statement->current_proto_field)
1612
statement->current_proto_field->set_type(message::Table::Field::DATETIME);
1616
Lex->charset=&my_charset_bin;
1617
$$=DRIZZLE_TYPE_BLOB;
1618
Lex->length=(char*) 0; /* use default length */
1620
statement::CreateTable *statement=
1621
(statement::CreateTable *)Lex->statement;
1623
if (statement->current_proto_field)
1625
statement->current_proto_field->set_type(message::Table::Field::BLOB);
1626
message::Table::Field::StringFieldOptions *string_field_options;
1628
string_field_options= statement->current_proto_field->mutable_string_options();
1629
string_field_options->set_collation_id(my_charset_bin.number);
1630
string_field_options->set_collation(my_charset_bin.name);
1635
$$=DRIZZLE_TYPE_BLOB;
1636
Lex->length=(char*) 0; /* use default length */
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::BLOB);
1644
| DECIMAL_SYM float_options
1646
$$=DRIZZLE_TYPE_DECIMAL;
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::DECIMAL);
1654
| NUMERIC_SYM float_options
1656
$$=DRIZZLE_TYPE_DECIMAL;
1658
statement::CreateTable *statement=
1659
(statement::CreateTable *)Lex->statement;
1661
if (statement->current_proto_field)
1662
statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1664
| FIXED_SYM float_options
1666
$$=DRIZZLE_TYPE_DECIMAL;
1668
statement::CreateTable *statement=
1669
(statement::CreateTable *)Lex->statement;
1671
if (statement->current_proto_field)
1672
statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1675
{Lex->interval_list.empty();}
1273
1678
$$=DRIZZLE_TYPE_ENUM;
1276
Lex->field()->set_type(message::Table::Field::ENUM);
1280
$$= parser::buildUuidColumn(Lex);
1284
$$= parser::buildBooleanColumn(Lex);
1680
statement::CreateTable *statement=
1681
(statement::CreateTable *)Lex->statement;
1683
if (statement->current_proto_field)
1684
statement->current_proto_field->set_type(message::Table::Field::ENUM);
1288
$$= parser::buildSerialColumn(Lex);
1688
$$=DRIZZLE_TYPE_LONGLONG;
1689
Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
1691
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1692
if (statement->current_proto_field)
1694
message::Table::Field::FieldConstraints *constraints;
1695
constraints= statement->current_proto_field->mutable_constraints();
1696
constraints->set_is_nullable(false);
1698
statement->current_proto_field->set_type(message::Table::Field::BIGINT);
4321
Lex->lock_option= TL_READ;
4323
Lex->current_select->parsing_place= SELECT_LIST;
4787
lex->lock_option= TL_READ;
4788
mysql_init_select(lex);
4789
lex->current_select->parsing_place= SELECT_LIST;
4331
4796
DATABASES show_wild
4333
if (not show::buildScemas(YYSession))
4799
Session *session= YYSession;
4801
lex->sql_command= SQLCOM_SELECT;
4803
new(std::nothrow) statement::Select(session);
4804
if (lex->statement == NULL)
4807
std::string column_name= "Database";
4810
column_name.append(" (");
4811
column_name.append(Lex->wild->ptr());
4812
column_name.append(")");
4815
if (Lex->current_select->where)
4817
if (prepare_new_schema_table(session, lex, "SCHEMAS"))
4822
if (prepare_new_schema_table(session, lex, "SHOW_SCHEMAS"))
4826
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
4827
my_field->is_autogenerated_name= false;
4828
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
4830
if (session->add_item_to_list(my_field))
4833
if (session->add_order_to_list(my_field, true))
4337
4836
| TABLES opt_db show_wild
4339
if (not show::buildTables(YYSession, $2))
4839
Session *session= YYSession;
4841
lex->sql_command= SQLCOM_SELECT;
4843
statement::Select *select=
4844
new(std::nothrow) statement::Select(YYSession);
4846
lex->statement= select;
4848
if (lex->statement == NULL)
4852
std::string column_name= "Tables_in_";
4856
SchemaIdentifier identifier($2);
4857
column_name.append($2);
4858
lex->select_lex.db= $2;
4859
if (not plugin::StorageEngine::doesSchemaExist(identifier))
4861
my_error(ER_BAD_DB_ERROR, MYF(0), $2);
4863
select->setShowPredicate($2, "");
4865
else if (not session->db.empty())
4867
column_name.append(session->db);
4868
select->setShowPredicate(session->db, "");
4872
my_error(ER_NO_DB_ERROR, MYF(0));
4878
column_name.append(" (");
4879
column_name.append(Lex->wild->ptr());
4880
column_name.append(")");
4883
if (prepare_new_schema_table(YYSession, lex, "SHOW_TABLES"))
4886
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
4887
my_field->is_autogenerated_name= false;
4888
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
4890
if (session->add_item_to_list(my_field))
4893
if (session->add_order_to_list(my_field, true))
4342
/* SHOW TEMPORARY TABLES */
4343
4896
| TEMPORARY_SYM TABLES show_wild
4345
if (not show::buildTemporaryTables(YYSession))
4899
Session *session= YYSession;
4901
lex->sql_command= SQLCOM_SELECT;
4903
statement::Select *select=
4904
new(std::nothrow) statement::Select(YYSession);
4906
lex->statement= select;
4908
if (lex->statement == NULL)
4912
if (prepare_new_schema_table(YYSession, lex, "SHOW_TEMPORARY_TABLES"))
4915
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
4919
(session->lex->current_select->with_wild)++;
4348
/* SHOW TABLE STATUS */
4349
4922
| TABLE_SYM STATUS_SYM opt_db show_wild
4351
if (not show::buildTableStatus(YYSession, $3))
4925
lex->sql_command= SQLCOM_SELECT;
4926
statement::Select *select=
4927
new(std::nothrow) statement::Select(YYSession);
4929
lex->statement= select;
4931
if (lex->statement == NULL)
4934
Session *session= YYSession;
4936
std::string column_name= "Tables_in_";
4940
lex->select_lex.db= $3;
4942
SchemaIdentifier identifier($3);
4943
if (not plugin::StorageEngine::doesSchemaExist(identifier))
4945
my_error(ER_BAD_DB_ERROR, MYF(0), $3);
4948
select->setShowPredicate($3, "");
4952
select->setShowPredicate(session->db, "");
4955
if (prepare_new_schema_table(session, lex, "SHOW_TABLE_STATUS"))
4958
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
4962
(session->lex->current_select->with_wild)++;
4354
/* SHOW COLUMNS FROM table_name */
4355
4964
| COLUMNS from_or_in table_ident opt_db show_wild
4357
if (not show::buildColumns(YYSession, $4, $3))
4360
/* SHOW INDEXES from table */
4967
Session *session= YYSession;
4968
statement::Select *select;
4970
lex->sql_command= SQLCOM_SELECT;
4972
select= new(std::nothrow) statement::Select(session);
4974
lex->statement= select;
4976
if (lex->statement == NULL)
4980
select->setShowPredicate($4, $3->table.str);
4981
else if ($3->db.str)
4982
select->setShowPredicate($3->db.str, $3->table.str);
4984
select->setShowPredicate(session->db, $3->table.str);
4987
drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
4988
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
4990
my_error(ER_NO_SUCH_TABLE, MYF(0),
4991
select->getShowSchema().c_str(),
4996
if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
4999
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5003
(session->lex->current_select->with_wild)++;
4361
5006
| keys_or_index from_or_in table_ident opt_db where_clause
4363
if (not show::buildIndex(YYSession, $4, $3))
5009
Session *session= YYSession;
5010
statement::Select *select;
5012
lex->sql_command= SQLCOM_SELECT;
5014
select= new(std::nothrow) statement::Select(session);
5016
lex->statement= select;
5018
if (lex->statement == NULL)
5022
select->setShowPredicate($4, $3->table.str);
5023
else if ($3->db.str)
5024
select->setShowPredicate($3->db.str, $3->table.str);
5026
select->setShowPredicate(session->db, $3->table.str);
5029
drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
5030
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
5032
my_error(ER_NO_SUCH_TABLE, MYF(0),
5033
select->getShowSchema().c_str(),
5038
if (prepare_new_schema_table(session, lex, "SHOW_INDEXES"))
5041
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5045
(session->lex->current_select->with_wild)++;
4366
5047
| COUNT_SYM '(' '*' ')' WARNINGS
4368
show::buildSelectWarning(YYSession);
5049
(void) create_select_for_variable("warning_count");
5051
lex->statement= new(std::nothrow) statement::Select(YYSession);
5052
if (lex->statement == NULL)
4370
5055
| COUNT_SYM '(' '*' ')' ERRORS
4372
show::buildSelectError(YYSession);
5057
(void) create_select_for_variable("error_count");
5059
lex->statement= new(std::nothrow) statement::Select(YYSession);
5060
if (lex->statement == NULL)
4374
5063
| WARNINGS opt_limit_clause_init
4376
show::buildWarnings(YYSession);
5065
Lex->sql_command = SQLCOM_SHOW_WARNS;
5066
Lex->statement= new(std::nothrow) statement::ShowWarnings(YYSession);
5067
if (Lex->statement == NULL)
4378
5070
| ERRORS opt_limit_clause_init
4380
show::buildErrors(YYSession);
5072
Lex->sql_command = SQLCOM_SHOW_ERRORS;
5073
Lex->statement= new(std::nothrow) statement::ShowErrors(YYSession);
5074
if (Lex->statement == NULL)
4382
5077
| opt_var_type STATUS_SYM show_wild
4384
if (not show::buildStatus(YYSession, $1))
4387
| engine_option_value STATUS_SYM
4389
if (not show::buildEngineStatus(YYSession, $1))
5080
lex->sql_command= SQLCOM_SELECT;
5082
new(std::nothrow) statement::Select(YYSession);
5083
if (lex->statement == NULL)
5086
Session *session= YYSession;
5088
if ($1 == OPT_GLOBAL)
5090
if (prepare_new_schema_table(session, lex, "GLOBAL_STATUS"))
5095
if (prepare_new_schema_table(session, lex, "SESSION_STATUS"))
5099
std::string key("Variable_name");
5100
std::string value("Value");
5102
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5103
my_field->is_autogenerated_name= false;
5104
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5106
if (session->add_item_to_list(my_field))
5109
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5110
my_field->is_autogenerated_name= false;
5111
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5113
if (session->add_item_to_list(my_field))
4392
5116
| CREATE TABLE_SYM table_ident
4394
if (not show::buildCreateTable(YYSession, $3))
5119
lex->sql_command= SQLCOM_SELECT;
5120
statement::Select *select=
5121
new(std::nothrow) statement::Select(YYSession);
5123
lex->statement= select;
5125
if (lex->statement == NULL)
5128
Session *session= YYSession;
5130
if (prepare_new_schema_table(session, lex, "TABLE_SQL_DEFINITION"))
5134
select->setShowPredicate($3->db.str, $3->table.str);
5136
select->setShowPredicate(session->db, $3->table.str);
5138
std::string key("Table");
5139
std::string value("Create Table");
5141
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
5142
my_field->is_autogenerated_name= false;
5143
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5145
if (session->add_item_to_list(my_field))
5148
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
5149
my_field->is_autogenerated_name= false;
5150
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5152
if (session->add_item_to_list(my_field))
4397
5155
| PROCESSLIST_SYM
4399
if (not show::buildProcesslist(YYSession))
5159
lex->sql_command= SQLCOM_SELECT;
5161
new(std::nothrow) statement::Select(YYSession);
5162
if (lex->statement == NULL)
5165
Session *session= YYSession;
5167
if (prepare_new_schema_table(session, lex, "PROCESSLIST"))
5170
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5174
(session->lex->current_select->with_wild)++;
4402
5177
| opt_var_type VARIABLES show_wild
4404
if (not show::buildVariables(YYSession, $1))
5180
lex->sql_command= SQLCOM_SELECT;
5182
new(std::nothrow) statement::Select(YYSession);
5183
if (lex->statement == NULL)
5186
Session *session= YYSession;
5188
if ($1 == OPT_GLOBAL)
5190
if (prepare_new_schema_table(session, lex, "GLOBAL_VARIABLES"))
5195
if (prepare_new_schema_table(session, lex, "SESSION_VARIABLES"))
5199
std::string key("Variable_name");
5200
std::string value("Value");
5202
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5203
my_field->is_autogenerated_name= false;
5204
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5206
if (session->add_item_to_list(my_field))
5209
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5210
my_field->is_autogenerated_name= false;
5211
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5213
if (session->add_item_to_list(my_field))
4407
5216
| CREATE DATABASE opt_if_not_exists ident
4409
if (not show::buildCreateSchema(YYSession, $4))
5219
lex->sql_command= SQLCOM_SELECT;
5220
statement::Select *select=
5221
new(std::nothrow) statement::Select(YYSession);
5223
lex->statement= select;
5225
if (lex->statement == NULL)
5228
Session *session= YYSession;
5230
if (prepare_new_schema_table(session, lex, "SCHEMA_SQL_DEFINITION"))
5234
select->setShowPredicate($4.str);
5236
select->setShowPredicate(session->db);
5238
std::string key("Database");
5239
std::string value("Create Database");
5241
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
5242
my_field->is_autogenerated_name= false;
5243
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5245
if (session->add_item_to_list(my_field))
5248
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
5249
my_field->is_autogenerated_name= false;
5250
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5252
if (session->add_item_to_list(my_field))
4414
5257
/* empty */ { $$= 0; }
4847
5762
simple_ident_q:
4848
5763
ident '.' ident
4850
$$= parser::buildIdent(Lex, NULL_LEX_STRING, $1, $3);
5765
Session *session= YYSession;
5766
LEX *lex= session->lex;
5769
Select_Lex *sel= lex->current_select;
5770
if (sel->no_table_names_allowed)
5772
my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5773
MYF(0), $1.str, session->where);
5775
$$= (sel->parsing_place != IN_HAVING ||
5776
sel->get_in_sum_expr() > 0) ?
5777
(Item*) new Item_field(Lex->current_context(),
5778
(const char *)NULL, $1.str, $3.str) :
5779
(Item*) new Item_ref(Lex->current_context(),
5780
(const char *)NULL, $1.str, $3.str);
4852
5783
| '.' ident '.' ident
4854
$$= parser::buildIdent(Lex, NULL_LEX_STRING, $2, $4);
5785
Session *session= YYSession;
5786
LEX *lex= session->lex;
5787
Select_Lex *sel= lex->current_select;
5788
if (sel->no_table_names_allowed)
5790
my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5791
MYF(0), $2.str, session->where);
5793
$$= (sel->parsing_place != IN_HAVING ||
5794
sel->get_in_sum_expr() > 0) ?
5795
(Item*) new Item_field(Lex->current_context(), NULL, $2.str, $4.str) :
5796
(Item*) new Item_ref(Lex->current_context(),
5797
(const char *)NULL, $2.str, $4.str);
4856
5799
| ident '.' ident '.' ident
4858
$$= parser::buildIdent(Lex, $1, $3, $5);
5801
Session *session= YYSession;
5802
LEX *lex= session->lex;
5803
Select_Lex *sel= lex->current_select;
5804
if (sel->no_table_names_allowed)
5806
my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5807
MYF(0), $3.str, session->where);
5809
$$= (sel->parsing_place != IN_HAVING ||
5810
sel->get_in_sum_expr() > 0) ?
5811
(Item*) new Item_field(Lex->current_context(), $1.str, $3.str,
5813
(Item*) new Item_ref(Lex->current_context(), $1.str, $3.str,
4867
5820
| ident '.' ident '.' ident
4869
if (not parser::checkFieldIdent(Lex, $1, $3))
5823
reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
5824
if (my_strcasecmp(table_alias_charset, $1.str, table->db))
5826
my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
5829
if (my_strcasecmp(table_alias_charset, $3.str,
5832
my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
4874
5837
| ident '.' ident
4876
if (not parser::checkFieldIdent(Lex, NULL_LEX_STRING, $1))
5840
reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
5841
if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
5843
my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
4877
5844
DRIZZLE_YYABORT;
5848
| '.' ident { $$=$2;} /* For Delphi */
4890
$$= new Table_ident($1);
4892
| schema_name '.' ident
4894
$$=new Table_ident($1,$3);
4898
$$= new Table_ident($2);
5852
ident { $$=new Table_ident($1); }
5853
| ident '.' ident { $$=new Table_ident($1,$3);}
5854
| '.' ident { $$=new Table_ident($2);} /* For Delphi */
4917
5861
const CHARSET_INFO * const cs= system_charset_info;