~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Stewart Smith
  • Date: 2010-11-03 03:27:09 UTC
  • mto: (1902.1.1 build) (1910.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1903.
  • Revision ID: stewart@flamingspork.com-20101103032709-oyvfrc6eb8fzj0mr
fix docs warning: docs/unlock.rst:2: (WARNING/2) Title underline too short.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
16
/* sql_yacc.yy */
17
17
 
38
38
#define Lex (YYSession->lex)
39
39
 
40
40
#include "config.h"
 
41
#include <cstdio>
41
42
#include "drizzled/parser.h"
42
43
 
43
44
int yylex(void *yylval, void *yysession);
66
67
#define DRIZZLE_YYABORT_UNLESS(A)         \
67
68
  if (!(A))                             \
68
69
  {                                     \
69
 
    my_parse_error(ER(ER_SYNTAX_ERROR));\
 
70
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };\
 
71
    my_parse_error(&pass);\
70
72
    DRIZZLE_YYABORT;                      \
71
73
  }
72
74
 
101
103
  parser.
102
104
*/
103
105
 
104
 
static void my_parse_error(const char *s)
 
106
struct my_parse_error_st {
 
107
  const char *s;
 
108
  Session *session;
 
109
};
 
110
 
 
111
static void my_parse_error(void *arg)
105
112
{
106
 
  Session *session= current_session;
 
113
 struct my_parse_error_st *ptr= (struct my_parse_error_st *)arg;
 
114
 
 
115
  const char *s= ptr->s;
 
116
  Session *session= ptr->session;
 
117
 
107
118
  Lex_input_stream *lip= session->m_lip;
108
119
 
109
120
  const char *yytext= lip->get_tok_start();
147
158
  /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */
148
159
  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
149
160
    s= ER(ER_SYNTAX_ERROR);
150
 
  my_parse_error(s);
 
161
 
 
162
  struct my_parse_error_st pass= { s, session };
 
163
  my_parse_error(&pass);
151
164
}
152
165
 
153
166
/**
239
252
   @return <code>false</code> if successful, <code>true</code> if an error was
240
253
   reported. In the latter case parsing should stop.
241
254
 */
242
 
static bool add_select_to_union_list(LEX *lex, bool is_union_distinct)
 
