summaryrefslogtreecommitdiff
path: root/sql/sql_udf.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_udf.cc')
-rw-r--r--sql/sql_udf.cc58
1 files changed, 15 insertions, 43 deletions
diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc
index 1ebf2a79d7c..adda7316e3a 100644
--- a/sql/sql_udf.cc
+++ b/sql/sql_udf.cc
@@ -37,36 +37,10 @@
#ifdef HAVE_DLOPEN
extern "C"
{
-#if defined(__WIN__)
- void* dlsym(void* lib,const char* name)
- {
- return GetProcAddress((HMODULE)lib,name);
- }
- void* dlopen(const char* libname,int unused)
- {
- return LoadLibraryEx(libname,NULL,0);
- }
- void dlclose(void* lib)
- {
- FreeLibrary((HMODULE)lib);
- }
-
-#elif !defined(OS2)
-#include <dlfcn.h>
-#endif
-
#include <stdarg.h>
#include <hash.h>
}
-#ifndef RTLD_NOW
-#define RTLD_NOW 1 // For FreeBSD 2.2.2
-#endif
-
-#ifndef HAVE_DLERROR
-#define dlerror() ""
-#endif
-
static bool initialized = 0;
static MEM_ROOT mem;
static HASH udf_hash;
@@ -139,8 +113,8 @@ void udf_init()
READ_RECORD read_record_info;
TABLE *table;
int error;
- char db[]= "mysql"; /* A subject to casednstr, can't be constant */
DBUG_ENTER("ufd_init");
+ char db[]= "mysql"; /* A subject to casednstr, can't be constant */
if (initialized)
DBUG_VOID_RETURN;
@@ -171,13 +145,14 @@ void udf_init()
if (simple_open_n_lock_tables(new_thd, &tables))
{
DBUG_PRINT("error",("Can't open udf table"));
- sql_print_error("Can't open the mysql.func table. Please run the mysql_install_db script to create it.");
+ sql_print_error("Can't open the mysql.func table. Please run the mysql_upgrade script to create it.");
goto end;
}
table= tables.table;
init_read_record(&read_record_info, new_thd, table, NULL,1,0);
- while (!(error = read_record_info.read_record(&read_record_info)))
+ table->use_all_columns();
+ while (!(error= read_record_info.read_record(&read_record_info)))
{
DBUG_PRINT("info",("init udf record"));
LEX_STRING name;
@@ -194,16 +169,14 @@ void udf_init()
This is done to ensure that only approved dll from the system
directories are used (to make this even remotely secure).
*/
- if (strchr(dl_name, '/') ||
- IF_WIN(strchr(dl_name, '\\'),0) ||
- strlen(name.str) > NAME_LEN)
+ if (my_strchr(files_charset_info, dl_name, dl_name + strlen(dl_name), FN_LIBCHAR) ||
+ strlen(name.str) > NAME_LEN)
{
sql_print_error("Invalid row in mysql.func table for function '%.64s'",
name.str);
continue;
}
-
if (!(tmp= add_udf(&name,(Item_result) table->field[1]->val_int(),
dl_name, udftype)))
{
@@ -214,10 +187,10 @@ void udf_init()
void *dl = find_udf_dl(tmp->dl);
if (dl == NULL)
{
- if (!(dl = dlopen(tmp->dl, RTLD_NOW)))
+ if (!(dl= dlopen(tmp->dl, RTLD_NOW)))
{
/* Print warning to log */
- sql_print_error(ER(ER_CANT_OPEN_LIBRARY), tmp->dl,errno,dlerror());
+ sql_print_error(ER(ER_CANT_OPEN_LIBRARY), tmp->dl, errno, dlerror());
/* Keep the udf in the hash so that we can remove it later */
continue;
}
@@ -419,7 +392,7 @@ int mysql_create_function(THD *thd,udf_func *udf)
This is done to ensure that only approved dll from the system
directories are used (to make this even remotely secure).
*/
- if (strchr(udf->dl, '/') || IF_WIN(strchr(udf->dl, '\\'),0))
+ if (my_strchr(files_charset_info, udf->dl, udf->dl + strlen(udf->dl), FN_LIBCHAR))
{
my_message(ER_UDF_NO_PATHS, ER(ER_UDF_NO_PATHS), MYF(0));
DBUG_RETURN(1);
@@ -438,13 +411,12 @@ int mysql_create_function(THD *thd,udf_func *udf)
}
if (!(dl = find_udf_dl(udf->dl)))
{
- DBUG_PRINT("info", ("Calling dlopen, udf->dl: %s", udf->dl));
if (!(dl = dlopen(udf->dl, RTLD_NOW)))
{
DBUG_PRINT("error",("dlopen of %s failed, error: %d (%s)",
- udf->dl,errno,dlerror()));
+ udf->dl, errno, dlerror()));
my_error(ER_CANT_OPEN_LIBRARY, MYF(0),
- udf->dl, errno, dlerror());
+ udf->dl, errno, dlerror());
goto err;
}
new_dl=1;
@@ -477,14 +449,14 @@ int mysql_create_function(THD *thd,udf_func *udf)
/* Allow creation of functions even if we can't open func table */
if (!(table = open_ltable(thd,&tables,TL_WRITE)))
goto err;
-
+ table->use_all_columns();
restore_record(table, s->default_values); // Default values for fields
table->field[0]->store(u_d->name.str, u_d->name.length, system_charset_info);
table->field[1]->store((longlong) u_d->returns, TRUE);
table->field[2]->store(u_d->dl,(uint) strlen(u_d->dl), system_charset_info);
if (table->s->fields >= 4) // If not old func format
table->field[3]->store((longlong) u_d->type, TRUE);
- error = table->file->write_row(table->record[0]);
+ error = table->file->ha_write_row(table->record[0]);
close_thread_tables(thd);
if (error)
@@ -535,15 +507,15 @@ int mysql_drop_function(THD *thd,const LEX_STRING *udf_name)
tables.table_name= tables.alias= (char*) "func";
if (!(table = open_ltable(thd,&tables,TL_WRITE)))
goto err;
+ table->use_all_columns();
table->field[0]->store(udf_name->str, udf_name->length, system_charset_info);
- table->file->extra(HA_EXTRA_RETRIEVE_ALL_COLS);
if (!table->file->index_read_idx(table->record[0], 0,
(byte*) table->field[0]->ptr,
table->key_info[0].key_length,
HA_READ_KEY_EXACT))
{
int error;
- if ((error = table->file->delete_row(table->record[0])))
+ if ((error = table->file->ha_delete_row(table->record[0])))
table->file->print_error(error, MYF(0));
}
close_thread_tables(thd);