~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Brian Aker
  • Date: 2011-01-22 07:12:16 UTC
  • mfrom: (2096.1.16 alter-table)
  • Revision ID: brian@tangent.org-20110122071216-j0e8bwecb1cqefm9
Merge in work for parser cleanup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
#define DRIZZLE_YYABORT_UNLESS(A)         \
68
68
  if (!(A))                             \
69
69
  {                                     \
70
 
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };\
71
 
    my_parse_error(&pass);\
 
70
    parser::error_t pass= { ER(ER_SYNTAX_ERROR), YYSession };\
 
71
    parser::my_parse_error(pass);\
72
72
    DRIZZLE_YYABORT;                      \
73
73
  }
74
74
 
90
90
}
91
91
 
92
92
 
93
 
static bool check_reserved_words(LEX_STRING *name)
94
 
{
95
 
  if (!my_strcasecmp(system_charset_info, name->str, "GLOBAL") ||
96
 
      !my_strcasecmp(system_charset_info, name->str, "LOCAL") ||
97
 
      !my_strcasecmp(system_charset_info, name->str, "SESSION"))
98
 
    return true;
99
 
  return false;
100
 
}
101
 
 
102
 
/**
103
 
  @brief Push an error message into MySQL error stack with line
104
 
  and position information.
105
 
 
106
 
  This function provides semantic action implementers with a way
107
 
  to push the famous "You have a syntax error near..." error
108
 
  message into the error stack, which is normally produced only if
109
 
  a parse error is discovered internally by the Bison generated
110
 
  parser.
111
 
*/
112
 
 
113
 
struct my_parse_error_st {
114
 
  const char *s;
115
 
  Session *session;
116
 
};
117
 
 
118
 
static void my_parse_error(void *arg)
119
 
{
120
 
 struct my_parse_error_st *ptr= (struct my_parse_error_st *)arg;
121
 
 
122
 
  const char *s= ptr->s;
123
 
  Session *session= ptr->session;
124
 
 
125
 
  Lex_input_stream *lip= session->m_lip;
126
 
 
127
 
  const char *yytext= lip->get_tok_start();
128
 
  /* Push an error into the error stack */
129
 
  my_printf_error(ER_PARSE_ERROR,  ER(ER_PARSE_ERROR), MYF(0), s,
130
 
                  (yytext ? yytext : ""),
131
 
                  lip->yylineno);
132
 
}
133
 
 
134
93
/**
135
94
  @brief Bison callback to report a syntax/OOM error
136
95
 
146
105
 
147
106
  This function is not for use in semantic actions and is internal to
148
107
  the parser, as it performs some pre-return cleanup.
149
 
  In semantic actions, please use my_parse_error or my_error to
 
108
  In semantic actions, please use parser::my_parse_error or my_error to
150
109
  push an error into the error stack and DRIZZLE_YYABORT
151
110
  to abort from the parser.
152
111
*/
166
125
  if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0)
167
126
    s= ER(ER_SYNTAX_ERROR);
168
127
 
169
 
  struct my_parse_error_st pass= { s, session };
170
 
  my_parse_error(&pass);
171
 
}
172
 
 
173
 
/**
174
 
  Helper to resolve the SQL:2003 Syntax exception 1) in <in predicate>.
175
 
  See SQL:2003, Part 2, section 8.4 <in predicate>, Note 184, page 383.
176
 
  This function returns the proper item for the SQL expression
177
 
  <code>left [NOT] IN ( expr )</code>
178
 
  @param session the current thread
179
 
  @param left the in predicand
180
 
  @param equal true for IN predicates, false for NOT IN predicates
181
 
  @param expr first and only expression of the in value list
182
 
  @return an expression representing the IN predicate.
183
 
*/
184
 
static Item* handle_sql2003_note184_exception(Session *session,
185
 
                                              Item* left, bool equal,
186
 
                                              Item *expr)
187
 
{
188
 
  /*
189
 
    Relevant references for this issue:
190
 
    - SQL:2003, Part 2, section 8.4 <in predicate>, page 383,
191
 
    - SQL:2003, Part 2, section 7.2 <row value expression>, page 296,
192
 
    - SQL:2003, Part 2, section 6.3 <value expression primary>, page 174,
193
 
    - SQL:2003, Part 2, section 7.15 <subquery>, page 370,
194
 
    - SQL:2003 Feature F561, "Full value expressions".
195
 
 
196
 
    The exception in SQL:2003 Note 184 means:
197
 
    Item_singlerow_subselect, which corresponds to a <scalar subquery>,
198
 
    should be re-interpreted as an Item_in_subselect, which corresponds
199
 
    to a <table subquery> when used inside an <in predicate>.
200
 
 
201
 
    Our reading of Note 184 is reccursive, so that all:
202
 
    - IN (( <subquery> ))
203
 
    - IN ((( <subquery> )))
204
 
    - IN '('^N <subquery> ')'^N
205
 
    - etc
206
 
    should be interpreted as a <table subquery>, no matter how deep in the
207
 
    expression the <subquery> is.
208
 
  */
209
 
 
210
 
  Item *result;
211
 
 
212
 
  if (expr->type() == Item::SUBSELECT_ITEM)
213
 
  {
214
 
    Item_subselect *expr2 = (Item_subselect*) expr;
215
 
 
216
 
    if (expr2->substype() == Item_subselect::SINGLEROW_SUBS)
217
 
    {
218
 
      Item_singlerow_subselect *expr3 = (Item_singlerow_subselect*) expr2;
219
 
      Select_Lex *subselect;
220
 
 
221
 
      /*
222
 
        Implement the mandated change, by altering the semantic tree:
223
 
          left IN Item_singlerow_subselect(subselect)
224
 
        is modified to
225
 
          left IN (subselect)
226
 
        which is represented as
227
 
          Item_in_subselect(left, subselect)
228
 
      */
229
 
      subselect= expr3->invalidate_and_restore_select_lex();
230
 
      result= new (session->mem_root) Item_in_subselect(left, subselect);
231
 
 
232
 
      if (! equal)
233
 
        result = negate_expression(session, result);
234
 
 
235
 
      return(result);
236
 
    }
237
 
  }
238
 
 
239
 
  if (equal)
240
 
    result= new (session->mem_root) Item_func_eq(left, expr);
241
 
  else
242
 
    result= new (session->mem_root) Item_func_ne(left, expr);
243
 
 
244
 
  return(result);
245
 
}
246
 
 
247
 
/**
248
 
   @brief Creates a new Select_Lex for a UNION branch.
249
 
 
250
 
   Sets up and initializes a Select_Lex structure for a query once the parser
251
 
   discovers a UNION token. The current Select_Lex is pushed on the stack and
252
 
   the new Select_Lex becomes the current one..=
253
 
 
254
 
   @lex The parser state.
255
 
 
256
 
   @is_union_distinct True if the union preceding the new select statement
257
 
   uses UNION DISTINCT.
258
 
 
259
 
   @return <code>false</code> if successful, <code>true</code> if an error was
260
 
   reported. In the latter case parsing should stop.
261
 
 */
