Commit 7356ae56 authored by unknown's avatar unknown

Merge mysql.com:/home/wax/mysql-4n into mysql.com:/home/wax/mysql-4rw


sql/item_func.cc:
  Auto merged
sql/sql_parse.cc:
  Auto merged
sql/sql_yacc.yy:
  Auto merged
parents d6a9713b e068011a
...@@ -1291,11 +1291,11 @@ udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func, ...@@ -1291,11 +1291,11 @@ udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func,
} }
else else
thd=current_thd; // In WHERE / const clause thd=current_thd; // In WHERE / const clause
udf_func *tmp_udf=find_udf(u_d->name,(uint) strlen(u_d->name),1); udf_func *tmp_udf=find_udf(u_d->name.str,(uint) u_d->name.length,1);
if (!tmp_udf) if (!tmp_udf)
{ {
my_printf_error(ER_CANT_FIND_UDF,ER(ER_CANT_FIND_UDF),MYF(0),u_d->name, my_printf_error(ER_CANT_FIND_UDF,ER(ER_CANT_FIND_UDF),MYF(0),u_d->name.str,
errno); errno);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
......
...@@ -2705,7 +2705,7 @@ mysql_execute_command(THD *thd) ...@@ -2705,7 +2705,7 @@ mysql_execute_command(THD *thd)
if (check_access(thd,DELETE_ACL,"mysql",0,1)) if (check_access(thd,DELETE_ACL,"mysql",0,1))
break; break;
#ifdef HAVE_DLOPEN #ifdef HAVE_DLOPEN
if (!(res = mysql_drop_function(thd,lex->udf.name))) if (!(res = mysql_drop_function(thd,&lex->udf.name)))
send_ok(thd); send_ok(thd);
#else #else
res= -1; res= -1;
......
...@@ -74,7 +74,7 @@ static HASH udf_hash; ...@@ -74,7 +74,7 @@ static HASH udf_hash;
static rw_lock_t THR_LOCK_udf; static rw_lock_t THR_LOCK_udf;
static udf_func *add_udf(char *name, Item_result ret, char *dl, static udf_func *add_udf(LEX_STRING *name, Item_result ret, char *dl,
Item_udftype typ); Item_udftype typ);
static void del_udf(udf_func *udf); static void del_udf(udf_func *udf);
static void *find_udf_dl(const char *dl); static void *find_udf_dl(const char *dl);
...@@ -84,8 +84,8 @@ static void init_syms(udf_func *tmp) ...@@ -84,8 +84,8 @@ static void init_syms(udf_func *tmp)
{ {
char nm[MAX_FIELD_NAME+16],*end; char nm[MAX_FIELD_NAME+16],*end;
tmp->func = dlsym(tmp->dlhandle, tmp->name); tmp->func = dlsym(tmp->dlhandle, tmp->name.str);
end=strmov(nm,tmp->name); end=strmov(nm,tmp->name.str);
(void) strmov(end,"_init"); (void) strmov(end,"_init");
tmp->func_init = dlsym(tmp->dlhandle, nm); tmp->func_init = dlsym(tmp->dlhandle, nm);
(void) strmov(end,"_deinit"); (void) strmov(end,"_deinit");
...@@ -103,8 +103,8 @@ extern "C" byte* get_hash_key(const byte *buff,uint *length, ...@@ -103,8 +103,8 @@ extern "C" byte* get_hash_key(const byte *buff,uint *length,
my_bool not_used __attribute__((unused))) my_bool not_used __attribute__((unused)))
{ {
udf_func *udf=(udf_func*) buff; udf_func *udf=(udf_func*) buff;
*length=(uint) udf->name_length; *length=(uint) udf->name.length;
return (byte*) udf->name; return (byte*) udf->name.str;
} }
/* /*
...@@ -161,14 +161,16 @@ void udf_init() ...@@ -161,14 +161,16 @@ void udf_init()
while (!(error = read_record_info.read_record(&read_record_info))) while (!(error = read_record_info.read_record(&read_record_info)))
{ {
DBUG_PRINT("info",("init udf record")); DBUG_PRINT("info",("init udf record"));
char *name=get_field(&mem, table, 0); LEX_STRING name;
name.str=get_field(&mem, table, 0);
name.length = strlen(name.str);
char *dl_name= get_field(&mem, table, 2); char *dl_name= get_field(&mem, table, 2);
bool new_dl=0; bool new_dl=0;
Item_udftype udftype=UDFTYPE_FUNCTION; Item_udftype udftype=UDFTYPE_FUNCTION;
if (table->fields >= 4) // New func table if (table->fields >= 4) // New func table
udftype=(Item_udftype) table->field[3]->val_int(); udftype=(Item_udftype) table->field[3]->val_int();
if (!(tmp = add_udf(name,(Item_result) table->field[1]->val_int(), if (!(tmp = add_udf(&name,(Item_result) table->field[1]->val_int(),
dl_name, udftype))) dl_name, udftype)))
{ {
sql_print_error("Can't alloc memory for udf function: name"); sql_print_error("Can't alloc memory for udf function: name");
...@@ -250,10 +252,10 @@ static void del_udf(udf_func *udf) ...@@ -250,10 +252,10 @@ static void del_udf(udf_func *udf)
The functions will be automaticly removed when the least threads The functions will be automaticly removed when the least threads
doesn't use it anymore doesn't use it anymore
*/ */
char *name= udf->name; char *name= udf->name.str;
uint name_length=udf->name_length; uint name_length=udf->name.length;
udf->name=(char*) "*"; udf->name.str=(char*) "*";
udf->name_length=1; udf->name.length=1;
hash_update(&udf_hash,(byte*) udf,(byte*) name,name_length); hash_update(&udf_hash,(byte*) udf,(byte*) name,name_length);
} }
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
...@@ -322,7 +324,7 @@ static void *find_udf_dl(const char *dl) ...@@ -322,7 +324,7 @@ static void *find_udf_dl(const char *dl)
/* Assume that name && dl is already allocated */ /* Assume that name && dl is already allocated */
static udf_func *add_udf(char *name, Item_result ret, char *dl, static udf_func *add_udf(LEX_STRING *name, Item_result ret, char *dl,
Item_udftype type) Item_udftype type)
{ {
if (!name || !dl || !(uint) type || (uint) type > (uint) UDFTYPE_AGGREGATE) if (!name || !dl || !(uint) type || (uint) type > (uint) UDFTYPE_AGGREGATE)
...@@ -331,8 +333,7 @@ static udf_func *add_udf(char *name, Item_result ret, char *dl, ...@@ -331,8 +333,7 @@ static udf_func *add_udf(char *name, Item_result ret, char *dl,
if (!tmp) if (!tmp)
return 0; return 0;
bzero((char*) tmp,sizeof(*tmp)); bzero((char*) tmp,sizeof(*tmp));
tmp->name = name; tmp->name = *name; //dup !!
tmp->name_length=(uint) strlen(tmp->name);
tmp->dl = dl; tmp->dl = dl;
tmp->returns = ret; tmp->returns = ret;
tmp->type = type; tmp->type = type;
...@@ -370,14 +371,14 @@ int mysql_create_function(THD *thd,udf_func *udf) ...@@ -370,14 +371,14 @@ int mysql_create_function(THD *thd,udf_func *udf)
send_error(thd, ER_UDF_NO_PATHS,ER(ER_UDF_NO_PATHS)); send_error(thd, ER_UDF_NO_PATHS,ER(ER_UDF_NO_PATHS));
DBUG_RETURN(1); DBUG_RETURN(1);
} }
if (udf->name_length > NAME_LEN) if (udf->name.length > NAME_LEN)
{ {
net_printf(thd, ER_TOO_LONG_IDENT,udf->name); net_printf(thd, ER_TOO_LONG_IDENT,udf->name);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
rw_wrlock(&THR_LOCK_udf); rw_wrlock(&THR_LOCK_udf);
if ((hash_search(&udf_hash,(byte*) udf->name, udf->name_length))) if ((hash_search(&udf_hash,(byte*) udf->name.str, udf->name.length)))
{ {
net_printf(thd, ER_UDF_EXISTS, udf->name); net_printf(thd, ER_UDF_EXISTS, udf->name);
goto err; goto err;
...@@ -401,9 +402,9 @@ int mysql_create_function(THD *thd,udf_func *udf) ...@@ -401,9 +402,9 @@ int mysql_create_function(THD *thd,udf_func *udf)
net_printf(thd, ER_CANT_FIND_DL_ENTRY, udf->name); net_printf(thd, ER_CANT_FIND_DL_ENTRY, udf->name);
goto err; goto err;
} }
udf->name=strdup_root(&mem,udf->name); udf->name.str=strdup_root(&mem,udf->name.str);
udf->dl=strdup_root(&mem,udf->dl); udf->dl=strdup_root(&mem,udf->dl);
if (!(u_d=add_udf(udf->name,udf->returns,udf->dl,udf->type))) if (!(u_d=add_udf(&udf->name,udf->returns,udf->dl,udf->type)))
{ {
send_error(thd,0); // End of memory send_error(thd,0); // End of memory
goto err; goto err;
...@@ -425,7 +426,7 @@ int mysql_create_function(THD *thd,udf_func *udf) ...@@ -425,7 +426,7 @@ int mysql_create_function(THD *thd,udf_func *udf)
goto err; goto err;
restore_record(table,2); // Get default values for fields restore_record(table,2); // Get default values for fields
table->field[0]->store(u_d->name, u_d->name_length, default_charset_info); table->field[0]->store(u_d->name.str, u_d->name.length, default_charset_info);
table->field[1]->store((longlong) u_d->returns); table->field[1]->store((longlong) u_d->returns);
table->field[2]->store(u_d->dl,(uint) strlen(u_d->dl), default_charset_info); table->field[2]->store(u_d->dl,(uint) strlen(u_d->dl), default_charset_info);
if (table->fields >= 4) // If not old func format if (table->fields >= 4) // If not old func format
...@@ -450,7 +451,7 @@ int mysql_create_function(THD *thd,udf_func *udf) ...@@ -450,7 +451,7 @@ int mysql_create_function(THD *thd,udf_func *udf)
} }
int mysql_drop_function(THD *thd,const char *udf_name) int mysql_drop_function(THD *thd,const LEX_STRING *udf_name)
{ {
TABLE *table; TABLE *table;
TABLE_LIST tables; TABLE_LIST tables;
...@@ -462,8 +463,8 @@ int mysql_drop_function(THD *thd,const char *udf_name) ...@@ -462,8 +463,8 @@ int mysql_drop_function(THD *thd,const char *udf_name)
DBUG_RETURN(1); DBUG_RETURN(1);
} }
rw_wrlock(&THR_LOCK_udf); rw_wrlock(&THR_LOCK_udf);
if (!(udf=(udf_func*) hash_search(&udf_hash,(byte*) udf_name, if (!(udf=(udf_func*) hash_search(&udf_hash,(byte*) udf_name->str,
(uint) strlen(udf_name)))) (uint) udf_name->length)))
{ {
net_printf(thd, ER_FUNCTION_NOT_DEFINED, udf_name); net_printf(thd, ER_FUNCTION_NOT_DEFINED, udf_name);
goto err; goto err;
...@@ -481,8 +482,8 @@ int mysql_drop_function(THD *thd,const char *udf_name) ...@@ -481,8 +482,8 @@ int mysql_drop_function(THD *thd,const char *udf_name)
tables.real_name= tables.alias= (char*) "func"; tables.real_name= tables.alias= (char*) "func";
if (!(table = open_ltable(thd,&tables,TL_WRITE))) if (!(table = open_ltable(thd,&tables,TL_WRITE)))
goto err; goto err;
if (!table->file->index_read_idx(table->record[0],0,(byte*) udf_name, if (!table->file->index_read_idx(table->record[0],0,(byte*) udf_name->str,
(uint) strlen(udf_name), (uint) udf_name->length,
HA_READ_KEY_EXACT)) HA_READ_KEY_EXACT))
{ {
int error; int error;
......
...@@ -25,8 +25,7 @@ enum Item_udftype {UDFTYPE_FUNCTION=1,UDFTYPE_AGGREGATE}; ...@@ -25,8 +25,7 @@ enum Item_udftype {UDFTYPE_FUNCTION=1,UDFTYPE_AGGREGATE};
typedef struct st_udf_func typedef struct st_udf_func
{ {
char *name; LEX_STRING name;
int name_length;
Item_result returns; Item_result returns;
Item_udftype type; Item_udftype type;
char *dl; char *dl;
...@@ -61,7 +60,7 @@ class udf_handler :public Sql_alloc ...@@ -61,7 +60,7 @@ class udf_handler :public Sql_alloc
initialized(0) initialized(0)
{} {}
~udf_handler(); ~udf_handler();
const char *name() const { return u_d ? u_d->name : "?"; } const char *name() const { return u_d ? u_d->name.str : "?"; }
Item_result result_type () const Item_result result_type () const
{ return u_d ? u_d->returns : STRING_RESULT;} { return u_d ? u_d->returns : STRING_RESULT;}
bool get_arguments(); bool get_arguments();
...@@ -140,5 +139,5 @@ void udf_init(void),udf_free(void); ...@@ -140,5 +139,5 @@ void udf_init(void),udf_free(void);
udf_func *find_udf(const char *name, uint len=0,bool mark_used=0); udf_func *find_udf(const char *name, uint len=0,bool mark_used=0);
void free_udf(udf_func *udf); void free_udf(udf_func *udf);
int mysql_create_function(THD *thd,udf_func *udf); int mysql_create_function(THD *thd,udf_func *udf);
int mysql_drop_function(THD *thd,const char *name); int mysql_drop_function(THD *thd,const LEX_STRING *name);
#endif #endif
...@@ -870,12 +870,11 @@ create: ...@@ -870,12 +870,11 @@ create:
lex->name=$4.str; lex->name=$4.str;
lex->create_info.options=$3; lex->create_info.options=$3;
} }
| CREATE udf_func_type UDF_SYM ident | CREATE udf_func_type UDF_SYM IDENT
{ {
LEX *lex=Lex; LEX *lex=Lex;
lex->sql_command = SQLCOM_CREATE_FUNCTION; lex->sql_command = SQLCOM_CREATE_FUNCTION;
lex->udf.name=$4.str; lex->udf.name = $4;
lex->udf.name_length=$4.length;
lex->udf.type= $2; lex->udf.type= $2;
} }
UDF_RETURNS_SYM udf_type UDF_SONAME_SYM TEXT_STRING UDF_RETURNS_SYM udf_type UDF_SONAME_SYM TEXT_STRING
...@@ -3013,11 +3012,11 @@ drop: ...@@ -3013,11 +3012,11 @@ drop:
lex->drop_if_exists=$3; lex->drop_if_exists=$3;
lex->name=$4.str; lex->name=$4.str;
} }
| DROP UDF_SYM ident | DROP UDF_SYM IDENT
{ {
LEX *lex=Lex; LEX *lex=Lex;
lex->sql_command = SQLCOM_DROP_FUNCTION; lex->sql_command = SQLCOM_DROP_FUNCTION;
lex->udf.name=$3.str; lex->udf.name = $3;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment