Drizzled Public API Documentation

create.cc
Go to the documentation of this file.
00001 /* Copyright (C) 2000-2003 MySQL AB
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00015 
00023 #include <config.h>
00024 #include <drizzled/item/create.h>
00025 #include <drizzled/item/func.h>
00026 #include <drizzled/error.h>
00027 
00028 #include <drizzled/function_container.h>
00029 
00030 #include <drizzled/function/str/binary.h>
00031 #include <drizzled/function/str/concat.h>
00032 #include <drizzled/function/str/conv.h>
00033 #include <drizzled/function/str/export_set.h>
00034 #include <drizzled/function/str/load_file.h>
00035 #include <drizzled/function/str/make_set.h>
00036 #include <drizzled/function/str/pad.h>
00037 #include <drizzled/function/str/repeat.h>
00038 #include <drizzled/function/str/str_conv.h>
00039 #include <drizzled/function/str/trim.h>
00040 
00041 #include <drizzled/function/time/date_format.h>
00042 #include <drizzled/function/time/dayname.h>
00043 #include <drizzled/function/time/dayofmonth.h>
00044 #include <drizzled/function/time/dayofyear.h>
00045 #include <drizzled/function/time/from_unixtime.h>
00046 #include <drizzled/function/time/from_days.h>
00047 #include <drizzled/function/time/last_day.h>
00048 #include <drizzled/function/time/makedate.h>
00049 #include <drizzled/function/time/month.h>
00050 #include <drizzled/function/time/period_add.h>
00051 #include <drizzled/function/time/period_diff.h>
00052 #include <drizzled/function/time/to_days.h>
00053 #include <drizzled/function/time/typecast.h>
00054 #include <drizzled/function/time/unix_timestamp.h>
00055 #include <drizzled/function/time/weekday.h>
00056 
00057 #include <drizzled/item/cmpfunc.h>
00058 #include <drizzled/plugin/function.h>
00059 #include <drizzled/session.h>
00060 
00061 /* Function declarations */
00062 
00063 #include <drizzled/function/func.h>
00064 #include <drizzled/function/additive_op.h>
00065 #include <drizzled/function/math/dec.h>
00066 #include <drizzled/function/math/decimal_typecast.h>
00067 #include <drizzled/function/field.h>
00068 #include <drizzled/function/find_in_set.h>
00069 #include <drizzled/function/found_rows.h>
00070 #include <drizzled/function/get_system_var.h>
00071 #include <drizzled/function/math/int_val.h>
00072 #include <drizzled/function/math/integer.h>
00073 #include <drizzled/function/last_insert.h>
00074 #include <drizzled/function/locate.h>
00075 #include <drizzled/function/min_max.h>
00076 #include <drizzled/function/num1.h>
00077 #include <drizzled/function/num_op.h>
00078 #include <drizzled/function/numhybrid.h>
00079 #include <drizzled/function/math/real.h>
00080 #include <drizzled/function/row_count.h>
00081 #include <drizzled/function/set_user_var.h>
00082 #include <drizzled/function/sign.h>
00083 #include <drizzled/function/math/tan.h>
00084 #include <drizzled/function/units.h>
00085 
00086 #include <drizzled/function/cast/boolean.h>
00087 #include <drizzled/function/cast/signed.h>
00088 #include <drizzled/function/cast/time.h>
00089 #include <drizzled/function/cast/unsigned.h>
00090 
00091 using namespace std;
00092 
00093 namespace drizzled
00094 {
00095 
00096 class Item;
00097 
00098 
00099 /*
00100 =============================================================================
00101   LOCAL DECLARATIONS
00102 =============================================================================
00103 */
00104 
00113 class Create_native_func : public Create_func
00114 {
00115 public:
00116   virtual Item *create(Session *session, LEX_STRING name, List<Item> *item_list);
00117 
00125   virtual Item *create_native(Session *session, LEX_STRING name,
00126                               List<Item> *item_list) = 0;
00127 
00128 protected:
00130   Create_native_func() {}
00132   virtual ~Create_native_func() {}
00133 };
00134 
00135 
00140 class Create_func_arg0 : public Create_func
00141 {
00142 public:
00143   virtual Item *create(Session *session, LEX_STRING name, List<Item> *item_list);
00144 
00150   virtual Item *create(Session *session) = 0;
00151 
00152 protected:
00154   Create_func_arg0() {}
00156   virtual ~Create_func_arg0() {}
00157 };
00158 
00159 
00164 class Create_func_arg1 : public Create_func
00165 {
00166 public:
00167   virtual Item *create(Session *session, LEX_STRING name, List<Item> *item_list);
00168 
00175   virtual Item *create(Session *session, Item *arg1) = 0;
00176 
00177 protected:
00179   Create_func_arg1() {}
00181   virtual ~Create_func_arg1() {}
00182 };
00183 
00184 
00189 class Create_func_arg2 : public Create_func
00190 {
00191 public:
00192   virtual Item *create(Session *session, LEX_STRING name, List<Item> *item_list);
00193 
00201   virtual Item *create(Session *session, Item *arg1, Item *arg2) = 0;
00202 
00203 protected:
00205   Create_func_arg2() {}
00207   virtual ~Create_func_arg2() {}
00208 };
00209 
00210 
00215 class Create_func_arg3 : public Create_func
00216 {
00217 public:
00218   virtual Item *create(Session *session, LEX_STRING name, List<Item> *item_list);
00219 
00228   virtual Item *create(Session *session, Item *arg1, Item *arg2, Item *arg3) = 0;
00229 
00230 protected:
00232   Create_func_arg3() {}
00234   virtual ~Create_func_arg3() {}
00235 };
00236 
00237 
00242 /*
00243   Concrete functions builders (native functions).
00244   Please keep this list sorted in alphabetical order,
00245   it helps to compare code between versions, and helps with merges conflicts.
00246 */
00247 
00248 
00249 class Create_func_bin : public Create_func_arg1
00250 {
00251 public:
00252   using Create_func_arg1::create;
00253 
00254   virtual Item *create(Session *session, Item *arg1);
00255 
00256   static Create_func_bin s_singleton;
00257 
00258 protected:
00259   Create_func_bin() {}
00260   virtual ~Create_func_bin() {}
00261 };
00262 
00263 class Create_func_concat : public Create_native_func
00264 {
00265 public:
00266   virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
00267 
00268   static Create_func_concat s_singleton;
00269 
00270 protected:
00271   Create_func_concat() {}
00272   virtual ~Create_func_concat() {}
00273 };
00274 
00275 
00276 class Create_func_concat_ws : public Create_native_func
00277 {
00278 public:
00279   virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
00280 
00281   static Create_func_concat_ws s_singleton;
00282 
00283 protected:
00284   Create_func_concat_ws() {}
00285   virtual ~Create_func_concat_ws() {}
00286 };
00287 
00288 
00289 class Create_func_conv : public Create_func_arg3
00290 {
00291 public:
00292   using Create_func_arg3::create;
00293 
00294   virtual Item *create(Session *session, Item *arg1, Item *arg2, Item *arg3);
00295 
00296   static Create_func_conv s_singleton;
00297 
00298 protected:
00299   Create_func_conv() {}
00300   virtual ~Create_func_conv() {}
00301 };
00302 
00303 class Create_func_cot : public Create_func_arg1
00304 {
00305 public:
00306   using Create_func_arg1::create;
00307 
00308   virtual Item *create(Session *session, Item *arg1);
00309 
00310   static Create_func_cot s_singleton;
00311 
00312 protected:
00313   Create_func_cot() {}
00314   virtual ~Create_func_cot() {}
00315 };
00316 
00317 class Create_func_date_format : public Create_func_arg2
00318 {
00319 public:
00320   using Create_func_arg2::create;
00321 
00322   virtual Item *create(Session *session, Item *arg1, Item *arg2);
00323 
00324   static Create_func_date_format s_singleton;
00325 
00326 protected:
00327   Create_func_date_format() {}
00328   virtual ~Create_func_date_format() {}
00329 };
00330 
00331 
00332 class Create_func_datediff : public Create_func_arg2
00333 {
00334 public:
00335   using Create_func_arg2::create;
00336 
00337   virtual Item *create(Session *session, Item *arg1, Item *arg2);
00338 
00339   static Create_func_datediff s_singleton;
00340 
00341 protected:
00342   Create_func_datediff() {}
00343   virtual ~Create_func_datediff() {}
00344 };
00345 
00346 
00347 class Create_func_dayname : public Create_func_arg1
00348 {
00349 public:
00350   using Create_func_arg1::create;
00351 
00352   virtual Item *create(Session *session, Item *arg1);
00353 
00354   static Create_func_dayname s_singleton;
00355 
00356 protected:
00357   Create_func_dayname() {}
00358   virtual ~Create_func_dayname() {}
00359 };
00360 
00361 
00362 class Create_func_dayofmonth : public Create_func_arg1
00363 {
00364 public:
00365   using Create_func_arg1::create;
00366 
00367   virtual Item *create(Session *session, Item *arg1);
00368 
00369   static Create_func_dayofmonth s_singleton;
00370 
00371 protected:
00372   Create_func_dayofmonth() {}
00373   virtual ~Create_func_dayofmonth() {}
00374 };
00375 
00376 
00377 class Create_func_dayofweek : public Create_func_arg1
00378 {
00379 public:
00380   using Create_func_arg1::create;
00381 
00382   virtual Item *create(Session *session, Item *arg1);
00383 
00384   static Create_func_dayofweek s_singleton;
00385 
00386 protected:
00387   Create_func_dayofweek() {}
00388   virtual ~Create_func_dayofweek() {}
00389 };
00390 
00391 
00392 class Create_func_dayofyear : public Create_func_arg1
00393 {
00394 public:
00395   using Create_func_arg1::create;
00396 
00397   virtual Item *create(Session *session, Item *arg1);
00398 
00399   static Create_func_dayofyear s_singleton;
00400 
00401 protected:
00402   Create_func_dayofyear() {}
00403   virtual ~Create_func_dayofyear() {}
00404 };
00405 
00406 
00407 class Create_func_decode : public Create_func_arg2
00408 {
00409 public:
00410   using Create_func_arg2::create;
00411 
00412   virtual Item *create(Session *session, Item *arg1, Item *arg2);
00413 
00414   static Create_func_decode s_singleton;
00415 
00416 protected:
00417   Create_func_decode() {}
00418   virtual ~Create_func_decode() {}
00419 };
00420 
00421 
00422 class Create_func_degrees : public Create_func_arg1
00423 {
00424 public:
00425   using Create_func_arg1::create;
00426 
00427   virtual Item *create(Session *session, Item *arg1);
00428 
00429   static Create_func_degrees s_singleton;
00430 
00431 protected:
00432   Create_func_degrees() {}
00433   virtual ~Create_func_degrees() {}
00434 };
00435 
00436 class Create_func_export_set : public Create_native_func
00437 {
00438 
00439 public:
00440   virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
00441 
00442   static Create_func_export_set s_singleton;
00443 
00444 protected:
00445   Create_func_export_set() {}
00446   virtual ~Create_func_export_set() {}
00447 };
00448 
00449 
00450 class Create_func_field : public Create_native_func
00451 {
00452 public:
00453   virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
00454 
00455   static Create_func_field s_singleton;
00456 
00457 protected:
00458   Create_func_field() {}
00459   virtual ~Create_func_field() {}
00460 };
00461 
00462 
00463 class Create_func_find_in_set : public Create_func_arg2
00464 {
00465 public:
00466   using Create_func_arg2::create;
00467 
00468   virtual Item *create(Session *session, Item *arg1, Item *arg2);
00469 
00470   static Create_func_find_in_set s_singleton;
00471 
00472 protected:
00473   Create_func_find_in_set() {}
00474   virtual ~Create_func_find_in_set() {}
00475 };
00476 
00477 class Create_func_found_rows : public Create_func_arg0
00478 {
00479 public:
00480   using Create_func_arg0::create;
00481 
00482   virtual Item *create(Session *session);
00483 
00484   static Create_func_found_rows s_singleton;
00485 
00486 protected:
00487   Create_func_found_rows() {}
00488   virtual ~Create_func_found_rows() {}
00489 };
00490 
00491 
00492 class Create_func_from_days : public Create_func_arg1
00493 {
00494 public:
00495   using Create_func_arg1::create;
00496 
00497   virtual Item *create(Session *session, Item *arg1);
00498 
00499   static Create_func_from_days s_singleton;
00500 
00501 protected:
00502   Create_func_from_days() {}
00503   virtual ~Create_func_from_days() {}
00504 };
00505 
00506 
00507 class Create_func_from_unixtime : public Create_native_func
00508 {
00509 public:
00510   virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
00511 
00512   static Create_func_from_unixtime s_singleton;
00513 
00514 protected:
00515   Create_func_from_unixtime() {}
00516   virtual ~Create_func_from_unixtime() {}
00517 };
00518 
00519 
00520 class Create_func_greatest : public Create_native_func
00521 {
00522 public:
00523   virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
00524 
00525   static Create_func_greatest s_singleton;
00526 
00527 protected:
00528   Create_func_greatest() {}
00529   virtual ~Create_func_greatest() {}
00530 };
00531 
00532 
00533 class Create_func_ifnull : public Create_func_arg2
00534 {
00535 public:
00536   using Create_func_arg2::create;
00537 
00538   virtual Item *create(Session *session, Item *arg1, Item *arg2);
00539 
00540   static Create_func_ifnull s_singleton;
00541 
00542 protected:
00543   Create_func_ifnull() {}
00544   virtual ~Create_func_ifnull() {}
00545 };
00546 
00547 
00548 class Create_func_instr : public Create_func_arg2
00549 {
00550 public:
00551   using Create_func_arg2::create;
00552 
00553   virtual Item *create(Session *session, Item *arg1, Item *arg2);
00554 
00555   static Create_func_instr s_singleton;
00556 
00557 protected:
00558   Create_func_instr() {}
00559   virtual ~Create_func_instr() {}
00560 };
00561 
00562 
00563 class Create_func_isnull : public Create_func_arg1
00564 {
00565 public:
00566   using Create_func_arg1::create;
00567 
00568   virtual Item *create(Session *session, Item *arg1);
00569 
00570   static Create_func_isnull s_singleton;
00571 
00572 protected:
00573   Create_func_isnull() {}
00574   virtual ~Create_func_isnull() {}
00575 };
00576 
00577 
00578 class Create_func_last_day : public Create_func_arg1
00579 {
00580 public:
00581   using Create_func_arg1::create;
00582 
00583   virtual Item *create(Session *session, Item *arg1);
00584 
00585   static Create_func_last_day s_singleton;
00586 
00587 protected:
00588   Create_func_last_day() {}
00589   virtual ~Create_func_last_day() {}
00590 };
00591 
00592 
00593 class Create_func_last_insert_id : public Create_native_func
00594 {
00595 public:
00596   virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
00597 
00598   static Create_func_last_insert_id s_singleton;
00599 
00600 protected:
00601   Create_func_last_insert_id() {}
00602   virtual ~Create_func_last_insert_id() {}
00603 };
00604 
00605 
00606 class Create_func_lcase : public Create_func_arg1
00607 {
00608 public:
00609   using Create_func_arg1::create;
00610 
00611   virtual Item *create(Session *session, Item *arg1);
00612 
00613   static Create_func_lcase s_singleton;
00614 
00615 protected:
00616   Create_func_lcase() {}
00617   virtual ~Create_func_lcase() {}
00618 };
00619 
00620 
00621 class Create_func_least : public Create_native_func
00622 {
00623 public:
00624   virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
00625 
00626   static Create_func_least s_singleton;
00627 
00628 protected:
00629   Create_func_least() {}
00630   virtual ~Create_func_least() {}
00631 };
00632 
00633 class Create_func_load_file : public Create_func_arg1
00634 {
00635 public:
00636   using Create_func_arg1::create;
00637 
00638   virtual Item *create(Session *session, Item *arg1);
00639 
00640   static Create_func_load_file s_singleton;
00641 
00642 protected:
00643   Create_func_load_file() {}
00644   virtual ~Create_func_load_file() {}
00645 };
00646 
00647 
00648 class Create_func_locate : public Create_native_func
00649 {
00650 public:
00651   virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
00652 
00653   static Create_func_locate s_singleton;
00654 
00655 protected:
00656   Create_func_locate() {}
00657   virtual ~Create_func_locate() {}
00658 };
00659 
00660 
00661 class Create_func_lpad : public Create_func_arg3
00662 {
00663 public:
00664   using Create_func_arg3::create;
00665 
00666   virtual Item *create(Session *session, Item *arg1, Item *arg2, Item *arg3);
00667 
00668   static Create_func_lpad s_singleton;
00669 
00670 protected:
00671   Create_func_lpad() {}
00672   virtual ~Create_func_lpad() {}
00673 };
00674 
00675 
00676 class Create_func_ltrim : public Create_func_arg1
00677 {
00678 public:
00679   using Create_func_arg1::create;
00680 
00681   virtual Item *create(Session *session, Item *arg1);
00682 
00683   static Create_func_ltrim s_singleton;
00684 
00685 protected:
00686   Create_func_ltrim() {}
00687   virtual ~Create_func_ltrim() {}
00688 };
00689 
00690 
00691 class Create_func_makedate : public Create_func_arg2
00692 {
00693 public:
00694   using Create_func_arg2::create;
00695 
00696   virtual Item *create(Session *session, Item *arg1, Item *arg2);
00697 
00698   static Create_func_makedate s_singleton;
00699 
00700 protected:
00701   Create_func_makedate() {}
00702   virtual ~Create_func_makedate() {}
00703 };
00704 
00705 class Create_func_make_set : public Create_native_func
00706 {
00707 public:
00708   virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
00709 
00710   static Create_func_make_set s_singleton;
00711 
00712 protected:
00713   Create_func_make_set() {}
00714   virtual ~Create_func_make_set() {}
00715 };
00716 
00717 
00718 class Create_func_monthname : public Create_func_arg1
00719 {
00720 public:
00721   using Create_func_arg1::create;
00722 
00723   virtual Item *create(Session *session, Item *arg1);
00724 
00725   static Create_func_monthname s_singleton;
00726 
00727 protected:
00728   Create_func_monthname() {}
00729   virtual ~Create_func_monthname() {}
00730 };
00731 
00732 
00733 class Create_func_name_const : public Create_func_arg2
00734 {
00735 public:
00736   using Create_func_arg2::create;
00737 
00738   virtual Item *create(Session *session, Item *arg1, Item *arg2);
00739 
00740   static Create_func_name_const s_singleton;
00741 
00742 protected:
00743   Create_func_name_const() {}
00744   virtual ~Create_func_name_const() {}
00745 };
00746 
00747 
00748 class Create_func_nullif : public Create_func_arg2
00749 {
00750 public:
00751   using Create_func_arg2::create;
00752 
00753   virtual Item *create(Session *session, Item *arg1, Item *arg2);
00754 
00755   static Create_func_nullif s_singleton;
00756 
00757 protected:
00758   Create_func_nullif() {}
00759   virtual ~Create_func_nullif() {}
00760 };
00761 
00762 
00763 class Create_func_oct : public Create_func_arg1
00764 {
00765 public:
00766   using Create_func_arg1::create;
00767 
00768   virtual Item *create(Session *session, Item *arg1);
00769 
00770   static Create_func_oct s_singleton;
00771 
00772 protected:
00773   Create_func_oct() {}
00774   virtual ~Create_func_oct() {}
00775 };
00776 
00777 class Create_func_period_add : public Create_func_arg2
00778 {
00779 public:
00780   using Create_func_arg2::create;
00781 
00782   virtual Item *create(Session *session, Item *arg1, Item *arg2);
00783 
00784   static Create_func_period_add s_singleton;
00785 
00786 protected:
00787   Create_func_period_add() {}
00788   virtual ~Create_func_period_add() {}
00789 };
00790 
00791 
00792 class Create_func_period_diff : public Create_func_arg2
00793 {
00794 public:
00795   using Create_func_arg2::create;
00796 
00797   virtual Item *create(Session *session, Item *arg1, Item *arg2);
00798 
00799   static Create_func_period_diff s_singleton;
00800 
00801 protected:
00802   Create_func_period_diff() {}
00803   virtual ~Create_func_period_diff() {}
00804 };
00805 
00806 
00807 class Create_func_pi : public Create_func_arg0
00808 {
00809 public:
00810   using Create_func_arg0::create;
00811 
00812   virtual Item *create(Session *session);
00813 
00814   static Create_func_pi s_singleton;
00815 
00816 protected:
00817   Create_func_pi() {}
00818   virtual ~Create_func_pi() {}
00819 };
00820 
00821 class Create_func_radians : public Create_func_arg1
00822 {
00823 public:
00824   using Create_func_arg1::create;
00825 
00826   virtual Item *create(Session *session, Item *arg1);
00827 
00828   static Create_func_radians s_singleton;
00829 
00830 protected:
00831   Create_func_radians() {}
00832   virtual ~Create_func_radians() {}
00833 };
00834 
00835 
00836 class Create_func_round : public Create_native_func
00837 {
00838 public:
00839   virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
00840 
00841   static Create_func_round s_singleton;
00842 
00843 protected:
00844   Create_func_round() {}
00845   virtual ~Create_func_round() {}
00846 };
00847 
00848 
00849 class Create_func_row_count : public Create_func_arg0
00850 {
00851 public:
00852   using Create_func_arg0::create;
00853 
00854   virtual Item *create(Session *session);
00855 
00856   static Create_func_row_count s_singleton;
00857 
00858 protected:
00859   Create_func_row_count() {}
00860   virtual ~Create_func_row_count() {}
00861 };
00862 
00863 
00864 class Create_func_rpad : public Create_func_arg3
00865 {
00866 public:
00867   using Create_func_arg3::create;
00868 
00869   virtual Item *create(Session *session, Item *arg1, Item *arg2, Item *arg3);
00870 
00871   static Create_func_rpad s_singleton;
00872 
00873 protected:
00874   Create_func_rpad() {}
00875   virtual ~Create_func_rpad() {}
00876 };
00877 
00878 
00879 class Create_func_rtrim : public Create_func_arg1
00880 {
00881 public:
00882   using Create_func_arg1::create;
00883 
00884   virtual Item *create(Session *session, Item *arg1);
00885 
00886   static Create_func_rtrim s_singleton;
00887 
00888 protected:
00889   Create_func_rtrim() {}
00890   virtual ~Create_func_rtrim() {}
00891 };
00892 
00893 class Create_func_sign : public Create_func_arg1
00894 {
00895 public:
00896   using Create_func_arg1::create;
00897 
00898   virtual Item *create(Session *session, Item *arg1);
00899 
00900   static Create_func_sign s_singleton;
00901 
00902 protected:
00903   Create_func_sign() {}
00904   virtual ~Create_func_sign() {}
00905 };
00906 
00907 class Create_func_space : public Create_func_arg1
00908 {
00909 public:
00910   using Create_func_arg1::create;
00911 
00912   virtual Item *create(Session *session, Item *arg1);
00913 
00914   static Create_func_space s_singleton;
00915 
00916 protected:
00917   Create_func_space() {}
00918   virtual ~Create_func_space() {}
00919 };
00920 
00921 class Create_func_strcmp : public Create_func_arg2
00922 {
00923 public:
00924   using Create_func_arg2::create;
00925 
00926   virtual Item *create(Session *session, Item *arg1, Item *arg2);
00927 
00928   static Create_func_strcmp s_singleton;
00929 
00930 protected:
00931   Create_func_strcmp() {}
00932   virtual ~Create_func_strcmp() {}
00933 };
00934 
00935 
00936 class Create_func_tan : public Create_func_arg1
00937 {
00938 public:
00939   using Create_func_arg1::create;
00940 
00941   virtual Item *create(Session *session, Item *arg1);
00942 
00943   static Create_func_tan s_singleton;
00944 
00945 protected:
00946   Create_func_tan() {}
00947   virtual ~Create_func_tan() {}
00948 };
00949 
00950 
00951 class Create_func_time_format : public Create_func_arg2
00952 {
00953 public:
00954   using Create_func_arg2::create;
00955 
00956   virtual Item *create(Session *session, Item *arg1, Item *arg2);
00957 
00958   static Create_func_time_format s_singleton;
00959 
00960 protected:
00961   Create_func_time_format() {}
00962   virtual ~Create_func_time_format() {}
00963 };
00964 
00965 
00966 class Create_func_time_to_sec : public Create_func_arg1
00967 {
00968 public:
00969   using Create_func_arg1::create;
00970 
00971   virtual Item *create(Session *session, Item *arg1);
00972 
00973   static Create_func_time_to_sec s_singleton;
00974 
00975 protected:
00976   Create_func_time_to_sec() {}
00977   virtual ~Create_func_time_to_sec() {}
00978 };
00979 
00980 
00981 class Create_func_to_days : public Create_func_arg1
00982 {
00983 public:
00984   using Create_func_arg1::create;
00985 
00986   virtual Item *create(Session *session, Item *arg1);
00987 
00988   static Create_func_to_days s_singleton;
00989 
00990 protected:
00991   Create_func_to_days() {}
00992   virtual ~Create_func_to_days() {}
00993 };
00994 
00995 
00996 class Create_func_ucase : public Create_func_arg1
00997 {
00998 public:
00999   using Create_func_arg1::create;
01000 
01001   virtual Item *create(Session *session, Item *arg1);
01002 
01003   static Create_func_ucase s_singleton;
01004 
01005 protected:
01006   Create_func_ucase() {}
01007   virtual ~Create_func_ucase() {}
01008 };
01009 
01010 
01011 class Create_func_unix_timestamp : public Create_native_func
01012 {
01013 public:
01014   virtual Item *create_native(Session *session, LEX_STRING name, List<Item> *item_list);
01015 
01016   static Create_func_unix_timestamp s_singleton;
01017 
01018 protected:
01019   Create_func_unix_timestamp() {}
01020   virtual ~Create_func_unix_timestamp() {}
01021 };
01022 
01023 
01024 class Create_func_weekday : public Create_func_arg1
01025 {
01026 public:
01027   using Create_func_arg1::create;
01028 
01029   virtual Item *create(Session *session, Item *arg1);
01030 
01031   static Create_func_weekday s_singleton;
01032 
01033 protected:
01034   Create_func_weekday() {}
01035   virtual ~Create_func_weekday() {}
01036 };
01037 
01038 /*
01039 =============================================================================
01040   IMPLEMENTATION
01041 =============================================================================
01042 */
01043 
01051 static bool has_named_parameters(List<Item> *params)
01052 {
01053   if (params)
01054   {
01055     Item *param;
01056     List<Item>::iterator it(params->begin());
01057     while ((param= it++))
01058     {
01059       if (! param->is_autogenerated_name)
01060         return true;
01061     }
01062   }
01063 
01064   return false;
01065 }
01066 
01067 
01068 Create_udf_func Create_udf_func::s_singleton;
01069 
01070 Item*
01071 Create_udf_func::create(Session *session, LEX_STRING name, List<Item> *item_list)
01072 {
01073   const plugin::Function *udf= plugin::Function::get(std::string(name.str, name.length));
01074   assert(udf);
01075   return create(session, udf, item_list);
01076 }
01077 
01078 
01079 Item*
01080 Create_udf_func::create(Session *session, const plugin::Function *udf,
01081                         List<Item> *item_list)
01082 {
01083   Item_func *func= NULL;
01084   int arg_count= 0;
01085 
01086   if (item_list != NULL)
01087     arg_count= item_list->size();
01088 
01089   func= (*udf)(session->mem_root);
01090 
01091   if(!func->check_argument_count(arg_count))
01092   {
01093     my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), func->func_name());
01094     return NULL;
01095   }
01096 
01097   if(item_list)
01098     func->set_arguments(*item_list);
01099 
01100   return func;
01101 }
01102 
01103 
01104 Item*
01105 Create_native_func::create(Session *session, LEX_STRING name, List<Item> *item_list)
01106 {
01107   if (has_named_parameters(item_list))
01108   {
01109     my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
01110     return NULL;
01111   }
01112 
01113   return create_native(session, name, item_list);
01114 }
01115 
01116 
01117 Item*
01118 Create_func_arg0::create(Session *session, LEX_STRING name, List<Item> *item_list)
01119 {
01120   int arg_count= 0;
01121 
01122   if (item_list != NULL)
01123     arg_count= item_list->size();
01124 
01125   if (arg_count != 0)
01126   {
01127     my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
01128     return NULL;
01129   }
01130 
01131   return create(session);
01132 }
01133 
01134 
01135 Item*
01136 Create_func_arg1::create(Session *session, LEX_STRING name, List<Item> *item_list)
01137 {
01138   int arg_count= 0;
01139 
01140   if (item_list)
01141     arg_count= item_list->size();
01142 
01143   if (arg_count != 1)
01144   {
01145     my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
01146     return NULL;
01147   }
01148 
01149   Item *param_1= item_list->pop();
01150 
01151   if (! param_1->is_autogenerated_name)
01152   {
01153     my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
01154     return NULL;
01155   }
01156 
01157   return create(session, param_1);
01158 }
01159 
01160 
01161 Item*
01162 Create_func_arg2::create(Session *session, LEX_STRING name, List<Item> *item_list)
01163 {
01164   int arg_count= 0;
01165 
01166   if (item_list)
01167     arg_count= item_list->size();
01168 
01169   if (arg_count != 2)
01170   {
01171     my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
01172     return NULL;
01173   }
01174 
01175   Item *param_1= item_list->pop();
01176   Item *param_2= item_list->pop();
01177 
01178   if (   (! param_1->is_autogenerated_name)
01179       || (! param_2->is_autogenerated_name))
01180   {
01181     my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
01182     return NULL;
01183   }
01184 
01185   return create(session, param_1, param_2);
01186 }
01187 
01188 
01189 Item*
01190 Create_func_arg3::create(Session *session, LEX_STRING name, List<Item> *item_list)
01191 {
01192   int arg_count= 0;
01193 
01194   if (item_list)
01195     arg_count= item_list->size();
01196 
01197   if (arg_count != 3)
01198   {
01199     my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
01200     return NULL;
01201   }
01202 
01203   Item *param_1= item_list->pop();
01204   Item *param_2= item_list->pop();
01205   Item *param_3= item_list->pop();
01206 
01207   if (   (! param_1->is_autogenerated_name)
01208       || (! param_2->is_autogenerated_name)
01209       || (! param_3->is_autogenerated_name))
01210   {
01211     my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name.str);
01212     return NULL;
01213   }
01214 
01215   return create(session, param_1, param_2, param_3);
01216 }
01217 
01218 Create_func_bin Create_func_bin::s_singleton;
01219 
01220 Item*
01221 Create_func_bin::create(Session *session, Item *arg1)
01222 {
01223   Item *i10= new (session->mem_root) Item_int((int32_t) 10,2);
01224   Item *i2= new (session->mem_root) Item_int((int32_t) 2,1);
01225   return new (session->mem_root) Item_func_conv(arg1, i10, i2);
01226 }
01227 
01228 Create_func_concat Create_func_concat::s_singleton;
01229 
01230 Item*
01231 Create_func_concat::create_native(Session *session, LEX_STRING name,
01232                                   List<Item> *item_list)
01233 {
01234   int arg_count= 0;
01235 
01236   if (item_list != NULL)
01237     arg_count= item_list->size();
01238 
01239   if (arg_count < 1)
01240   {
01241     my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
01242     return NULL;
01243   }
01244 
01245   return new (session->mem_root) Item_func_concat(*session, *item_list);
01246 }
01247 
01248 
01249 Create_func_concat_ws Create_func_concat_ws::s_singleton;
01250 
01251 Item*
01252 Create_func_concat_ws::create_native(Session *session, LEX_STRING name,
01253                                      List<Item> *item_list)
01254 {
01255   int arg_count= 0;
01256 
01257   if (item_list != NULL)
01258     arg_count= item_list->size();
01259 
01260   /* "WS" stands for "With Separator": this function takes 2+ arguments */
01261   if (arg_count < 2)
01262   {
01263     my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
01264     return NULL;
01265   }
01266 
01267   return new (session->mem_root) Item_func_concat_ws(*session, *item_list);
01268 }
01269 
01270 
01271 Create_func_conv Create_func_conv::s_singleton;
01272 
01273 Item*
01274 Create_func_conv::create(Session *session, Item *arg1, Item *arg2, Item *arg3)
01275 {
01276   return new (session->mem_root) Item_func_conv(arg1, arg2, arg3);
01277 }
01278 
01279 Create_func_cot Create_func_cot::s_singleton;
01280 
01281 Item*
01282 Create_func_cot::create(Session *session, Item *arg1)
01283 {
01284   Item *i1= new (session->mem_root) Item_int((char*) "1", 1, 1);
01285   Item *i2= new (session->mem_root) Item_func_tan(arg1);
01286   return new (session->mem_root) Item_func_div(session, i1, i2);
01287 }
01288 
01289 Create_func_date_format Create_func_date_format::s_singleton;
01290 
01291 Item*
01292 Create_func_date_format::create(Session *session, Item *arg1, Item *arg2)
01293 {
01294   return new (session->mem_root) Item_func_date_format(arg1, arg2, 0);
01295 }
01296 
01297 
01298 Create_func_datediff Create_func_datediff::s_singleton;
01299 
01300 Item*
01301 Create_func_datediff::create(Session *session, Item *arg1, Item *arg2)
01302 {
01303   Item *i1= new (session->mem_root) Item_func_to_days(arg1);
01304   Item *i2= new (session->mem_root) Item_func_to_days(arg2);
01305 
01306   return new (session->mem_root) Item_func_minus(i1, i2);
01307 }
01308 
01309 
01310 Create_func_dayname Create_func_dayname::s_singleton;
01311 
01312 Item*
01313 Create_func_dayname::create(Session *session, Item *arg1)
01314 {
01315   return new (session->mem_root) Item_func_dayname(arg1);
01316 }
01317 
01318 
01319 Create_func_dayofmonth Create_func_dayofmonth::s_singleton;
01320 
01321 Item*
01322 Create_func_dayofmonth::create(Session *session, Item *arg1)
01323 {
01324   return new (session->mem_root) Item_func_dayofmonth(arg1);
01325 }
01326 
01327 
01328 Create_func_dayofweek Create_func_dayofweek::s_singleton;
01329 
01330 Item*
01331 Create_func_dayofweek::create(Session *session, Item *arg1)
01332 {
01333   return new (session->mem_root) Item_func_weekday(arg1, 1);
01334 }
01335 
01336 
01337 Create_func_dayofyear Create_func_dayofyear::s_singleton;
01338 
01339 Item*
01340 Create_func_dayofyear::create(Session *session, Item *arg1)
01341 {
01342   return new (session->mem_root) Item_func_dayofyear(arg1);
01343 }
01344 
01345 
01346 Create_func_degrees Create_func_degrees::s_singleton;
01347 
01348 Item*
01349 Create_func_degrees::create(Session *session, Item *arg1)
01350 {
01351   return new (session->mem_root) Item_func_units((char*) "degrees", arg1,
01352                                              180/M_PI, 0.0);
01353 }
01354 
01355 Create_func_export_set Create_func_export_set::s_singleton;
01356 
01357 Item*
01358 Create_func_export_set::create_native(Session *session, LEX_STRING name,
01359                                       List<Item> *item_list)
01360 {
01361   Item *func= NULL;
01362   int arg_count= 0;
01363 
01364   if (item_list != NULL)
01365     arg_count= item_list->size();
01366 
01367   switch (arg_count) {
01368   case 3:
01369   {
01370     Item *param_1= item_list->pop();
01371     Item *param_2= item_list->pop();
01372     Item *param_3= item_list->pop();
01373     func= new (session->mem_root) Item_func_export_set(param_1, param_2, param_3);
01374     break;
01375   }
01376   case 4:
01377   {
01378     Item *param_1= item_list->pop();
01379     Item *param_2= item_list->pop();
01380     Item *param_3= item_list->pop();
01381     Item *param_4= item_list->pop();
01382     func= new (session->mem_root) Item_func_export_set(param_1, param_2, param_3,
01383                                                    param_4);
01384     break;
01385   }
01386   case 5:
01387   {
01388     Item *param_1= item_list->pop();
01389     Item *param_2= item_list->pop();
01390     Item *param_3= item_list->pop();
01391     Item *param_4= item_list->pop();
01392     Item *param_5= item_list->pop();
01393     func= new (session->mem_root) Item_func_export_set(param_1, param_2, param_3,
01394                                                    param_4, param_5);
01395     break;
01396   }
01397   default:
01398   {
01399     my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
01400     break;
01401   }
01402   }
01403 
01404   return func;
01405 }
01406 
01407 
01408 Create_func_field Create_func_field::s_singleton;
01409 
01410 Item*
01411 Create_func_field::create_native(Session *session, LEX_STRING name,
01412                                  List<Item> *item_list)
01413 {
01414   int arg_count= 0;
01415 
01416   if (item_list != NULL)
01417     arg_count= item_list->size();
01418 
01419   if (arg_count < 2)
01420   {
01421     my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
01422     return NULL;
01423   }
01424 
01425   return new (session->mem_root) Item_func_field(*item_list);
01426 }
01427 
01428 
01429 Create_func_find_in_set Create_func_find_in_set::s_singleton;
01430 
01431 Item*
01432 Create_func_find_in_set::create(Session *session, Item *arg1, Item *arg2)
01433 {
01434   return new (session->mem_root) Item_func_find_in_set(arg1, arg2);
01435 }
01436 
01437 Create_func_found_rows Create_func_found_rows::s_singleton;
01438 
01439 Item*
01440 Create_func_found_rows::create(Session *session)
01441 {
01442   return new (session->mem_root) Item_func_found_rows();
01443 }
01444 
01445 
01446 Create_func_from_days Create_func_from_days::s_singleton;
01447 
01448 Item*
01449 Create_func_from_days::create(Session *session, Item *arg1)
01450 {
01451   return new (session->mem_root) Item_func_from_days(arg1);
01452 }
01453 
01454 
01455 Create_func_from_unixtime Create_func_from_unixtime::s_singleton;
01456 
01457 Item*
01458 Create_func_from_unixtime::create_native(Session *session, LEX_STRING name,
01459                                          List<Item> *item_list)
01460 {
01461   Item *func= NULL;
01462   int arg_count= 0;
01463 
01464   if (item_list != NULL)
01465     arg_count= item_list->size();
01466 
01467   switch (arg_count) {
01468   case 1:
01469   {
01470     Item *param_1= item_list->pop();
01471     func= new (session->mem_root) Item_func_from_unixtime(param_1);
01472     break;
01473   }
01474   case 2:
01475   {
01476     Item *param_1= item_list->pop();
01477     Item *param_2= item_list->pop();
01478     Item *ut= new (session->mem_root) Item_func_from_unixtime(param_1);
01479     func= new (session->mem_root) Item_func_date_format(ut, param_2, 0);
01480     break;
01481   }
01482   default:
01483   {
01484     my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
01485     break;
01486   }
01487   }
01488 
01489   return func;
01490 }
01491 
01492 
01493 Create_func_greatest Create_func_greatest::s_singleton;
01494 
01495 Item*
01496 Create_func_greatest::create_native(Session *session, LEX_STRING name,
01497                                     List<Item> *item_list)
01498 {
01499   int arg_count= 0;
01500 
01501   if (item_list != NULL)
01502     arg_count= item_list->size();
01503 
01504   if (arg_count < 2)
01505   {
01506     my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
01507     return NULL;
01508   }
01509 
01510   return new (session->mem_root) Item_func_max(*item_list);
01511 }
01512 
01513 Create_func_ifnull Create_func_ifnull::s_singleton;
01514 
01515 Item*
01516 Create_func_ifnull::create(Session *session, Item *arg1, Item *arg2)
01517 {
01518   return new (session->mem_root) Item_func_ifnull(arg1, arg2);
01519 }
01520 
01521 
01522 Create_func_instr Create_func_instr::s_singleton;
01523 
01524 Item*
01525 Create_func_instr::create(Session *session, Item *arg1, Item *arg2)
01526 {
01527   return new (session->mem_root) Item_func_locate(arg1, arg2);
01528 }
01529 
01530 
01531 Create_func_isnull Create_func_isnull::s_singleton;
01532 
01533 Item*
01534 Create_func_isnull::create(Session *session, Item *arg1)
01535 {
01536   return new (session->mem_root) Item_func_isnull(arg1);
01537 }
01538 
01539 
01540 Create_func_last_day Create_func_last_day::s_singleton;
01541 
01542 Item*
01543 Create_func_last_day::create(Session *session, Item *arg1)
01544 {
01545   return new (session->mem_root) Item_func_last_day(arg1);
01546 }
01547 
01548 
01549 Create_func_last_insert_id Create_func_last_insert_id::s_singleton;
01550 
01551 Item*
01552 Create_func_last_insert_id::create_native(Session *session, LEX_STRING name,
01553                                           List<Item> *item_list)
01554 {
01555   Item *func= NULL;
01556   int arg_count= 0;
01557 
01558   if (item_list != NULL)
01559     arg_count= item_list->size();
01560 
01561   switch (arg_count) {
01562   case 0:
01563   {
01564     func= new (session->mem_root) Item_func_last_insert_id();
01565     break;
01566   }
01567   case 1:
01568   {
01569     Item *param_1= item_list->pop();
01570     func= new (session->mem_root) Item_func_last_insert_id(param_1);
01571     break;
01572   }
01573   default:
01574   {
01575     my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
01576     break;
01577   }
01578   }
01579 
01580   return func;
01581 }
01582 
01583 
01584 Create_func_lcase Create_func_lcase::s_singleton;
01585 
01586 Item*
01587 Create_func_lcase::create(Session *session, Item *arg1)
01588 {
01589   return new (session->mem_root) Item_func_lcase(arg1);
01590 }
01591 
01592 
01593 Create_func_least Create_func_least::s_singleton;
01594 
01595 Item*
01596 Create_func_least::create_native(Session *session, LEX_STRING name,
01597                                  List<Item> *item_list)
01598 {
01599   int arg_count= 0;
01600 
01601   if (item_list != NULL)
01602     arg_count= item_list->size();
01603 
01604   if (arg_count < 2)
01605   {
01606     my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
01607     return NULL;
01608   }
01609 
01610   return new (session->mem_root) Item_func_min(*item_list);
01611 }
01612 
01613 Create_func_load_file Create_func_load_file::s_singleton;
01614 
01615 Item*
01616 Create_func_load_file::create(Session *session, Item *arg1)
01617 {
01618   return new (session->mem_root) Item_load_file(*session, arg1);
01619 }
01620 
01621 
01622 Create_func_locate Create_func_locate::s_singleton;
01623 
01624 Item*
01625 Create_func_locate::create_native(Session *session, LEX_STRING name,
01626                                   List<Item> *item_list)
01627 {
01628   Item *func= NULL;
01629   int arg_count= 0;
01630 
01631   if (item_list != NULL)
01632     arg_count= item_list->size();
01633 
01634   switch (arg_count) {
01635   case 2:
01636   {
01637     Item *param_1= item_list->pop();
01638     Item *param_2= item_list->pop();
01639     /* Yes, parameters in that order : 2, 1 */
01640     func= new (session->mem_root) Item_func_locate(param_2, param_1);
01641     break;
01642   }
01643   case 3:
01644   {
01645     Item *param_1= item_list->pop();
01646     Item *param_2= item_list->pop();
01647     Item *param_3= item_list->pop();
01648     /* Yes, parameters in that order : 2, 1, 3 */
01649     func= new (session->mem_root) Item_func_locate(param_2, param_1, param_3);
01650     break;
01651   }
01652   default:
01653   {
01654     my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
01655     break;
01656   }
01657   }
01658 
01659   return func;
01660 }
01661 
01662 Create_func_lpad Create_func_lpad::s_singleton;
01663 
01664 Item*
01665 Create_func_lpad::create(Session *session, Item *arg1, Item *arg2, Item *arg3)
01666 {
01667   return new (session->mem_root) Item_func_lpad(*session, arg1, arg2, arg3);
01668 }
01669 
01670 
01671 Create_func_ltrim Create_func_ltrim::s_singleton;
01672 
01673 Item*
01674 Create_func_ltrim::create(Session *session, Item *arg1)
01675 {
01676   return new (session->mem_root) Item_func_ltrim(arg1);
01677 }
01678 
01679 
01680 Create_func_makedate Create_func_makedate::s_singleton;
01681 
01682 Item*
01683 Create_func_makedate::create(Session *session, Item *arg1, Item *arg2)
01684 {
01685   return new (session->mem_root) Item_func_makedate(arg1, arg2);
01686 }
01687 
01688 
01689 Create_func_make_set Create_func_make_set::s_singleton;
01690 
01691 Item*
01692 Create_func_make_set::create_native(Session *session_arg, LEX_STRING name,
01693                                     List<Item> *item_list)
01694 {
01695   int arg_count= 0;
01696 
01697   if (item_list != NULL)
01698     arg_count= item_list->size();
01699 
01700   if (arg_count < 2)
01701   {
01702     my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
01703     return NULL;
01704   }
01705 
01706   Item *param_1= item_list->pop();
01707   return new (session_arg->mem_root) Item_func_make_set(*session_arg, param_1, *item_list);
01708 }
01709 
01710 
01711 Create_func_monthname Create_func_monthname::s_singleton;
01712 
01713 Item*
01714 Create_func_monthname::create(Session *session, Item *arg1)
01715 {
01716   return new (session->mem_root) Item_func_monthname(arg1);
01717 }
01718 
01719 
01720 Create_func_nullif Create_func_nullif::s_singleton;
01721 
01722 Item*
01723 Create_func_nullif::create(Session *session, Item *arg1, Item *arg2)
01724 {
01725   return new (session->mem_root) Item_func_nullif(arg1, arg2);
01726 }
01727 
01728 
01729 Create_func_oct Create_func_oct::s_singleton;
01730 
01731 Item*
01732 Create_func_oct::create(Session *session, Item *arg1)
01733 {
01734   Item *i10= new (session->mem_root) Item_int((int32_t) 10,2);
01735   Item *i8= new (session->mem_root) Item_int((int32_t) 8,1);
01736   return new (session->mem_root) Item_func_conv(arg1, i10, i8);
01737 }
01738 
01739 Create_func_period_add Create_func_period_add::s_singleton;
01740 
01741 Item*
01742 Create_func_period_add::create(Session *session, Item *arg1, Item *arg2)
01743 {
01744   return new (session->mem_root) Item_func_period_add(arg1, arg2);
01745 }
01746 
01747 
01748 Create_func_period_diff Create_func_period_diff::s_singleton;
01749 
01750 Item*
01751 Create_func_period_diff::create(Session *session, Item *arg1, Item *arg2)
01752 {
01753   return new (session->mem_root) Item_func_period_diff(arg1, arg2);
01754 }
01755 
01756 
01757 Create_func_pi Create_func_pi::s_singleton;
01758 
01759 Item*
01760 Create_func_pi::create(Session *session)
01761 {
01762   return new (session->mem_root) Item_static_float_func("pi()", M_PI, 6, 8);
01763 }
01764 
01765 Create_func_radians Create_func_radians::s_singleton;
01766 
01767 Item*
01768 Create_func_radians::create(Session *session, Item *arg1)
01769 {
01770   return new (session->mem_root) Item_func_units((char*) "radians", arg1,
01771                                              M_PI/180, 0.0);
01772 }
01773 
01774 Create_func_round Create_func_round::s_singleton;
01775 
01776 Item*
01777 Create_func_round::create_native(Session *session, LEX_STRING name,
01778                                  List<Item> *item_list)
01779 {
01780   Item *func= NULL;
01781   int arg_count= 0;
01782 
01783   if (item_list != NULL)
01784     arg_count= item_list->size();
01785 
01786   switch (arg_count) {
01787   case 1:
01788   {
01789     Item *param_1= item_list->pop();
01790     Item *i0 = new (session->mem_root) Item_int((char*)"0", 0, 1);
01791     func= new (session->mem_root) Item_func_round(param_1, i0, 0);
01792     break;
01793   }
01794   case 2:
01795   {
01796     Item *param_1= item_list->pop();
01797     Item *param_2= item_list->pop();
01798     func= new (session->mem_root) Item_func_round(param_1, param_2, 0);
01799     break;
01800   }
01801   default:
01802   {
01803     my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
01804     break;
01805   }
01806   }
01807 
01808   return func;
01809 }
01810 
01811 
01812 Create_func_row_count Create_func_row_count::s_singleton;
01813 
01814 Item*
01815 Create_func_row_count::create(Session *session)
01816 {
01817   return new (session->mem_root) Item_func_row_count();
01818 }
01819 
01820 
01821 Create_func_rpad Create_func_rpad::s_singleton;
01822 
01823 Item*
01824 Create_func_rpad::create(Session *session, Item *arg1, Item *arg2, Item *arg3)
01825 {
01826   return new (session->mem_root) Item_func_rpad(*session, arg1, arg2, arg3);
01827 }
01828 
01829 
01830 Create_func_rtrim Create_func_rtrim::s_singleton;
01831 
01832 Item*
01833 Create_func_rtrim::create(Session *session, Item *arg1)
01834 {
01835   return new (session->mem_root) Item_func_rtrim(arg1);
01836 }
01837 
01838 
01839 Create_func_sign Create_func_sign::s_singleton;
01840 
01841 Item*
01842 Create_func_sign::create(Session *session, Item *arg1)
01843 {
01844   return new (session->mem_root) Item_func_sign(arg1);
01845 }
01846 
01847 Create_func_space Create_func_space::s_singleton;
01848 
01849 Item*
01850 Create_func_space::create(Session *session, Item *arg1)
01851 {
01857   const CHARSET_INFO * const cs= session->variables.getCollation();
01858   Item *sp;
01859 
01860   if (cs->mbminlen > 1)
01861   {
01862     size_t dummy_errors;
01863     sp= new (session->mem_root) Item_string("", 0, cs, DERIVATION_COERCIBLE);
01864     sp->str_value.copy(" ", 1, &my_charset_utf8_general_ci, cs, &dummy_errors);
01865   }
01866   else
01867   {
01868     sp= new (session->mem_root) Item_string(" ", 1, cs, DERIVATION_COERCIBLE);
01869   }
01870 
01871   return new (session->mem_root) Item_func_repeat(*session, sp, arg1);
01872 }
01873 
01874 Create_func_strcmp Create_func_strcmp::s_singleton;
01875 
01876 Item*
01877 Create_func_strcmp::create(Session *session, Item *arg1, Item *arg2)
01878 {
01879   return new (session->mem_root) Item_func_strcmp(arg1, arg2);
01880 }
01881 
01882 
01883 Create_func_tan Create_func_tan::s_singleton;
01884 
01885 Item*
01886 Create_func_tan::create(Session *session, Item *arg1)
01887 {
01888   return new (session->mem_root) Item_func_tan(arg1);
01889 }
01890 
01891 
01892 Create_func_time_format Create_func_time_format::s_singleton;
01893 
01894 Item*
01895 Create_func_time_format::create(Session *session, Item *arg1, Item *arg2)
01896 {
01897   return new (session->mem_root) Item_func_date_format(arg1, arg2, 1);
01898 }
01899 
01900 Create_func_to_days Create_func_to_days::s_singleton;
01901 
01902 Item*
01903 Create_func_to_days::create(Session *session, Item *arg1)
01904 {
01905   return new (session->mem_root) Item_func_to_days(arg1);
01906 }
01907 
01908 
01909 Create_func_ucase Create_func_ucase::s_singleton;
01910 
01911 Item*
01912 Create_func_ucase::create(Session *session, Item *arg1)
01913 {
01914   return new (session->mem_root) Item_func_ucase(arg1);
01915 }
01916 
01917 Create_func_unix_timestamp Create_func_unix_timestamp::s_singleton;
01918 
01919 Item*
01920 Create_func_unix_timestamp::create_native(Session *session, LEX_STRING name,
01921                                           List<Item> *item_list)
01922 {
01923   Item *func= NULL;
01924   int arg_count= 0;
01925 
01926   if (item_list != NULL)
01927     arg_count= item_list->size();
01928 
01929   switch (arg_count) {
01930   case 0:
01931   {
01932     func= new (session->mem_root) Item_func_unix_timestamp();
01933     break;
01934   }
01935   case 1:
01936   {
01937     Item *param_1= item_list->pop();
01938     func= new (session->mem_root) Item_func_unix_timestamp(param_1);
01939     break;
01940   }
01941   default:
01942   {
01943     my_error(ER_WRONG_PARAMCOUNT_TO_FUNCTION, MYF(0), name.str);
01944     break;
01945   }
01946   }
01947 
01948   return func;
01949 }
01950 
01951 
01952 Create_func_weekday Create_func_weekday::s_singleton;
01953 
01954 Item*
01955 Create_func_weekday::create(Session *session, Item *arg1)
01956 {
01957   return new (session->mem_root) Item_func_weekday(arg1, 0);
01958 }
01959 
01960 struct Native_func_registry
01961 {
01962   LEX_STRING name;
01963   Create_func *builder;
01964 };
01965 
01966 #define BUILDER(F) & F::s_singleton
01967 
01968 /*
01969   MySQL native functions.
01970   MAINTAINER:
01971   - Keep sorted for human lookup. At runtime, a hash table is used.
01972   - keep 1 line per entry, it makes grep | sort easier
01973 */
01974 
01975 static Native_func_registry func_array[] =
01976 {
01977   { { C_STRING_WITH_LEN("BIN") }, BUILDER(Create_func_bin)},
01978   { { C_STRING_WITH_LEN("CONCAT") }, BUILDER(Create_func_concat)},
01979   { { C_STRING_WITH_LEN("CONCAT_WS") }, BUILDER(Create_func_concat_ws)},
01980   { { C_STRING_WITH_LEN("CONV") }, BUILDER(Create_func_conv)},
01981   { { C_STRING_WITH_LEN("COT") }, BUILDER(Create_func_cot)},
01982   { { C_STRING_WITH_LEN("DATEDIFF") }, BUILDER(Create_func_datediff)},
01983   { { C_STRING_WITH_LEN("DATE_FORMAT") }, BUILDER(Create_func_date_format)},
01984   { { C_STRING_WITH_LEN("DAYNAME") }, BUILDER(Create_func_dayname)},
01985   { { C_STRING_WITH_LEN("DAYOFMONTH") }, BUILDER(Create_func_dayofmonth)},
01986   { { C_STRING_WITH_LEN("DAYOFWEEK") }, BUILDER(Create_func_dayofweek)},
01987   { { C_STRING_WITH_LEN("DAYOFYEAR") }, BUILDER(Create_func_dayofyear)},
01988   { { C_STRING_WITH_LEN("DEGREES") }, BUILDER(Create_func_degrees)},
01989   { { C_STRING_WITH_LEN("EXPORT_SET") }, BUILDER(Create_func_export_set)},
01990   { { C_STRING_WITH_LEN("FIELD") }, BUILDER(Create_func_field)},
01991   { { C_STRING_WITH_LEN("FIND_IN_SET") }, BUILDER(Create_func_find_in_set)},
01992   { { C_STRING_WITH_LEN("FOUND_ROWS") }, BUILDER(Create_func_found_rows)},
01993   { { C_STRING_WITH_LEN("FROM_DAYS") }, BUILDER(Create_func_from_days)},
01994   { { C_STRING_WITH_LEN("FROM_UNIXTIME") }, BUILDER(Create_func_from_unixtime)},
01995   { { C_STRING_WITH_LEN("GREATEST") }, BUILDER(Create_func_greatest)},
01996   { { C_STRING_WITH_LEN("IFNULL") }, BUILDER(Create_func_ifnull)},
01997   { { C_STRING_WITH_LEN("INSTR") }, BUILDER(Create_func_instr)},
01998   { { C_STRING_WITH_LEN("ISNULL") }, BUILDER(Create_func_isnull)},
01999   { { C_STRING_WITH_LEN("LAST_DAY") }, BUILDER(Create_func_last_day)},
02000   { { C_STRING_WITH_LEN("LAST_INSERT_ID") }, BUILDER(Create_func_last_insert_id)},
02001   { { C_STRING_WITH_LEN("LCASE") }, BUILDER(Create_func_lcase)},
02002   { { C_STRING_WITH_LEN("LEAST") }, BUILDER(Create_func_least)},
02003   { { C_STRING_WITH_LEN("LOAD_FILE") }, BUILDER(Create_func_load_file)},
02004   { { C_STRING_WITH_LEN("LOCATE") }, BUILDER(Create_func_locate)},
02005   { { C_STRING_WITH_LEN("LOWER") }, BUILDER(Create_func_lcase)},
02006   { { C_STRING_WITH_LEN("LPAD") }, BUILDER(Create_func_lpad)},
02007   { { C_STRING_WITH_LEN("LTRIM") }, BUILDER(Create_func_ltrim)},
02008   { { C_STRING_WITH_LEN("MAKEDATE") }, BUILDER(Create_func_makedate)},
02009   { { C_STRING_WITH_LEN("MAKE_SET") }, BUILDER(Create_func_make_set)},
02010   { { C_STRING_WITH_LEN("MONTHNAME") }, BUILDER(Create_func_monthname)},
02011   { { C_STRING_WITH_LEN("NULLIF") }, BUILDER(Create_func_nullif)},
02012   { { C_STRING_WITH_LEN("OCT") }, BUILDER(Create_func_oct)},
02013   { { C_STRING_WITH_LEN("PERIOD_ADD") }, BUILDER(Create_func_period_add)},
02014   { { C_STRING_WITH_LEN("PERIOD_DIFF") }, BUILDER(Create_func_period_diff)},
02015   { { C_STRING_WITH_LEN("PI") }, BUILDER(Create_func_pi)},
02016   { { C_STRING_WITH_LEN("RADIANS") }, BUILDER(Create_func_radians)},
02017   { { C_STRING_WITH_LEN("ROUND") }, BUILDER(Create_func_round)},
02018   { { C_STRING_WITH_LEN("ROW_COUNT") }, BUILDER(Create_func_row_count)},
02019   { { C_STRING_WITH_LEN("RPAD") }, BUILDER(Create_func_rpad)},
02020   { { C_STRING_WITH_LEN("RTRIM") }, BUILDER(Create_func_rtrim)},
02021   { { C_STRING_WITH_LEN("SIGN") }, BUILDER(Create_func_sign)},
02022   { { C_STRING_WITH_LEN("SPACE") }, BUILDER(Create_func_space)},
02023   { { C_STRING_WITH_LEN("STRCMP") }, BUILDER(Create_func_strcmp)},
02024   { { C_STRING_WITH_LEN("TAN") }, BUILDER(Create_func_tan)},
02025   { { C_STRING_WITH_LEN("TIME_FORMAT") }, BUILDER(Create_func_time_format)},
02026   { { C_STRING_WITH_LEN("TO_DAYS") }, BUILDER(Create_func_to_days)},
02027   { { C_STRING_WITH_LEN("UCASE") }, BUILDER(Create_func_ucase)},
02028   { { C_STRING_WITH_LEN("UNIX_TIMESTAMP") }, BUILDER(Create_func_unix_timestamp)},
02029   { { C_STRING_WITH_LEN("UPPER") }, BUILDER(Create_func_ucase)},
02030   { { C_STRING_WITH_LEN("WEEKDAY") }, BUILDER(Create_func_weekday)},
02031 
02032   { {0, 0}, NULL}
02033 };
02034 
02035 /*
02036   Load the hash table for native functions.
02037   Note: this code is not thread safe, and is intended to be used at server
02038   startup only (before going multi-threaded)
02039 */
02040 
02041 int item_create_init()
02042 {
02043   string func_name;
02044 
02045   Native_func_registry *func;
02046   for (func= func_array; func->builder != NULL; func++)
02047   {
02048     func_name.assign(func->name.str, func->name.length);
02049 
02050     FunctionContainer::getMap()[func_name]= func->builder;
02051   }
02052 
02053   return 0;
02054 }
02055 
02056 
02057 Create_func *
02058 find_native_function_builder(LEX_STRING name)
02059 {
02060   Create_func *builder= NULL;
02061 
02062   string func_name(name.str, name.length);
02063 
02064   FunctionContainer::Map::iterator func_iter=
02065     FunctionContainer::getMap().find(func_name);
02066 
02067   if (func_iter != FunctionContainer::getMap().end())
02068   {
02069     builder= (*func_iter).second;
02070   }
02071 
02072   return builder;
02073 }
02074 
02075 
02076 Item*
02077 create_func_char_cast(Session *session, Item *a, int len, const CHARSET_INFO * const cs)
02078 {
02079   const CHARSET_INFO * const real_cs= (cs ? cs : session->variables.getCollation());
02080   return new (session->mem_root) Item_char_typecast(a, len, real_cs);
02081 }
02082 
02083 
02084 Item *
02085 create_func_cast(Session *session, Item *a, Cast_target cast_type,
02086                  const char *c_len, const char *c_dec,
02087                  const CHARSET_INFO * const cs)
02088 {
02089   Item *res= NULL;
02090   uint32_t len;
02091   uint32_t dec;
02092 
02093   switch (cast_type) {
02094   case ITEM_CAST_SIGNED:
02095     res= new (session->mem_root) function::cast::Signed(a);
02096     break;
02097 
02098   case ITEM_CAST_UNSIGNED:
02099     res= new (session->mem_root) function::cast::Unsigned(a);
02100     break;
02101 
02102   case ITEM_CAST_BINARY:
02103     res= new (session->mem_root) Item_func_binary(a);
02104     break;
02105 
02106   case ITEM_CAST_BOOLEAN:
02107     res= new (session->mem_root) function::cast::Boolean(a);
02108     break;
02109 
02110   case ITEM_CAST_TIME:
02111     res= new (session->mem_root) function::cast::Time(a);
02112     break;
02113 
02114   case ITEM_CAST_DATE:
02115     res= new (session->mem_root) Item_date_typecast(a);
02116     break;
02117 
02118   case ITEM_CAST_DATETIME:
02119     res= new (session->mem_root) Item_datetime_typecast(a);
02120     break;
02121 
02122   case ITEM_CAST_DECIMAL:
02123     {
02124       len= c_len ? atoi(c_len) : 0;
02125       dec= c_dec ? atoi(c_dec) : 0;
02126       class_decimal_trim(&len, &dec);
02127       if (len < dec)
02128       {
02129         my_error(ER_M_BIGGER_THAN_D, MYF(0), "");
02130         return 0;
02131       }
02132       if (len > DECIMAL_MAX_PRECISION)
02133       {
02134         my_error(ER_TOO_BIG_PRECISION, MYF(0), len, a->name,
02135                  DECIMAL_MAX_PRECISION);
02136         return 0;
02137       }
02138       if (dec > DECIMAL_MAX_SCALE)
02139       {
02140         my_error(ER_TOO_BIG_SCALE, MYF(0), dec, a->name,
02141                  DECIMAL_MAX_SCALE);
02142         return 0;
02143       }
02144       res= new (session->mem_root) Item_decimal_typecast(a, len, dec);
02145       break;
02146     }
02147   case ITEM_CAST_CHAR:
02148     {
02149       len= c_len ? atoi(c_len) : -1;
02150       res= create_func_char_cast(session, a, len, cs);
02151       break;
02152     }
02153   }
02154 
02155   return res;
02156 }
02157 
02158 } /* namespace drizzled */