| 657 | |
| 658 | |
| 659 | enum drop_udf_result mysql_drop_function(THD *thd, const LEX_CSTRING *udf_name) |
| 660 | { |
| 661 | TABLE *table; |
| 662 | udf_func *udf; |
| 663 | DBUG_ENTER("mysql_drop_function"); |
| 664 | |
| 665 | if (thd->locked_tables_mode) |
| 666 | { |
| 667 | my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0)); |
| 668 | DBUG_RETURN(UDF_DEL_RESULT_ERROR); |
| 669 | } |
| 670 | |
| 671 | if (!(table= open_udf_func_table(thd))) |
| 672 | DBUG_RETURN(UDF_DEL_RESULT_ERROR); |
| 673 | |
| 674 | // Fast pre-check |
| 675 | if (!mysql_rwlock_tryrdlock(&THR_LOCK_udf)) |
| 676 | { |
| 677 | bool found= find_udf_everywhere(thd, *udf_name, table); |
| 678 | mysql_rwlock_unlock(&THR_LOCK_udf); |
| 679 | if (!found) |
| 680 | { |
| 681 | close_mysql_tables(thd); |
| 682 | DBUG_RETURN(UDF_DEL_RESULT_ABSENT); |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | if (!initialized) |
| 687 | { |
| 688 | close_mysql_tables(thd); |
| 689 | if (opt_noacl) |
| 690 | DBUG_RETURN(UDF_DEL_RESULT_ABSENT); // SP should be checked |
| 691 | |
| 692 | my_message(ER_OUT_OF_RESOURCES, ER_THD(thd, ER_OUT_OF_RESOURCES), MYF(0)); |
| 693 | DBUG_RETURN(UDF_DEL_RESULT_ERROR); |
| 694 | } |
| 695 | |
| 696 | mysql_rwlock_wrlock(&THR_LOCK_udf); |
| 697 | |
| 698 | // re-check under protection |
| 699 | if (!find_udf_everywhere(thd, *udf_name, table)) |
| 700 | { |
| 701 | close_mysql_tables(thd); |
| 702 | mysql_rwlock_unlock(&THR_LOCK_udf); |
| 703 | DBUG_RETURN(UDF_DEL_RESULT_ABSENT); |
| 704 | } |
| 705 | |
| 706 | if (check_access(thd, DELETE_ACL, "mysql", NULL, NULL, 1, 0)) |
| 707 | goto err; |
| 708 | |
| 709 | |
| 710 | DEBUG_SYNC(current_thd, "mysql_drop_function_after_lock"); |
| 711 | |
| 712 | if (!(udf= (udf_func*) my_hash_search(&udf_hash, (uchar*) udf_name->str, |
| 713 | (uint) udf_name->length)) ) |
| 714 | { |
| 715 | if (remove_udf_in_table(*udf_name, table)) |
| 716 | goto err; |
no test coverage detected