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;
131
354
drizzled::Key_part_spec *key_part;
132
355
const drizzled::plugin::Function *udf;
133
356
drizzled::TableList *table_list;
134
drizzled::enum_field_types field_val;
135
drizzled::sys_var_with_base variable;
136
drizzled::sql_var_t var_type;
357
struct drizzled::sys_var_with_base variable;
358
enum drizzled::sql_var_t var_type;
137
359
drizzled::Key::Keytype key_type;
138
drizzled::ha_key_alg key_alg;
139
drizzled::ha_rkey_function ha_rkey_mode;
140
drizzled::enum_tx_isolation tx_isolation;
141
drizzled::Cast_target cast_type;
360
enum drizzled::ha_key_alg key_alg;
361
enum drizzled::column_format_type column_format_type;
362
enum drizzled::ha_rkey_function ha_rkey_mode;
363
enum drizzled::enum_tx_isolation tx_isolation;
364
enum drizzled::Cast_target cast_type;
142
365
const drizzled::CHARSET_INFO *charset;
143
366
drizzled::thr_lock_type lock_type;
144
367
drizzled::interval_type interval, interval_time_st;
145
drizzled::type::timestamp_t date_time_type;
368
enum drizzled::enum_drizzle_timestamp_type date_time_type;
146
369
drizzled::Select_Lex *select_lex;
147
370
drizzled::chooser_compare_func_creator boolfunc2creator;
148
drizzled::st_lex *lex;
149
drizzled::index_hint_type index_hint;
150
drizzled::enum_filetype filetype;
151
drizzled::ha_build_method build_method;
152
drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption m_fk_option;
153
drizzled::execute_string_t execute_string;
371
struct drizzled::st_lex *lex;
372
enum drizzled::index_hint_type index_hint;
373
enum drizzled::enum_filetype filetype;
374
enum drizzled::ha_build_method build_method;
375
enum drizzled::Foreign_key::fk_option m_fk_option;
157
379
namespace drizzled
159
bool my_yyoverflow(short **a, union ParserType **b, unsigned long *yystacksize);
381
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
166
%name-prefix="base_sql_"
167
%parse-param { drizzled::Session *session }
168
%lex-param { drizzled::Session *session }
385
%pure_parser /* We have threads */
173
Currently there are 70 shift/reduce conflicts.
387
Currently there are 88 shift/reduce conflicts.
174
388
We should not introduce new conflicts any more.
179
393
Comments for TOKENS.
827
1027
/* 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);
1030
CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
1032
Session *session= YYSession;
1033
LEX *lex= session->lex;
1034
lex->sql_command= SQLCOM_CREATE_TABLE;
1035
statement::CreateTable *statement= new(std::nothrow) statement::CreateTable(YYSession);
1036
lex->statement= statement;
1037
if (lex->statement == NULL)
1039
if (!lex->select_lex.add_table_to_list(session, $5, NULL,
1043
lex->col_list.empty();
1044
statement->change=NULL;
1045
statement->is_if_not_exists= $4;
1046
statement->create_info.db_type= NULL;
1047
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();
1050
message::Table &proto= statement->create_table_message;
1052
proto.set_name($5->table.str);
1054
proto.set_type(message::Table::TEMPORARY);
1056
proto.set_type(message::Table::STANDARD);
844
create_table_definition
846
Lex->current_select= &Lex->select_lex;
1060
LEX *lex= YYSession->lex;
1061
lex->current_select= &lex->select_lex;
848
1063
| CREATE build_method
850
Lex->statement= new statement::CreateIndex(YYSession, $2);
1066
lex->sql_command= SQLCOM_CREATE_INDEX;
1067
statement::CreateIndex *statement= new(std::nothrow) statement::CreateIndex(YYSession);
1068
lex->statement= statement;
1069
if (lex->statement == NULL)
1071
statement->alter_info.flags.set(ALTER_ADD_INDEX);
1072
statement->alter_info.build_method= $2;
1073
lex->col_list.empty();
1074
statement->change=NULL;
852
1076
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,
1079
statement::CreateIndex *statement= (statement::CreateIndex *)Lex->statement;
1081
if (!lex->current_select->add_table_to_list(lex->session, $9,
1083
TL_OPTION_UPDATING))
857
1084
DRIZZLE_YYABORT;
859
parser::buildKey(Lex, $4, $6);
1086
key= new Key($4, $6, &statement->key_create_info, 0, lex->col_list);
1087
statement->alter_info.key_list.push_back(key);
1088
lex->col_list.empty();
861
| CREATE DATABASE opt_if_not_exists schema_name
1090
| CREATE DATABASE opt_if_not_exists ident
863
Lex->statement= new statement::CreateSchema(YYSession);
1094
lex->sql_command=SQLCOM_CREATE_DB;
1095
statement::CreateSchema *statement= new(std::nothrow) statement::CreateSchema(YYSession);
1096
lex->statement= statement;
1097
if (lex->statement == NULL)
1099
statement->is_if_not_exists= $3;
865
1101
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);
1109
| opt_create_table_options
1111
| LIKE table_ident opt_create_table_options
1113
Session *session= YYSession;
1114
LEX *lex= session->lex;
1115
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1117
statement->is_create_table_like= true;
1118
if (!lex->select_lex.add_table_to_list(session, $2, NULL, 0, TL_READ))
1121
| '(' LIKE table_ident ')'
1123
Session *session= YYSession;
1124
LEX *lex= session->lex;
1125
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1127
statement->is_create_table_like= true;
1128
if (!lex->select_lex.add_table_to_list(session, $3, NULL, 0, TL_READ))
1134
field_list ')' opt_create_table_options
1137
{ 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);
1143
| opt_duplicate opt_as create_select
1144
{ Lex->current_select->set_braces(0);}
894
| opt_duplicate_as '(' create_select ')'
896
Lex->current_select->set_braces(1);
1146
| opt_duplicate opt_as '(' create_select ')'
1147
{ 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)
1155
lex->lock_option= TL_READ;
1156
if (lex->sql_command == SQLCOM_INSERT)
926
delete Lex->statement;
927
Lex->statement= new statement::InsertSelect(YYSession);
1158
lex->sql_command= SQLCOM_INSERT_SELECT;
1159
delete lex->statement;
1161
new(std::nothrow) statement::InsertSelect(YYSession);
1162
if (lex->statement == NULL)
929
else if (Lex->sql_command == SQLCOM_REPLACE)
1165
else if (lex->sql_command == SQLCOM_REPLACE)
931
delete Lex->statement;
932
Lex->statement= new statement::ReplaceSelect(YYSession);
1167
lex->sql_command= SQLCOM_REPLACE_SELECT;
1168
delete lex->statement;
1170
new(std::nothrow) statement::ReplaceSelect(YYSession);
1171
if (lex->statement == NULL)
935
1175
The following work only with the local list, the global list
936
1176
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;
1178
lex->current_select->table_list.save_and_clear(&lex->save_list);
1179
mysql_init_select(lex);
1180
lex->current_select->parsing_place= SELECT_LIST;
942
1182
select_options select_item_list
1109
1367
field_spec opt_check_constraint
1110
1368
| field_spec references
1112
Lex->col_list.clear(); /* Alloced by memory::sql_alloc */
1370
Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1117
1375
key_type opt_ident key_alg '(' key_list ')' key_options
1119
parser::buildKey(Lex, $1, $2);
1378
statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1379
Key *key= new Key($1, $2, &statement->key_create_info, 0,
1381
statement->alter_info.key_list.push_back(key);
1382
lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1121
1384
| opt_constraint constraint_key_type opt_ident key_alg
1122
1385
'(' key_list ')' key_options
1124
parser::buildKey(Lex, $2, $3.str ? $3 : $1);
1388
statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1389
Key *key= new Key($2, $3.str ? $3 : $1, &statement->key_create_info, 0,
1391
statement->alter_info.key_list.push_back(key);
1392
lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1126
1394
| opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
1128
parser::buildForeignKey(Lex, $1.str ? $1 : $4, $8);
1397
statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1398
Key *key= new Foreign_key($4.str ? $4 : $1, lex->col_list,
1401
statement->fk_delete_opt,
1402
statement->fk_update_opt,
1403
statement->fk_match_option);
1404
statement->alter_info.key_list.push_back(key);
1405
key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
1406
&default_key_create_info, 1,
1408
statement->alter_info.key_list.push_back(key);
1409
lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1410
/* Only used for ALTER TABLE. Ignored otherwise. */
1411
statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
1130
1413
| constraint opt_check_constraint
1132
Lex->col_list.clear(); /* Alloced by memory::sql_alloc */
1415
Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1134
1417
| opt_constraint check_constraint
1136
Lex->col_list.clear(); /* Alloced by memory::sql_alloc */
1419
Lex->col_list.empty(); /* Alloced by memory::sql_alloc */
1161
parser::buildCreateFieldIdent(Lex);
1445
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1446
lex->length=lex->dec=0;
1448
statement->default_value= statement->on_update_value= 0;
1449
statement->comment= null_lex_str;
1451
statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
1453
message::AlterTable &alter_proto=
1454
((statement::CreateTable *)Lex->statement)->alter_info.alter_proto;
1455
statement->current_proto_field= alter_proto.add_added_field();
1165
1460
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1169
Lex->field()->set_name($1.str);
1462
if (statement->current_proto_field)
1463
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,
1465
if (add_field_to_list(lex->session, &$1, (enum enum_field_types) $3,
1466
lex->length,lex->dec,lex->type,
1174
1467
statement->column_format,
1175
1468
statement->default_value, statement->on_update_value,
1176
1469
&statement->comment,
1177
statement->change, &Lex->interval_list, Lex->charset))
1470
statement->change, &lex->interval_list, lex->charset))
1178
1471
DRIZZLE_YYABORT;
1180
Lex->setField(NULL);
1473
statement->current_proto_field= NULL;
1185
field_definition opt_attribute {}
1477
type opt_attribute {}
1189
int_type ignored_field_number_length opt_field_number_signed opt_zerofill
1191
$$= parser::buildIntegerColumn(Lex, $1, ($3 or $4));
1484
Lex->length=(char*) 0; /* use default length */
1485
statement::CreateTable *statement=
1486
(statement::CreateTable *)Lex->statement;
1488
if (statement->current_proto_field)
1490
if ($1 == DRIZZLE_TYPE_LONG)
1491
statement->current_proto_field->set_type(message::Table::Field::INTEGER);
1492
else if ($1 == DRIZZLE_TYPE_LONGLONG)
1493
statement->current_proto_field->set_type(message::Table::Field::BIGINT);
1193
1498
| 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);
1502
statement::CreateTable *statement=
1503
(statement::CreateTable *)Lex->statement;
1505
if (statement->current_proto_field)
1507
assert ($1 == DRIZZLE_TYPE_DOUBLE);
1508
statement->current_proto_field->set_type(message::Table::Field::DOUBLE);
1514
$$=DRIZZLE_TYPE_VARCHAR;
1516
statement::CreateTable *statement=
1517
(statement::CreateTable *)Lex->statement;
1519
if (statement->current_proto_field)
1521
statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1522
message::Table::Field::StringFieldOptions *string_field_options;
1524
string_field_options= statement->current_proto_field->mutable_string_options();
1526
string_field_options->set_length(atoi($3.str));
1531
Lex->length=(char*) "1";
1532
$$=DRIZZLE_TYPE_VARCHAR;
1534
statement::CreateTable *statement=
1535
(statement::CreateTable *)Lex->statement;
1537
if (statement->current_proto_field)
1538
statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1540
| varchar '(' NUM ')'
1543
$$= DRIZZLE_TYPE_VARCHAR;
1545
statement::CreateTable *statement=
1546
(statement::CreateTable *)Lex->statement;
1548
if (statement->current_proto_field)
1550
statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1552
message::Table::Field::StringFieldOptions *string_field_options;
1554
string_field_options= statement->current_proto_field->mutable_string_options();
1556
string_field_options->set_length(atoi($3.str));
1559
| VARBINARY '(' NUM ')'
1562
Lex->charset=&my_charset_bin;
1563
$$= DRIZZLE_TYPE_VARCHAR;
1565
statement::CreateTable *statement=
1566
(statement::CreateTable *)Lex->statement;
1568
if (statement->current_proto_field)
1570
statement->current_proto_field->set_type(message::Table::Field::VARCHAR);
1571
message::Table::Field::StringFieldOptions *string_field_options;
1573
string_field_options= statement->current_proto_field->mutable_string_options();
1575
string_field_options->set_length(atoi($3.str));
1576
string_field_options->set_collation_id(my_charset_bin.number);
1577
string_field_options->set_collation(my_charset_bin.name);
1216
1582
$$=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);
1584
statement::CreateTable *statement=
1585
(statement::CreateTable *)Lex->statement;
1587
if (statement->current_proto_field)
1588
statement->current_proto_field->set_type(message::Table::Field::DATE);
1592
$$=DRIZZLE_TYPE_TIMESTAMP;
1594
statement::CreateTable *statement=
1595
(statement::CreateTable *)Lex->statement;
1597
if (statement->current_proto_field)
1598
statement->current_proto_field->set_type(message::Table::Field::TIMESTAMP);
1238
1602
$$=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();
1604
statement::CreateTable *statement=
1605
(statement::CreateTable *)Lex->statement;
1607
if (statement->current_proto_field)
1608
statement->current_proto_field->set_type(message::Table::Field::DATETIME);
1612
Lex->charset=&my_charset_bin;
1613
$$=DRIZZLE_TYPE_BLOB;
1614
Lex->length=(char*) 0; /* use default length */
1616
statement::CreateTable *statement=
1617
(statement::CreateTable *)Lex->statement;
1619
if (statement->current_proto_field)
1621
statement->current_proto_field->set_type(message::Table::Field::BLOB);
1622
message::Table::Field::StringFieldOptions *string_field_options;
1624
string_field_options= statement->current_proto_field->mutable_string_options();
1625
string_field_options->set_collation_id(my_charset_bin.number);
1626
string_field_options->set_collation(my_charset_bin.name);
1631
$$=DRIZZLE_TYPE_BLOB;
1632
Lex->length=(char*) 0; /* use default length */
1634
statement::CreateTable *statement=
1635
(statement::CreateTable *)Lex->statement;
1637
if (statement->current_proto_field)
1638
statement->current_proto_field->set_type(message::Table::Field::BLOB);
1640
| DECIMAL_SYM float_options
1642
$$=DRIZZLE_TYPE_DECIMAL;
1644
statement::CreateTable *statement=
1645
(statement::CreateTable *)Lex->statement;
1647
if (statement->current_proto_field)
1648
statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1650
| NUMERIC_SYM float_options
1652
$$=DRIZZLE_TYPE_DECIMAL;
1654
statement::CreateTable *statement=
1655
(statement::CreateTable *)Lex->statement;
1657
if (statement->current_proto_field)
1658
statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1660
| FIXED_SYM float_options
1662
$$=DRIZZLE_TYPE_DECIMAL;
1664
statement::CreateTable *statement=
1665
(statement::CreateTable *)Lex->statement;
1667
if (statement->current_proto_field)
1668
statement->current_proto_field->set_type(message::Table::Field::DECIMAL);
1671
{Lex->interval_list.empty();}
1273
1674
$$=DRIZZLE_TYPE_ENUM;
1276
Lex->field()->set_type(message::Table::Field::ENUM);
1280
$$= parser::buildUuidColumn(Lex);
1284
$$= parser::buildBooleanColumn(Lex);
1676
statement::CreateTable *statement=
1677
(statement::CreateTable *)Lex->statement;
1679
if (statement->current_proto_field)
1680
statement->current_proto_field->set_type(message::Table::Field::ENUM);
1288
$$= parser::buildSerialColumn(Lex);
1684
$$=DRIZZLE_TYPE_LONGLONG;
1685
Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
1687
statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1688
if (statement->current_proto_field)
1690
message::Table::Field::FieldConstraints *constraints;
1691
constraints= statement->current_proto_field->mutable_constraints();
1692
constraints->set_is_nullable(false);
1694
statement->current_proto_field->set_type(message::Table::Field::BIGINT);
2679
3117
{ $$= new (YYSession->mem_root) Item_date_add_interval($3, $6, $7, 1); }
2680
3118
| SUBSTRING '(' expr ',' expr ',' expr ')'
3120
std::string reverse_str("substr");
2682
3121
List<Item> *args= new (YYSession->mem_root) List<Item>;
2683
3122
args->push_back($3);
2684
3123
args->push_back($5);
2685
3124
args->push_back($7);
2686
if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
3125
if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2688
3127
DRIZZLE_YYABORT;
2691
3130
| SUBSTRING '(' expr ',' expr ')'
3132
std::string reverse_str("substr");
2693
3133
List<Item> *args= new (YYSession->mem_root) List<Item>;
2694
3134
args->push_back($3);
2695
3135
args->push_back($5);
2696
if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
3136
if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2698
3138
DRIZZLE_YYABORT;
2701
3141
| SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
3143
std::string reverse_str("substr");
2703
3144
List<Item> *args= new (YYSession->mem_root) List<Item>;
2704
3145
args->push_back($3);
2705
3146
args->push_back($5);
2706
3147
args->push_back($7);
2707
if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
3148
if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2709
3150
DRIZZLE_YYABORT;
2712
3153
| SUBSTRING '(' expr FROM expr ')'
3155
std::string reverse_str("substr");
2714
3156
List<Item> *args= new (YYSession->mem_root) List<Item>;
2715
3157
args->push_back($3);
2716
3158
args->push_back($5);
2717
if (! ($$= parser::reserved_keyword_function(YYSession, "substr", args)))
3159
if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
2719
3161
DRIZZLE_YYABORT;
2722
3164
| SYSDATE optional_braces
2724
$$= new (YYSession->mem_root) Item_func_sysdate_local();
2725
Lex->setCacheable(false);
3165
{ $$= new (YYSession->mem_root) Item_func_sysdate_local(); }
2727
3166
| SYSDATE '(' expr ')'
2729
$$= new (YYSession->mem_root) Item_func_sysdate_local($3);
2730
Lex->setCacheable(false);
3167
{ $$= new (YYSession->mem_root) Item_func_sysdate_local($3); }
2732
3168
| TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
2733
3169
{ $$= new (YYSession->mem_root) Item_date_add_interval($7,$5,$3,0); }
2734
3170
| TIMESTAMP_DIFF '(' interval_time_stamp ',' expr ',' expr ')'
4321
Lex->lock_option= TL_READ;
4323
Lex->current_select->parsing_place= SELECT_LIST;
4732
lex->lock_option= TL_READ;
4733
mysql_init_select(lex);
4734
lex->current_select->parsing_place= SELECT_LIST;
4331
4741
DATABASES show_wild
4333
if (not show::buildScemas(YYSession))
4744
Session *session= YYSession;
4746
lex->sql_command= SQLCOM_SELECT;
4748
new(std::nothrow) statement::Select(session);
4749
if (lex->statement == NULL)
4752
std::string column_name= "Database";
4755
column_name.append(" (");
4756
column_name.append(Lex->wild->ptr());
4757
column_name.append(")");
4760
if (Lex->current_select->where)
4762
if (prepare_new_schema_table(session, lex, "SCHEMAS"))
4767
if (prepare_new_schema_table(session, lex, "SHOW_SCHEMAS"))
4771
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
4772
my_field->is_autogenerated_name= false;
4773
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
4775
if (session->add_item_to_list(my_field))
4778
if (session->add_order_to_list(my_field, true))
4337
4781
| TABLES opt_db show_wild
4339
if (not show::buildTables(YYSession, $2))
4784
Session *session= YYSession;
4786
lex->sql_command= SQLCOM_SELECT;
4788
statement::Select *select=
4789
new(std::nothrow) statement::Select(YYSession);
4791
lex->statement= select;
4793
if (lex->statement == NULL)
4797
std::string column_name= "Tables_in_";
4801
SchemaIdentifier identifier($2);
4802
column_name.append($2);
4803
lex->select_lex.db= $2;
4804
if (not plugin::StorageEngine::doesSchemaExist(identifier))
4806
my_error(ER_BAD_DB_ERROR, MYF(0), $2);
4808
select->setShowPredicate($2, "");
4810
else if (not session->db.empty())
4812
column_name.append(session->db);
4813
select->setShowPredicate(session->db, "");
4817
my_error(ER_NO_DB_ERROR, MYF(0));
4823
column_name.append(" (");
4824
column_name.append(Lex->wild->ptr());
4825
column_name.append(")");
4828
if (prepare_new_schema_table(YYSession, lex, "SHOW_TABLES"))
4831
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
4832
my_field->is_autogenerated_name= false;
4833
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
4835
if (session->add_item_to_list(my_field))
4838
if (session->add_order_to_list(my_field, true))
4342
/* SHOW TEMPORARY TABLES */
4343
4841
| TEMPORARY_SYM TABLES show_wild
4345
if (not show::buildTemporaryTables(YYSession))
4844
Session *session= YYSession;
4846
lex->sql_command= SQLCOM_SELECT;
4848
statement::Select *select=
4849
new(std::nothrow) statement::Select(YYSession);
4851
lex->statement= select;
4853
if (lex->statement == NULL)
4857
if (prepare_new_schema_table(YYSession, lex, "SHOW_TEMPORARY_TABLES"))
4860
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
4864
(session->lex->current_select->with_wild)++;
4348
/* SHOW TABLE STATUS */
4349
4867
| TABLE_SYM STATUS_SYM opt_db show_wild
4351
if (not show::buildTableStatus(YYSession, $3))
4870
lex->sql_command= SQLCOM_SELECT;
4871
statement::Select *select=
4872
new(std::nothrow) statement::Select(YYSession);
4874
lex->statement= select;
4876
if (lex->statement == NULL)
4879
Session *session= YYSession;
4881
std::string column_name= "Tables_in_";
4885
lex->select_lex.db= $3;
4887
SchemaIdentifier identifier($3);
4888
if (not plugin::StorageEngine::doesSchemaExist(identifier))
4890
my_error(ER_BAD_DB_ERROR, MYF(0), $3);
4893
select->setShowPredicate($3, "");
4897
select->setShowPredicate(session->db, "");
4900
if (prepare_new_schema_table(session, lex, "SHOW_TABLE_STATUS"))
4903
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
4907
(session->lex->current_select->with_wild)++;
4354
/* SHOW COLUMNS FROM table_name */
4355
4909
| COLUMNS from_or_in table_ident opt_db show_wild
4357
if (not show::buildColumns(YYSession, $4, $3))
4360
/* SHOW INDEXES from table */
4912
Session *session= YYSession;
4913
statement::Select *select;
4915
lex->sql_command= SQLCOM_SELECT;
4917
select= new(std::nothrow) statement::Select(session);
4919
lex->statement= select;
4921
if (lex->statement == NULL)
4925
select->setShowPredicate($4, $3->table.str);
4926
else if ($3->db.str)
4927
select->setShowPredicate($3->db.str, $3->table.str);
4929
select->setShowPredicate(session->db, $3->table.str);
4932
drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
4933
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
4935
my_error(ER_NO_SUCH_TABLE, MYF(0),
4936
select->getShowSchema().c_str(),
4941
if (prepare_new_schema_table(session, lex, "SHOW_COLUMNS"))
4944
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
4948
(session->lex->current_select->with_wild)++;
4361
4951
| keys_or_index from_or_in table_ident opt_db where_clause
4363
if (not show::buildIndex(YYSession, $4, $3))
4954
Session *session= YYSession;
4955
statement::Select *select;
4957
lex->sql_command= SQLCOM_SELECT;
4959
select= new(std::nothrow) statement::Select(session);
4961
lex->statement= select;
4963
if (lex->statement == NULL)
4967
select->setShowPredicate($4, $3->table.str);
4968
else if ($3->db.str)
4969
select->setShowPredicate($3->db.str, $3->table.str);
4971
select->setShowPredicate(session->db, $3->table.str);
4974
drizzled::TableIdentifier identifier(select->getShowSchema().c_str(), $3->table.str);
4975
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
4977
my_error(ER_NO_SUCH_TABLE, MYF(0),
4978
select->getShowSchema().c_str(),
4983
if (prepare_new_schema_table(session, lex, "SHOW_INDEXES"))
4986
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
4990
(session->lex->current_select->with_wild)++;
4366
4992
| COUNT_SYM '(' '*' ')' WARNINGS
4368
show::buildSelectWarning(YYSession);
4994
(void) create_select_for_variable("warning_count");
4996
lex->statement= new(std::nothrow) statement::Select(YYSession);
4997
if (lex->statement == NULL)
4370
5000
| COUNT_SYM '(' '*' ')' ERRORS
4372
show::buildSelectError(YYSession);
5002
(void) create_select_for_variable("error_count");
5004
lex->statement= new(std::nothrow) statement::Select(YYSession);
5005
if (lex->statement == NULL)
4374
5008
| WARNINGS opt_limit_clause_init
4376
show::buildWarnings(YYSession);
5010
Lex->sql_command = SQLCOM_SHOW_WARNS;
5011
Lex->statement= new(std::nothrow) statement::ShowWarnings(YYSession);
5012
if (Lex->statement == NULL)
4378
5015
| ERRORS opt_limit_clause_init
4380
show::buildErrors(YYSession);
5017
Lex->sql_command = SQLCOM_SHOW_ERRORS;
5018
Lex->statement= new(std::nothrow) statement::ShowErrors(YYSession);
5019
if (Lex->statement == NULL)
4382
5022
| 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))
4392
| CREATE TABLE_SYM table_ident
4394
if (not show::buildCreateTable(YYSession, $3))
5025
lex->sql_command= SQLCOM_SELECT;
5027
new(std::nothrow) statement::Select(YYSession);
5028
if (lex->statement == NULL)
5031
Session *session= YYSession;
5033
if ($1 == OPT_GLOBAL)
5035
if (prepare_new_schema_table(session, lex, "GLOBAL_STATUS"))
5040
if (prepare_new_schema_table(session, lex, "SESSION_STATUS"))
5044
std::string key("Variable_name");
5045
std::string value("Value");
5047
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5048
my_field->is_autogenerated_name= false;
5049
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5051
if (session->add_item_to_list(my_field))
5054
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5055
my_field->is_autogenerated_name= false;
5056
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5058
if (session->add_item_to_list(my_field))
4397
5061
| PROCESSLIST_SYM
4399
if (not show::buildProcesslist(YYSession))
5065
lex->sql_command= SQLCOM_SELECT;
5067
new(std::nothrow) statement::Select(YYSession);
5068
if (lex->statement == NULL)
5071
Session *session= YYSession;
5073
if (prepare_new_schema_table(session, lex, "PROCESSLIST"))
5076
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
5080
(session->lex->current_select->with_wild)++;
4402
5083
| opt_var_type VARIABLES show_wild
4404
if (not show::buildVariables(YYSession, $1))
5086
lex->sql_command= SQLCOM_SELECT;
5088
new(std::nothrow) statement::Select(YYSession);
5089
if (lex->statement == NULL)
5092
Session *session= YYSession;
5094
if ($1 == OPT_GLOBAL)
5096
if (prepare_new_schema_table(session, lex, "GLOBAL_VARIABLES"))
5101
if (prepare_new_schema_table(session, lex, "SESSION_VARIABLES"))
5105
std::string key("Variable_name");
5106
std::string value("Value");
5108
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5109
my_field->is_autogenerated_name= false;
5110
my_field->set_name(key.c_str(), key.length(), system_charset_info);
5112
if (session->add_item_to_list(my_field))
5115
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5116
my_field->is_autogenerated_name= false;
5117
my_field->set_name(value.c_str(), value.length(), system_charset_info);
5119
if (session->add_item_to_list(my_field))
4407
5122
| CREATE DATABASE opt_if_not_exists ident
4409
if (not show::buildCreateSchema(YYSession, $4))
5124
Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
5125
statement::ShowCreateSchema *statement= new(std::nothrow) statement::ShowCreateSchema(YYSession);
5126
Lex->statement= statement;
5127
if (Lex->statement == NULL)
5129
statement->is_if_not_exists= $3;
5132
| CREATE TABLE_SYM table_ident
5135
lex->sql_command = SQLCOM_SHOW_CREATE;
5136
lex->statement= new(std::nothrow) statement::ShowCreate(YYSession);
5137
if (lex->statement == NULL)
5139
if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
4410
5140
DRIZZLE_YYABORT;
4847
5649
simple_ident_q:
4848
5650
ident '.' ident
4850
$$= parser::buildIdent(Lex, NULL_LEX_STRING, $1, $3);
5652
Session *session= YYSession;
5653
LEX *lex= session->lex;
5656
Select_Lex *sel= lex->current_select;
5657
if (sel->no_table_names_allowed)
5659
my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5660
MYF(0), $1.str, session->where);
5662
$$= (sel->parsing_place != IN_HAVING ||
5663
sel->get_in_sum_expr() > 0) ?
5664
(Item*) new Item_field(Lex->current_context(),
5665
(const char *)NULL, $1.str, $3.str) :
5666
(Item*) new Item_ref(Lex->current_context(),
5667
(const char *)NULL, $1.str, $3.str);
4852
5670
| '.' ident '.' ident
4854
$$= parser::buildIdent(Lex, NULL_LEX_STRING, $2, $4);
5672
Session *session= YYSession;
5673
LEX *lex= session->lex;
5674
Select_Lex *sel= lex->current_select;
5675
if (sel->no_table_names_allowed)
5677
my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5678
MYF(0), $2.str, session->where);
5680
$$= (sel->parsing_place != IN_HAVING ||
5681
sel->get_in_sum_expr() > 0) ?
5682
(Item*) new Item_field(Lex->current_context(), NULL, $2.str, $4.str) :
5683
(Item*) new Item_ref(Lex->current_context(),
5684
(const char *)NULL, $2.str, $4.str);
4856
5686
| ident '.' ident '.' ident
4858
$$= parser::buildIdent(Lex, $1, $3, $5);
5688
Session *session= YYSession;
5689
LEX *lex= session->lex;
5690
Select_Lex *sel= lex->current_select;
5691
if (sel->no_table_names_allowed)
5693
my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
5694
MYF(0), $3.str, session->where);
5696
$$= (sel->parsing_place != IN_HAVING ||
5697
sel->get_in_sum_expr() > 0) ?
5698
(Item*) new Item_field(Lex->current_context(), $1.str, $3.str,
5700
(Item*) new Item_ref(Lex->current_context(), $1.str, $3.str,
4867
5707
| ident '.' ident '.' ident
4869
if (not parser::checkFieldIdent(Lex, $1, $3))
5710
reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
5711
if (my_strcasecmp(table_alias_charset, $1.str, table->db))
5713
my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
5716
if (my_strcasecmp(table_alias_charset, $3.str,
5719
my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
4874
5724
| ident '.' ident
4876
if (not parser::checkFieldIdent(Lex, NULL_LEX_STRING, $1))
5727
reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
5728
if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
5730
my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);
4877
5731
DRIZZLE_YYABORT;
5735
| '.' ident { $$=$2;} /* For Delphi */
4890
$$= new Table_ident($1);
4892
| schema_name '.' ident
4894
$$=new Table_ident($1,$3);
4898
$$= new Table_ident($2);
5739
ident { $$=new Table_ident($1); }
5740
| ident '.' ident { $$=new Table_ident($1,$3);}
5741
| '.' ident { $$=new Table_ident($2);} /* For Delphi */
4917
5748
const CHARSET_INFO * const cs= system_charset_info;