262
 
static bool add_select_to_union_list(Session *session, LEX *lex, bool is_union_distinct)
263
 
{
264
 
  if (lex->result)
265
 
  {
266
 
    /* Only the last SELECT can have  INTO...... */
267
 
    my_error(ER_WRONG_USAGE, MYF(0), "UNION", "INTO");
268
 
    return true;
269
 
  }
270
 
  if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
271
 
  {
272
 
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
273
 
    my_parse_error(&pass);
274
 
    return true;
275
 
  }
276
 
  /* This counter shouldn't be incremented for UNION parts */
277
 
  lex->nest_level--;
278
 
  if (new_select(lex, 0))
279
 
    return true;
280
 
  init_select(lex);
281
 
  lex->current_select->linkage=UNION_TYPE;
282
 
  if (is_union_distinct) /* UNION DISTINCT - remember position */
283
 
    lex->current_select->master_unit()->union_distinct=
284
 
      lex->current_select;
285
 
  return false;
286
 
}
287
 
 
288
 
/**
289
 
   @brief Initializes a Select_Lex for a query within parentheses (aka
290
 
   braces).
291
 
 
292
 
   @return false if successful, true if an error was reported. In the latter
293
 
   case parsing should stop.
294
 
 */
295
 
static bool setup_select_in_parentheses(Session *session, LEX *lex)
296
 
{
297
 
  Select_Lex * sel= lex->current_select;
298
 
  if (sel->set_braces(1))
299
 
  {
300
 
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
301
 
    my_parse_error(&pass);
302
 
    return true;
303
 
  }
304
 
  if (sel->linkage == UNION_TYPE &&
305
 
      !sel->master_unit()->first_select()->braces &&
306
 
      sel->master_unit()->first_select()->linkage ==
307
 
      UNION_TYPE)
308
 
  {
309
 
    struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), session };
310
 
    my_parse_error(&pass);
311
 
    return true;
312
 
  }
313
 
  if (sel->linkage == UNION_TYPE &&
314
 
      sel->olap != UNSPECIFIED_OLAP_TYPE &&
315
 
      sel->master_unit()->fake_select_lex)
316
 
  {
317
 
    my_error(ER_WRONG_USAGE, MYF(0), "CUBE/ROLLUP", "ORDER BY");
318
 
    return true;
319
 
  }
320
 
  /* select in braces, can't contain global parameters */
321
 
  if (sel->master_unit()->fake_select_lex)
322
 
    sel->master_unit()->global_parameters=
323
 
      sel->master_unit()->fake_select_lex;
324
 
  return false;
325
 
}
326
 
 
327
 
static Item* reserved_keyword_function(Session *session, const std::string &name, List<Item> *item_list)
328
 
{
329
 
  const plugin::Function *udf= plugin::Function::get(name.c_str(), name.length());
330
 
  Item *item= NULL;
331
 
 
332
 
  if (udf)
333
 
  {
334
 
    item= Create_udf_func::s_singleton.create(session, udf, item_list);
335
 
  } else {
336
 
    my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", name.c_str());
337
 
  }
338
 
 
339
 
  return item;
 
128
  parser::error_t pass= { s, session };
 
129
  parser::my_parse_error(pass);
340
130
}
341
131
 
342
132
} /* namespace drizzled; */
362
152
  drizzled::Key_part_spec *key_part;
363
153
  const drizzled::plugin::Function *udf;
364
154
  drizzled::TableList *table_list;
365
 
  enum drizzled::enum_field_types field_val;
366
 
  struct drizzled::sys_var_with_base variable;
367
 
  enum drizzled::sql_var_t var_type;
 
155
  drizzled::enum_field_types field_val;
 
156
  drizzled::sys_var_with_base variable;
 
157
  drizzled::sql_var_t var_type;
368
158
  drizzled::Key::Keytype key_type;
369
 
  enum drizzled::ha_key_alg key_alg;
370
 
  enum drizzled::ha_rkey_function ha_rkey_mode;
371
 
  enum drizzled::enum_tx_isolation tx_isolation;
372
 
  enum drizzled::Cast_target cast_type;
 
159
  drizzled::ha_key_alg key_alg;
 
160
  drizzled::ha_rkey_function ha_rkey_mode;
 
161
  drizzled::enum_tx_isolation tx_isolation;
 
162
  drizzled::Cast_target cast_type;
373
163
  const drizzled::CHARSET_INFO *charset;
374
164
  drizzled::thr_lock_type lock_type;
375
165
  drizzled::interval_type interval, interval_time_st;
376
166
  drizzled::type::timestamp_t date_time_type;
377
167
  drizzled::Select_Lex *select_lex;
378
168
  drizzled::chooser_compare_func_creator boolfunc2creator;
379
 
  struct drizzled::st_lex *lex;
380
 
  enum drizzled::index_hint_type index_hint;
381
 
  enum drizzled::enum_filetype filetype;
382
 
  enum drizzled::ha_build_method build_method;
 
169
  drizzled::st_lex *lex;
 
170
  drizzled::index_hint_type index_hint;
 
171
  drizzled::enum_filetype filetype;
 
172
  drizzled::ha_build_method build_method;
383
173
  drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption m_fk_option;
384
174
  drizzled::execute_string_t execute_string;
385
175
}
1062
852
        | CREATE opt_table_options TABLE_SYM opt_if_not_exists table_ident
1063
853
          {
1064
854
            Lex->sql_command= SQLCOM_CREATE_TABLE;
1065
 
            Lex->statement= new statement::CreateTable(YYSession);
 
855
            Lex->statement= new statement::CreateTable(YYSession, $5, $2);
1066
856
 
1067
857
            if (not Lex->select_lex.add_table_to_list(YYSession, $5, NULL,
1068
858
                                                     TL_OPTION_UPDATING,
1069
859
                                                     TL_WRITE))
1070
860
              DRIZZLE_YYABORT;
1071
861
            Lex->col_list.empty();
1072
 
 
1073
 
            Lex->table()->set_name($5->table.str);
1074
 
            if ($2)
1075
 
              Lex->table()->set_type(message::Table::TEMPORARY);
1076
 
            else
1077
 
              Lex->table()->set_type(message::Table::STANDARD);
1078
862
          }
1079
863
          create_table_definition