255
static bool add_select_to_union_list(Session *session, LEX *lex, bool is_union_distinct)
243
256
{
244
257
  if (lex->result)
245
258
  {
249
262
  }
250
263
  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
251
264
  {
252
 
    my_parse_error(ER(ER_SYNTAX_ERROR));
 
265
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
 
266
    my_parse_error(&pass);
253
267
    return true;
254
268
  }
255
269
  /* This counter shouldn't be incremented for UNION parts */
271
285
   @return false if successful, true if an error was reported. In the latter
272
286
   case parsing should stop.
273
287
 */
274
 
static bool setup_select_in_parentheses(LEX *lex)
 
288
static bool setup_select_in_parentheses(Session *session, LEX *lex)
275
289
{
276
290
  Select_Lex * sel= lex->current_select;
277
291
  if (sel->set_braces(1))
278
292
  {
279
 
    my_parse_error(ER(ER_SYNTAX_ERROR));
 
293
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
 
294
    my_parse_error(&pass);
280
295
    return true;
281
296
  }
282
297
  if (sel->linkage == UNION_TYPE &&
284
299
      sel->master_unit()->first_select()->linkage ==
285
300
      UNION_TYPE)
286
301
  {
287
 
    my_parse_error(ER(ER_SYNTAX_ERROR));
 
302
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
 
303
    my_parse_error(&pass);
288
304
    return true;
289
305
  }
290
306
  if (sel->linkage == UNION_TYPE &&
301
317
  return false;
302
318
}
303
319
 
304
 
static Item* reserved_keyword_function(const std::string &name, List<Item> *item_list)
 
320
static Item* reserved_keyword_function(Session *session, const std::string &name, List<Item> *item_list)
305
321
{
306
322
  const plugin::Function *udf= plugin::Function::get(name.c_str(), name.length());
307
323
  Item *item= NULL;
308
324
 
309
325
  if (udf)
310
326
  {
311
 
    item= Create_udf_func::s_singleton.create(current_session, udf, item_list);
 
327
    item= Create_udf_func::s_singleton.create(session, udf, item_list);
312
328
  } else {
313
329
    my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", name.c_str());
314
330
  }
342
358
  enum drizzled::sql_var_t var_type;
343
359
  drizzled::Key::Keytype key_type;
344
360
  enum drizzled::ha_key_alg key_alg;
345
 
  enum drizzled::row_type row_type;
346
361
  enum drizzled::column_format_type column_format_type;
347
362
  enum drizzled::ha_rkey_function ha_rkey_mode;
348
363
  enum drizzled::enum_tx_isolation tx_isolation;
357
372
  enum drizzled::index_hint_type index_hint;
358
373
  enum drizzled::enum_filetype filetype;
359
374
  enum drizzled::ha_build_method build_method;
360
 
  enum drizzled::Foreign_key::fk_option m_fk_option;
 
375
  drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption m_fk_option;
361
376
}
362
377
 
363
378
%{
372
387
  Currently there are 88 shift/reduce conflicts.
373
388
  We should not introduce new conflicts any more.
374
389
*/
375
 
%expect 88
 
390
%expect 94
376
391
 
377
392
/*
378
393
   Comments for TOKENS.
417
432
%token  BIN_NUM
418
433
%token  BIT_SYM                       /* MYSQL-FUNC */
419
434
%token  BLOB_SYM                      /* SQL-2003-R */
420
 
%token  BLOCK_SIZE_SYM
421
 
%token  BLOCK_SYM
422
435
%token  BOOLEAN_SYM                   /* SQL-2003-R */
423
436
%token  BOOL_SYM
424
437
%token  BOTH                          /* SQL-2003-R */
508
521
%token  ESCAPED
509
522
%token  ESCAPE_SYM                    /* SQL-2003-R */
510
523
%token  EXCLUSIVE_SYM
 
524
%token  EXECUTE_SYM
511
525
%token  EXISTS                        /* SQL-2003-R */
512
526
%token  EXTENDED_SYM
513
527
%token  EXTRACT_SYM                   /* SQL-2003-N */
683
697
%token  SET_VAR
684
698
%token  SHARE_SYM
685
699
%token  SHOW
686
 
%token  SHUTDOWN
687
700
%token  SIMPLE_SYM                    /* SQL-2003-N */
688
701
%token  SNAPSHOT_SYM
689
702
%token  SPECIFIC_SYM                  /* SQL-2003-R */
790
803
        IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
791
804
        opt_component
792
805
        BIN_NUM TEXT_STRING_filesystem ident_or_empty
 
806
        execute_var_or_string
793
807
        opt_constraint constraint opt_ident
794
808
 
795
809
%type <lex_str_ptr>
873
887
 
874
888
%type <interval_time_st> interval_time_stamp
875
889
 
876
 
%type <row_type> row_types
877
 
 
878
890
%type <column_format_type> column_format_types
879
891
 
880
892
%type <tx_isolation> isolation_types
902
914
        insert_values update delete truncate rename
903
915
        show describe load alter flush
904
916
        begin commit rollback savepoint release
905
 
        analyze check start checksum
 
917
        analyze check start
906
918
        field_list field_list_item field_spec kill column_def key_def
907
919
        select_item_list select_item values_list no_braces
908
920
        opt_limit_clause delete_limit_clause fields opt_values values
923
935
        subselect_end select_var_list select_var_list_init opt_len
924
936
        opt_extended_describe
925
937
        statement
 
938
        execute
926
939
        opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
927
940
        init_key_options key_options key_opts key_opt key_using_alg
928
941
END_OF_INPUT
989
1002
          alter
990
1003
        | analyze
991
1004
        | check
992
 
        | checksum
993
1005
        | commit
994
1006
        | create
995
1007
        | delete
996
1008
        | describe
997
1009
        | drop
 
1010
        | execute
998
1011
        | flush
999
1012
        | insert
1000
1013
        | kill
1191
1204
opt_create_database_options:
1192
1205
          /* empty */ {}
1193
1206
        | default_collation_schema {}
 
1207
        | opt_database_custom_options {}
 
1208
        ;
 
1209
 
 
1210
opt_database_custom_options:
 
1211
        custom_database_option
 
1212
        | custom_database_option ',' opt_database_custom_options
 
1213
        ;
 
1214
 
 
1215
custom_database_option:
 
1216
          ident_or_text
 
1217
        {
 
1218
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1219
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1220
 
 
1221
          opt->set_name($1.str);
 
1222
        }
 
1223
        | ident_or_text equal ident_or_text
 
1224
        {
 
1225
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1226
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1227
 
 
1228
          opt->set_name($1.str);
 
1229
          opt->set_state($3.str);
 
1230
        }
 
1231
        | ident_or_text equal ulonglong_num
 
1232
        {
 
1233
          statement::CreateSchema *statement= (statement::CreateSchema *)Lex->statement;
 
1234
          char number_as_string[22];
 
1235
 
 
1236
          snprintf(number_as_string, sizeof(number_as_string), "%"PRIu64, $3);
 
1237
 
 
1238
          drizzled::message::Engine::Option *opt= statement->schema_message.mutable_engine()->add_options();
 
1239
 
 
1240
          opt->set_name($1.str);
 
1241
          opt->set_state(number_as_string);
 
1242
        }
1194
1243
        ;
1195
1244
 
1196
1245
opt_table_options:
1217
1266
          create_table_option
1218
1267
        | create_table_option     create_table_options
1219
1268
        | create_table_option ',' create_table_options
1220
 
        ;
1221
1269
 
1222
1270
create_table_option:
1223
 
          ENGINE_SYM opt_equal ident_or_text
 
1271
          custom_engine_option;
 
1272
 
 
1273
custom_engine_option:
 
1274
        ENGINE_SYM equal ident_or_text
1224
1275
          {
1225
1276
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1226
 
            message::Table::StorageEngine *protoengine;
1227
 
            protoengine= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine();
1228
1277
 
1229
1278
            statement->is_engine_set= true;
1230
1279
 
1231
 
            protoengine->set_name($3.str);
1232
 
          }
1233
 
        | BLOCK_SIZE_SYM opt_equal ulong_num
1234
 
          {
1235
 
            message::Table::TableOptions *tableopts;
1236
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1237
 
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
1238
 
 
1239
 
            tableopts->set_block_size($3);
1240
 
            statement->create_info.used_fields|= HA_CREATE_USED_BLOCK_SIZE;
 
1280
            ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->set_name($3.str);
1241
1281
          }
1242
1282
        | COMMENT_SYM opt_equal TEXT_STRING_sys
1243
1283
          {
1257
1297
            statement->create_info.used_fields|= HA_CREATE_USED_AUTO;
1258
1298
            tableopts->set_auto_increment_value($3);
1259
1299
          }
1260
 
        | ROW_FORMAT_SYM opt_equal row_types
1261
 
          {
1262
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1263
 
            message::Table::TableOptions *table_options= statement->createTableMessage().mutable_options();
1264
 
 
1265
 
            statement->create_info.row_type= $3;
1266
 
            statement->create_info.used_fields|= HA_CREATE_USED_ROW_FORMAT;
1267
 
            statement->alter_info.flags.set(ALTER_ROW_FORMAT);
1268
 
 
1269
 
            switch(statement->create_info.row_type)
1270
 
            {
1271
 
            case ROW_TYPE_DEFAULT:
1272
 
              /* No use setting a default row type... just adds redundant info to message */
1273
 
              break;
1274
 
            case ROW_TYPE_FIXED:
1275
 
              table_options->set_row_type(message::Table::TableOptions::ROW_TYPE_FIXED);
1276
 
              break;
1277
 
            case ROW_TYPE_DYNAMIC:
1278
 
              table_options->set_row_type(message::Table::TableOptions::ROW_TYPE_DYNAMIC);
1279
 
              break;
1280
 
            case ROW_TYPE_COMPRESSED:
1281
 
              table_options->set_row_type(message::Table::TableOptions::ROW_TYPE_COMPRESSED);
1282
 
              break;
1283
 
            case ROW_TYPE_REDUNDANT:
1284
 
              table_options->set_row_type(message::Table::TableOptions::ROW_TYPE_REDUNDANT);
1285
 
              break;
1286
 
            case ROW_TYPE_COMPACT:
1287
 
              table_options->set_row_type(message::Table::TableOptions::ROW_TYPE_COMPACT);
1288
 
              break;
1289
 
            case ROW_TYPE_PAGE:
1290
 
              table_options->set_row_type(message::Table::TableOptions::ROW_TYPE_PAGE);
1291
 
              break;
1292
 
            default:
1293
 
              abort();
1294
 
            }
 
1300
        |  ident_or_text equal ident_or_text
 
1301
          {
 
1302
            drizzled::message::Engine::Option *opt= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->add_options();
 
1303
 
 
1304
            opt->set_name($1.str);
 
1305
            opt->set_state($3.str);
 
1306
          }
 
1307
        | ident_or_text equal ulonglong_num
 
1308
          {
 
1309
            char number_as_string[22];
 
1310
            snprintf(number_as_string, sizeof(number_as_string), "%"PRIu64, $3);
 
1311
 
 
1312
            drizzled::message::Engine::Option *opt= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_engine()->add_options();
 
1313
            opt->set_name($1.str);
 
1314
            opt->set_state(number_as_string);
1295
1315
          }
1296
1316
        | default_collation
1297
 
        | KEY_BLOCK_SIZE opt_equal ulong_num
1298
 
          {
1299
 
            statement::CreateTable *statement= (statement::CreateTable *)Lex->statement;
1300
 
 
1301
 
            statement->create_info.used_fields|= HA_CREATE_USED_KEY_BLOCK_SIZE;
1302
 
 
1303
 
            message::Table::TableOptions *tableopts;
1304
 
            tableopts= ((statement::CreateTable *)Lex->statement)->create_table_message.mutable_options();
1305
 
            tableopts->set_key_block_size($3);
1306
 
          }
1307
1317
        ;
1308
1318
 
1309
1319
default_collation:
1340
1350
        | FIXED_SYM   { $$= COLUMN_FORMAT_TYPE_FIXED; }
1341
1351
        | DYNAMIC_SYM { $$= COLUMN_FORMAT_TYPE_DYNAMIC; };
1342
1352
 
1343
 
row_types:
1344
 
          DEFAULT        { $$= ROW_TYPE_DEFAULT; }
1345
 
        | FIXED_SYM      { $$= ROW_TYPE_FIXED; }
1346
 
        | DYNAMIC_SYM    { $$= ROW_TYPE_DYNAMIC; }
1347
 
        | COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; }
1348
 
        | REDUNDANT_SYM  { $$= ROW_TYPE_REDUNDANT; }
1349
 
        | COMPACT_SYM    { $$= ROW_TYPE_COMPACT; }
1350
 
        | PAGE_SYM       { $$= ROW_TYPE_PAGE; }
1351
 
        ;
1352
1353
 
1353
1354
opt_select_from:
1354
1355
          opt_limit_clause {}
1397
1398
          {
1398
1399
            LEX *lex=Lex;
1399
1400
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1400
 
            Key *key= new Foreign_key($4.str ? $4 : $1, lex->col_list,
 
1401
            Key *key= new Foreign_key($1.str ? $1 : $4, lex->col_list,
1401
1402
                                      $8,
1402
1403
                                      lex->ref_list,
1403
1404
                                      statement->fk_delete_opt,
1404
1405
                                      statement->fk_update_opt,
1405
1406
                                      statement->fk_match_option);
 
1407
 
1406
1408
            statement->alter_info.key_list.push_back(key);
1407
1409
            key= new Key(Key::MULTIPLE, $1.str ? $1 : $4,
1408
1410
                         &default_key_create_info, 1,
1947
1949
 
1948
1950
opt_match_clause:
1949
1951
          /* empty */
1950
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_UNDEF; }
 
1952
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_UNDEFINED; }
1951
1953
        | MATCH FULL
1952
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_FULL; }
 
1954
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_FULL; }
1953
1955
        | MATCH PARTIAL
1954
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_PARTIAL; }
 
1956
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_PARTIAL; }
1955
1957
        | MATCH SIMPLE_SYM
