From dac54674e421d4c161f5970cfb468dbe0bca8ef9 Mon Sep 17 00:00:00 2001 From: Eriksen Costa Date: Fri, 16 Jul 2010 15:33:34 -0300 Subject: [PATCH] Atualizada classe {{{clsBanco_}}} para tornar reescrita de SQL opcional --- ieducar/intranet/include/clsBancoPgSql.inc.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/ieducar/intranet/include/clsBancoPgSql.inc.php b/ieducar/intranet/include/clsBancoPgSql.inc.php index 7b51282..c179a9f 100755 --- a/ieducar/intranet/include/clsBancoPgSql.inc.php +++ b/ieducar/intranet/include/clsBancoPgSql.inc.php @@ -378,11 +378,13 @@ abstract class clsBancoSQL_ /** * Executa uma consulta SQL. * - * @param string $consulta + * @param string $consulta Consulta SQL. + * @param bool $reescrever (Opcional) SQL é reescrita para transformar + * sintaxe MySQL em PostgreSQL. * @return bool|resource FALSE em caso de erro ou o identificador da consulta * em caso de sucesso. */ - public function Consulta($consulta) + public function Consulta($consulta, $reescrever = true) { $cronometro = new clsCronometro(); $cronometro->marca('inicio'); @@ -403,20 +405,21 @@ abstract class clsBancoSQL_ } // Alterações de padrão MySQL para PostgreSQL + if ($reescrever) { + // Altera o Limit + $this->strStringSQL = eregi_replace( "LIMIT[ ]{0,3}([0-9]+)[ ]{0,3},[ ]{0,3}([0-9]+)", "LIMIT \\2 OFFSET \\1", $this->strStringSQL ); - // Altera o Limit - $this->strStringSQL = eregi_replace( "LIMIT[ ]{0,3}([0-9]+)[ ]{0,3},[ ]{0,3}([0-9]+)", "LIMIT \\2 OFFSET \\1", $this->strStringSQL ); + // Altera selects com YEAR( campo ) ou MONTH ou DAY + $this->strStringSQL = eregi_replace( "(YEAR|MONTH|DAY)[(][ ]{0,3}(([a-z]|_|[0-9])+)[ ]{0,3}[)]", "EXTRACT( \\1 FROM \\2 )", $this->strStringSQL ); - // Altera selects com YEAR( campo ) ou MONTH ou DAY - $this->strStringSQL = eregi_replace( "(YEAR|MONTH|DAY)[(][ ]{0,3}(([a-z]|_|[0-9])+)[ ]{0,3}[)]", "EXTRACT( \\1 FROM \\2 )", $this->strStringSQL ); + // Remove os ORDER BY das querys COUNT() + // Altera os LIKE para ILIKE (ignore case) + $this->strStringSQL = eregi_replace(" LIKE ", " ILIKE ", $this->strStringSQL); - // Remove os ORDER BY das querys COUNT() - // Altera os LIKE para ILIKE (ignore case) - $this->strStringSQL = eregi_replace(" LIKE ", " ILIKE ", $this->strStringSQL); + $this->strStringSQL = eregi_replace("([a-z_0-9.]+) +ILIKE +'([^']+)'", "to_ascii(\\1) ILIKE to_ascii('\\2')", $this->strStringSQL); - $this->strStringSQL = eregi_replace("([a-z_0-9.]+) +ILIKE +'([^']+)'", "to_ascii(\\1) ILIKE to_ascii('\\2')", $this->strStringSQL); - - $this->strStringSQL = eregi_replace("fcn_upper_nrm", "to_ascii", $this->strStringSQL); + $this->strStringSQL = eregi_replace("fcn_upper_nrm", "to_ascii", $this->strStringSQL); + } $temp = explode("'", $this->strStringSQL); -- libgit2 0.21.2