~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

  • Committer: Stewart Smith
  • Date: 2010-02-15 02:27:14 UTC
  • mto: (1273.13.96 build)
  • mto: This revision was merged to the branch mainline in revision 1308.
  • Revision ID: stewart@flamingspork.com-20100215022714-lbp61dmrew1vjww3
make REVERSE() a plugin instead of built in function. Generalise the code for such keyword functions otu into reserved_keyword_function() in sql_yacc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
301
301
  return false;
302
302
}
303
303
 
 
304
static Item* reserved_keyword_function(const std::string &name, List<Item> *item_list)
 
305
{
 
306
  const plugin::Function *udf= plugin::Function::get(name.c_str(), name.length());
 
307
  Item *item= NULL;
 
308
 
 
309
  if (udf)
 
310
  {
 
311
    item= Create_udf_func::s_singleton.create(current_session, udf, item_list);
 
312
  } else {
 
313
    my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", name.c_str());
 
314
  }
 
315
 
 
316
  return item;
 
317
}
 
318
 
304
319
} /* namespace drizzled; */
305
320
 
306
321
using namespace drizzled;
3111
3126
          { $$= new (YYSession->mem_root) Item_func_collation($3); }
3112
3127
        | DATABASE '(' ')'
3113
3128
          {
3114
 
            std::string database_str("database");
3115
 
            const plugin::Function *udf= plugin::Function::get(database_str.c_str(), database_str.length());
3116
 
            Session *session= YYSession;
3117
 
            Item *item= NULL;
3118
 
 
3119
 
            if (udf)
3120
 
            {
3121
 
              item= Create_udf_func::s_singleton.create(session, udf, NULL);
3122
 
            } else {
3123
 
              my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", database_str.c_str());
3124
 
            }
3125
 
 
3126
 
            if (! ($$= item))
 
3129
            std::string database_str("database");
 
3130
            if (! ($$= reserved_keyword_function(database_str, NULL)))
3127
3131
            {
3128
3132
              DRIZZLE_YYABORT;
3129
3133
            }
3130
 
          }
 
3134
          }
3131
3135
        | IF '(' expr ',' expr ',' expr ')'
3132
3136
          { $$= new (YYSession->mem_root) Item_func_if($3,$5,$7); }
3133
3137
        | MICROSECOND_SYM '(' expr ')'
3141
3145
        | REPLACE '(' expr ',' expr ',' expr ')'
3142
3146
          { $$= new (YYSession->mem_root) Item_func_replace($3,$5,$7); }
3143
3147
        | REVERSE_SYM '(' expr ')'
3144
 
          { $$= new (YYSession->mem_root) Item_func_reverse($3); }
 
3148
          {
 
3149
            std::string reverse_str("reverse");
 
3150
            List<Item> *args= new (YYSession->mem_root) List<Item>;
 
3151
            args->push_back($3);
 
3152
            if (! ($$= reserved_keyword_function(reverse_str, args)))
 
3153
            {
 
3154
              DRIZZLE_YYABORT;
 
3155
            }
 
3156
          }
3145
3157
        | TRUNCATE_SYM '(' expr ',' expr ')'
3146
3158
          { $$= new (YYSession->mem_root) Item_func_round($3,$5,1); }
3147
3159
        ;