1956
 
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= Foreign_key::FK_MATCH_SIMPLE; }
 
1958
          { ((statement::CreateTable *)Lex->statement)->fk_match_option= drizzled::message::Table::ForeignKeyConstraint::MATCH_SIMPLE; }
1957
1959
        ;
1958
1960
 
1959
1961
opt_on_update_delete:
1960
1962
          /* empty */
1961
1963
          {
1962
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
1963
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
 
1964
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
 
1965
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
1964
1966
          }
1965
1967
        | ON UPDATE_SYM delete_option
1966
1968
          {
1967
1969
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= $3;
1968
 
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
 
1970
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
1969
1971
          }
1970
1972
        | ON DELETE_SYM delete_option
1971
1973
          {
1972
 
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
 
1974
            ((statement::CreateTable *)Lex->statement)->fk_update_opt= drizzled::message::Table::ForeignKeyConstraint::OPTION_UNDEF;
1973
1975
            ((statement::CreateTable *)Lex->statement)->fk_delete_opt= $3;
1974
1976
          }
1975
1977
        | ON UPDATE_SYM delete_option
1987
1989
        ;
1988
1990
 
1989
1991
delete_option:
1990
 
          RESTRICT      { $$= Foreign_key::FK_OPTION_RESTRICT; }
1991
 
        | CASCADE       { $$= Foreign_key::FK_OPTION_CASCADE; }
1992
 
        | SET NULL_SYM  { $$= Foreign_key::FK_OPTION_SET_NULL; }
1993
 
        | NO_SYM ACTION { $$= Foreign_key::FK_OPTION_NO_ACTION; }
1994
 
        | SET DEFAULT   { $$= Foreign_key::FK_OPTION_DEFAULT;  }
 
1992
          RESTRICT      { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_RESTRICT; }
 
1993
        | CASCADE       { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_CASCADE; }
 
1994
        | SET NULL_SYM  { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_NULL; }
 
1995
        | NO_SYM ACTION { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_NO_ACTION; }
 
1996
        | SET DEFAULT   { $$= drizzled::message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT;  }
1995
1997
        ;
1996
1998
 
1997
1999
key_type:
2123
2125
              DRIZZLE_YYABORT;
2124
2126
            lex->col_list.empty();
2125
2127
            lex->select_lex.init_order();
2126
 
            lex->select_lex.db=
2127
 
              ((TableList*) lex->select_lex.table_list.first)->db;
2128
 
            statement->create_info.row_type= ROW_TYPE_NOT_USED;
 
2128
            lex->select_lex.db= const_cast<char *>(((TableList*) lex->select_lex.table_list.first)->getSchemaName());
2129
2129
            statement->alter_info.build_method= $2;
2130
2130
          }
2131
2131
          alter_commands
2259
2259
        | DROP FOREIGN KEY_SYM opt_ident
2260
2260
          {
2261
2261
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
2262
 
 
 
2262
            statement->alter_info.drop_list.push_back(new AlterDrop(AlterDrop::FOREIGN_KEY,
 
2263
                                                                    $4.str));
2263
2264
            statement->alter_info.flags.set(ALTER_DROP_INDEX);
2264
2265
            statement->alter_info.flags.set(ALTER_FOREIGN_KEY);
2265
2266
          }
2413
2414
          }
2414
2415
        ;
2415
2416
 
2416
 
 
2417
 
checksum:
2418
 
          CHECKSUM_SYM table_or_tables
2419
 
          {
2420
 
            LEX *lex=Lex;
2421
 
            lex->sql_command = SQLCOM_CHECKSUM;
2422
 
            lex->statement= new(std::nothrow) statement::Checksum(YYSession);
2423
 
            if (lex->statement == NULL)
2424
 
              DRIZZLE_YYABORT;
2425
 
          }
