| 1 | /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. |
| 2 | |
| 3 | This program is free software; you can redistribute it and/or modify |
| 4 | it under the terms of the GNU General Public License as published by |
| 5 | the Free Software Foundation; version 2 of the License. |
| 6 | |
| 7 | This program is distributed in the hope that it will be useful, |
| 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | GNU General Public License for more details. |
| 11 | |
| 12 | You should have received a copy of the GNU General Public License |
| 13 | along with this program; if not, write to the Free Software |
| 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 15 | |
| 16 | |
| 17 | /* Procedures (functions with changes output of select) */ |
| 18 | |
| 19 | #ifdef USE_PRAGMA_IMPLEMENTATION |
| 20 | #pragma implementation // gcc: Class implementation |
| 21 | #endif |
| 22 | |
| 23 | #include "mariadb.h" |
| 24 | #include "sql_priv.h" |
| 25 | #include "procedure.h" |
| 26 | #include "sql_analyse.h" // Includes procedure |
| 27 | #ifdef USE_PROC_RANGE |
| 28 | #include "proc_range.h" |
| 29 | #endif |
| 30 | |
| 31 | static struct st_procedure_def { |
| 32 | const char *name; |
| 33 | Procedure *(*init)(THD *thd,ORDER *param,select_result *result, |
| 34 | List<Item> &field_list); |
| 35 | } sql_procs[] = { |
| 36 | #ifdef USE_PROC_RANGE |
| 37 | { "split_sum" ,proc_sum_range_init }, // Internal procedure at TCX |
| 38 | { "split_count" ,proc_count_range_init }, // Internal procedure at TCX |
| 39 | { "matris_ranges" ,proc_matris_range_init }, // Internal procedure at TCX |
| 40 | #endif |
| 41 | { "analyse" ,proc_analyse_init } // Analyse a result |
| 42 | }; |
| 43 | |
| 44 | |
| 45 | my_decimal *Item_proc_string::val_decimal(my_decimal *decimal_value) |
| 46 | { |
| 47 | if (null_value) |
| 48 | return 0; |
| 49 | string2my_decimal(E_DEC_FATAL_ERROR, &str_value, decimal_value); |
| 50 | return (decimal_value); |
| 51 | } |
| 52 | |
| 53 | |
| 54 | my_decimal *Item_proc_int::val_decimal(my_decimal *decimal_value) |
| 55 | { |
| 56 | if (null_value) |
| 57 | return 0; |
| 58 | int2my_decimal(E_DEC_FATAL_ERROR, value, unsigned_flag, decimal_value); |
| 59 | return (decimal_value); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | my_decimal *Item_proc_real::val_decimal(my_decimal *decimal_value) |
| 64 | { |
| 65 | if (null_value) |
| 66 | return 0; |
| 67 | double2my_decimal(E_DEC_FATAL_ERROR, value, decimal_value); |
| 68 | return (decimal_value); |
| 69 | } |
| 70 | |
| 71 | |
| 72 | /** |
| 73 | Setup handling of procedure. |
| 74 | |
| 75 | @return |
| 76 | Return 0 if everything is ok |
| 77 | */ |
| 78 | |
| 79 | |
| 80 | Procedure * |
| 81 | setup_procedure(THD *thd,ORDER *param,select_result *result, |
| 82 | List<Item> &field_list,int *error) |
| 83 | { |
| 84 | uint i; |
| 85 | DBUG_ENTER("setup_procedure" ); |
| 86 | *error=0; |
| 87 | if (!param) |
| 88 | DBUG_RETURN(0); |
| 89 | for (i=0 ; i < array_elements(sql_procs) ; i++) |
| 90 | { |
| 91 | if (!my_strcasecmp(system_charset_info, |
| 92 | (*param->item)->name.str, sql_procs[i].name)) |
| 93 | { |
| 94 | Procedure *proc=(*sql_procs[i].init)(thd,param,result,field_list); |
| 95 | *error= !proc; |
| 96 | DBUG_RETURN(proc); |
| 97 | } |
| 98 | } |
| 99 | my_error(ER_UNKNOWN_PROCEDURE, MYF(0), (*param->item)->name.str); |
| 100 | *error=1; |
| 101 | DBUG_RETURN(0); |
| 102 | } |
| 103 | |