Commit dac54674e421d4c161f5970cfb468dbe0bca8ef9
1 parent
23c0ad79
Exists in
master
Atualizada classe {{{clsBanco_}}} para tornar reescrita de SQL opcional
Showing
1 changed file
with
15 additions
and
12 deletions
Show diff stats
ieducar/intranet/include/clsBancoPgSql.inc.php
| ... | ... | @@ -378,11 +378,13 @@ abstract class clsBancoSQL_ |
| 378 | 378 | /** |
| 379 | 379 | * Executa uma consulta SQL. |
| 380 | 380 | * |
| 381 | - * @param string $consulta | |
| 381 | + * @param string $consulta Consulta SQL. | |
| 382 | + * @param bool $reescrever (Opcional) SQL é reescrita para transformar | |
| 383 | + * sintaxe MySQL em PostgreSQL. | |
| 382 | 384 | * @return bool|resource FALSE em caso de erro ou o identificador da consulta |
| 383 | 385 | * em caso de sucesso. |
| 384 | 386 | */ |
| 385 | - public function Consulta($consulta) | |
| 387 | + public function Consulta($consulta, $reescrever = true) | |
| 386 | 388 | { |
| 387 | 389 | $cronometro = new clsCronometro(); |
| 388 | 390 | $cronometro->marca('inicio'); |
| ... | ... | @@ -403,20 +405,21 @@ abstract class clsBancoSQL_ |
| 403 | 405 | } |
| 404 | 406 | |
| 405 | 407 | // Alterações de padrão MySQL para PostgreSQL |
| 408 | + if ($reescrever) { | |
| 409 | + // Altera o Limit | |
| 410 | + $this->strStringSQL = eregi_replace( "LIMIT[ ]{0,3}([0-9]+)[ ]{0,3},[ ]{0,3}([0-9]+)", "LIMIT \\2 OFFSET \\1", $this->strStringSQL ); | |
| 406 | 411 | |
| 407 | - // Altera o Limit | |
| 408 | - $this->strStringSQL = eregi_replace( "LIMIT[ ]{0,3}([0-9]+)[ ]{0,3},[ ]{0,3}([0-9]+)", "LIMIT \\2 OFFSET \\1", $this->strStringSQL ); | |
| 412 | + // Altera selects com YEAR( campo ) ou MONTH ou DAY | |
| 413 | + $this->strStringSQL = eregi_replace( "(YEAR|MONTH|DAY)[(][ ]{0,3}(([a-z]|_|[0-9])+)[ ]{0,3}[)]", "EXTRACT( \\1 FROM \\2 )", $this->strStringSQL ); | |
| 409 | 414 | |
| 410 | - // Altera selects com YEAR( campo ) ou MONTH ou DAY | |
| 411 | - $this->strStringSQL = eregi_replace( "(YEAR|MONTH|DAY)[(][ ]{0,3}(([a-z]|_|[0-9])+)[ ]{0,3}[)]", "EXTRACT( \\1 FROM \\2 )", $this->strStringSQL ); | |
| 415 | + // Remove os ORDER BY das querys COUNT() | |
| 416 | + // Altera os LIKE para ILIKE (ignore case) | |
| 417 | + $this->strStringSQL = eregi_replace(" LIKE ", " ILIKE ", $this->strStringSQL); | |
| 412 | 418 | |
| 413 | - // Remove os ORDER BY das querys COUNT() | |
| 414 | - // Altera os LIKE para ILIKE (ignore case) | |
| 415 | - $this->strStringSQL = eregi_replace(" LIKE ", " ILIKE ", $this->strStringSQL); | |
| 419 | + $this->strStringSQL = eregi_replace("([a-z_0-9.]+) +ILIKE +'([^']+)'", "to_ascii(\\1) ILIKE to_ascii('\\2')", $this->strStringSQL); | |
| 416 | 420 | |
| 417 | - $this->strStringSQL = eregi_replace("([a-z_0-9.]+) +ILIKE +'([^']+)'", "to_ascii(\\1) ILIKE to_ascii('\\2')", $this->strStringSQL); | |
| 418 | - | |
| 419 | - $this->strStringSQL = eregi_replace("fcn_upper_nrm", "to_ascii", $this->strStringSQL); | |
| 421 | + $this->strStringSQL = eregi_replace("fcn_upper_nrm", "to_ascii", $this->strStringSQL); | |
| 422 | + } | |
| 420 | 423 | |
| 421 | 424 | $temp = explode("'", $this->strStringSQL); |
| 422 | 425 | ... | ... |