2426
 
          table_list
2427
 
          {}
2428
 
        ;
2429
 
 
2430
 
 
2431
2417
analyze:
2432
2418
          ANALYZE_SYM table_or_tables
2433
2419
          {
2510
2496
select_paren:
2511
2497
          SELECT_SYM select_part2
2512
2498
          {
2513
 
            if (setup_select_in_parentheses(Lex))
 
2499
            if (setup_select_in_parentheses(YYSession, Lex))
2514
2500
              DRIZZLE_YYABORT;
2515
2501
          }
2516
2502
        | '(' select_paren ')'
2520
2506
select_paren_derived:
2521
2507
          SELECT_SYM select_part2_derived
2522
2508
          {
2523
 
            if (setup_select_in_parentheses(Lex))
 
2509
            if (setup_select_in_parentheses(YYSession, Lex))
2524
2510
              DRIZZLE_YYABORT;
2525
2511
          }
2526
2512
        | '(' select_paren_derived ')'
2533
2519
            Select_Lex * sel= lex->current_select;
2534
2520
            if (lex->current_select->set_braces(0))
2535
2521
            {
2536
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
2522
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
2523
              my_parse_error(&pass);
2537
2524
              DRIZZLE_YYABORT;
2538
2525
            }
2539
2526
            if (sel->linkage == UNION_TYPE &&
2540
2527
                sel->master_unit()->first_select()->braces)
2541
2528
            {
2542
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
2529
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
2530
              my_parse_error(&pass);
2543
2531
              DRIZZLE_YYABORT;
2544
2532
            }
2545
2533
          }
2890
2878
        | bit_expr '*' bit_expr %prec '*'
2891
2879
          { $$= new Item_func_mul($1,$3); }
2892
2880
        | bit_expr '/' bit_expr %prec '/'
2893
 
          { $$= new Item_func_div($1,$3); }
 
2881
          { $$= new Item_func_div(YYSession,$1,$3); }
2894
2882
        | bit_expr '%' bit_expr %prec '%'
2895
2883
          { $$= new Item_func_mod($1,$3); }
2896
2884
        | bit_expr DIV_SYM bit_expr %prec DIV_SYM
2943
2931
        | literal
2944
2932
        | variable
2945
2933
        | sum_expr
 
2934
          {
 
2935
            Lex->setSumExprUsed();
 
2936
          }
2946
2937
        | '+' simple_expr %prec NEG { $$= $2; }
2947
2938
        | '-' simple_expr %prec NEG
2948
2939
          { $$= new (YYSession->mem_root) Item_func_neg($2); }
3015
3006
        | CURRENT_USER optional_braces
3016
3007
          {
3017
3008
            std::string user_str("user");
3018
 
            if (! ($$= reserved_keyword_function(user_str, NULL)))
 
3009
            if (! ($$= reserved_keyword_function(YYSession, user_str, NULL)))
3019
3010
            {
3020
3011
              DRIZZLE_YYABORT;
3021
3012
            }
 
3013
            Lex->setCacheable(false);
3022
3014
          }
3023
3015
        | DATE_SYM '(' expr ')'
3024
3016
          { $$= new (YYSession->mem_root) Item_date_typecast($3); }
3027
3019
        | HOUR_SYM '(' expr ')'
3028
3020
          { $$= new (YYSession->mem_root) Item_func_hour($3); }
3029
3021
        | INSERT '(' expr ',' expr ',' expr ',' expr ')'
3030
 
          { $$= new (YYSession->mem_root) Item_func_insert($3,$5,$7,$9); }
 
3022
          { $$= new (YYSession->mem_root) Item_func_insert(*YYSession, $3, $5, $7, $9); }
3031
3023
        | INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
3032
3024
          {
3033
3025
            Session *session= YYSession;
3076
3068
        | USER '(' ')'
3077
3069
          {
3078
3070
            std::string user_str("user");
3079
 
            if (! ($$= reserved_keyword_function(user_str, NULL)))
 
3071
            if (! ($$= reserved_keyword_function(YYSession, user_str, NULL)))
3080
3072
            {
3081
3073
              DRIZZLE_YYABORT;
3082
3074
            }
 
3075
            Lex->setCacheable(false);
3083
3076
          }
3084
3077
        | YEAR_SYM '(' expr ')'
3085
3078
          { $$= new (YYSession->mem_root) Item_func_year($3); }
3107
3100
        | CURDATE optional_braces
3108
3101
          {
3109
3102
            $$= new (YYSession->mem_root) Item_func_curdate_local();
 
3103
            Lex->setCacheable(false);
3110
3104
          }
3111
3105
        | DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
3112
3106
          { $$= new (YYSession->mem_root) Item_date_add_interval($3,$6,$7,0); }
3117
3111
        | NOW_SYM optional_braces
3118
3112
          {
3119
3113
            $$= new (YYSession->mem_root) Item_func_now_local();
 
3114
            Lex->setCacheable(false);
3120
3115
          }
3121
3116
        | NOW_SYM '(' expr ')'
3122
3117
          {
3123
3118
            $$= new (YYSession->mem_root) Item_func_now_local($3);
 
3119
            Lex->setCacheable(false);
3124
3120
          }
3125
3121
        | POSITION_SYM '(' bit_expr IN_SYM expr ')'
3126
3122
          { $$ = new (YYSession->mem_root) Item_func_locate($5,$3); }
3138
3134
            args->push_back($3);
3139
3135
            args->push_back($5);
3140
3136
            args->push_back($7);
3141
 
            if (! ($$= reserved_keyword_function(reverse_str, args)))
 
3137
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
3142
3138
            {
3143
3139
              DRIZZLE_YYABORT;
3144
3140
            }
3149
3145
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3150
3146
            args->push_back($3);
3151
3147
            args->push_back($5);
3152
 
            if (! ($$= reserved_keyword_function(reverse_str, args)))
 
3148
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
3153
3149
            {
3154
3150
              DRIZZLE_YYABORT;
3155
3151
            }
3161
3157
            args->push_back($3);
3162
3158
            args->push_back($5);
3163
3159
            args->push_back($7);
3164
 
            if (! ($$= reserved_keyword_function(reverse_str, args)))
 
3160
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
3165
3161
            {
3166
3162
              DRIZZLE_YYABORT;
3167
3163
            }
3172
3168
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3173
3169
            args->push_back($3);
3174
3170
            args->push_back($5);
3175
 
            if (! ($$= reserved_keyword_function(reverse_str, args)))
 
3171
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
3176
3172
            {
3177
3173
              DRIZZLE_YYABORT;
3178
3174
            }
3179
3175
          }
3180
3176
        | SYSDATE optional_braces