1080
864
          {
1694
1478
        | SERIAL_SYM
1695
1479
          {
1696
1480
            $$=DRIZZLE_TYPE_LONGLONG;
1697
 
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
 
1481
            Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG | UNSIGNED_FLAG);
1698
1482
 
1699
1483
            if (Lex->field())
1700
1484
            {
1701
 
              message::Table::Field::FieldConstraints *constraints;
1702
 
              constraints= Lex->field()->mutable_constraints();
1703
 
              constraints->set_is_notnull(true);
 
1485
              Lex->field()->mutable_constraints()->set_is_notnull(true);
 
1486
              Lex->field()->mutable_constraints()->set_is_unsigned(true);
1704
1487
 
1705
1488
              Lex->field()->set_type(message::Table::Field::BIGINT);
1706
1489
            }
1789
1572
          NULL_SYM
1790
1573
          {
1791
1574
            Lex->type&= ~ NOT_NULL_FLAG;
1792
 
 
1793
 
            if (Lex->field())
1794
 
            {
1795
 
              message::Table::Field::FieldConstraints *constraints;
1796
 
              constraints= Lex->field()->mutable_constraints();
1797
 
              constraints->set_is_notnull(false);
1798
 
            }
1799
1575
          }
1800
1576
        | not NULL_SYM
1801
1577
          {
1803
1579
 
1804
1580
            if (Lex->field())
1805
1581
            {
1806
 
              message::Table::Field::FieldConstraints *constraints;
1807
 
              constraints= Lex->field()->mutable_constraints();
1808
 
              constraints->set_is_notnull(true);
 
1582
              Lex->field()->mutable_constraints()->set_is_notnull(true);
1809
1583
            }
1810
1584
          }
1811
1585
        | DEFAULT now_or_signed_literal
1825
1599
 
1826
1600
            if (Lex->field())
1827
1601
            {
1828
 
              message::Table::Field::FieldConstraints *constraints;
1829
 
 
1830
 
              constraints= Lex->field()->mutable_constraints();
1831
 
              constraints->set_is_notnull(true);
 
1602
              Lex->field()->mutable_constraints()->set_is_notnull(true);
1832
1603
            }
1833
1604
          }
1834
1605
        | SERIAL_SYM DEFAULT VALUE_SYM
1835
1606
          {
1836
1607
            statement::AlterTable *statement= (statement::AlterTable *)Lex->statement;
1837
1608
 
1838
 
            Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
 
1609
            Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG | UNSIGNED_FLAG;
1839
1610
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
1840
1611
 
1841
1612
            if (Lex->field())
1842
1613
            {
1843
 
              message::Table::Field::FieldConstraints *constraints;
1844
 
              constraints= Lex->field()->mutable_constraints();
1845
 
              constraints->set_is_notnull(true);
 
1614
              Lex->field()->mutable_constraints()->set_is_notnull(true);
 
1615
              Lex->field()->mutable_constraints()->set_is_unsigned(true);
1846
1616
            }
1847
1617
          }
1848
1618
        | opt_primary KEY_SYM
1854
1624
 
1855
1625
            if (Lex->field())
1856
1626
            {
1857
 
              message::Table::Field::FieldConstraints *constraints;
1858
 
              constraints= Lex->field()->mutable_constraints();
1859
 
              constraints->set_is_notnull(true);
 
1627
              Lex->field()->mutable_constraints()->set_is_notnull(true);
1860
1628
            }
1861
1629
          }
1862
1630
        | UNIQUE_SYM
1865
1633
 
1866
1634
            Lex->type|= UNIQUE_FLAG;
1867
1635
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1636
 
 
1637
            if (Lex->field())
 
1638
            {
 
1639
              Lex->field()->mutable_constraints()->set_is_unique(true);
 
1640
            }
1868
1641
          }
1869
1642
        | UNIQUE_SYM KEY_SYM
1870
1643
          {
1872
1645
 
1873
1646
            Lex->type|= UNIQUE_KEY_FLAG;
1874
1647
            statement->alter_info.flags.set(ALTER_ADD_INDEX);
 
1648
 
 
1649
            if (Lex->field())
 
1650
            {
 
1651
              Lex->field()->mutable_constraints()->set_is_unique(true);
 
1652
            }
1875
1653
          }
1876
1654
        | COMMENT_SYM TEXT_STRING_sys
1877
1655
          {
2118
1896
alter:
2119
1897
          ALTER_SYM build_method opt_ignore TABLE_SYM table_ident
2120
1898
          {
2121
 
            Lex->sql_command= SQLCOM_ALTER_TABLE;
2122
 
            statement::AlterTable *statement= new statement::AlterTable(YYSession);
 
1899
            statement::AlterTable *statement= new statement::AlterTable(YYSession, $5, $2);
2123
1900
            Lex->statement= statement;
2124
1901
            Lex->duplicates= DUP_ERROR;
2125
 
            if (not Lex->select_lex.add_table_to_list(YYSession, $5, NULL,
2126
 
                                                     TL_OPTION_UPDATING))
 
1902
            if (not Lex->select_lex.add_table_to_list(YYSession, $5, NULL, TL_OPTION_UPDATING))
 
1903
            {
2127
1904
              DRIZZLE_YYABORT;
 
1905
            }
2128
1906
 
2129
1907
            Lex->col_list.empty();
2130
1908
            Lex->select_lex.init_order();
2131
1909
            Lex->select_lex.db= const_cast<char *>(((TableList*) Lex->select_lex.table_list.first)->getSchemaName());
2132
 
            statement->alter_info.build_method= $2;
2133
1910
          }
2134
1911
          alter_commands
2135
1912
          {}
2471
2248
select_paren:
2472
2249
          SELECT_SYM select_part2
2473
2250
          {
2474
 
            if (setup_select_in_parentheses(YYSession, Lex))
 
2251
            if (parser::setup_select_in_parentheses(YYSession, Lex))
2475
2252
              DRIZZLE_YYABORT;
2476
2253
          }
2477
2254
        | '(' select_paren ')'
2481
2258
select_paren_derived:
2482
2259
          SELECT_SYM select_part2_derived
2483
2260
          {
2484
 
            if (setup_select_in_parentheses(YYSession, Lex))
 
2261
            if (parser::setup_select_in_parentheses(YYSession, Lex))
2485
2262
              DRIZZLE_YYABORT;
2486
2263
          }
2487
2264
        | '(' select_paren_derived ')'
2493
2270
            Select_Lex * sel= Lex->current_select;
2494
2271
            if (Lex->current_select->set_braces(0))
2495
2272
            {
2496
 
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
2497
 
              my_parse_error(&pass);
 
2273
              parser::error_t pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
2274
              parser::my_parse_error(pass);
2498
2275
              DRIZZLE_YYABORT;
2499
2276
            }
2500
2277
            if (sel->linkage == UNION_TYPE &&
2501
2278
                sel->master_unit()->first_select()->braces)
2502
2279
            {
2503
 
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
2504
 
              my_parse_error(&pass);
 
2280
              parser::error_t pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
2281
              parser::my_parse_error(pass);
2505
2282
              DRIZZLE_YYABORT;
2506
2283
            }
2507
2284
          }
