Commit 90151874b62e92c2b0721cfb672d7a8349cea6c4
1 parent
fe04b077
Exists in
master
and in
7 other branches
Inclusão de gerenciador de tabelas no sistema de metadados estatísticos
Showing
6 changed files
with
402 additions
and
29 deletions
Show diff stats
... | ... | @@ -0,0 +1,99 @@ |
1 | +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | |
2 | +<html> | |
3 | +<head> | |
4 | +<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> | |
5 | +<title>Conexao com banco de dados</title> | |
6 | +<style type="text/css"> | |
7 | +/*margin and padding on body element | |
8 | + can introduce errors in determining | |
9 | + element position and are not recommended; | |
10 | + we turn them off as a foundation for YUI | |
11 | + CSS treatments. */ | |
12 | +body { | |
13 | + margin: 0; | |
14 | + padding: 0; | |
15 | +} | |
16 | +</style> | |
17 | +<script type="text/javascript" src="../js/core.js"></script> | |
18 | +<script type="text/javascript" src="../js/estat_editor.js"></script> | |
19 | +<link rel="stylesheet" type="text/css" href="admin.css"> | |
20 | + | |
21 | +</head> | |
22 | +<body class=" yui-skin-sam fundoPonto"> | |
23 | + <div class="bordaSuperior"> </div> | |
24 | + <div class="mascaraPrincipal" id="divGeral"> | |
25 | + <div id=cabecalhoPrincipal></div> | |
26 | + <h1> | |
27 | + Metadados estatísticos - editor de tabelas | |
28 | + de dados <img src="../imagens/04.png" style="cursor: pointer" | |
29 | + id=botaoAjuda /> | |
30 | + </h1> | |
31 | + | |
32 | + <div id="formulario" style="display: none"> | |
33 | + <div id="ajuda" style="display: none"> | |
34 | + <div class="hd">Ajuda</div> | |
35 | + <div class="bd" style="height: 144px; overflow: auto"> | |
36 | + <p>Este formulário permite editar as tabelas de dados utilizadas pelo | |
37 | + sistema de metadados estatísticos | |
38 | + </div> | |
39 | + <div class="ft"></div> | |
40 | + </div> | |
41 | + <p><br> | |
42 | + Atenção: para poder editar o banco de dados, o usuário da conexão escolhida deve ter direitos de edição<br> | |
43 | + Apenas as tabelas e os dados existentes no esquema i3geo_metaestat podem ser editados<br> | |
44 | + <div id="i3GEOadminEditorConexao" style="left: -5px;"></div><br> | |
45 | + <div id="i3GEOadminEditorEsquema" style="left: -5px;"></div> | |
46 | + <div id="i3GEOadminEditorTabela" style="left: -5px;"></div> | |
47 | + <div id="i3GEOadminEditorColuna" style="left: -5px;"></div> | |
48 | + </div> | |
49 | + </div> | |
50 | + <div id=logajax style="display: block"></div> | |
51 | + <script> | |
52 | + /* | |
53 | + Title: Editor de tabelas do sistema de metadados estatísticos | |
54 | + | |
55 | + Licenca: | |
56 | + | |
57 | + GPL2 | |
58 | + | |
59 | + i3Geo Interface Integrada de Ferramentas de Geoprocessamento para Internet | |
60 | + | |
61 | + Direitos Autorais Reservados (c) 2006 Ministério do Meio Ambiente Brasil | |
62 | + Desenvolvedor: Edmar Moretti edmar.moretti@mma.gov.br | |
63 | + | |
64 | + Este programa é software livre; você pode redistribuí-lo | |
65 | + e/ou modificá-lo sob os termos da Licença Pública Geral | |
66 | + GNU conforme publicada pela Free Software Foundation; | |
67 | + | |
68 | + Este programa é distribuído na expectativa de que seja útil, | |
69 | + porém, SEM NENHUMA GARANTIA; nem mesmo a garantia implícita | |
70 | + de COMERCIABILIDADE OU ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. | |
71 | + Consulte a Licença Pública Geral do GNU para mais detalhes. | |
72 | + Você deve ter recebido uma cópia da Licença Pública Geral do | |
73 | + GNU junto com este programa; se não, escreva para a | |
74 | + Free Software Foundation, Inc., no endereço | |
75 | + 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. | |
76 | + | |
77 | + Arquivo: | |
78 | + | |
79 | + i3geo/admin/html/estat_editor.html | |
80 | + */ | |
81 | + if (screen.availWidth > 700) { | |
82 | + document.getElementById("divGeral").style.width = "700px"; | |
83 | + } | |
84 | + //necessario para a ferramenta login e outras | |
85 | + i3GEO.configura = { | |
86 | + locaplic : "../.." | |
87 | + }; | |
88 | + cabecalhoMetaestat("cabecalhoPrincipal", "editor"); | |
89 | + document.getElementById("formulario").style.display = "block"; | |
90 | + i3GEOadmin.editor.inicia(); | |
91 | + /* | |
92 | + temp = function() { | |
93 | + document.getElementById("formulario").style.display = "block"; | |
94 | + initEditor(); | |
95 | + }; | |
96 | + i3GEO.login.verificaOperacao("admin/html/menus",i3GEO.configura.locaplic, temp, "sessao"); | |
97 | + */ | |
98 | + </script> | |
99 | +</body> | |
0 | 100 | \ No newline at end of file | ... | ... |
admin/index.html
... | ... | @@ -183,6 +183,10 @@ |
183 | 183 | <td><div class=aplicar></div></td> |
184 | 184 | <td>Cadastro de fontes de informação</td> |
185 | 185 | </tr> |
186 | + <tr onclick="abre('html/estat_editor.html')"> | |
187 | + <td><div class=aplicar></div></td> | |
188 | + <td>Editor de tabelas de dados estatícos</td> | |
189 | + </tr> | |
186 | 190 | </table> |
187 | 191 | </div> |
188 | 192 | </fieldset> | ... | ... |
admin/js/core.js
... | ... | @@ -72,11 +72,12 @@ function cabecalhoMetaestat(id,excluir){ |
72 | 72 | botoes = [ |
73 | 73 | {id:"principal",titulo:"Início",link:"../index.html"}, |
74 | 74 | {id:"arvore",titulo:"Árvore completa",link:"estat_variavel.html"}, |
75 | - {id:"unidade_medida",titulo:"Unidades de medida",link:"estat_unidade_medida.html"}, | |
75 | + {id:"unidade_medida",titulo:"Unidades",link:"estat_unidade_medida.html"}, | |
76 | 76 | {id:"periodo_tempo",titulo:"Períodos",link:"estat_tipo_periodo.html"}, |
77 | 77 | {id:"conexao",titulo:"Conexões",link:"estat_conexao.html"}, |
78 | 78 | {id:"tipo_regiao",titulo:"Regiões",link:"estat_tipo_regiao.html"}, |
79 | 79 | {id:"fonteinfo",titulo:"Fonte",link:"estat_fonteinfo.html"}, |
80 | + {id:"editor",titulo:"Editor",link:"estat_editor.html"}, | |
80 | 81 | {id:"login",titulo:"Login",js:"i3GEO.login.dialogo.abreLogin()"} |
81 | 82 | ]; |
82 | 83 | n = botoes.length; | ... | ... |
... | ... | @@ -0,0 +1,228 @@ |
1 | +if(typeof(i3GEOadmin) === 'undefined'){ | |
2 | + var i3GEOadmin = {}; | |
3 | +} | |
4 | +i3GEOadmin.editor = { | |
5 | + /* | |
6 | + * Inicializa o sistema | |
7 | + */ | |
8 | + inicia: function(){ | |
9 | + YAHOO.namespace("editor"); | |
10 | + YAHOO.namespace("admin.container"); | |
11 | + //opcao de escolha da conexao | |
12 | + i3GEOadmin.editor.conexao.lista(); | |
13 | + }, | |
14 | + /* | |
15 | + * algumas operacoes sao permitidas apenas para o esquema i3geo_metaestat do banco de dados | |
16 | + */ | |
17 | + verificaEsquema: function(nomeEsquema){ | |
18 | + if(nomeEsquema != "i3geo_metaestat"){ | |
19 | + alert("Operacao permitida apenas para o esquema i3geo_metaestat"); | |
20 | + return; | |
21 | + } | |
22 | + }, | |
23 | + conexao:{ | |
24 | + onde: "i3GEOadminEditorConexao", | |
25 | + lista: function(){ | |
26 | + var callback = { | |
27 | + success:function(o){ | |
28 | + try { | |
29 | + var dados = YAHOO.lang.JSON.parse(o.responseText), | |
30 | + temp = "Escolha a conexão com o banco: "; | |
31 | + temp += "<select id='i3GEOadmincodigo_estat_conexao' onchange='i3GEOadmin.editor.esquema.lista()'>"; | |
32 | + temp += core_comboObjeto(dados,"i3GEOadmincodigo_estat_conexao","bancodedados","","usuario"); | |
33 | + temp += "</select>"; | |
34 | + $i(i3GEOadmin.editor.conexao.onde).innerHTML = temp; | |
35 | + core_carregando("desativa"); | |
36 | + } | |
37 | + catch(e){core_handleFailure(e,o.responseText);} | |
38 | + }, | |
39 | + failure:core_handleFailure, | |
40 | + argument: { foo:"foo", bar:"bar" } | |
41 | + }; | |
42 | + core_carregando("buscando dados..."); | |
43 | + core_makeRequest("../php/metaestat.php?funcao=listaConexao",callback); | |
44 | + } | |
45 | + }, | |
46 | + esquema: { | |
47 | + onde: "i3GEOadminEditorEsquema", | |
48 | + lista: function(){ | |
49 | + var callback = { | |
50 | + success:function(o){ | |
51 | + try { | |
52 | + var dados = YAHOO.lang.JSON.parse(o.responseText), | |
53 | + temp = "<fieldset>Escolha um esquema: "; | |
54 | + temp += "<select id='i3GEOadminesquema' onchange='i3GEOadmin.editor.tabela.lista()'>"; | |
55 | + temp += core_comboObjeto(dados,"esquema","esquema"); | |
56 | + temp += "</select>"; | |
57 | + $i(i3GEOadmin.editor.esquema.onde).innerHTML = temp+"</fieldset>"; | |
58 | + core_carregando("desativa"); | |
59 | + $i(i3GEOadmin.editor.tabela.onde).innerHTML = ""; | |
60 | + } | |
61 | + catch(e){core_handleFailure(e,o.responseText);} | |
62 | + }, | |
63 | + failure:core_handleFailure, | |
64 | + argument: { foo:"foo", bar:"bar" } | |
65 | + }, | |
66 | + codigo_estat_conexao = $i("i3GEOadmincodigo_estat_conexao").value; | |
67 | + if(codigo_estat_conexao == ""){ | |
68 | + alert("Escolha uma conexao"); | |
69 | + $i(i3GEOadmin.editor.esquema.onde).innerHTML = ""; | |
70 | + $i(i3GEOadmin.editor.tabela.onde).innerHTML = ""; | |
71 | + return; | |
72 | + } | |
73 | + core_carregando("buscando dados..."); | |
74 | + core_makeRequest("../php/metaestat.php?funcao=esquemasConexao&formato=json&codigo_estat_conexao="+codigo_estat_conexao,callback); | |
75 | + }, | |
76 | + }, | |
77 | + tabela:{ | |
78 | + onde: "i3GEOadminEditorTabela", | |
79 | + lista: function(){ | |
80 | + var callback = { | |
81 | + success:function(o){ | |
82 | + try { | |
83 | + var dados = YAHOO.lang.JSON.parse(o.responseText), | |
84 | + temp = "<fieldset>Escolha uma tabela: "; | |
85 | + temp += "<select id='i3GEOadmintabela' onchange='i3GEOadmin.editor.coluna.lista()'>"; | |
86 | + temp += core_comboObjeto(dados,"tabela","tabela"); | |
87 | + temp += "</select>"; | |
88 | + temp += "" + | |
89 | + "<p>Digite um nome: <input id='i3GEOadmintabelaNomeNovo' title='digite o nome' type=text width=30 style='cursor:text' />" + | |
90 | + "<input type=button value='Criar tabela' id='i3GEOadmintabelaCriar' onclick='i3GEOadmin.editor.tabela.criar()'/>" + | |
91 | + "<input type=button value='Alterar nome atual' id='i3GEOadmintabelaAlterarNome' onclick='i3GEOadmin.editor.tabela.alterarNome()'/>" + | |
92 | + "<input type=button value='Copiar para' id='i3GEOadmintabelaCopiar' onclick='i3GEOadmin.editor.tabela.copiar()'/>"; | |
93 | + | |
94 | + $i(i3GEOadmin.editor.tabela.onde).innerHTML = temp+"</fieldset>"; | |
95 | + core_carregando("desativa"); | |
96 | + $i(i3GEOadmin.editor.coluna.onde).innerHTML = ""; | |
97 | + } | |
98 | + catch(e){core_handleFailure(e,o.responseText);} | |
99 | + }, | |
100 | + failure:core_handleFailure, | |
101 | + argument: { foo:"foo", bar:"bar" } | |
102 | + }, | |
103 | + codigo_estat_conexao = $i("i3GEOadmincodigo_estat_conexao").value, | |
104 | + nome_esquema = $i("i3GEOadminesquema").value; | |
105 | + if(nome_esquema == ""){ | |
106 | + alert("Escolha um esquema"); | |
107 | + $i(i3GEOadmin.editor.tabela.onde).innerHTML = ""; | |
108 | + $i(i3GEOadmin.editor.coluna.onde).innerHTML = ""; | |
109 | + return; | |
110 | + } | |
111 | + core_carregando("adicionando..."); | |
112 | + core_makeRequest("../php/metaestat.php?funcao=tabelasEsquema&formato=json&nome_esquema="+nome_esquema+"&codigo_estat_conexao="+codigo_estat_conexao,callback); | |
113 | + }, | |
114 | + criar: function(){ | |
115 | + if(!window.confirm("Cria nova tabela?")){ | |
116 | + return; | |
117 | + } | |
118 | + var callback = { | |
119 | + success:function(o){ | |
120 | + try { | |
121 | + core_carregando("desativa"); | |
122 | + i3GEOadmin.editor.tabela.lista(); | |
123 | + } | |
124 | + catch(e){core_handleFailure(e,o.responseText);} | |
125 | + }, | |
126 | + failure:core_handleFailure, | |
127 | + argument: { foo:"foo", bar:"bar" } | |
128 | + }, | |
129 | + novaTabela = $i("i3GEOadmintabelaNomeNovo").value, | |
130 | + nomeEsquema = $i("i3GEOadminesquema").value; | |
131 | + if(i3GEOadmin.editor.verificaEsquema(nomeEsquema) == false){ | |
132 | + return; | |
133 | + } | |
134 | + if(novaTabela == ""){ | |
135 | + alert("Digite um nome"); | |
136 | + return; | |
137 | + } | |
138 | + if(i3GEOadmin.editor.tabela.verificaExiste(novaTabela) == false){ | |
139 | + core_carregando("adicionando..."); | |
140 | + core_makeRequest("../php/metaestat.php?funcao=criaTabelaDB&formato=json&nome_tabela="+novaTabela+"&nome_esquema="+nomeEsquema+"&codigo_estat_conexao="+$i("i3GEOadmincodigo_estat_conexao").value,callback); | |
141 | + } | |
142 | + else{ | |
143 | + alert("Tabela ja existe"); | |
144 | + } | |
145 | + }, | |
146 | + alterarNome: function(){ | |
147 | + if(!window.confirm("Altera o nome?")){ | |
148 | + return; | |
149 | + } | |
150 | + var callback = { | |
151 | + success:function(o){ | |
152 | + try { | |
153 | + core_carregando("desativa"); | |
154 | + i3GEOadmin.editor.tabela.lista(); | |
155 | + } | |
156 | + catch(e){core_handleFailure(e,o.responseText);} | |
157 | + }, | |
158 | + failure:core_handleFailure, | |
159 | + argument: { foo:"foo", bar:"bar" } | |
160 | + }, | |
161 | + novaTabela = $i("i3GEOadmintabelaNomeNovo").value, | |
162 | + nomeEsquema = $i("i3GEOadminesquema").value; | |
163 | + if(i3GEOadmin.editor.verificaEsquema(nomeEsquema) == false){ | |
164 | + return; | |
165 | + } | |
166 | + if(novaTabela == ""){ | |
167 | + alert("Digite um nome"); | |
168 | + return; | |
169 | + } | |
170 | + if(i3GEOadmin.editor.tabela.verificaExiste(novaTabela) == false){ | |
171 | + core_carregando("adicionando..."); | |
172 | + core_makeRequest("../php/metaestat.php?funcao=alteraNomeTabelaDB&formato=json&nome_tabela="+$i("i3GEOadmintabela").value+"&novonome_tabela="+novaTabela+"&nome_esquema="+nomeEsquema+"&codigo_estat_conexao="+$i("i3GEOadmincodigo_estat_conexao").value,callback); | |
173 | + } | |
174 | + else{ | |
175 | + alert("Tabela ja existe"); | |
176 | + } | |
177 | + }, | |
178 | + copiar: function(){ | |
179 | + if(!window.confirm("Copiar tabela?")){ | |
180 | + return; | |
181 | + } | |
182 | + var callback = { | |
183 | + success:function(o){ | |
184 | + try { | |
185 | + core_carregando("desativa"); | |
186 | + i3GEOadmin.editor.tabela.lista(); | |
187 | + } | |
188 | + catch(e){core_handleFailure(e,o.responseText);} | |
189 | + }, | |
190 | + failure:core_handleFailure, | |
191 | + argument: { foo:"foo", bar:"bar" } | |
192 | + }, | |
193 | + novaTabela = $i("i3GEOadmintabelaNomeNovo").value, | |
194 | + nomeEsquema = $i("i3GEOadminesquema").value; | |
195 | + if(i3GEOadmin.editor.verificaEsquema(nomeEsquema) == false){ | |
196 | + return; | |
197 | + } | |
198 | + if(novaTabela == ""){ | |
199 | + alert("Digite um nome"); | |
200 | + return; | |
201 | + } | |
202 | + if(i3GEOadmin.editor.tabela.verificaExiste(novaTabela) == false){ | |
203 | + core_carregando("adicionando..."); | |
204 | + core_makeRequest("../php/metaestat.php?funcao=copiaTabelaDB&formato=json&nome_tabela="+$i("i3GEOadmintabela").value+"&novonome_tabela="+novaTabela+"&nome_esquema="+nomeEsquema+"&codigo_estat_conexao="+$i("i3GEOadmincodigo_estat_conexao").value,callback); | |
205 | + } | |
206 | + else{ | |
207 | + alert("Tabela ja existe"); | |
208 | + } | |
209 | + }, | |
210 | + verificaExiste: function(valor){ | |
211 | + var combo = $i("i3GEOadmintabela"), | |
212 | + n = combo.options.length, | |
213 | + i; | |
214 | + for(i=0;i<n;i++){ | |
215 | + if(combo.options[i].value == valor){ | |
216 | + return true; | |
217 | + } | |
218 | + } | |
219 | + return false; | |
220 | + } | |
221 | + }, | |
222 | + coluna: { | |
223 | + onde: "i3GEOadminEditorColuna", | |
224 | + lista: function(){ | |
225 | + | |
226 | + } | |
227 | + } | |
228 | +}; | |
0 | 229 | \ No newline at end of file | ... | ... |
admin/php/classe_metaestat.php
... | ... | @@ -134,7 +134,7 @@ class Metaestat{ |
134 | 134 | /* |
135 | 135 | Function: execSQL |
136 | 136 | |
137 | - Executa um SQL no banco | |
137 | + Executa um SQL no banco de administracao | |
138 | 138 | |
139 | 139 | Parametros: |
140 | 140 | |
... | ... | @@ -146,7 +146,7 @@ class Metaestat{ |
146 | 146 | |
147 | 147 | {array} |
148 | 148 | */ |
149 | - function execSQL($sql,$id=""){ | |
149 | + function execSQL($sql,$id="",$convTexto=true){ | |
150 | 150 | try { |
151 | 151 | $q = $this->dbh->query($sql,PDO::FETCH_ASSOC); |
152 | 152 | } |
... | ... | @@ -155,6 +155,9 @@ class Metaestat{ |
155 | 155 | } |
156 | 156 | if($q){ |
157 | 157 | $r = $q->fetchAll(); |
158 | + if($convTexto == false){ | |
159 | + return $r; | |
160 | + } | |
158 | 161 | if($r){ |
159 | 162 | if($id != ""){ |
160 | 163 | if(count($r) == 1){ |
... | ... | @@ -177,6 +180,20 @@ class Metaestat{ |
177 | 180 | return false; |
178 | 181 | } |
179 | 182 | } |
183 | + /* | |
184 | + Function: execSQLDB | |
185 | + | |
186 | + Executa um SQL no banco de dados definido em uma conexao | |
187 | + */ | |
188 | + function execSQLDB($codigo_estat_conexao,$sql){ | |
189 | + $c = $this->listaConexao($codigo_estat_conexao,true); | |
190 | + $dbhold = $this->dbh; | |
191 | + $dbh = new PDO('pgsql:dbname='.$c["bancodedados"].';user='.$c["usuario"].';password='.$c["senha"].';host='.$c["host"].';port='.$c["porta"]); | |
192 | + $this->dbh = $dbh; | |
193 | + $res = $this->execSQL($sql,"",false); | |
194 | + $this->dbh = $dbhold; | |
195 | + return $res; | |
196 | + } | |
180 | 197 | function insertId($tabela,$colunatemp,$colunaid){ |
181 | 198 | $idtemp = (rand (9000,10000)) * -1; |
182 | 199 | //echo "INSERT INTO ".$this->esquemaadmin.$tabela." ($colunatemp) VALUES ('$idtemp')";exit; |
... | ... | @@ -1041,44 +1058,41 @@ class Metaestat{ |
1041 | 1058 | return $this->execSQL($sql,$id_agregaregiao); |
1042 | 1059 | } |
1043 | 1060 | function esquemasConexao($codigo_estat_conexao){ |
1044 | - $c = $this->listaConexao($codigo_estat_conexao,true); | |
1045 | - $dbhold = $this->dbh; | |
1046 | - $dbh = new PDO('pgsql:dbname='.$c["bancodedados"].';user='.$c["usuario"].';password='.$c["senha"].';host='.$c["host"].';port='.$c["porta"]); | |
1047 | - $this->dbh = $dbh; | |
1048 | - $res = $this->execSQL("SELECT oid,nspname as esquema FROM pg_namespace group by nspname,oid order by nspname"); | |
1049 | - $this->dbh = $dbhold; | |
1050 | - return $res; | |
1061 | + return $this->execSQLDB($codigo_estat_conexao,"SELECT oid,nspname as esquema FROM pg_namespace group by nspname,oid order by nspname"); | |
1062 | + } | |
1063 | + function criaEsquemaDB($codigo_estat_conexao,$nome_esquema){ | |
1064 | + return $this->execSQLDB($codigo_estat_conexao,"create schema $nome_esquema"); | |
1051 | 1065 | } |
1052 | 1066 | function tabelasEsquema($codigo_estat_conexao,$nome_esquema){ |
1053 | - $c = $this->listaConexao($codigo_estat_conexao,true); | |
1054 | - $dbhold = $this->dbh; | |
1055 | - $dbh = new PDO('pgsql:dbname='.$c["bancodedados"].';user='.$c["usuario"].';password='.$c["senha"].';host='.$c["host"].';port='.$c["porta"]); | |
1056 | - $this->dbh = $dbh; | |
1057 | - $res = $this->execSQL("SELECT table_name as tabela FROM information_schema.tables where table_schema = '$nome_esquema'"); | |
1058 | - $this->dbh = $dbhold; | |
1067 | + return $this->execSQLDB($codigo_estat_conexao,"SELECT table_name as tabela FROM information_schema.tables where table_schema = '$nome_esquema'"); | |
1068 | + } | |
1069 | + function criaTabelaDB($codigo_estat_conexao,$nome_esquema,$nome_tabela){ | |
1070 | + return $this->execSQLDB($codigo_estat_conexao,"create table ".$nome_esquema.".".$nome_tabela." (gid serial, CONSTRAINT ".$nome_tabela."_pkey PRIMARY KEY (gid ))"); | |
1071 | + } | |
1072 | + function alteraNomeTabelaDB($codigo_estat_conexao,$nome_esquema,$nome_tabela,$novonome_tabela){ | |
1073 | + $res = $this->execSQLDB($codigo_estat_conexao,"ALTER TABLE ".$nome_esquema.".".$nome_tabela." RENAME TO ".$novonome_tabela ); | |
1074 | + $tabela = $this->execSQLDB($codigo_estat_conexao,"SELECT table_name FROM information_schema.tables where table_name = '$novonome_tabela' and table_schema = '$nome_esquema'"); | |
1075 | + if(count($tabela) > 0){ | |
1076 | + $sql = "UPDATE i3geoestat_medida_variavel SET tabela = '$novonome_tabela' WHERE esquemadb = '$nome_esquema' and tabela = '$nome_tabela'"; | |
1077 | + $this->execSQL($sql,"",false); | |
1078 | + $sql = "UPDATE i3geoestat_tipo_regiao SET tabela = '$novonome_tabela' WHERE esquemadb = '$nome_esquema' and tabela = '$nome_tabela'"; | |
1079 | + $this->execSQL($sql,"",false); | |
1080 | + } | |
1059 | 1081 | return $res; |
1060 | 1082 | } |
1083 | + function copiaTabelaDB($codigo_estat_conexao,$nome_esquema,$nome_tabela,$novonome_tabela){ | |
1084 | + return $this->execSQLDB($codigo_estat_conexao,"CREATE TABLE ".$nome_esquema.".".$novonome_tabela." AS select * from ".$nome_esquema.".".$nome_tabela ); | |
1085 | + } | |
1061 | 1086 | function colunasTabela($codigo_estat_conexao,$nome_esquema,$nome_tabela){ |
1062 | 1087 | $colunas = array(); |
1063 | - $c = $this->listaConexao($codigo_estat_conexao,true); | |
1064 | - $dbhold = $this->dbh; | |
1065 | - $dbh = new PDO('pgsql:dbname='.$c["bancodedados"].';user='.$c["usuario"].';password='.$c["senha"].';host='.$c["host"].';port='.$c["porta"]); | |
1066 | - $this->dbh = $dbh; | |
1067 | - $res = $this->execSQL("SELECT column_name as coluna FROM information_schema.columns where table_schema = '$nome_esquema' and table_name = '$nome_tabela'"); | |
1068 | - $this->dbh = $dbhold; | |
1088 | + $res = $this->execSQLDB($codigo_estat_conexao,"SELECT column_name as coluna FROM information_schema.columns where table_schema = '$nome_esquema' and table_name = '$nome_tabela'"); | |
1069 | 1089 | foreach($res as $c){ |
1070 | 1090 | $colunas[] = $c["coluna"]; |
1071 | 1091 | } |
1072 | 1092 | return $colunas; |
1073 | 1093 | } |
1074 | 1094 | function descreveColunasTabela($codigo_estat_conexao,$nome_esquema,$nome_tabela){ |
1075 | - $c = $this->listaConexao($codigo_estat_conexao,true); | |
1076 | - $dbhold = $this->dbh; | |
1077 | - $dbh = new PDO('pgsql:dbname='.$c["bancodedados"].';user='.$c["usuario"].';password='.$c["senha"].';host='.$c["host"].';port='.$c["porta"]); | |
1078 | - $this->dbh = $dbh; | |
1079 | - $res = $this->execSQL("SELECT a.attnum,a.attname AS field,t.typname AS type,a.attlen AS length,a.atttypmod AS lengthvar,a.attnotnull AS notnull,p.nspname as esquema FROM pg_class c,pg_attribute a,pg_type t,pg_namespace p WHERE c.relname = '$nome_tabela' and p.nspname = '$nome_esquema' and a.attnum > 0 and a.attrelid = c.oid and a.atttypid = t.oid and c.relnamespace = p.oid ORDER BY a.attname"); | |
1080 | - $this->dbh = $dbhold; | |
1081 | - return $res; | |
1095 | + return $this->execSQLDB($codigo_estat_conexao,"SELECT a.attnum,a.attname AS field,t.typname AS type,a.attlen AS length,a.atttypmod AS lengthvar,a.attnotnull AS notnull,p.nspname as esquema FROM pg_class c,pg_attribute a,pg_type t,pg_namespace p WHERE c.relname = '$nome_tabela' and p.nspname = '$nome_esquema' and a.attnum > 0 and a.attrelid = c.oid and a.atttypid = t.oid and c.relnamespace = p.oid ORDER BY a.attname"); | |
1082 | 1096 | } |
1083 | 1097 | function relatorioCompleto($codigo_variavel=""){ |
1084 | 1098 | $dados = array(); | ... | ... |
admin/php/metaestat.php
... | ... | @@ -883,6 +883,33 @@ switch (strtoupper($funcao)) |
883 | 883 | } |
884 | 884 | exit; |
885 | 885 | break; |
886 | + case "CRIATABELADB": | |
887 | + $m = new Metaestat(); | |
888 | + if($nome_esquema != "i3geo_metaestat"){ | |
889 | + retornaJSON("erro"); | |
890 | + exit; | |
891 | + } | |
892 | + retornaJSON($m->criaTabelaDB($codigo_estat_conexao,$nome_esquema,$nome_tabela)); | |
893 | + exit; | |
894 | + break; | |
895 | + case "ALTERANOMETABELADB": | |
896 | + $m = new Metaestat(); | |
897 | + if($nome_esquema != "i3geo_metaestat"){ | |
898 | + retornaJSON("erro"); | |
899 | + exit; | |
900 | + } | |
901 | + retornaJSON($m->alteraNomeTabelaDB($codigo_estat_conexao,$nome_esquema,$nome_tabela,$novonome_tabela)); | |
902 | + exit; | |
903 | + break; | |
904 | + case "COPIATABELADB": | |
905 | + $m = new Metaestat(); | |
906 | + if($nome_esquema != "i3geo_metaestat"){ | |
907 | + retornaJSON("erro"); | |
908 | + exit; | |
909 | + } | |
910 | + retornaJSON($m->copiaTabelaDB($codigo_estat_conexao,$nome_esquema,$nome_tabela,$novonome_tabela)); | |
911 | + exit; | |
912 | + break; | |
886 | 913 | /* |
887 | 914 | Valor: COLUNASTABELA |
888 | 915 | ... | ... |