3181
 
          { $$= new (YYSession->mem_root) Item_func_sysdate_local(); }
 
3177
          { 
 
3178
            $$= new (YYSession->mem_root) Item_func_sysdate_local(); 
 
3179
            Lex->setCacheable(false);
 
3180
          }
3182
3181
        | SYSDATE '(' expr ')'
3183
 
          { $$= new (YYSession->mem_root) Item_func_sysdate_local($3); }
 
3182
          { 
 
3183
            $$= new (YYSession->mem_root) Item_func_sysdate_local($3); 
 
3184
            Lex->setCacheable(false);
 
3185
          }
3184
3186
        | TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
3185
3187
          { $$= new (YYSession->mem_root) Item_date_add_interval($7,$5,$3,0); }
3186
3188
        | TIMESTAMP_DIFF '(' interval_time_stamp ',' expr ',' expr ')'
3188
3190
        | UTC_DATE_SYM optional_braces
3189
3191
          {
3190
3192
            $$= new (YYSession->mem_root) Item_func_curdate_utc();
 
3193
            Lex->setCacheable(false);
3191
3194
          }
3192
3195
        | UTC_TIMESTAMP_SYM optional_braces
3193
3196
          {
3194
3197
            $$= new (YYSession->mem_root) Item_func_now_utc();
 
3198
            Lex->setCacheable(false);
3195
3199
          }
3196
3200
        ;
3197
3201
 
3208
3212
        | DATABASE '(' ')'
3209
3213
          {
3210
3214
            std::string database_str("database");
3211
 
            if (! ($$= reserved_keyword_function(database_str, NULL)))
 
3215
            if (! ($$= reserved_keyword_function(YYSession, database_str, NULL)))
3212
3216
            {
3213
3217
              DRIZZLE_YYABORT;
3214
3218
            }
 
3219
            Lex->setCacheable(false);
3215
3220
          }
3216
3221
        | IF '(' expr ',' expr ',' expr ')'
3217
3222
          { $$= new (YYSession->mem_root) Item_func_if($3,$5,$7); }
3222
3227
        | QUARTER_SYM '(' expr ')'
3223
3228
          { $$ = new (YYSession->mem_root) Item_func_quarter($3); }
3224
3229
        | REPEAT_SYM '(' expr ',' expr ')'
3225
 
          { $$= new (YYSession->mem_root) Item_func_repeat($3,$5); }
 
3230
          { $$= new (YYSession->mem_root) Item_func_repeat(*YYSession, $3, $5); }
3226
3231
        | REPLACE '(' expr ',' expr ',' expr ')'
3227
 
          { $$= new (YYSession->mem_root) Item_func_replace($3,$5,$7); }
 
3232
          { $$= new (YYSession->mem_root) Item_func_replace(*YYSession, $3, $5, $7); }
3228
3233
        | REVERSE_SYM '(' expr ')'
3229
3234
          {
3230
3235
            std::string reverse_str("reverse");
3231
3236
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3232
3237
            args->push_back($3);
3233
 
            if (! ($$= reserved_keyword_function(reverse_str, args)))
 
3238
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
3234
3239
            {
3235
3240
              DRIZZLE_YYABORT;
3236
3241
            }
3292
3297
            {
3293
3298
              DRIZZLE_YYABORT;
3294
3299
            }
 
3300
            Lex->setCacheable(false);
3295
3301
          }
3296
3302
        ;
3297
3303
 
3400
3406
          ident_or_text SET_VAR expr
3401
3407
          {
3402
3408
            $$= new Item_func_set_user_var($1, $3);
 
3409
            Lex->setCacheable(false);
3403
3410
          }
3404
3411
        | ident_or_text
3405
3412
          {
3406
 
            $$= new Item_func_get_user_var($1);
 
3413
            $$= new Item_func_get_user_var(*YYSession, $1);
 
3414
            Lex->setCacheable(false);
3407
3415
          }
3408
3416
        | '@' opt_var_ident_type ident_or_text opt_component
3409
3417
          {
3410
3418
            /* disallow "SELECT @@global.global.variable" */
3411
3419
            if ($3.str && $4.str && check_reserved_words(&$3))
3412
3420
            {
3413
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
3421
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3422
              my_parse_error(&pass);
3414
3423
              DRIZZLE_YYABORT;
3415
3424
            }
3416
3425
            if (!($$= get_system_var(YYSession, $2, $3, $4)))
3452
3461
            LEX *lex= Lex;
3453
3462
            if (lex->current_select->inc_in_sum_expr())
3454
3463
            {
3455
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
3464
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3465
              my_parse_error(&pass);
3456
3466
              DRIZZLE_YYABORT;
3457
3467
            }
3458
3468
          }
3567
3577
            left-associative joins.
3568
3578
          */
3569
3579
          table_ref normal_join table_ref %prec TABLE_REF_PRIORITY
3570
 
          { DRIZZLE_YYABORT_UNLESS($1 && ($$=$3)); }
 
3580
          { 
 
3581
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$3));
 
3582
            Lex->is_cross= false;
 
3583
          }
3571
3584
        | table_ref STRAIGHT_JOIN table_factor
3572
 
          { DRIZZLE_YYABORT_UNLESS($1 && ($$=$3)); $3->straight=1; }
 
3585
          { 
 
3586
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$3)); $3->straight=1; 
 
3587
          }
3573
3588
        | table_ref normal_join table_ref
3574
3589
          ON