2836
2613
          }
2837
2614
        | bit_expr IN_SYM '(' expr ')'
2838
2615
          {
2839
 
            $$= handle_sql2003_note184_exception(YYSession, $1, true, $4);
 
2616
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, true, $4);
2840
2617
          }
2841
2618
        | bit_expr IN_SYM '(' expr ',' expr_list ')'
2842
2619
          {
2846
2623
          }
2847
2624
        | bit_expr not IN_SYM '(' expr ')'
2848
2625
          {
2849
 
            $$= handle_sql2003_note184_exception(YYSession, $1, false, $5);
 
2626
            $$= parser::handle_sql2003_note184_exception(YYSession, $1, false, $5);
2850
2627
          }
2851
2628
        | bit_expr not IN_SYM '(' expr ',' expr_list ')'
2852
2629
          {
2879
2656
            List<Item> *args= new (YYSession->mem_root) List<Item>;
2880
2657
            args->push_back($1);
2881
2658
            args->push_back($3);
2882
 
            if (! ($$= reserved_keyword_function(YYSession, "regex", args)))
 
2659
            if (! ($$= parser::reserved_keyword_function(YYSession, "regex", args)))
2883
2660
            {
2884
2661
              DRIZZLE_YYABORT;
2885
2662
            }
2890
2667
            args->push_back($1);
2891
2668
            args->push_back($4);
2892
2669
            args->push_back(new (YYSession->mem_root) Item_int(1));
2893
 
            if (! ($$= reserved_keyword_function(YYSession, "regex", args)))
 
2670
            if (! ($$= parser::reserved_keyword_function(YYSession, "regex", args)))
2894
2671
            {
2895
2672
              DRIZZLE_YYABORT;
2896
2673
            }
3036
2813
        | CURRENT_USER optional_braces
3037
2814
          {
3038
2815
            std::string user_str("user");
3039
 
            if (! ($$= reserved_keyword_function(YYSession, user_str, NULL)))
 
2816
            if (! ($$= parser::reserved_keyword_function(YYSession, user_str, NULL)))
3040
2817
            {
3041
2818
              DRIZZLE_YYABORT;
3042
2819
            }
3095
2872
          { $$= new (YYSession->mem_root) Item_func_trim($5,$3); }
3096
2873
        | USER '(' ')'
3097
2874
          {
3098
 
            if (! ($$= reserved_keyword_function(YYSession, "user", NULL)))
 
2875
            if (! ($$= parser::reserved_keyword_function(YYSession, "user", NULL)))
3099
2876
            {
3100
2877
              DRIZZLE_YYABORT;
3101
2878
            }
3161
2938
            args->push_back($3);
3162
2939
            args->push_back($5);
3163
2940
            args->push_back($7);
3164
 
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
 
2941
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
3165
2942
            {
3166
2943
              DRIZZLE_YYABORT;
3167
2944
            }
3172
2949
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3173
2950
            args->push_back($3);
3174
2951
            args->push_back($5);
3175
 
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
 
2952
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
3176
2953
            {
3177
2954
              DRIZZLE_YYABORT;
3178
2955
            }
3184
2961
            args->push_back($3);
3185
2962
            args->push_back($5);
3186
2963
            args->push_back($7);
3187
 
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
 
2964
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
3188
2965
            {
3189
2966
              DRIZZLE_YYABORT;
3190
2967
            }
3195
2972
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3196
2973
            args->push_back($3);
3197
2974
            args->push_back($5);
3198
 
            if (! ($$= reserved_keyword_function(YYSession, reverse_str, args)))
 
2975
            if (! ($$= parser::reserved_keyword_function(YYSession, reverse_str, args)))
3199
2976
            {
3200
2977
              DRIZZLE_YYABORT;
3201
2978
            }
3238
3015
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
3239
3016
        | DATABASE '(' ')'
3240
3017
          {
3241
 
            if (! ($$= reserved_keyword_function(YYSession, "database", NULL)))
 
3018
            if (! ($$= parser::reserved_keyword_function(YYSession, "database", NULL)))
3242
3019
            {
3243
3020
              DRIZZLE_YYABORT;
3244
3021
            }
3246
3023
          }
3247
3024
        | CATALOG_SYM '(' ')'
3248
3025
          {
3249
 
            if (! ($$= reserved_keyword_function(YYSession, "catalog", NULL)))
 
3026
            if (! ($$= parser::reserved_keyword_function(YYSession, "catalog", NULL)))
3250
3027
            {
3251
3028
              DRIZZLE_YYABORT;
3252
3029
            }
3262
3039
              args->push_back(new (YYSession->mem_root) Item_int(1));
3263
3040
            }
3264
3041
 
3265
 
            if (! ($$= reserved_keyword_function(YYSession, "execute", args)))
 
3042
            if (! ($$= parser::reserved_keyword_function(YYSession, "execute", args)))
3266
3043
            {
3267
3044
              DRIZZLE_YYABORT;
3268
3045
            }
3280
3057
              args->push_back(new (YYSession->mem_root) Item_uint(1));
3281
3058
            }
3282
3059
 
3283
 
            if (! ($$= reserved_keyword_function(YYSession, kill_str, args)))
 
3060
            if (! ($$= parser::reserved_keyword_function(YYSession, kill_str, args)))
3284
3061
            {
3285
3062
              DRIZZLE_YYABORT;
3286
3063
            }
3302
3079
            std::string wait_str("wait");
3303
3080
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3304
3081
            args->push_back($3);
3305
 
            if (! ($$= reserved_keyword_function(YYSession, wait_str, args)))
 
3082
            if (! ($$= parser::reserved_keyword_function(YYSession, wait_str, args)))
3306
3083
            {
3307
3084
              DRIZZLE_YYABORT;
3308
3085
            }
3309
3086
          }
3310
3087
        | UUID_SYM '(' ')'
3311
3088
          {
3312
 
            if (! ($$= reserved_keyword_function(YYSession, "uuid", NULL)))
 
3089
            if (! ($$= parser::reserved_keyword_function(YYSession, "uuid", NULL)))
3313
3090
            {
3314
3091
              DRIZZLE_YYABORT;
3315
3092
            }
3321
3098
            List<Item> *args= new (YYSession->mem_root) List<Item>;
3322
3099
            args->push_back($3);
3323
3100
            args->push_back($5);
3324
 
            if (! ($$= reserved_keyword_function(YYSession, wait_str, args)))
 
3101
            if (! ($$= parser::reserved_keyword_function(YYSession, wait_str, args)))
3325
3102
            {
3326
3103
              DRIZZLE_YYABORT;
3327
3104
            }
3499
3276
        | '@' opt_var_ident_type user_variable_ident opt_component
3500
3277
          {
3501
3278
            /* disallow "SELECT @@global.global.variable" */
3502
 
            if ($3.str && $4.str && check_reserved_words(&$3))
 
3279
            if ($3.str && $4.str && parser::check_reserved_words(&$3))
3503
3280
            {
3504
 
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3505
 
              my_parse_error(&pass);
 
3281
              parser::error_t pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3282
              parser::my_parse_error(pass);
3506
3283
              DRIZZLE_YYABORT;
3507
3284
            }
3508
3285
            if (!($$= get_system_var(YYSession, $2, $3, $4)))
3543
3320
          {
3544
3321
            if (Lex->current_select->inc_in_sum_expr())
3545
3322
            {
3546
 
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3547
 
              my_parse_error(&pass);
 
3323
              parser::error_t pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3324
              parser::my_parse_error(pass);
3548
3325
              DRIZZLE_YYABORT;
3549
3326
            }
3550
3327
          }
3831
3608
            {
3832
3609
              if (sel->set_braces(1))
3833
3610
              {
3834
 
                struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3835
 
                my_parse_error(&pass);
 
3611
                parser::error_t pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3612
                parser::my_parse_error(pass);
3836
3613
                DRIZZLE_YYABORT;
3837
3614
              }
3838
3615
              /* select in braces, can't contain global parameters */
3896
3673
            else if (($3->select_lex && $3->select_lex->master_unit()->is_union()) || $5)
3897
3674
            {
3898
3675
              /* simple nested joins cannot have aliases or unions */
3899
 
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3900
 
              my_parse_error(&pass);
 
3676
              parser::error_t pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3677
              parser::my_parse_error(pass);
3901
3678
              DRIZZLE_YYABORT;
3902
3679
            }
3903
3680
            else
3911
3688
          UNION_SYM
3912
3689
          union_option
3913
3690
          {
3914
 
            if (add_select_to_union_list(YYSession, Lex, (bool)$3))
 
3691
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
3915
3692
              DRIZZLE_YYABORT;
3916
3693
          }
3917
3694
          query_specification
3932
3709
            Select_Lex * sel= Lex->current_select;
3933
3710
            if (Lex->current_select->set_braces(0))
3934
3711
            {
3935
 
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3936
 
              my_parse_error(&pass);
 
3712
              parser::error_t pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3713
              parser::my_parse_error(pass);
3937
3714
              DRIZZLE_YYABORT;
3938
3715
            }
3939
3716
            if (sel->linkage == UNION_TYPE &&
3940
3717
                sel->master_unit()->first_select()->braces)
3941
3718
            {
3942
 
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3943
 
              my_parse_error(&pass);
 
3719
              parser::error_t pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3720
              parser::my_parse_error(pass);
3944
3721
              DRIZZLE_YYABORT;
3945
3722
            }
3946
3723
          }
3977
3754
              DRIZZLE_YYABORT;
3978
3755
            if (!$3 && $$)
3979
3756
            {
3980
 
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3981
 
              my_parse_error(&pass);
 
3757
              parser::error_t pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3758
              parser::my_parse_error(pass);
3982
3759
              DRIZZLE_YYABORT;
3983
3760
            }
3984
3761
          }
3989
3766
            Lex->derived_tables|= DERIVED_SUBQUERY;
3990
3767
            if (not Lex->expr_allows_subselect)
3991
3768
            {
3992
 
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
3993
 
              my_parse_error(&pass);
 
3769
              parser::error_t pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3770
              parser::my_parse_error(pass);
3994
3771
              DRIZZLE_YYABORT;
3995
3772
            }
3996
3773
            if (Lex->current_select->linkage == GLOBAL_OPTIONS_TYPE || new_select(Lex, 1))
4018
3795
            if (!sel->embedding || sel->end_nested_join(Lex->session))
4019
3796
            {
4020
3797
              /* we are not in parentheses */
4021
 
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
4022
 
              my_parse_error(&pass);
 
3798
              parser::error_t pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
3799
              parser::my_parse_error(pass);
4023
3800
              DRIZZLE_YYABORT;
4024
3801
            }
4025
3802
            embedding= Lex->current_select->embedding;
4858
4635
show_param:
4859
4636
           DATABASES show_wild
4860
4637
           {
4861
 
             Lex->sql_command= SQLCOM_SELECT;
4862
 
             Lex->statement= new statement::Show(YYSession);
4863
 
 
4864
 
             std::string column_name= "Database";
4865
 
             if (Lex->wild)
4866
 
             {
4867
 
               column_name.append(" (");
4868
 
               column_name.append(Lex->wild->ptr());
4869
 
               column_name.append(")");
4870
 
             }
4871
 
 
4872
 
             if (Lex->current_select->where)
4873
 
             {
4874
 
               if (prepare_new_schema_table(YYSession, Lex, "SCHEMAS"))
4875
 
                 DRIZZLE_YYABORT;
4876
 
             }
4877
 
             else
4878
 
             {
4879
 
               if (prepare_new_schema_table(YYSession, Lex, "SHOW_SCHEMAS"))
4880
 
                 DRIZZLE_YYABORT;
4881
 
             }
4882
 
 
4883
 
             Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
4884
 
             my_field->is_autogenerated_name= false;
4885
 
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
4886
 
 
4887
 
             if (YYSession->add_item_to_list(my_field))
 
4638
             if (not show::buildScemas(YYSession))
4888
4639
               DRIZZLE_YYABORT;
4889
 
 
4890
 
              if (YYSession->add_order_to_list(my_field, true))
4891
 
                DRIZZLE_YYABORT;
4892
4640
           }
4893
4641
           /* SHOW TABLES */
4894
4642
         | TABLES opt_db show_wild
4895
4643
           {
4896
 
             Lex->sql_command= SQLCOM_SELECT;
4897
 
 
4898
 
             drizzled::statement::Show *select= new statement::Show(YYSession);
4899
 
             Lex->statement= select;
4900
 
 
4901
 
              std::string column_name= "Tables_in_";
4902
 
 
4903
 
              util::string::const_shared_ptr schema(YYSession->schema());
4904
 
              if ($2)
4905
 
              {
4906
 
                identifier::Schema identifier($2);
4907
 
                column_name.append($2);
4908
 
                Lex->select_lex.db= $2;
4909
 
                if (not plugin::StorageEngine::doesSchemaExist(identifier))
4910
 
                {
4911
 
                  my_error(ER_BAD_DB_ERROR, MYF(0), $2);
4912
 
                }
4913
 
                select->setShowPredicate($2, "");
4914
 
              }
4915
 
              else if (schema and not schema->empty())
4916
 
              {
4917
 
                column_name.append(*schema);
4918
 
                select->setShowPredicate(*schema, "");
4919
 
              }
4920
 
              else
4921
 
              {
4922
 
                my_error(ER_NO_DB_ERROR, MYF(0));
4923
 
                DRIZZLE_YYABORT;
4924
 
              }
4925
 
 
4926
 
 
4927
 
             if (Lex->wild)
4928
 
             {
4929
 
               column_name.append(" (");
4930
 
               column_name.append(Lex->wild->ptr());
4931
 
               column_name.append(")");
4932
 
             }
4933
 
 
4934
 
             if (prepare_new_schema_table(YYSession, Lex, "SHOW_TABLES"))
4935
 
               DRIZZLE_YYABORT;
4936
 
 
4937
 
             Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "TABLE_NAME");
4938
 
             my_field->is_autogenerated_name= false;
4939
 
             my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
4940
 
 
4941
 
             if (YYSession->add_item_to_list(my_field))
4942
 
               DRIZZLE_YYABORT;
4943
 
 
4944
 
              if (YYSession->add_order_to_list(my_field, true))
4945
 
                DRIZZLE_YYABORT;
 
4644
             if (not show::buildTables(YYSession, $2))
 
4645
               DRIZZLE_YYABORT;
4946
4646
           }
4947
4647
           /* SHOW TEMPORARY TABLES */
4948
4648
         | TEMPORARY_SYM TABLES show_wild
4949
4649
           {
4950
 
             Lex->sql_command= SQLCOM_SELECT;
4951
 
 
4952
 
             Lex->statement= new statement::Show(YYSession);
4953
 
 
4954
 
 
4955
 
             if (prepare_new_schema_table(YYSession, Lex, "SHOW_TEMPORARY_TABLES"))
4956
 
               DRIZZLE_YYABORT;
4957
 
 
4958
 
             if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
4959
 
                                                           context,
4960
 
                                                           NULL, NULL, "*")))
