Monday, October 24, 2011

How to save procedure and function code by mysql5.1?

some people ask a question:How to save procedure and function code by MYSQL?
check mysql5.1 source code,we get the answer.
1)MYSQL use a table to save this text code,the table name is MYSQL.PROC and table type is MYISAM.
2)The source code is sql/sp.cc and the method is "int sp_create_routine(THD *thd, int type, sp_head *sp)".
3)we can get the comment as following:
/**
Write stored-routine object into mysql.proc.

This operation stores attributes of the stored procedure/function into
the mysql.proc.

@param thd Thread context.
@param type Stored routine type
(TYPE_ENUM_PROCEDURE or TYPE_ENUM_FUNCTION).
@param sp Stored routine object to store.

@note Opens and closes the thread tables. Therefore assumes
that there are no locked tables in this thread at the time of
invocation.
Unlike some other DDL statements, *does* close the tables
in the end, since the call to this function is normally
followed by an implicit grant (sp_grant_privileges())
and this subsequent call opens and closes mysql.procs_priv.

@return Error code. SP_OK is returned on success. Other
SP_ constants are used to indicate about errors.
*/

No comments:

Post a Comment