Commit f9480e1fbdf4b42ff638ba23cd24ce13658151e7
1 parent
5b1b6c13
Exists in
master
and in
6 other branches
Correção na montagem do SQL em camadas do METAESTAT, evitando usar typecast quan…
…do não for necessário, melhorando assim a performance das camadas
Showing
1 changed file
with
59 additions
and
4 deletions
Show diff stats
classesphp/classe_metaestatinfo.php
| @@ -152,14 +152,20 @@ class MetaestatInfo{ | @@ -152,14 +152,20 @@ class MetaestatInfo{ | ||
| 152 | */ | 152 | */ |
| 153 | function execSQL($sql,$id="",$convTexto=true){ | 153 | function execSQL($sql,$id="",$convTexto=true){ |
| 154 | $sql = str_ireplace(array("update","delete","insert","--","drop",";"),"",$sql); | 154 | $sql = str_ireplace(array("update","delete","insert","--","drop",";"),"",$sql); |
| 155 | + //error_log("-- "); | ||
| 156 | + //error_log("--xxxxxxxxxxx---- SQL: ".$sql); | ||
| 155 | try { | 157 | try { |
| 156 | $q = $this->dbh->query($sql,PDO::FETCH_ASSOC); | 158 | $q = $this->dbh->query($sql,PDO::FETCH_ASSOC); |
| 157 | } | 159 | } |
| 158 | catch (PDOException $e) { | 160 | catch (PDOException $e) { |
| 161 | + //error_log("-- "); | ||
| 162 | + //error_log("--erro i3geo-- classe_metaestatinfo execSQL: ".$sql); | ||
| 159 | return "Error!: "; | 163 | return "Error!: "; |
| 160 | } | 164 | } |
| 161 | if($q){ | 165 | if($q){ |
| 166 | + //error_log("--xxxxxxxxxxx---- Executando o SQL "); | ||
| 162 | $r = $q->fetchAll(); | 167 | $r = $q->fetchAll(); |
| 168 | + //error_log("--xxxxxxxxxxx---- Executado "); | ||
| 163 | if($convTexto == false){ | 169 | if($convTexto == false){ |
| 164 | return $r; | 170 | return $r; |
| 165 | } | 171 | } |
| @@ -182,6 +188,8 @@ class MetaestatInfo{ | @@ -182,6 +188,8 @@ class MetaestatInfo{ | ||
| 182 | } | 188 | } |
| 183 | } | 189 | } |
| 184 | else{ | 190 | else{ |
| 191 | + //error_log("--"); | ||
| 192 | + //error_log("--erro i3geo-- classe_metaestatinfo execSQL"); | ||
| 185 | return false; | 193 | return false; |
| 186 | } | 194 | } |
| 187 | } | 195 | } |
| @@ -352,10 +360,50 @@ class MetaestatInfo{ | @@ -352,10 +360,50 @@ class MetaestatInfo{ | ||
| 352 | else{ | 360 | else{ |
| 353 | $nomeColunaValor = $dados["colunavalor"]; | 361 | $nomeColunaValor = $dados["colunavalor"]; |
| 354 | } | 362 | } |
| 363 | + //pega o tipo das coluna regiao.".$dadosgeo["identificador"] | ||
| 364 | + $propColuna1 = $this->descreveColunasTabela( | ||
| 365 | + $dadosgeo["codigo_estat_conexao"], | ||
| 366 | + $dados["esquemadb"], | ||
| 367 | + $dados["tabela"], | ||
| 368 | + $dados["colunaidgeo"] | ||
| 369 | + ); | ||
| 370 | + $propColuna2 = $this->descreveColunasTabela( | ||
| 371 | + $dadosgeo["codigo_estat_conexao"], | ||
| 372 | + $dadosgeo["esquemadb"], | ||
| 373 | + $dadosgeo["tabela"], | ||
| 374 | + $dadosgeo["identificador"] | ||
| 375 | + ); | ||
| 376 | + if(in_array(array('oid','float4','float8','int2','int4','int8','int16','smallint','integer','real','double precision','bigint','numeric'),$propColuna1["type"])){ | ||
| 377 | + $propColuna1 = 'numeric'; | ||
| 378 | + } else { | ||
| 379 | + $propColuna1 = 'text'; | ||
| 380 | + } | ||
| 381 | + if(in_array(array('oid','float4','float8','int2','int4','int8','int16','smallint','integer','real','double precision','bigint','numeric'),$propColuna2["type"])){ | ||
| 382 | + $propColuna2 = 'numeric'; | ||
| 383 | + } else { | ||
| 384 | + $propColuna2 = 'text'; | ||
| 385 | + } | ||
| 386 | + if($propColuna1 == $propColuna2){ | ||
| 387 | + $propColuna1 = ""; | ||
| 388 | + $propColuna2 = ""; | ||
| 389 | + } else { | ||
| 390 | + if($propColuna1 == 'numeric'){ | ||
| 391 | + $propColuna1 = 'text'; | ||
| 392 | + } | ||
| 393 | + if($propColuna2 == 'numeric'){ | ||
| 394 | + $propColuna2 = 'text'; | ||
| 395 | + } | ||
| 396 | + if($propColuna1 != ''){ | ||
| 397 | + $propColuna1 = '::'.$propColuna1; | ||
| 398 | + } | ||
| 399 | + if($propColuna2 != ''){ | ||
| 400 | + $propColuna2 = '::'.$propColuna2; | ||
| 401 | + } | ||
| 402 | + } | ||
| 355 | $sqlIntermediario = "SELECT (j.valorcalculado) AS ".$nomeColunaValor.", __COLUNASSEMGEO__". | 403 | $sqlIntermediario = "SELECT (j.valorcalculado) AS ".$nomeColunaValor.", __COLUNASSEMGEO__". |
| 356 | " FROM ".$dadosgeo["esquemadb"].".".$dadosgeo["tabela"]." AS regiao ". | 404 | " FROM ".$dadosgeo["esquemadb"].".".$dadosgeo["tabela"]." AS regiao ". |
| 357 | " INNER JOIN ( __SQLDADOS__ ) ". | 405 | " INNER JOIN ( __SQLDADOS__ ) ". |
| 358 | - " AS j ON j.cod_regiao::text = regiao.".$dadosgeo["identificador"]."::text"; | 406 | + " AS j ON j.cod_regiao" . $propColuna1 . " = regiao.".$dadosgeo["identificador"] . $propColuna2; |
| 359 | //inclui os sqls de regioes de niveis inferiores | 407 | //inclui os sqls de regioes de niveis inferiores |
| 360 | if($agregaregiao == true && $direto == false){ | 408 | if($agregaregiao == true && $direto == false){ |
| 361 | $hierarquia = $this->regiaoFilhaAoPai($dados["codigo_tipo_regiao"],$codigo_tipo_regiao); | 409 | $hierarquia = $this->regiaoFilhaAoPai($dados["codigo_tipo_regiao"],$codigo_tipo_regiao); |
| @@ -510,7 +558,8 @@ class MetaestatInfo{ | @@ -510,7 +558,8 @@ class MetaestatInfo{ | ||
| 510 | $this->nomecache = $this->nomecache . $this->nomeRandomico(5); | 558 | $this->nomecache = $this->nomecache . $this->nomeRandomico(5); |
| 511 | } | 559 | } |
| 512 | $arq = $this->dir_tmp."/".$this->nomecache.".map"; | 560 | $arq = $this->dir_tmp."/".$this->nomecache.".map"; |
| 513 | - | 561 | + //error_log("-- "); |
| 562 | + //error_log("--xxxxxxxxxxx---- nomecache: ".$arq); | ||
| 514 | if(!file_exists($arq)){ | 563 | if(!file_exists($arq)){ |
| 515 | $meta = $this->listaMedidaVariavel("",$id_medida_variavel); | 564 | $meta = $this->listaMedidaVariavel("",$id_medida_variavel); |
| 516 | //evita agregar regioes qd nao e necessario | 565 | //evita agregar regioes qd nao e necessario |
| @@ -529,6 +578,8 @@ class MetaestatInfo{ | @@ -529,6 +578,8 @@ class MetaestatInfo{ | ||
| 529 | $suportaWMST, | 578 | $suportaWMST, |
| 530 | $filtro | 579 | $filtro |
| 531 | ); | 580 | ); |
| 581 | + //error_log("-- "); | ||
| 582 | + //error_log("--xxxxxxxxxxx---- sqlMedidaVariavel: ".$sql); | ||
| 532 | if(empty($codigo_tipo_regiao)){ | 583 | if(empty($codigo_tipo_regiao)){ |
| 533 | $d = $this->listaMedidaVariavel("",$id_medida_variavel); | 584 | $d = $this->listaMedidaVariavel("",$id_medida_variavel); |
| 534 | $codigo_tipo_regiao = $d["codigo_tipo_regiao"]; | 585 | $codigo_tipo_regiao = $d["codigo_tipo_regiao"]; |
| @@ -555,7 +606,11 @@ class MetaestatInfo{ | @@ -555,7 +606,11 @@ class MetaestatInfo{ | ||
| 555 | $classes = $this->listaClasseClassificacao($classificacoes[0]["id_classificacao"]); | 606 | $classes = $this->listaClasseClassificacao($classificacoes[0]["id_classificacao"]); |
| 556 | } | 607 | } |
| 557 | if($classes == false){ | 608 | if($classes == false){ |
| 609 | + //error_log("-- "); | ||
| 610 | + //error_log("--xxxxxxxxxxx---- dadosMedidaVariavel: ".$sql); | ||
| 558 | $valores = $this->dadosMedidaVariavel($id_medida_variavel,$filtro." AND ".$meta["colunavalor"]." > 0 "); | 611 | $valores = $this->dadosMedidaVariavel($id_medida_variavel,$filtro." AND ".$meta["colunavalor"]." > 0 "); |
| 612 | + //error_log("-- "); | ||
| 613 | + //error_log("--xxxxxxxxxxx---- dadosMedidaVariavel obtidos "); | ||
| 559 | $valores = array_column($valores,$meta["colunavalor"]); | 614 | $valores = array_column($valores,$meta["colunavalor"]); |
| 560 | $item = $meta["colunavalor"]; | 615 | $item = $meta["colunavalor"]; |
| 561 | $classes = array(); | 616 | $classes = array(); |
| @@ -1726,9 +1781,9 @@ class MetaestatInfo{ | @@ -1726,9 +1781,9 @@ class MetaestatInfo{ | ||
| 1726 | */ | 1781 | */ |
| 1727 | function colunasTabela($codigo_estat_conexao,$nome_esquema,$nome_tabela,$tipo="",$tipotratamento="="){ | 1782 | function colunasTabela($codigo_estat_conexao,$nome_esquema,$nome_tabela,$tipo="",$tipotratamento="="){ |
| 1728 | $colunas = array(); | 1783 | $colunas = array(); |
| 1729 | - $res = $this->execSQLDB($codigo_estat_conexao,"SELECT column_name as coluna,udt_name FROM information_schema.columns where table_schema = '$nome_esquema' and table_name = '$nome_tabela'"); | 1784 | + $res = $this->execSQLDB($codigo_estat_conexao,"SELECT column_name as coluna,udt_name, data_type FROM information_schema.columns where table_schema = '$nome_esquema' and table_name = '$nome_tabela'"); |
| 1730 | if($tipo != ""){ | 1785 | if($tipo != ""){ |
| 1731 | - $res = $this->execSQLDB($codigo_estat_conexao,"SELECT column_name as coluna,udt_name FROM information_schema.columns where table_schema = '$nome_esquema' and udt_name $tipotratamento '$tipo' and table_name = '$nome_tabela'"); | 1786 | + $res = $this->execSQLDB($codigo_estat_conexao,"SELECT column_name as coluna,udt_name, data_type FROM information_schema.columns where table_schema = '$nome_esquema' and udt_name $tipotratamento '$tipo' and table_name = '$nome_tabela'"); |
| 1732 | } | 1787 | } |
| 1733 | foreach($res as $c){ | 1788 | foreach($res as $c){ |
| 1734 | $colunas[] = $c["coluna"]; | 1789 | $colunas[] = $c["coluna"]; |