4961
 
               DRIZZLE_YYABORT;
4962
 
             (YYSession->lex->current_select->with_wild)++;
4963
 
 
 
4650
             if (not show::buildTemporaryTables(YYSession))
 
4651
               DRIZZLE_YYABORT;
4964
4652
           }
4965
4653
           /* SHOW TABLE STATUS */
4966
4654
         | TABLE_SYM STATUS_SYM opt_db show_wild
4967
4655
           {
4968
 
             Lex->sql_command= SQLCOM_SELECT;
4969
 
             drizzled::statement::Show *select= new statement::Show(YYSession);
4970
 
             Lex->statement= select;
4971
 
 
4972
 
             std::string column_name= "Tables_in_";
4973
 
 
4974
 
             util::string::const_shared_ptr schema(YYSession->schema());
4975
 
             if ($3)
4976
 
             {
4977
 
               Lex->select_lex.db= $3;
4978
 
 
4979
 
               identifier::Schema identifier($3);
4980
 
               if (not plugin::StorageEngine::doesSchemaExist(identifier))
4981
 
               {
4982
 
                 my_error(ER_BAD_DB_ERROR, MYF(0), $3);
4983
 
               }
4984
 
 
4985
 
               select->setShowPredicate($3, "");
4986
 
             }
4987
 
             else if (schema)
4988
 
             {
4989
 
               select->setShowPredicate(*schema, "");
4990
 
             }
4991
 
             else
4992
 
             {
4993
 
               my_error(ER_NO_DB_ERROR, MYF(0));
4994
 
               DRIZZLE_YYABORT;
4995
 
             }
4996
 
 
4997
 
             if (prepare_new_schema_table(YYSession, Lex, "SHOW_TABLE_STATUS"))
4998
 
               DRIZZLE_YYABORT;
4999
 
 
5000
 
             if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
5001
 
                                                           context,
5002
 
                                                           NULL, NULL, "*")))
