vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hello, I'm french and I need some help. In a stored procedure, I want to create a database. The name of database is a parametre, but it don't work... ex : create procedure test(IN dbname varchar(20)) begin create database dbname; end call test('toto'); This stored procedure create a database named dbname but not toto, how I can do for create a database named toto (parametre). I hope you understand me... Thanks, Matt... |
| |||
| matt wrote: > Hello, > > I'm french and I need some help. > > In a stored procedure, I want to create a database. > The name of database is a parametre, but it don't work... > > ex : > > create procedure test(IN dbname varchar(20)) > begin > create database dbname; > end > > call test('toto'); > > This stored procedure create a database named dbname but not toto, how I > can do for create a database named toto (parametre). > > I hope you understand me... > > Thanks, > > Matt... Unfortunately, with today's implementation of stored procedures, you can't do that. The only way to create a database dynamically would be with a prepared statement, which however does not support the "CREATE DATABASE" statement yet. There is a plan from MySQL to implement in prepared statements all the instructions that are valid in stored procedures, but it has not been completed yet. Therefore, the only official way to do it dynamically is to use an external language. There is an unofficial way as well (see the abstract at http://conferences.oreillynet.com/cs...ew/e_sess/8015 and the source code here: http://sourceforge.net/projects/mysql-sr-lib/), but it's a undocumented hack. ciao gmax -- _ _ _ _ (_|| | |(_|>< The Data Charmer _| http://datacharmer.org/ |
| ||||
| Giuseppe Maxia a écrit : > matt wrote: >> Hello, >> >> I'm french and I need some help. >> >> In a stored procedure, I want to create a database. >> The name of database is a parametre, but it don't work... >> >> ex : >> >> create procedure test(IN dbname varchar(20)) >> begin >> create database dbname; >> end >> >> call test('toto'); >> >> This stored procedure create a database named dbname but not toto, how I >> can do for create a database named toto (parametre). >> >> I hope you understand me... >> >> Thanks, >> >> Matt... > > > Unfortunately, with today's implementation of stored procedures, you can't do that. > The only way to create a database dynamically would be with a prepared statement, > which however does not support the "CREATE DATABASE" statement yet. There is a plan > from MySQL to implement in prepared statements all the instructions that are valid > in stored procedures, but it has not been completed yet. > > Therefore, the only official way to do it dynamically is to use an external language. > There is an unofficial way as well (see the abstract at > http://conferences.oreillynet.com/cs...ew/e_sess/8015 and the source code > here: http://sourceforge.net/projects/mysql-sr-lib/), but it's a undocumented hack. > > ciao > gmax > Hello, Ok, thanks for you answer. I do it, in c language : retour = system("mysql -e script.sql") and if retour != 0, it's ok for me. I don't know if it's the best way, but it work. Matt... |