3575
3590
          {
3576
3591
            DRIZZLE_YYABORT_UNLESS($1 && $3);
 
3592
            DRIZZLE_YYABORT_UNLESS( not Lex->is_cross );
3577
3593
            /* Change the current name resolution context to a local context. */
3578
3594
            if (push_new_name_resolution_context(YYSession, $1, $3))
3579
3595
              DRIZZLE_YYABORT;
3693
3709
normal_join:
3694
3710
          JOIN_SYM {}
3695
3711
        | INNER_SYM JOIN_SYM {}
3696
 
        | CROSS JOIN_SYM {}
 
3712
        | CROSS JOIN_SYM { Lex->is_cross= true; }
3697
3713
        ;
3698
3714
 
3699
3715
/*
3706
3722
/* Warning - may return NULL in case of incomplete SELECT */
3707
3723
table_factor:
3708
3724
          {
3709
 
            Select_Lex *sel= Lex->current_select;
3710
 
            sel->table_join_options= 0;
3711
3725
          }
3712
3726
          table_ident opt_table_alias opt_key_definition
3713
3727
          {
3714
3728
            if (!($$= Lex->current_select->add_table_to_list(YYSession, $2, $3,
3715
 
                             Lex->current_select->get_table_join_options(),
 
3729
                             0,
3716
3730
                             Lex->lock_option,
3717
3731
                             Lex->current_select->pop_index_hints())))
3718
3732
              DRIZZLE_YYABORT;
3726
3740
            {
3727
3741
              if (sel->set_braces(1))
3728
3742
              {
3729
 
                my_parse_error(ER(ER_SYNTAX_ERROR));
 
3743
                struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3744
                my_parse_error(&pass);
3730
3745
                DRIZZLE_YYABORT;
3731
3746
              }
3732
3747
              /* select in braces, can't contain global parameters */
3763
3778
            /* Use $2 instead of Lex->current_select as derived table will
3764
3779
               alter value of Lex->current_select. */
3765
3780
            if (!($3 || $5) && $2->embedding &&
3766
 
                !$2->embedding->nested_join->join_list.elements)
 
3781
                !$2->embedding->getNestedJoin()->join_list.elements)
3767
3782
            {
3768
3783
              /* we have a derived table ($3 == NULL) but no alias,
3769
3784
                 Since we are nested in further parentheses so we
3791
3806
            else if (($3->select_lex && $3->select_lex->master_unit()->is_union()) || $5)
3792
3807
            {
3793
3808
              /* simple nested joins cannot have aliases or unions */
3794
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
3809
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3810
              my_parse_error(&pass);
3795
3811
              DRIZZLE_YYABORT;
3796
3812
            }
3797
3813
            else
3805
3821
          UNION_SYM
3806
3822
          union_option
3807
3823
          {
3808
 
            if (add_select_to_union_list(Lex, (bool)$3))
 
3824
            if (add_select_to_union_list(YYSession, Lex, (bool)$3))
3809
3825
              DRIZZLE_YYABORT;
3810
3826
          }
3811
3827
          query_specification
3827
3843
            Select_Lex * sel= lex->current_select;
3828
3844
            if (lex->current_select->set_braces(0))
3829
3845
            {
3830
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
3846
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3847
              my_parse_error(&pass);
3831
3848
              DRIZZLE_YYABORT;
3832
3849
            }
3833
3850
            if (sel->linkage == UNION_TYPE &&
3834
3851
                sel->master_unit()->first_select()->braces)
3835
3852
            {
3836
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
3853
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3854
              my_parse_error(&pass);
3837
3855
              DRIZZLE_YYABORT;
3838
3856
            }
3839
3857
          }
3873
3891
              DRIZZLE_YYABORT;
3874
3892
            if (!$3 && $$)
3875
3893
            {
3876
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
3894
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3895
              my_parse_error(&pass);
3877
3896
              DRIZZLE_YYABORT;
3878
3897
            }
3879
3898
          }
3885
3904
            lex->derived_tables|= DERIVED_SUBQUERY;
3886
3905
            if (!lex->expr_allows_subselect)
3887
3906
            {
3888
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
3907
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3908
              my_parse_error(&pass);
3889
3909
              DRIZZLE_YYABORT;
3890
3910
            }
3891
3911
            if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE ||
3916
3936
            if (!sel->embedding || sel->end_nested_join(lex->session))
3917
3937
            {
3918
3938
              /* we are not in parentheses */
3919
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
3939
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3940
              my_parse_error(&pass);
3920
3941
              DRIZZLE_YYABORT;
3921
3942
            }
3922
3943
            embedding= Lex->current_select->embedding;
3923
3944
            $$= embedding &&
3924
 
                !embedding->nested_join->join_list.elements;
 
3945
                !embedding->getNestedJoin()->join_list.elements;
3925
3946
            /* return true if we are deeply nested */
3926
3947
          }
3927
3948
        ;
4356
4377
          OUTFILE TEXT_STRING_filesystem
4357
4378
          {
4358
4379
            LEX *lex= Lex;
 
4380
            lex->setCacheable(false);
4359
4381
            if (!(lex->exchange= new file_exchange($2.str, 0)) ||
4360
4382
                !(lex->result= new select_export(lex->exchange)))
4361
4383
              DRIZZLE_YYABORT;
4366
4388
            LEX *lex=Lex;
4367
4389
            if (!lex->describe)
4368
4390
            {
 
4391
              lex->setCacheable(false);
4369
4392
              if (!(lex->exchange= new file_exchange($2.str,1)))
4370
4393
                DRIZZLE_YYABORT;
4371
4394
              if (!(lex->result= new select_dump(lex->exchange)))
4373
4396
            }
4374
4397
          }
4375
4398
        | select_var_list_init
4376
 
          { }
 
4399
          {Lex->setCacheable(false);}
4377
4400
        ;
4378
4401
 
4379
4402
/*
4440
4463
          /* empty */ { $$= 0; }
4441
4464
        | TEMPORARY_SYM { $$= 1; }
4442
4465
        ;
 
4466
 
 
4467
/*
 
4468
  Execute a string as dynamic SQL.
 
4469
  */
 
4470
 
 
4471
execute:
 
4472
       EXECUTE_SYM execute_var_or_string
 
4473
       {
 
4474
       }
 
4475
 
 
4476
 
 
4477
execute_var_or_string:
 
4478
         ident_or_text
 
4479
         {
 
4480
            LEX *lex= Lex;
 
4481
            statement::Execute *statement= new(std::nothrow) statement::Execute(YYSession);
 
4482
            lex->statement= statement;
 
4483
            if (lex->statement == NULL)
 
4484
              DRIZZLE_YYABORT;
 
4485
 
 
4486
            statement->setQuery($1);
 
4487
         }
 
4488
        | '@' ident_or_text
 
4489
        {
 
4490
          LEX *lex= Lex;
 
4491
          statement::Execute *statement= new(std::nothrow) statement::Execute(YYSession);
 
4492
          lex->statement= statement;
 
4493
          if (lex->statement == NULL)
 
4494
            DRIZZLE_YYABORT;
 
4495
 
 
4496
          statement->setVar();
 
4497
          statement->setQuery($2);
 
4498
        }
 
4499
 
4443
4500
/*
4444
4501
** Insert : add new data to table
4445
4502
*/
4738
4795
          {}
4739
4796
        ;
4740
4797
 
 
4798
/* SHOW SCHEMAS */
4741
4799
show_param:
4742
4800
           DATABASES show_wild
4743
4801
           {
4746
4804
 
4747
4805
             lex->sql_command= SQLCOM_SELECT;
4748
4806
             lex->statement=
4749
 
               new(std::nothrow) statement::Select(session);
 
4807
               new(std::nothrow) statement::Show(session);
4750
4808
             if (lex->statement == NULL)
4751
4809
               DRIZZLE_YYABORT;
4752
4810
 
4775
4833
 
4776
4834
             if (session->add_item_to_list(my_field))
4777
4835
               DRIZZLE_YYABORT;
 
4836
 
 
4837
              if (session->add_order_to_list(my_field, true))
 
4838
                DRIZZLE_YYABORT;
4778
4839
           }
 
