source: trunk/admin/modules/Elezioni/aggiornadb.php@ 408

Last change on this file since 408 was 408, checked in by roby, 3 months ago

Correzione refuso nel nome di una tabella nella rev 407

File size: 24.8 KB
Line 
1<?php
2
3#imposta il charset su utf8, qualsiasi altro valore per cambiarlo in latin1;
4$newcs='utf8';
5global $ctrlerr;
6
7/*
8@require_once("../../config.php");
9 try{
10 $dbi = new PDO("mysql:host=$dbhost", $dbuname, $dbpass, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION));
11 $sql = "use $dbname";
12 $dbi->exec($sql);
13 }
14 catch(PDOException $e)
15 {
16 die( $sql . "<br>" . $e->getMessage());
17 }
18*/
19
20###############
21function aggiorna($sql,$dbi,$sql2,$num){
22 $ret=0;
23 try{
24 $res = $dbi->prepare("$sql");
25 $res->execute();
26 $ret= 1;
27 }
28 catch(PDOException $e)
29 {
30 $ret=0;
31 $ctrlerr=1;
32 echo "<br><span style=\"color: red;\">- Aggiornamento Fallito: $sql</span>";
33 return $ret;
34 }
35
36 if("$sql2"!=""){
37 try{
38 $res = $dbi->prepare("$sql2");
39 $res->execute();
40 $ret=2;
41 }
42 catch(PDOException $e)
43 {
44 $ret=0;
45 $ctrlerr=1;
46 echo "<br><span style=\"color: red;\">- Aggiornamento Fallito: $sql2</span>";
47 return $ret;
48 }
49 }
50 echo "<br><span style=\"color: green;\">- Aggiornamento eseguito correttamente</span>";
51 return $ret;
52}
53
54function aggiorna_index($tab,$ind,$dbi,$sql2,$num){
55 $ret=0;
56# $conn->getAttribute( constant( "PDO::ATTR_$val" ) )
57 $sqltest="SHOW INDEX FROM `$tab` WHERE KEY_NAME = '$ind'";
58 $res = $dbi->prepare("$sqltest");
59 $res->execute();
60
61 if($res->rowCount()) {
62 if($ind=='PRIMARY')
63 $sql="ALTER TABLE `$tab` DROP PRIMARY KEY , $sql2 ";
64 else
65 $sql="ALTER TABLE `$tab` DROP INDEX `$ind`";
66 try{
67 $res = $dbi->prepare("$sql");
68 $res->execute();
69 $ret= 1;
70 }
71 catch(PDOException $e)
72 {
73 $ret=0;
74 $ctrlerr=1;
75 echo "<br><span style=\"color: red;\">- Tabella: $tab - Indice: $ind - Aggiornamento Fallito: $sql</span>";
76 return $ret;
77 }
78 }
79 if("$sql2"!="" and $ind!='PRIMARY'){
80 try{
81 $res = $dbi->prepare("$sql2");
82 $res->execute();
83 $ret=2;
84 }
85 catch(PDOException $e)
86 {
87 $ret=0;
88 $ctrlerr=1;
89 echo "<br><span style=\"color: red;\">- Tabella: $tab - Indice: $ind - Aggiornamento Fallito: $sql2</span>";
90 return $ret;
91 }
92 }
93 echo "<br><span style=\"color: green;\">- Tabella: $tab - Indice: $ind - Index aggiornato</span>";
94 return $ret;
95}
96
97
98
99
100function controllo($tabella,$campo,$num)
101{
102 global $dbi, $dbname;
103 $sql="SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '$dbname' AND TABLE_NAME = '$tabella'";
104 $res = $dbi->prepare("$sql");
105 $res->execute();
106 if($res->rowCount() and $campo=='') return 1;
107 while(list($nome)=$res->fetch(PDO::FETCH_NUM)) {if($nome==$campo) { echo "<br>".$num.") Il campo: $campo Ú presente nella tabella: $tabella"; return 1;}}
108 if($campo) echo "<br>$num) Il campo: $campo non Ú presente nella tabella: $tabella";
109 return 0;
110}
111
112$num=0;
113
114if(controllo($prefix.'_authors','admincomune',++$num))
115{
116 $sql="UPDATE `".$prefix."_authors` SET `adminop` = '1', `adminsuper` = '0',`admincomune` = '0' WHERE `".$prefix."_authors`.`aid` != 'admin' AND `".$prefix."_authors`.`adminsuper` != '1'";
117 $ret=aggiorna($sql,$dbi,'',$num);
118 $sql="UPDATE `".$prefix."_authors` SET `adminop` = '0', `adminsuper` = '0',`admincomune` = '1' WHERE `".$prefix."_authors`.`aid` = 'admin'";
119 $ret=aggiorna($sql,$dbi,'',$num);
120 $sql="UPDATE `".$prefix."_authors` SET `adminop` = '0', `adminsuper` = '1',`admincomune` = '0' WHERE `".$prefix."_authors`.`aid` = 'suser' or `".$prefix."_authors`.`adminsuper` = '1'";
121 $ret=aggiorna($sql,$dbi,'',$num);
122 echo "<br> La tabella dei permessi Ú stata aggiornata<br>";
123}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_authors non richiede questo aggiornamento</span><br>";
124
125$sql="SELECT * from `".$prefix."_ele_widget` WHERE `soraldo_ele_widget`.`id` = 29";
126$res = $dbi->prepare("$sql");
127$res->execute();
128if($res->rowCount()) {
129 $sql="DELETE FROM soraldo_ele_widget WHERE `soraldo_ele_widget`.`id` = 29";
130 $res = $dbi->prepare("$sql");
131 $res->execute();
132 echo "<br> Il record cookie_law.php Ú stato eliminato dalla tabella dei widget, usare privacy.php<br>";
133} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_widget non richiede questo aggiornamento</span><br>";
134
135
136if(!controllo($prefix.'_ele_cons_comune','proiezione',++$num))
137{
138 $sql="ALTER TABLE `".$prefix."_ele_cons_comune` ADD `proiezione` ENUM('0','1') NOT NULL DEFAULT '0' AFTER `disgiunto`";
139 $ret=aggiorna($sql,$dbi,'',$num);
140 $sql="update `".$prefix."_ele_cons_comune` set proiezione='1' where chiusa='1' and id_conf=4";
141 $ret=aggiorna($sql,$dbi,'',$num);
142} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_cons_comune non richiede questo aggiornamento</span><br>";
143
144if(!controllo($prefix.'_config','versione',++$num))
145{
146 $sql="alter table `".$prefix."_config` change column `Versione` `versione` int(3)";
147 $ret=aggiorna($sql,$dbi,'',$num);
148} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_config non richiede questo aggiornamento</span><br>";
149if(!controllo($prefix.'_config','versione',++$num))
150{
151 $sql="alter table `".$prefix."_config` change column `Versione` `versione` int(3)";
152 $ret=aggiorna($sql,$dbi,'',$num);
153} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_config non richiede questo aggiornamento</span><br>";
154if(controllo($prefix.'_config','secret',++$num))
155{
156 $sql="alter table `".$prefix."_config` DROP `secret`";
157 $ret=aggiorna($sql,$dbi,'',$num);
158} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_config non richiede questo aggiornamento</span><br>";
159if(controllo($prefix.'_config','aggiornamento',++$num))
160{
161 $sql="alter table `".$prefix."_config` DROP `aggiornamento`";
162 $ret=aggiorna($sql,$dbi,'',$num);
163} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_config non richiede questo aggiornamento</span><br>";
164if(!controllo($prefix.'_ele_conf','votolista',++$num))
165{
166 $sql="ALTER TABLE `".$prefix."_ele_conf` ADD `votolista` enum('0', '1') NOT NULL DEFAULT '0' AFTER `supdisgiunto`";
167 $ret=aggiorna($sql,$dbi,'',$num);
168} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_conf non richiede questo aggiornamento</span><br>";
169if(!controllo($prefix.'_ele_conf','inffisso',++$num))
170{
171 $sql="ALTER TABLE `".$prefix."_ele_conf` ADD `inffisso` enum('0', '1') NOT NULL DEFAULT '0' AFTER `votolista`";
172 $ret=aggiorna($sql,$dbi,'',$num);
173} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_conf non richiede questo aggiornamento</span><br>";
174if(!controllo($prefix.'_ele_conf','supfisso',++$num))
175{
176 $sql="ALTER TABLE `".$prefix."_ele_conf` ADD `supfisso` enum('0', '1') NOT NULL DEFAULT '0' AFTER `inffisso`";
177 $ret=aggiorna($sql,$dbi,'',$num);
178} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_conf non richiede questo aggiornamento</span><br>";
179if(!controllo($prefix.'_ele_conf','fascia_capoluogo',++$num))
180{
181 $sql="ALTER TABLE `".$prefix."_ele_conf` ADD `fascia_capoluogo` int(2) NOT NULL DEFAULT '0' AFTER `supfisso`";
182 $ret=aggiorna($sql,$dbi,'',$num);
183} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_conf non richiede questo aggiornamento</span><br>";
184if(controllo($prefix.'_ele_sezioni','bianchi_lista',++$num))
185{
186 $sql="alter table `".$prefix."_ele_sezioni` DROP `bianchi_lista`";
187 $ret=aggiorna($sql,$dbi,'',$num);
188} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_sezioni non richiede questo aggiornamento</span><br>";
189if(controllo($prefix.'_ele_sezioni','nulli_lista',++$num))
190{
191 $sql="alter table `".$prefix."_ele_sezioni` DROP `nulli_lista`";
192 $ret=aggiorna($sql,$dbi,'',$num);
193} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_sezioni non richiede questo aggiornamento</span><br>";
194if(controllo($prefix.'_ele_voti_parziale','data',++$num))
195{
196 $sql="ALTER TABLE `".$prefix."_ele_voti_parziale` CHANGE `data` `data` DATE NOT NULL DEFAULT '1900-01-01'";
197 $ret=aggiorna($sql,$dbi,'',$num);
198 echo "<br>";
199}
200++$num;
201$sql="ALTER TABLE `".$prefix."_ele_come` CHANGE `title` `title` VARCHAR(150) NOT NULL DEFAULT ' ', CHANGE `preamble` `preamble` TEXT, CHANGE `content` `content` TEXT, CHANGE `editimage` `editimage` VARCHAR(100) NOT NULL DEFAULT ' '";
202$ret=aggiorna($sql,$dbi,'',$num);
203echo "<br>";
204if(!$ret) echo "Il tuo sistema non necessita di questo aggiornamento, questo avviso di errore va ignorato<br>";
205++$num;
206$sql="ALTER TABLE `".$prefix."_ele_link` CHANGE `title` `title` VARCHAR(150) NOT NULL DEFAULT ' ', CHANGE `preamble` `preamble` TEXT, CHANGE `content` `content` TEXT, CHANGE `editimage` `editimage` VARCHAR(100) NOT NULL DEFAULT ' '";
207$ret=aggiorna($sql,$dbi,'',$num);
208echo "<br>";
209if(!$ret) echo "Il tuo sistema non necessita di questo aggiornamento, questo avviso di errore va ignorato<br>";
210++$num;
211$sql="ALTER TABLE `".$prefix."_ele_servizi` CHANGE `title` `title` VARCHAR(150) NOT NULL DEFAULT ' ', CHANGE `preamble` `preamble` TEXT, CHANGE `content` `content` TEXT, CHANGE `editimage` `editimage` VARCHAR(100) NOT NULL DEFAULT ' '";
212$ret=aggiorna($sql,$dbi,'',$num);
213echo "<br>";
214if(!$ret) echo "Il tuo sistema non necessita di questo aggiornamento, questo avviso di errore va ignorato<br>";
215
216if(controllo($prefix.'_ele_rilaff','data',++$num))
217{
218 $sql="ALTER TABLE `".$prefix."_ele_rilaff` CHANGE `data` `data` DATE NOT NULL DEFAULT '1900-01-01'";
219 $ret=aggiorna($sql,$dbi,'',$num);
220 echo "<br>";
221}
222
223if(!controllo($prefix.'_ele_gruppo','num_circ',++$num))
224{
225 $sql="ALTER TABLE `".$prefix."_ele_gruppo` ADD `num_circ` INT(2) UNSIGNED NOT NULL AFTER `id_circ`";
226 $ret=aggiorna($sql,$dbi,'',$num);
227} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_gruppo non richiede questo aggiornamento</span><br>";
228
229if(!controllo($prefix.'_ele_voti_gruppo','num_gruppo',++$num))
230{
231 $sql="ALTER TABLE `".$prefix."_ele_voti_gruppo` ADD `num_gruppo` INT(2) UNSIGNED NOT NULL AFTER `id_sez`";
232 $ret=aggiorna($sql,$dbi,'',$num);
233} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_gruppo non richiede questo aggiornamento</span><br>";
234
235if(!controllo($prefix.'_ele_lista','num_gruppo',++$num))
236{
237 $sql="ALTER TABLE `".$prefix."_ele_lista` ADD `num_gruppo` INT(2) UNSIGNED NOT NULL AFTER `id_gruppo`";
238 $sql2="update `".$prefix."_ele_lista` as t1 set t1.num_gruppo=(select t2.num_gruppo from `".$prefix."_ele_gruppo` as t2 where t2.id_gruppo=t1.id_gruppo) where t1.num_gruppo=0 and (select t2.num_gruppo from `".$prefix."_ele_gruppo` as t2 where t2.id_gruppo=t1.id_gruppo) is not null";
239 $ret=aggiorna($sql,$dbi,$sql2,$num);
240}else{
241 $sql="update `".$prefix."_ele_lista` as t1 set t1.num_gruppo=(select t2.num_gruppo from `".$prefix."_ele_gruppo` as t2 where t2.id_gruppo=t1.id_gruppo) where t1.num_gruppo=0 and (select t2.num_gruppo from `".$prefix."_ele_gruppo` as t2 where t2.id_gruppo=t1.id_gruppo) is not null";
242 $ret=aggiorna($sql,$dbi,'',$num);
243echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_lista non richiede questo aggiornamento</span><br>";
244}
245if(!controllo($prefix.'_ele_lista','num_circ',++$num))
246{
247 $sql="ALTER TABLE `".$prefix."_ele_lista` ADD `num_circ` INT(2) UNSIGNED NOT NULL AFTER `id_circ`";
248 $ret=aggiorna($sql,$dbi,'',$num);
249}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_lista non richiede questo aggiornamento</span><br>";
250
251if(!controllo($prefix.'_ele_operatori','id_circ',++$num))
252{
253 $sql="ALTER TABLE `".$prefix."_ele_operatori` ADD `id_circ` INT(11) NOT NULL DEFAULT 0 AFTER `aid`";
254 $ret=aggiorna($sql,$dbi,'',$num);
255}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_operatori non richiede questo aggiornamento</span><br>";
256
257if(!controllo($prefix.'_ele_operatori','id_sez',++$num))
258{
259 $sql="ALTER TABLE `".$prefix."_ele_operatori` ADD `id_sez` INT(11) NOT NULL DEFAULT 0 AFTER `id_circ`";
260 $ret=aggiorna($sql,$dbi,'',$num);
261}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_operatori non richiede questo aggiornamento</span><br>";
262
263if(!controllo($prefix.'_ele_temi','id',++$num))
264{
265 $sql="ALTER TABLE `".$prefix."_ele_temi` ADD `id` INT(11) NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`id`)";
266 $ret=aggiorna($sql,$dbi,'',$num);
267}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_operatori non richiede questo aggiornamento</span><br>";
268
269if(!controllo($prefix.'_ele_voti_lista','num_lista',++$num))
270{
271 $sql="ALTER TABLE `".$prefix."_ele_voti_lista` ADD `num_lista` INT(2) UNSIGNED NOT NULL AFTER `id_sez`";
272 $ret=aggiorna($sql,$dbi,'',$num);
273}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_voti_lista non richiede questo aggiornamento</span><br>";
274
275if(!controllo($prefix.'_ele_voti_ref','num_gruppo',++$num))
276{
277 $sql="ALTER TABLE `".$prefix."_ele_voti_ref` ADD `num_gruppo` INT(2) UNSIGNED NOT NULL AFTER `id_sez`";
278 $ret=aggiorna($sql,$dbi,'',$num);
279}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_voti_ref non richiede questo aggiornamento</span><br>";
280
281if(controllo($prefix.'_ele_candidati','Sesso',++$num))
282{
283 $sql="ALTER TABLE `".$prefix."_ele_candidati` DROP `Sesso`";
284 $ret=aggiorna($sql,$dbi,'',$num);
285} else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_candidati non richiede questo aggiornamento</span><br>";
286if(!controllo($prefix.'_ele_voti_candidati','num_cand',++$num))
287{
288 $sql="ALTER TABLE `".$prefix."_ele_voti_candidati` ADD `num_cand` INT(2) UNSIGNED NOT NULL AFTER `id_sez`";
289 $ret=aggiorna($sql,$dbi,'',$num);
290}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_voti_candidati non richiede questo aggiornamento</span><br>";
291
292if(!controllo($prefix.'_ele_candidati','num_lista',++$num))
293{
294 $sql="ALTER TABLE `".$prefix."_ele_candidati` ADD `num_lista` INT(2) UNSIGNED NOT NULL AFTER `id_lista`";
295 $ret=aggiorna($sql,$dbi,'',$num);
296}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_candidati non richiede questo aggiornamento</span><br>";
297
298if(!controllo($prefix.'_ele_sezioni','colore',++$num))
299{
300 $sql="ALTER TABLE `".$prefix."_ele_sezioni` ADD `colore` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '#FAFAD2' AFTER `solo_lista`";
301 $ret=aggiorna($sql,$dbi,'',$num);
302}else{
303 $sql="ALTER TABLE `".$prefix."_ele_sezioni` CHANGE `colore` `colore` VARCHAR(50) DEFAULT '#FAFAD2'";
304 $ret=aggiorna($sql,$dbi,'',$num);
305} echo "<br>";
306
307echo "<br>Aggiornamento per nuovo sistema dei controlli di congruità";
308
309if(!controllo($prefix.'_ele_controlli','id_cons',++$num))
310{
311 $sql="CREATE TABLE if not exists`".$prefix."_ele_controlli` ( `id_cons` INT(11) NOT NULL , `id_sez` INT(11) NOT NULL , `tipo` VARCHAR(10) NOT NULL , `id` INT(11) NOT NULL , INDEX `sezione` (`id_sez`)) ENGINE = MyISAM";
312 echo "<br>".$num.") Creazione tabella dei controlli: ";
313 $ret=aggiorna($sql,$dbi,'',$num);
314}else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_controlli non richiede questo aggiornamento</span><br>";
315
316echo "<br>".++$num.") Eliminazione della vecchia tabella dei controlli: ";
317if(controllo($prefix.'_ele_controllisez','',$num))
318{
319$sql="DROP TABLE if exists `".$prefix."_ele_controllisez`";
320$ret=aggiorna($sql,$dbi,'',$num);
321} else echo "<br><span style=\"color: green;\">- Tabella non presente</span><br>";
322
323echo "<br>".++$num.") Aggiornamento tabella ".$prefix."_ele_voti_gruppo";
324$sql="update `".$prefix."_ele_voti_gruppo` as t1 left join `".$prefix."_ele_gruppo` as t2 on t1.id_gruppo=t2.id_gruppo set t1.num_gruppo=t2.num_gruppo;";
325$ret=aggiorna($sql,$dbi,'',$num);
326
327echo "<br><br>".++$num.") Aggiornamento dei valori di default: ".$prefix."_ele_voti_lista";
328$sql="ALTER TABLE `".$prefix."_ele_voti_lista` CHANGE `num_lista` `num_lista` INT(2) UNSIGNED NULL DEFAULT '0';";
329$ret=aggiorna($sql,$dbi,'',$num);
330
331echo "<br><br>".++$num.") Aggiornamento tabella ".$prefix."_ele_voti_lista";
332$sql="update `".$prefix."_ele_voti_lista` as t1 left join `".$prefix."_ele_lista` as t2 on t1.id_lista=t2.id_lista set t1.num_lista=t2.num_lista;";
333$ret=aggiorna($sql,$dbi,'',$num);
334##############################################
335
336echo "<br><br>".++$num.") Aggiornamento dei valori di default: ".$prefix."_ele_gruppo";
337$sql="ALTER TABLE `".$prefix."_ele_gruppo` CHANGE `num_circ` `num_circ` INT(2) UNSIGNED NOT NULL DEFAULT '1';";
338$ret=aggiorna($sql,$dbi,'',$num);
339
340$sql="ALTER TABLE `".$prefix."_authors` CHANGE `adminsuper` `adminsuper` TINYINT(2) NOT NULL DEFAULT '0';";
341$ret=aggiorna($sql,$dbi,'',$num);
342
343$sql="ALTER TABLE `".$prefix."_ele_lista` CHANGE `num_gruppo` `num_gruppo` INT(2) UNSIGNED NOT NULL DEFAULT '0';";
344$ret=aggiorna($sql,$dbi,'',$num);
345
346$sql="ALTER TABLE `".$prefix."_ele_lista` CHANGE `num_circ` `num_circ` INT(2) UNSIGNED NOT NULL DEFAULT '1';";
347$ret=aggiorna($sql,$dbi,'',$num);
348
349echo "<br><br>".++$num.") Aggiornamento della tabella _ele_conf per la nuova gestione della L.R. Sicilia";
350$sql="UPDATE `".$prefix."_ele_conf` SET `inffisso` = '1' WHERE `id_conf` = 4;";
351$ret=aggiorna($sql,$dbi,'',$num);
352
353echo "<br><br>".++$num.") Ricostruzione della tabella ".$prefix."_ele_fasce`";
354$sql="DROP TABLE `".$prefix."_ele_fasce`";
355$ret=aggiorna($sql,$dbi,'',$num);
356
357$sql="CREATE TABLE `".$prefix."_ele_fasce` (
358 `id_fascia` int(2) NOT NULL,
359 `abitanti` int(11) NOT NULL,
360 `seggi` int(4) NOT NULL,
361 `id_conf` int(11) DEFAULT 1
362) ENGINE=MyISAM DEFAULT CHARSET 'utf8';";
363
364
365$sql2="INSERT INTO `".$prefix."_ele_fasce` (`id_fascia`, `abitanti`, `seggi`, `id_conf`) VALUES
366(1, 3000, 12, 1),
367(2, 10000, 16, 1),
368(3, 15000, 20, 1),
369(4, 30000, 20, 1),
370(5, 100000, 30, 1),
371(6, 250000, 40, 1),
372(7, 500000, 46, 1),
373(8, 1000000, 50, 1),
374(9, 100000000, 60, 1),
375(1, 3000, 12, 2),
376(2, 10000, 16, 2),
377(3, 15000, 20, 2),
378(4, 30000, 20, 2),
379(5, 100000, 30, 2),
380(6, 250000, 40, 2),
381(7, 500000, 46, 2),
382(8, 1000000, 50, 2),
383(9, 100000000, 60, 2),
384(1, 3000, 9, 3),
385(2, 5000, 9, 3),
386(4, 15000, 16, 3),
387(3, 10000, 12, 3),
388(5, 30000, 16, 3),
389(6, 100000, 24, 3),
390(7, 250000, 32, 3),
391(8, 500000, 36, 3),
392(9, 1000000, 40, 3),
393(10, 100000000, 48, 3),
394(1, 3000, 6, 4),
395(2, 5000, 7, 4),
396(3, 10000, 12, 4),
397(4, 15000, 16, 4),
398(5, 30000, 16, 4),
399(6, 100000, 24, 4),
400(7, 250000, 32, 4),
401(8, 500000, 36, 4),
402(9, 1000000, 40, 4),
403(10, 100000000, 48, 4),
404(1, 3000, 9, 5),
405(2, 5000, 9, 5),
406(3, 10000, 12, 5),
407(4, 15000, 16, 5),
408(5, 30000, 16, 5),
409(6, 100000, 24, 5),
410(7, 250000, 32, 5),
411(8, 500000, 36, 5),
412(9, 1000000, 40, 5),
413(10, 100000000, 48, 5),
414(1, 3000, 6, 6),
415(2, 5000, 7, 6),
416(3, 10000, 10, 6),
417(4, 15000, 16, 6),
418(5, 30000, 16, 6),
419(6, 100000, 24, 6),
420(7, 250000, 32, 6),
421(8, 500000, 36, 6),
422(9, 1000000, 40, 6),
423(10, 100000000, 48, 6),
424(1, 3000, 10, 7),
425(2, 10000, 12, 7),
426(3, 15000, 16, 7),
427(4, 30000, 16, 7),
428(5, 100000, 24, 7),
429(6, 250000, 32, 7),
430(7, 500000, 36, 7),
431(8, 1000000, 40, 7),
432(9, 100000000, 48, 7);";
433$ret=aggiorna($sql,$dbi,$sql2,$num);
434#if(!$ret) echo "<br>".$num++.") Fallito: $sql"; else echo "<br>".$num++.") Aggiornato<br>";
435
436$sql="ALTER TABLE `".$prefix."_ele_fasce`
437 ADD KEY `id_fascia` (`id_fascia`);";
438$ret=aggiorna($sql,$dbi,'',$num);
439#if(!$ret) echo "<br>".$num++.") Fallito: $sql"; else echo "<br>".$num++.") Aggiornato<br>";
440
441
442
443#if(!$ret)
444# echo "<br>".$num++.") Fallito: $sql";
445#elseif ($ret==1)
446# echo "<br>".$num++.") Index eliminato";
447#else
448# echo "<br>".$num++.") Index aggiunto";
449#$sql="ALTER TABLE `".$prefix."_ele_voti_lista` DROP INDEX if exists `id_cons`";
450echo "<br><br>".++$num.") Ricostruzione e aggioramento indici";
451$tab=$prefix."_ele_voti_ref";
452$ind="id_cons";
453# $sql="ALTER TABLE `".$prefix."_ele_voti_ref` DROP INDEX `id_cons`; ";
454$sql2="ALTER TABLE `".$prefix."_ele_voti_ref` ADD INDEX `id_cons` (`id_cons`, `id_gruppo`) USING BTREE";
455$ret=aggiorna_index($tab, $ind,$dbi,$sql2,$num);
456
457$tab=$prefix."_ele_sezioni";
458$ind="id_cons";
459$sql2="ALTER TABLE `".$prefix."_ele_sezioni` ADD UNIQUE `id_cons` (`id_cons`, `num_sez`) USING BTREE";
460$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
461
462$tab=$prefix."_ele_voti_lista";
463$ind="id_cons";
464$sql2="ALTER TABLE `".$prefix."_ele_voti_lista` ADD INDEX `id_cons` (`id_cons`, `id_sez`, `id_lista`) USING BTREE";
465$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
466
467$tab=$prefix."_ele_voti_gruppo";
468$ind="id_cons";
469#$sql="ALTER TABLE `".$prefix."_ele_voti_gruppo` DROP INDEX if exists `id_cons`";
470$sql2="ALTER TABLE `".$prefix."_ele_voti_gruppo` ADD INDEX `id_cons` (`id_cons`, `id_sez`, `id_gruppo`) USING BTREE";
471$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
472
473$tab=$prefix."_ele_voti_candidati";
474$ind="id_cons";
475#$sql="ALTER TABLE `".$prefix."_ele_voti_candidati` DROP INDEX if exists `id_cons`";
476$sql2="ALTER TABLE `".$prefix."_ele_voti_candidati` ADD INDEX `id_cons` (`id_cons`, `id_sez`, `id_cand`) USING BTREE";
477$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
478
479$tab=$prefix."_ele_lista";
480$ind="id_cons";
481#$sql="ALTER TABLE `".$prefix."_ele_lista` DROP INDEX if exists `id_cons`";
482$sql2="ALTER TABLE `".$prefix."_ele_lista` ADD INDEX `id_cons` (`id_cons`, `id_gruppo`) USING BTREE";
483$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
484
485$tab=$prefix."_ele_lista";
486$ind="PRIMARY";
487#$sql="ALTER TABLE `".$prefix."_ele_lista` DROP INDEX if exists `PRIMARY`";
488$sql2="ADD PRIMARY KEY (`id_lista`) USING BTREE";
489$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
490
491$tab=$prefix."_ele_gruppo";
492$ind="id_cons";
493#$sql="ALTER TABLE `".$prefix."_ele_gruppo` DROP INDEX if exists `id_cons`";
494$sql2="ALTER TABLE `".$prefix."_ele_gruppo` ADD INDEX `id_cons` (`id_cons`, `id_circ`) USING BTREE";
495$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
496
497$tab=$prefix."_ele_gruppo";
498$ind="PRIMARY";
499#$sql="ALTER TABLE `".$prefix."_ele_gruppo` DROP INDEX if exists `PRIMARY`";
500$sql2="ADD PRIMARY KEY (`id_gruppo`) USING BTREE";
501$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
502
503$tab=$prefix."_ele_candidati";
504$ind="id_cons";
505#$sql="ALTER TABLE `".$prefix."_ele_candidati` DROP INDEX if exists `id_cons`";
506$sql2="ALTER TABLE `".$prefix."_ele_candidati` ADD INDEX `id_cons` (`id_cons`, `id_lista`) USING BTREE";
507$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
508
509$tab=$prefix."_ele_candidati";
510$ind="PRIMARY";
511#$sql="ALTER TABLE `".$prefix."_ele_candidati` DROP INDEX if exists `PRIMARY`";
512$sql2="ADD PRIMARY KEY (`id_cand`) USING BTREE";
513$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
514
515$tab=$prefix."_ele_consultazione";
516$ind="descrizione";
517#$sql="ALTER TABLE `".$prefix."_ele_consultazione` DROP INDEX if exists `descrizione`";
518$sql2="ALTER TABLE `".$prefix."_ele_consultazione` ADD UNIQUE `descrizione` (`descrizione`(100))";
519$ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
520
521echo "<br><br>".++$num.") Modifica Charset del database";
522if($newcs=='utf8') {
523 $cset='utf8';
524 $ccollate='utf8_general_ci';
525 $preset='latin1';
526}else{
527 $cset='latin1';
528 $ccollate='latin1_swedish_ci';
529 $preset='utf8';
530}
531#$sql="ALTER DATABASE $dbname CHARACTER SET '$cset' COLLATE '$ccollate'";
532#$res = $dbi->prepare("$sql");
533#$res->execute();
534
535$sql="SELECT table_name,column_name,column_default,column_type,is_nullable FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '$dbname' and (character_set_name='$preset' or collation_name like '$preset%')";
536$res = $dbi->prepare("$sql");
537$res->execute();
538$tab='';
539$agg=$res->rowCount();
540
541while(list($nometab,$campo,$def,$tipo,$nul)=$res->fetch(PDO::FETCH_NUM)) {
542 if($tab!=$nometab){
543 $sql="alter table $nometab DEFAULT CHARSET=$cset COLLATE $ccollate";
544 try{
545 $res2 = $dbi->prepare("$sql");
546 $res2->execute();
547 }
548 catch(PDOException $e)
549 {
550 die( $sql . "<br>" . $e->getMessage());
551 }
552 $tab=$nometab; echo "<br><span style=\"color: green;\">- Tabella: $nometab</span>";
553 }
554 if($def!='') $default="DEFAULT '$def'"; else $default='';
555 if($nul=='NO') $nullable='NOT NULL'; else $nullable='NULL';
556 $sql="ALTER TABLE $nometab CHANGE $campo $campo $tipo CHARACTER SET '$cset' COLLATE '$ccollate' $nullable $default;";
557 try{
558 $res2 = $dbi->prepare("$sql");
559 $res2->execute();
560 }
561 catch(PDOException $e)
562 {
563 $default="DEFAULT $def";
564 $sql="ALTER TABLE $nometab CHANGE $campo $campo $tipo CHARACTER SET '$cset' COLLATE '$ccollate' $nullable $default;";
565 try{
566 $res2 = $dbi->prepare("$sql");
567 $res2->execute();
568 }
569 catch(PDOException $e)
570 {
571 die( $sql . "<br>" . $e->getMessage());
572 }
573 }
574 echo "<br><span style=\"color: green;\">-- $campo</span>";
575}
576 $sql="SELECT table_name FROM INFORMATION_SCHEMA.tables WHERE TABLE_SCHEMA = '$dbname' and table_collation like '$preset%'";
577 $res = $dbi->prepare("$sql");
578 $res->execute();
579$tab='';
580if(!$agg) $agg=$res->rowCount();
581while(list($nometab)=$res->fetch(PDO::FETCH_NUM)) {
582 $sql="alter table $nometab DEFAULT CHARSET=$cset COLLATE $ccollate";
583 try{
584 $res2 = $dbi->prepare("$sql");
585 $res2->execute();
586 }
587 catch(PDOException $e)
588 {
589 die( $sql . "<br>" . $e->getMessage());
590 }
591 echo "<br><span style=\"color: green;\">- Tabella: $nometab</span>";
592}
593if(!$agg) echo "<br><span style=\"color: green;\">- Nessuna tabella da aggiornare</span>";
594echo "<br><br>";
595?>
Note: See TracBrowser for help on using the repository browser.