5003
 
               DRIZZLE_YYABORT;
5004
 
             (YYSession->lex->current_select->with_wild)++;
 
4656
             if (not show::buildTableStatus(YYSession, $3))
 
4657
               DRIZZLE_YYABORT;
5005
4658
           }
5006
4659
           /* SHOW COLUMNS FROM table_name */
5007
4660
        | COLUMNS from_or_in table_ident opt_db show_wild
5008
 
          {
5009
 
             Lex->sql_command= SQLCOM_SELECT;
5010
 
 
5011
 
             drizzled::statement::Show *select= new statement::Show(YYSession);
5012
 
             Lex->statement= select;
5013
 
 
5014
 
             util::string::const_shared_ptr schema(YYSession->schema());
5015
 
             if ($4)
5016
 
             {
5017
 
              select->setShowPredicate($4, $3->table.str);
5018
 
             }
5019
 
             else if ($3->db.str)
5020
 
             {
5021
 
              select->setShowPredicate($3->db.str, $3->table.str);
5022
 
             }
5023
 
             else if (schema)
5024
 
             {
5025
 
               select->setShowPredicate(*schema, $3->table.str);
5026
 
             }
5027
 
             else
5028
 
             {
5029
 
               my_error(ER_NO_DB_ERROR, MYF(0));
5030
 
               DRIZZLE_YYABORT;
5031
 
             }
5032
 
 
5033
 
             {
5034
 
               drizzled::identifier::Table identifier(select->getShowSchema().c_str(), $3->table.str);
5035
 
               if (not plugin::StorageEngine::doesTableExist(*YYSession, identifier))
5036
 
               {
5037
 
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
5038
 
                            select->getShowSchema().c_str(), 
5039
 
                            $3->table.str);
5040
 
               }
5041
 
             }
5042
 
 
5043
 
             if (prepare_new_schema_table(YYSession, Lex, "SHOW_COLUMNS"))
5044
 
               DRIZZLE_YYABORT;
5045
 
 
5046
 
             if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
5047
 
                                                           context,
5048
 
                                                           NULL, NULL, "*")))
5049
 
               DRIZZLE_YYABORT;
5050
 
             (YYSession->lex->current_select->with_wild)++;
5051
 
 
5052
 
          }
 
4661
           {
 
4662
             if (not show::buildColumns(YYSession, $4, $3))
 
4663
               DRIZZLE_YYABORT;
 
4664
           }
5053
4665
          /* SHOW INDEXES from table */
5054
4666
        | keys_or_index from_or_in table_ident opt_db where_clause
5055
 
          {
5056
 
             Lex->sql_command= SQLCOM_SELECT;
5057
 
             drizzled::statement::Show *select= new statement::Show(YYSession);
5058
 
             Lex->statement= select;
5059
 
 
5060
 
             util::string::const_shared_ptr schema(YYSession->schema());
5061
 
             if ($4)
5062
 
             {
5063
 
              select->setShowPredicate($4, $3->table.str);
5064
 
             }
5065
 
             else if ($3->db.str)
5066
 
             {
5067
 
              select->setShowPredicate($3->db.str, $3->table.str);
5068
 
             }
5069
 
             else if (schema)
5070
 
             {
5071
 
               select->setShowPredicate(*schema, $3->table.str);
5072
 
             }
5073
 
             else
5074
 
             {
5075
 
               my_error(ER_NO_DB_ERROR, MYF(0));
5076
 
               DRIZZLE_YYABORT;
5077
 
             }
5078
 
 
5079
 
             {
5080
 
               drizzled::identifier::Table identifier(select->getShowSchema().c_str(), $3->table.str);
5081
 
               if (not plugin::StorageEngine::doesTableExist(*YYSession, identifier))
5082
 
               {
5083
 
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
5084
 
                            select->getShowSchema().c_str(), 
5085
 
                            $3->table.str);
5086
 
               }
5087
 
             }