4840
           /* SHOW TABLES */
4779
4841
         | TABLES opt_db show_wild
4780
4842
           {
4781
4843
             LEX *lex= Lex;
4783
4845
 
4784
4846
             lex->sql_command= SQLCOM_SELECT;
4785
4847
 
4786
 
             statement::Select *select=
4787
 
               new(std::nothrow) statement::Select(YYSession);
 
4848
             statement::Show *select=
 
4849
               new(std::nothrow) statement::Show(YYSession);
4788
4850
 
4789
4851
             lex->statement= select;
4790
4852
 
4832
4894
 
4833
4895
             if (session->add_item_to_list(my_field))
4834
4896
               DRIZZLE_YYABORT;
 
4897
 
 
4898
              if (session->add_order_to_list(my_field, true))
 
4899
                DRIZZLE_YYABORT;
4835
4900
           }
 
4901
           /* SHOW TEMPORARY TABLES */
4836
4902
         | TEMPORARY_SYM TABLES show_wild
4837
4903
           {
4838
4904
             LEX *lex= Lex;
4840
4906
 
4841
4907
             lex->sql_command= SQLCOM_SELECT;
4842
4908
 
4843
 
             statement::Select *select=
4844
 
               new(std::nothrow) statement::Select(YYSession);
 
4909
             statement::Show *select=
 
4910
               new(std::nothrow) statement::Show(YYSession);
4845
4911
 
4846
4912
             lex->statement= select;
4847
4913
 
4859
4925
             (session->lex->current_select->with_wild)++;
4860
4926
 
4861
4927
           }
 
4928
           /* SHOW TABLE STATUS */
4862
4929
         | TABLE_SYM STATUS_SYM opt_db show_wild
4863
4930
           {
4864
4931
             LEX *lex= Lex;
4865
4932
             lex->sql_command= SQLCOM_SELECT;
4866
 
             statement::Select *select=
4867
 
               new(std::nothrow) statement::Select(YYSession);
 
4933
             statement::Show *select=
 
4934
               new(std::nothrow) statement::Show(YYSession);
4868
4935
 
4869
4936
             lex->statement= select;
4870
4937
 
4901
4968
               DRIZZLE_YYABORT;
4902
4969
             (session->lex->current_select->with_wild)++;
4903
4970
           }
 
4971
           /* SHOW COLUMNS FROM table_name */
4904
4972
        | COLUMNS from_or_in table_ident opt_db show_wild
4905
4973
          {
4906
4974
             LEX *lex= Lex;
4907
4975
             Session *session= YYSession;
4908
 
             statement::Select *select;
 
4976
             statement::Show *select;
4909
4977
 
4910
4978
             lex->sql_command= SQLCOM_SELECT;
4911
4979
 
4912
 
             select= new(std::nothrow) statement::Select(session);
 
4980
             select= new(std::nothrow) statement::Show(session);
4913
4981
 
4914
4982
             lex->statement= select;
4915
4983
 
4943
5011
             (session->lex->current_select->with_wild)++;
4944
5012
 
4945
5013
          }
 
5014
          /* SHOW INDEXES from table */
4946
5015
        | keys_or_index from_or_in table_ident opt_db where_clause
4947
5016
          {
4948
5017
             LEX *lex= Lex;
4949
5018
             Session *session= YYSession;
4950
 
             statement::Select *select;
 
5019
             statement::Show *select;
4951
5020
 
4952
5021
             lex->sql_command= SQLCOM_SELECT;
4953
5022
 
4954
 
             select= new(std::nothrow) statement::Select(session);
 
5023
             select= new(std::nothrow) statement::Show(session);
4955
5024
 
4956
5025
             lex->statement= select;
4957
5026
 
4988
5057
          {
4989
5058
            (void) create_select_for_variable("warning_count");
4990
5059
            LEX *lex= Lex;
4991
 
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
5060
            lex->statement= new(std::nothrow) statement::Show(YYSession);
4992
5061
            if (lex->statement == NULL)
4993
5062
              DRIZZLE_YYABORT;
4994
5063
          }
4996
5065
          {
4997
5066
            (void) create_select_for_variable("error_count");
4998
5067
            LEX *lex= Lex;
4999
 
            lex->statement= new(std::nothrow) statement::Select(YYSession);
 
5068
            lex->statement= new(std::nothrow) statement::Show(YYSession);
5000
5069
            if (lex->statement == NULL)
5001
5070
              DRIZZLE_YYABORT;
5002
5071
          }
5019
5088
             LEX *lex= Lex;
5020
5089
             lex->sql_command= SQLCOM_SELECT;
5021
5090
             lex->statement=
5022
 
               new(std::nothrow) statement::Select(YYSession);
 
5091
               new(std::nothrow) statement::Show(YYSession);
5023
5092
             if (lex->statement == NULL)
5024
5093
               DRIZZLE_YYABORT;
5025
5094
 
5053
5122
             if (session->add_item_to_list(my_field))
5054
5123
               DRIZZLE_YYABORT;
5055
5124
           }
 
5125
        | CREATE TABLE_SYM table_ident
 
5126
           {
 
5127
             LEX *lex= Lex;
 
5128
             lex->sql_command= SQLCOM_SELECT;
 
5129
             statement::Show *select=
 
5130
               new(std::nothrow) statement::Show(YYSession);
 
5131
 
 
5132
             lex->statement= select;
 
5133
 
 
5134
             if (lex->statement == NULL)
 
5135
               DRIZZLE_YYABORT;
 
5136
 
 
5137
             Session *session= YYSession;
 
5138
 
 
5139
             if (prepare_new_schema_table(session, lex, "TABLE_SQL_DEFINITION"))
 
5140
               DRIZZLE_YYABORT;
 
5141
 
 
5142
             if ($3->db.str)
 
5143
              select->setShowPredicate($3->db.str, $3->table.str);
 
5144
             else
 
5145
              select->setShowPredicate(session->db, $3->table.str);
 
5146
 
 
5147
             std::string key("Table");
 
5148
             std::string value("Create Table");
 
5149
 
 
5150
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
 
5151
             my_field->is_autogenerated_name= false;
 
5152
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5153
 
 
5154
             if (session->add_item_to_list(my_field))
 
5155
               DRIZZLE_YYABORT;
 
5156
 
 
5157
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
 
5158
             my_field->is_autogenerated_name= false;
 
5159
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5160
 
 
5161
             if (session->add_item_to_list(my_field))
 
5162
               DRIZZLE_YYABORT;
 
5163
           }
5056
5164
        | PROCESSLIST_SYM
