Create or clone table - Forum

Forum Navigation
You need to log in to create posts and topics.

Create or clone table

Hola gente, estoy intentando clonar una tabla con las sentencias convencionales de MySql pero no logro hacerlo con VisualNeo.

La sentencia que uso es la siguiente:

CREATE TABLE nueva LIKE demo

Si la coloco tal cual funciona y crea una tabla llamada "nueva" con la estructura de "demo". Entonces interpreto que la sentencia es la correcta.

El problema viene cuando quiero que el usuario coloque el nuevo nombre de dicha tabla, a lo que hago algo así:

CREATE TABLE ? LIKE demo

Ejecuto y envío la variable como una consulta convencional desde VisualNeo, pero eso no funciona. He intentado con paréntesis, comillas y demás pero no logro hacerlo. Sé que es algo sencillo pero no logro que funcione.

 

Saludos!

@palamar

CREATE TABLE ? LIKE demo

I run and send the variable as a conventional query from VisualNeo, but that doesn't work. I have tried with parentheses, quotation marks and so on but I cannot do it. I know it's a simple thing but I can't make it work.

1) Just a thought but you might try using the escape code for the question mark character ...

CREATE TABLE %3F LIKE demo

2) If that does not work, you might ...

- have a template string (e.g. "CREATE TABLE newName LIKE demo")
- prompt the user for this new name via VisualNEO dialog boxes
- use the template string in a StrReplace command
- use the resulting variable in your sql request

3) Otherwise, please provide the context within which you are trying to use this command within your web app

@palamar eso que quieres hacer no es posible porque sería una puerta de entrada a ataques de tipo "SQL injection".
Tampoco puedes usar parámetros de consulta para nombres de columna. Esto es una limitación impuesta por PHP (utilizando PDO).

Saludos.

@luishp Sospeche esto , pero de ser así cual sería una solución?. A ver, teniendo en cuenta que el comando funciona, no sería también problemático?. Porque no es que no sea posible, el comando funciona, lo que no es posible es asignar un nombre distinto al que pones en el PHP. Quizás copiarla con el formato y luego renombrarla? en este caso creo que estaría en la misma.

@gaev La segunda forma es la que probablemente pueda funcionar, aunque he hecho pruebas y aún no puedo concretarla. No he terminado de entender lo de %3F-

Saludos!

@palamar

The second way is the one that can probably work, although I have done tests and I still can't nail it down.

Please ignore my previous suggestions.

After reading response from @luishp , it appears that dynamic (i.e. run time) parameters are not allowed for fear for malicious use.

I haven't quite understood %3F-

It was a suggestion based on the outside chance that the special character "?", which is also used as a "wildcard" , might be interfering with the parsing of the command ... I thought that perhaps the ascii code might get around this (like they do with url strings with special characters).

If you can share the purpose for allowing the user to dynamically create/copy tables, there might be solutions that restrict the use of names to one of predefined ones.