5088
 
 
5089
 
             if (prepare_new_schema_table(YYSession, Lex, "SHOW_INDEXES"))
5090
 
               DRIZZLE_YYABORT;
5091
 
 
5092
 
             if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
5093
 
                                                           context,
5094
 
                                                           NULL, NULL, "*")))
5095
 
               DRIZZLE_YYABORT;
5096
 
             (YYSession->lex->current_select->with_wild)++;
5097
 
          }
 
4667
           {
 
4668
             if (not show::buildIndex(YYSession, $4, $3))
 
4669
               DRIZZLE_YYABORT;
 
4670
           }
5098
4671
        | COUNT_SYM '(' '*' ')' WARNINGS
5099
4672
          {
5100
4673
            (void) create_select_for_variable("warning_count");
5107
4680
          }
5108
4681
        | WARNINGS opt_limit_clause_init
5109
4682
          {
5110
 
            Lex->sql_command = SQLCOM_SHOW_WARNS;
5111
 
            Lex->statement= new statement::ShowWarnings(YYSession);
 
4683
            if (not show::buildWarnings(YYSession))
 
4684
              DRIZZLE_YYABORT;
5112
4685
          }
5113
4686
        | ERRORS opt_limit_clause_init
5114
4687
          {
5115
 
            Lex->sql_command = SQLCOM_SHOW_ERRORS;
5116
 
            Lex->statement= new statement::ShowErrors(YYSession);
 
4688
            if (not show::buildErrors(YYSession))
 
4689
              DRIZZLE_YYABORT;
5117
4690
          }
5118
4691
        | opt_var_type STATUS_SYM show_wild
5119
 
           {
5120
 
             Lex->sql_command= SQLCOM_SELECT;
5121
 
             Lex->statement= new statement::Show(YYSession);
5122
 
 
5123
 
             if ($1 == OPT_GLOBAL)
5124
 
             {
5125
 
               if (prepare_new_schema_table(YYSession, Lex, "GLOBAL_STATUS"))
5126
 
                 DRIZZLE_YYABORT;
5127
 
             }
5128
 
             else
5129
 
             {
5130
 
               if (prepare_new_schema_table(YYSession, Lex, "SESSION_STATUS"))
5131
 
                 DRIZZLE_YYABORT;
5132
 
             }
5133
 
 
5134
 
             std::string key("Variable_name");
5135
 
             std::string value("Value");
5136
 
 
5137
 
             Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5138
 
             my_field->is_autogenerated_name= false;
5139
 
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
5140
 
 
5141
 
             if (YYSession->add_item_to_list(my_field))
5142
 
               DRIZZLE_YYABORT;
5143
 
 
5144
 
             my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5145
 
             my_field->is_autogenerated_name= false;
5146
 
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
5147
 
 
5148
 
             if (YYSession->add_item_to_list(my_field))
5149
 
               DRIZZLE_YYABORT;
5150
 
           }
 
4692
          {
 
4693
            if (not show::buildStatus(YYSession, $1))
 
4694
              DRIZZLE_YYABORT;
 
4695
          }
5151
4696
        | CREATE TABLE_SYM table_ident
5152
 
           {
5153
 
             Lex->sql_command= SQLCOM_SELECT;
5154
 
             statement::Show *select= new statement::Show(YYSession);
5155
 
             Lex->statement= select;
5156
 
 
5157
 
             if (Lex->statement == NULL)
5158
 
               DRIZZLE_YYABORT;
5159
 
 
5160
 
             if (prepare_new_schema_table(YYSession, Lex, "TABLE_SQL_DEFINITION"))
5161
 
               DRIZZLE_YYABORT;
5162
 
 
5163
 
             util::string::const_shared_ptr schema(YYSession->schema());
5164
 
             if ($3->db.str)
5165
 
             {
5166
 
               select->setShowPredicate($3->db.str, $3->table.str);
5167
 
             }
5168
 
             else if (schema)
5169
 
             {
5170
 
               select->setShowPredicate(*schema, $3->table.str);
5171
 
             }
5172
 
             else
5173
 
             {
5174
 
               my_error(ER_NO_DB_ERROR, MYF(0));
5175
 
               DRIZZLE_YYABORT;
5176
 
             }
5177
 
 
5178
 
             std::string key("Table");
5179
 
             std::string value("Create Table");
5180
 
 
5181
 
             Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "TABLE_NAME");
5182
 
             my_field->is_autogenerated_name= false;
5183
 
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
5184
 
 
5185
 
             if (YYSession->add_item_to_list(my_field))
5186
 
               DRIZZLE_YYABORT;
5187
 
 
5188
 
             my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
5189
 
             my_field->is_autogenerated_name= false;
5190
 
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
5191
 
 
5192
 
             if (YYSession->add_item_to_list(my_field))
5193
 
               DRIZZLE_YYABORT;
5194
 
           }
 
4697
          {
 
4698
            if (not show::buildCreateTable(YYSession, $3))
 
4699
              DRIZZLE_YYABORT;
 
4700
          }
5195
4701
        | PROCESSLIST_SYM
5196
4702
          {
5197
 
           {
5198
 
             Lex->sql_command= SQLCOM_SELECT;
5199
 
             Lex->statement= new statement::Show(YYSession);
5200
 
 
5201
 
             if (prepare_new_schema_table(YYSession, Lex, "PROCESSLIST"))
5202
 
               DRIZZLE_YYABORT;
5203
 
 
5204
 
             if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
5205
 
                                                           context,
5206
 
                                                           NULL, NULL, "*")))
5207
 
               DRIZZLE_YYABORT;
5208
 
             (YYSession->lex->current_select->with_wild)++;
5209
 
           }
 
4703
            if (not show::buildProcesslist(YYSession))
 
4704
              DRIZZLE_YYABORT;
5210
4705
          }
5211
4706
        | opt_var_type  VARIABLES show_wild
