VaioWay
VaioWay

Reputation: 402

It's okay to pass a MySQL query with a lot of spaces?

I'm using this query with PHP:

$query = "UPDATE viajens SET tipo_operacao = $tipo_operacao, 
                             percurso = $percurso, 
                             tipo_cliente = $tipo_cliente, 
                             previsao_inicio = '$previsao_inicio', 
                             previsao_fim = '$previsao_fim', 
                             quilometragem_estimada = '$km_estimada', 
                             origem_empresa_id = $origem, 
                             transportador_empresa_id = $transportador, 
                             motorista_id = $motorista, 
                             veiculo_id = $veiculo1, 
                             reboque1_veiculo_id = $veiculo2, 
                             reboque2_veiculo_id = $veiculo3, 
                             reboque3_veiculo_id = $veiculo4 
                       WHERE id_viajem = $id_viajem;";

Parsed view:

$query = "UPDATE viajens SET tipo_operacao = $tipo_operacao,                                percurso = $percurso,                                tipo_cliente = $tipo_cliente,                               previsao_inicio = '$previsao_inicio',                                previsao_fim = '$previsao_fim',                                quilometragem_estimada = '$km_estimada',                                origem_empresa_id = $origem,                                transportador_empresa_id = $transportador,                                motorista_id = $motorista,                                veiculo_id = $veiculo1,                                reboque1_veiculo_id = $veiculo2,                                reboque2_veiculo_id = $veiculo3,                                reboque3_veiculo_id = $veiculo4                                WHERE id_viajem = $id_viajem;";

By doing this, will MySQL process this query any slower than an inline query?

Upvotes: 3

Views: 95

Answers (2)

levi
levi

Reputation: 22697

There isn't problem with spaces, remember, SQL like others languages, before executing the code, it's parsed to construct AST(abstract syntax tree derived from your code) ignoring comments and spaces.

btw, AST contains only necesary information to execute code.

Upvotes: 0

Tim Fountain
Tim Fountain

Reputation: 33148

Yes, spaces are fine, so stick with what you have if you find it more readable. Stripping out spaces is not something computers have any trouble doing.

Upvotes: 4

Related Questions