5057
5165
          {
5058
5166
           {
5059
5167
             LEX *lex= Lex;
5060
5168
             lex->sql_command= SQLCOM_SELECT;
5061
5169
             lex->statement=
5062
 
               new(std::nothrow) statement::Select(YYSession);
 
5170
               new(std::nothrow) statement::Show(YYSession);
5063
5171
             if (lex->statement == NULL)
5064
5172
               DRIZZLE_YYABORT;
5065
5173
 
5080
5188
             LEX *lex= Lex;
5081
5189
             lex->sql_command= SQLCOM_SELECT;
5082
5190
             lex->statement=
5083
 
               new(std::nothrow) statement::Select(YYSession);
 
5191
               new(std::nothrow) statement::Show(YYSession);
5084
5192
             if (lex->statement == NULL)
5085
5193
               DRIZZLE_YYABORT;
5086
5194
 
5115
5223
               DRIZZLE_YYABORT;
5116
5224
           }
5117
5225
        | CREATE DATABASE opt_if_not_exists ident
5118
 
          {
5119
 
            Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
5120
 
            statement::ShowCreateSchema *statement= new(std::nothrow) statement::ShowCreateSchema(YYSession);
5121
 
            Lex->statement= statement;
5122
 
            if (Lex->statement == NULL)
5123
 
              DRIZZLE_YYABORT;
5124
 
            statement->is_if_not_exists= $3;
5125
 
            Lex->name= $4;
5126
 
          }
5127
 
        | CREATE TABLE_SYM table_ident
5128
 
          {
5129
 
            LEX *lex= Lex;
5130
 
            lex->sql_command = SQLCOM_SHOW_CREATE;
5131
 
            lex->statement= new(std::nothrow) statement::ShowCreate(YYSession);
5132
 
            if (lex->statement == NULL)
5133
 
              DRIZZLE_YYABORT;
5134
 
            if (!lex->select_lex.add_table_to_list(YYSession, $3, NULL,0))
5135
 
              DRIZZLE_YYABORT;
5136
 
          }
 
5226
           {
 
5227
             LEX *lex= Lex;
 
5228
             lex->sql_command= SQLCOM_SELECT;
 
5229
             statement::Show *select=
 
5230
               new(std::nothrow) statement::Show(YYSession);
 
5231
 
 
5232
             lex->statement= select;
 
5233
 
 
5234
             if (lex->statement == NULL)
 
5235
               DRIZZLE_YYABORT;
 
5236
 
 
5237
             Session *session= YYSession;
 
5238
 
 
5239
             if (prepare_new_schema_table(session, lex, "SCHEMA_SQL_DEFINITION"))
 
5240
               DRIZZLE_YYABORT;
 
5241
 
 
5242
             if ($4.str)
 
5243
              select->setShowPredicate($4.str);
 
5244
             else
 
5245
              select->setShowPredicate(session->db);
 
5246
 
 
5247
             std::string key("Database");
 
5248
             std::string value("Create Database");
 
5249
 
 
5250
             Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
 
5251
             my_field->is_autogenerated_name= false;
 
5252
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
 
5253
 
 
5254
             if (session->add_item_to_list(my_field))
 
5255
               DRIZZLE_YYABORT;
 
5256
 
 
5257
             my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
 
5258
             my_field->is_autogenerated_name= false;
 
5259
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
 
5260
 
 
5261
             if (session->add_item_to_list(my_field))
 
5262
               DRIZZLE_YYABORT;
 
5263
           }
5137
5264
 
5138
5265
opt_db:
5139
5266
          /* empty */  { $$= 0; }
5167
5294
          describe_command table_ident
5168
5295
          {
5169
5296
            Session *session= YYSession;
5170
 
            statement::Select *select;
 
5297
            statement::Show *select;
5171
5298
            LEX *lex= Lex;
5172
5299
            lex->lock_option= TL_READ;
5173
5300
            mysql_init_select(lex);
5174
5301
            lex->current_select->parsing_place= SELECT_LIST;
5175
5302
            lex->sql_command= SQLCOM_SELECT;
5176
 
            select= new(std::nothrow) statement::Select(session);
 
5303
            select= new(std::nothrow) statement::Show(session);
5177
5304
            lex->statement= select;
5178
5305
            if (lex->statement == NULL)
5179
5306
              DRIZZLE_YYABORT;
5703
5830
          {
5704
5831
            TableList *table=
5705
5832
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
5706
 
            if (my_strcasecmp(table_alias_charset, $1.str, table->db))
 
5833
            if (my_strcasecmp(table_alias_charset, $1.str, table->getSchemaName()))
5707
5834
            {
5708
5835
              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
5709
5836
              DRIZZLE_YYABORT;
5710
5837
            }
5711
5838
            if (my_strcasecmp(table_alias_charset, $3.str,
5712
 
                              table->table_name))
 
5839
                              table->getTableName()))
5713
5840
            {
5714
5841
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str);
5715
5842
              DRIZZLE_YYABORT;
5833
5960
        | AVG_ROW_LENGTH           {}
5834
5961
        | AVG_SYM                  {}
5835
5962
        | BIT_SYM                  {}
5836
 
        | BLOCK_SIZE_SYM           {}
5837
 
        | BLOCK_SYM                {}
5838
5963
        | BOOL_SYM                 {}
5839
5964
        | BOOLEAN_SYM              {}
5840
5965
        | BTREE_SYM                {}
5936
6061
        | SESSION_SYM              {}
5937
6062
        | SIMPLE_SYM               {}
5938
6063
        | SHARE_SYM                {}
5939
 
        | SHUTDOWN                 {}
5940
6064
        | SNAPSHOT_SYM             {}
5941
6065
        | SQL_BUFFER_RESULT        {}
5942
6066
        | STATUS_SYM               {}
6234
6358
union_list:
6235
6359
          UNION_SYM union_option
6236
6360
          {
6237
 
            if (add_select_to_union_list(Lex, (bool)$2))
 
6361
            if (add_select_to_union_list(YYSession, Lex, (bool)$2))
6238
6362
              DRIZZLE_YYABORT;
6239
6363
          }
6240
6364
          select_init
6304
6428
        | query_expression_body
6305
6429
          UNION_SYM union_option
6306
6430
          {
6307
 
            if (add_select_to_union_list(Lex, (bool)$3))
 
6431
            if (add_select_to_union_list(YYSession, Lex, (bool)$3))
6308
6432
              DRIZZLE_YYABORT;
6309
6433
          }
6310
6434
          query_specification
6327
6451
            LEX *lex=Lex;
6328
6452
            if (!lex->expr_allows_subselect)
6329
6453
            {
6330
 
              my_parse_error(ER(ER_SYNTAX_ERROR));
 
6454
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
6455
              my_parse_error(&pass);
6331
6456
              DRIZZLE_YYABORT;
6332
6457
            }
6333
6458
            /*