| 1999 | // |
| 2000 | |
| 2001 | static void declare_udf( gpre_req* request, const act* action) |
| 2002 | { |
| 2003 | const decl_udf* udf_declaration = (decl_udf*) action->act_object; |
| 2004 | const TEXT* udf_name = udf_declaration->decl_udf_name; |
| 2005 | put_cstring(request, isc_dyn_def_function, udf_name); |
| 2006 | put_cstring(request, isc_dyn_func_entry_point, udf_declaration->decl_udf_entry_point); |
| 2007 | put_cstring(request, isc_dyn_func_module_name, udf_declaration->decl_udf_module_name); |
| 2008 | |
| 2009 | // Reverse the order of arguments which parse left backwords. |
| 2010 | |
| 2011 | //for (field = udf_declaration->decl_udf_arg_list, udf_declaration->decl_udf_arg_list = NULL; field; field = next) |
| 2012 | //{ |
| 2013 | // next = field->fld_next; |
| 2014 | // field->fld_next = udf_declaration->decl_udf_arg_list; |
| 2015 | // udf_declaration->decl_udf_arg_list = field; |
| 2016 | //} |
| 2017 | |
| 2018 | SSHORT position, blob_position = 0; |
| 2019 | const gpre_fld* field = udf_declaration->decl_udf_return_type; |
| 2020 | if (field) |
| 2021 | { |
| 2022 | // Function returns a value |
| 2023 | |
| 2024 | // Some data types can not be returned as value |
| 2025 | if (udf_declaration->decl_udf_return_mode == FUN_value) |
| 2026 | { |
| 2027 | switch (field->fld_dtype) |
| 2028 | { |
| 2029 | case dtype_text: |
| 2030 | case dtype_varying: |
| 2031 | case dtype_cstring: |
| 2032 | case dtype_blob: |
| 2033 | case dtype_timestamp: |
| 2034 | CPR_error("return mode by value not allowed for this data type"); |
| 2035 | } |
| 2036 | } |
| 2037 | |
| 2038 | // For functions returning a blob, coerce return argument position to |
| 2039 | // be the last parameter. |
| 2040 | |
| 2041 | if (field->fld_dtype == dtype_blob) |
| 2042 | { |
| 2043 | blob_position = 1; |
| 2044 | for (const gpre_fld* next = udf_declaration->decl_udf_arg_list; next; next = next->fld_next) |
| 2045 | { |
| 2046 | ++blob_position; |
| 2047 | } |
| 2048 | put_numeric(request, isc_dyn_func_return_argument, blob_position); |
| 2049 | } |
| 2050 | else |
| 2051 | put_numeric(request, isc_dyn_func_return_argument, 0); |
| 2052 | |
| 2053 | position = 0; |
| 2054 | } |
| 2055 | else { |
| 2056 | position = 1; |
| 2057 | |
| 2058 | // Function modifies an argument whose value is the function return value |
no test coverage detected