views:

195

answers:

2

Is it possible to retrieve stored procedure information like name, parameter nane/position/type from the Information Schema in MySQL or possible in some other way?

+2  A: 

You can get a lot of information, including the name, from INFORMATION_SCHEMA.ROUTINES. See the MySQL Manual for details.

The parameter information would be contained in the INFORMATION_SCHEMA.PARAMETERS table, but this table is not available in MySQL, so I'm not sure that you can get that information from INFORMATION_SCHEMA.

If you just need the argument list, you can select the procedure names from INFORMATION_SCHEMA.ROUTINES then get the CREATE PROCEDURE statements for each of them using SHOW CREATE PROCEDURE. If you just need the arguments and types, you should be able to parse them without too much trouble.

James McNellis
INFORMATION_SCHEMA.PARAMETERS does not seem to exist..?
Ropstah
Nope. It _was_ in MySQL 6, but it was never backported to MySQL 5.
James McNellis
grrrr so no way on generating stored procedure classes from the database?
Ropstah
You can use `SHOW CREATE PROCEDURE` (http://dev.mysql.com/doc/refman/5.0/en/show-create-procedure.html) and parse it yourself... if you're just parsing the parameter list, that wouldn't be too difficult.
James McNellis
nice, thanks a lot!
Ropstah
You're welcome.
James McNellis
A: 

I believe something like what you are looking for is possible using MySQL's built in backup program: mysqldump. Give this a try:

mysqldump --routines --triggers --nodata --skip-opt YOURDB

Details: A quick look at the documentation (MySQL 5.4) shows you definitely want to run it with the --routines option, as well as probably --triggers. I'm guessing you'll want to skip most of the data in this dump, just to look at the procedures, in which case you may want the options --nodata --skip-opt and probably some other options I haven't identified yet. Check out the documentation for your version for whatever other options you want. Also note you can specify just some of the tables in the DB by adding their names on the end.

Willfulwizard
Thanks for thinking along, i think James' solutions is sufficient, but I will surely look into this!
Ropstah