5212
 
           {
5213
 
             Lex->sql_command= SQLCOM_SELECT;
5214
 
             Lex->statement= new statement::Show(YYSession);
5215
 
 
5216
 
             if ($1 == OPT_GLOBAL)
5217
 
             {
5218
 
               if (prepare_new_schema_table(YYSession, Lex, "GLOBAL_VARIABLES"))
5219
 
                 DRIZZLE_YYABORT;
5220
 
             }
5221
 
             else
5222
 
             {
5223
 
               if (prepare_new_schema_table(YYSession, Lex, "SESSION_VARIABLES"))
5224
 
                 DRIZZLE_YYABORT;
5225
 
             }
5226
 
 
5227
 
             std::string key("Variable_name");
5228
 
             std::string value("Value");
5229
 
 
5230
 
             Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
5231
 
             my_field->is_autogenerated_name= false;
5232
 
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
5233
 
 
5234
 
             if (YYSession->add_item_to_list(my_field))
5235
 
               DRIZZLE_YYABORT;
5236
 
 
5237
 
             my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
5238
 
             my_field->is_autogenerated_name= false;
5239
 
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
5240
 
 
5241
 
             if (YYSession->add_item_to_list(my_field))
5242
 
               DRIZZLE_YYABORT;
5243
 
           }
 
4707
          {
 
4708
            if (not show::buildVariables(YYSession, $1))
 
4709
              DRIZZLE_YYABORT;
 
4710
          }
5244
4711
        | CREATE DATABASE opt_if_not_exists ident
5245
 
           {
5246
 
             Lex->sql_command= SQLCOM_SELECT;
5247
 
             drizzled::statement::Show *select= new statement::Show(YYSession);
5248
 
             Lex->statement= select;
5249
 
 
5250
 
             if (prepare_new_schema_table(YYSession, Lex, "SCHEMA_SQL_DEFINITION"))
5251
 
               DRIZZLE_YYABORT;
5252
 
 
5253
 
             util::string::const_shared_ptr schema(YYSession->schema());
5254
 
             if ($4.str)
5255
 
             {
5256
 
              select->setShowPredicate($4.str);
5257
 
             }
5258
 
             else if (schema)
5259
 
             {
5260
 
               select->setShowPredicate(*schema);
5261
 
             }
5262
 
             else
5263
 
             {
5264
 
               my_error(ER_NO_DB_ERROR, MYF(0));
5265
 
               DRIZZLE_YYABORT;
5266
 
             }
5267
 
 
5268
 
             std::string key("Database");
5269
 
             std::string value("Create Database");
5270
 
 
5271
 
             Item_field *my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
5272
 
             my_field->is_autogenerated_name= false;
5273
 
             my_field->set_name(key.c_str(), key.length(), system_charset_info);
5274
 
 
5275
 
             if (YYSession->add_item_to_list(my_field))
5276
 
               DRIZZLE_YYABORT;
5277
 
 
5278
 
             my_field= new Item_field(&YYSession->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
5279
 
             my_field->is_autogenerated_name= false;
5280
 
             my_field->set_name(value.c_str(), value.length(), system_charset_info);
5281
 
 
5282
 
             if (YYSession->add_item_to_list(my_field))
5283
 
               DRIZZLE_YYABORT;
5284
 
           }
 
4712
          {
 
4713
            if (not show::buildCreateSchema(YYSession, $4))
 
4714
              DRIZZLE_YYABORT;
 
4715
          }
5285
4716
 
5286
4717
opt_db:
5287
4718
          /* empty */  { $$= 0; }
5314
4745
describe:
5315
4746
          describe_command table_ident
5316
4747
          {
5317
 
            Lex->lock_option= TL_READ;
5318
 
            init_select(Lex);
5319
 
            Lex->current_select->parsing_place= SELECT_LIST;
5320
 
            Lex->sql_command= SQLCOM_SELECT;
5321
 
            drizzled::statement::Show *select= new statement::Show(YYSession);
5322
 
            Lex->statement= select;
5323
 
            Lex->select_lex.db= 0;
5324
 
 
5325
 
             util::string::const_shared_ptr schema(YYSession->schema());
5326
 
             if ($2->db.str)
5327
 
             {
5328
 
               select->setShowPredicate($2->db.str, $2->table.str);
5329
 
             }
5330
 
             else if (schema)
5331
 
             {
5332
 
               select->setShowPredicate(*schema, $2->table.str);
5333
 
             }
5334
 
             else
5335
 
             {
5336
 
               my_error(ER_NO_DB_ERROR, MYF(0));
5337
 
               DRIZZLE_YYABORT;
5338
 
             }
5339
 
 
5340
 
             {
5341
 
               drizzled::identifier::Table identifier(select->getShowSchema().c_str(), $2->table.str);
5342
 
               if (not plugin::StorageEngine::doesTableExist(*YYSession, identifier))
5343
 
               {
5344
 
                   my_error(ER_NO_SUCH_TABLE, MYF(0),
5345
 
                            select->getShowSchema().c_str(), 
5346
 
                            $2->table.str);
5347
 
               }
5348
 
             }
5349
 
 
5350
 
             if (prepare_new_schema_table(YYSession, Lex, "SHOW_COLUMNS"))
5351
 
               DRIZZLE_YYABORT;
5352
 
 
5353
 
             if (YYSession->add_item_to_list( new Item_field(&YYSession->lex->current_select->
5354
 
                                                           context,
5355
 
                                                           NULL, NULL, "*")))
5356
 
             {
5357
 
               DRIZZLE_YYABORT;
5358
 
             }
5359
 
             (YYSession->lex->current_select->with_wild)++;
5360
 
 
 
4748
            if (not show::buildDescribe(YYSession, $2))
 
4749
            {
 
4750
              DRIZZLE_YYABORT;
 
4751
            }
5361
4752
          }
5362
4753
          opt_describe_column {}
5363
4754
        | describe_command opt_extended_describe
6373
5764
union_list:
6374
5765
          UNION_SYM union_option
6375
5766
          {
6376
 
            if (add_select_to_union_list(YYSession, Lex, (bool)$2))
 
5767
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$2))
6377
5768
              DRIZZLE_YYABORT;
6378
5769
          }
6379
5770
          select_init
6440
5831
        | query_expression_body
6441
5832
          UNION_SYM union_option
6442
5833
          {
6443
 
            if (add_select_to_union_list(YYSession, Lex, (bool)$3))
 
5834
            if (parser::add_select_to_union_list(YYSession, Lex, (bool)$3))
6444
5835
              DRIZZLE_YYABORT;
6445
5836
          }
6446
5837
          query_specification
6462
5853
          {
6463
5854
            if (not Lex->expr_allows_subselect)
6464
5855
            {
6465
 
              struct my_parse_error_st pass= { ER(ER_SYNTAX_ERROR), YYSession };
6466
 
              my_parse_error(&pass);
 
5856
              parser::error_t pass= { ER(ER_SYNTAX_ERROR), YYSession };
 
5857
              parser::my_parse_error(pass);
6467
5858
              DRIZZLE_YYABORT;
6468
5859
            }
6469
5860
            /*