[296] | 1 | <?php
|
---|
[324] | 2 |
|
---|
[362] | 3 | #imposta il charset su utf8, qualsiasi altro valore per cambiarlo in latin1;
|
---|
| 4 | $newcs='utf8';
|
---|
| 5 |
|
---|
[296] | 6 | @require_once("config.php");
|
---|
| 7 | try{
|
---|
[362] | 8 | $dbi = new PDO("mysql:host=$dbhost", $dbuname, $dbpass, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION));
|
---|
| 9 | $sql = "use $dbname";
|
---|
| 10 | $dbi->exec($sql);
|
---|
| 11 | }
|
---|
[296] | 12 | catch(PDOException $e)
|
---|
| 13 | {
|
---|
| 14 | die( $sql . "<br>" . $e->getMessage());
|
---|
| 15 | }
|
---|
[362] | 16 |
|
---|
| 17 |
|
---|
[296] | 18 | ###############
|
---|
[357] | 19 | function aggiorna($sql,$dbi,$sql2,$num){
|
---|
[330] | 20 | $ret=0;
|
---|
[296] | 21 | try{
|
---|
| 22 | $res = $dbi->prepare("$sql");
|
---|
| 23 | $res->execute();
|
---|
[330] | 24 | $ret= 1;
|
---|
[363] | 25 | }
|
---|
[296] | 26 | catch(PDOException $e)
|
---|
| 27 | {
|
---|
[363] | 28 | $ret=0;
|
---|
| 29 | echo "<br><span style=\"color: red;\">- Aggiornamento Fallito: $sql</span>";
|
---|
| 30 | return $ret;
|
---|
[330] | 31 | }
|
---|
| 32 |
|
---|
| 33 | if("$sql2"!=""){
|
---|
| 34 | try{
|
---|
| 35 | $res = $dbi->prepare("$sql2");
|
---|
| 36 | $res->execute();
|
---|
| 37 | $ret=2;
|
---|
| 38 | }
|
---|
| 39 | catch(PDOException $e)
|
---|
| 40 | {
|
---|
| 41 | $ret=0;
|
---|
[363] | 42 | echo "<br><span style=\"color: red;\">- Aggiornamento Fallito: $sql2</span>";
|
---|
[357] | 43 | return $ret;
|
---|
[330] | 44 | }
|
---|
[296] | 45 | }
|
---|
[363] | 46 | echo "<br><span style=\"color: green;\">- Aggiornamento eseguito correttamente</span>";
|
---|
[330] | 47 | return $ret;
|
---|
[324] | 48 | }
|
---|
[359] | 49 | function aggiorna_index($tab,$ind,$dbi,$sql2,$num){
|
---|
[357] | 50 | $ret=0;
|
---|
[359] | 51 | $sqltest="SHOW INDEX FROM `$tab` WHERE KEY_NAME = '$ind'";
|
---|
| 52 | $res = $dbi->prepare("$sqltest");
|
---|
| 53 | $res->execute();
|
---|
| 54 | if($res->rowCount()) {
|
---|
| 55 | $sql="ALTER TABLE `$tab` DROP INDEX `$ind`";
|
---|
| 56 | try{
|
---|
| 57 | $res = $dbi->prepare("$sql");
|
---|
| 58 | $res->execute();
|
---|
| 59 | $ret= 1;
|
---|
| 60 | }
|
---|
| 61 | catch(PDOException $e)
|
---|
| 62 | {
|
---|
[363] | 63 | $ret=0;
|
---|
| 64 | echo "<br><span style=\"color: red;\">- Tabella: $tab - Indice: $ind - Aggiornamento Fallito: $sql</span>";
|
---|
| 65 | return $ret;
|
---|
[359] | 66 | }
|
---|
[357] | 67 | }
|
---|
| 68 | if("$sql2"!=""){
|
---|
| 69 | try{
|
---|
| 70 | $res = $dbi->prepare("$sql2");
|
---|
| 71 | $res->execute();
|
---|
| 72 | $ret=2;
|
---|
| 73 | }
|
---|
| 74 | catch(PDOException $e)
|
---|
| 75 | {
|
---|
| 76 | $ret=0;
|
---|
[363] | 77 | echo "<br><span style=\"color: red;\">- Tabella: $tab - Indice: $ind - Aggiornamento Fallito: $sql2</span>";
|
---|
[357] | 78 | return $ret;
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
[363] | 81 | echo "<br><span style=\"color: green;\">- Tabella: $tab - Indice: $ind - Index aggiornato</span>";
|
---|
[357] | 82 | return $ret;
|
---|
| 83 | }
|
---|
[324] | 84 |
|
---|
[357] | 85 |
|
---|
| 86 |
|
---|
[360] | 87 |
|
---|
[357] | 88 | function controllo($tabella,$campo,$num)
|
---|
| 89 | {
|
---|
| 90 | global $dbi, $dbname;
|
---|
| 91 | $sql="SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '$dbname' AND TABLE_NAME = '$tabella'";
|
---|
| 92 | $res = $dbi->prepare("$sql");
|
---|
| 93 | $res->execute();
|
---|
| 94 | if($res->rowCount() and $campo=='') return 1;
|
---|
[363] | 95 | while(list($nome)=$res->fetch(PDO::FETCH_NUM)) {if($nome==$campo) { echo "<br>".$num.") Il campo: $campo Ú presente nella tabella: $tabella"; return 1;}}
|
---|
| 96 | if($campo) echo "<br>$num) Il campo: $campo non Ú presente nella tabella: $tabella";
|
---|
[357] | 97 | return 0;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[360] | 100 | $num=0;
|
---|
[357] | 101 |
|
---|
[362] | 102 | if(controllo($prefix.'_authors','admincomune',++$num))
|
---|
| 103 | {
|
---|
[371] | 104 | $sql="UPDATE `soraldo_authors` SET `adminop` = '1', `adminsuper` = '0',`admincomune` = '0' WHERE `soraldo_authors`.`aid` != 'admin' AND `soraldo_authors`.`aid` != 'suser'";
|
---|
[362] | 105 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[371] | 106 | $sql="UPDATE `soraldo_authors` SET `adminop` = '0', `adminsuper` = '1',`admincomune` = '0' WHERE `soraldo_authors`.`aid` = 'suser'";
|
---|
[362] | 107 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[371] | 108 | $sql="UPDATE `soraldo_authors` SET `adminop` = '0', `adminsuper` = '0',`admincomune` = '1' WHERE `soraldo_authors`.`aid` = 'admin'";
|
---|
| 109 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[363] | 110 | echo "<br> La tabella dei permessi Ú stata aggiornata<br>";
|
---|
| 111 | }else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_authors non richiede questo aggiornamento</span><br>";
|
---|
[362] | 112 |
|
---|
[357] | 113 | if(!controllo($prefix.'_config','versione',++$num))
|
---|
[324] | 114 | {
|
---|
[357] | 115 | $sql="alter table `".$prefix."_config` change column `Versione` `versione` int(3)";
|
---|
| 116 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[363] | 117 | } else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_config non richiede questo aggiornamento</span><br>";
|
---|
[296] | 118 |
|
---|
[362] | 119 |
|
---|
[363] | 120 | if(controllo($prefix.'_config','secret',++$num))
|
---|
[362] | 121 | {
|
---|
| 122 | $sql="alter table `".$prefix."_config` DROP `secret`";
|
---|
| 123 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[363] | 124 | } else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_config non richiede questo aggiornamento</span><br>";
|
---|
[362] | 125 |
|
---|
[363] | 126 | if(controllo($prefix.'_ele_voti_parziale','data',++$num))
|
---|
[361] | 127 | {
|
---|
| 128 | $sql="ALTER TABLE `".$prefix."_ele_voti_parziale` CHANGE `data` `data` DATE NOT NULL DEFAULT '1900-01-01'";
|
---|
| 129 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[363] | 130 | echo "<br>";
|
---|
[361] | 131 | }
|
---|
[371] | 132 | ++$num;
|
---|
| 133 | $sql="ALTER TABLE `soraldo_ele_come` CHANGE `title` `title` VARCHAR(150) NOT NULL DEFAULT ' ', CHANGE `preamble` `preamble` TEXT NOT NULL DEFAULT ' ', CHANGE `content` `content` TEXT NOT NULL DEFAULT ' ', CHANGE `editimage` `editimage` VARCHAR(100) NOT NULL DEFAULT ' '";
|
---|
| 134 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
| 135 | echo "<br>";
|
---|
| 136 | ++$num;
|
---|
| 137 | $sql="ALTER TABLE `soraldo_ele_link` CHANGE `title` `title` VARCHAR(150) NOT NULL DEFAULT ' ', CHANGE `preamble` `preamble` TEXT NOT NULL DEFAULT ' ', CHANGE `content` `content` TEXT NOT NULL DEFAULT ' ', CHANGE `editimage` `editimage` VARCHAR(100) NOT NULL DEFAULT ' '";
|
---|
| 138 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
| 139 | echo "<br>";
|
---|
| 140 | ++$num;
|
---|
| 141 | $sql="ALTER TABLE `soraldo_ele_servizi` CHANGE `title` `title` VARCHAR(150) NOT NULL DEFAULT ' ', CHANGE `preamble` `preamble` TEXT NOT NULL DEFAULT ' ', CHANGE `content` `content` TEXT NOT NULL DEFAULT ' ', CHANGE `editimage` `editimage` VARCHAR(100) NOT NULL DEFAULT ' '";
|
---|
| 142 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
| 143 | echo "<br>";
|
---|
[361] | 144 |
|
---|
[363] | 145 | if(controllo($prefix.'_ele_rilaff','data',++$num))
|
---|
[361] | 146 | {
|
---|
| 147 | $sql="ALTER TABLE `".$prefix."_ele_rilaff` CHANGE `data` `data` DATE NOT NULL DEFAULT '1900-01-01'";
|
---|
| 148 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[363] | 149 | echo "<br>";
|
---|
[361] | 150 | }
|
---|
| 151 |
|
---|
[357] | 152 | if(!controllo($prefix.'_ele_gruppo','num_circ',++$num))
|
---|
| 153 | {
|
---|
| 154 | $sql="ALTER TABLE `".$prefix."_ele_gruppo` ADD `num_circ` INT(2) UNSIGNED NOT NULL AFTER `id_circ`";
|
---|
| 155 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[363] | 156 | } else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_gruppo non richiede questo aggiornamento</span><br>";
|
---|
[357] | 157 |
|
---|
| 158 | if(!controllo($prefix.'_ele_voti_gruppo','num_gruppo',++$num))
|
---|
| 159 | {
|
---|
| 160 | $sql="ALTER TABLE `".$prefix."_ele_voti_gruppo` ADD `num_gruppo` INT(2) UNSIGNED NOT NULL AFTER `id_sez`";
|
---|
| 161 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[363] | 162 | } else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_gruppo non richiede questo aggiornamento</span><br>";
|
---|
[357] | 163 |
|
---|
| 164 | if(!controllo($prefix.'_ele_lista','num_gruppo',++$num))
|
---|
| 165 | {
|
---|
| 166 | $sql="ALTER TABLE `".$prefix."_ele_lista` ADD `num_gruppo` INT(2) UNSIGNED NOT NULL AFTER `id_gruppo`";
|
---|
| 167 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[363] | 168 | }else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_lista non richiede questo aggiornamento</span><br>";
|
---|
[357] | 169 |
|
---|
| 170 | if(!controllo($prefix.'_ele_lista','num_circ',++$num))
|
---|
| 171 | {
|
---|
| 172 | $sql="ALTER TABLE `".$prefix."_ele_lista` ADD `num_circ` INT(2) UNSIGNED NOT NULL AFTER `id_circ`";
|
---|
| 173 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[363] | 174 | }else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_lista non richiede questo aggiornamento</span><br>";
|
---|
| 175 |
|
---|
[358] | 176 | if(!controllo($prefix.'_ele_operatori','id_circ',++$num))
|
---|
| 177 | {
|
---|
| 178 | $sql="ALTER TABLE `".$prefix."_ele_operatori` ADD `id_circ` INT(11) NOT NULL DEFAULT 0 AFTER `aid`";
|
---|
| 179 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[363] | 180 | }else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_operatori non richiede questo aggiornamento</span><br>";
|
---|
| 181 |
|
---|
[359] | 182 | if(!controllo($prefix.'_ele_operatori','id_sez',++$num))
|
---|
[358] | 183 | {
|
---|
| 184 | $sql="ALTER TABLE `".$prefix."_ele_operatori` ADD `id_sez` INT(11) NOT NULL DEFAULT 0 AFTER `id_circ`";
|
---|
| 185 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[363] | 186 | }else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_operatori non richiede questo aggiornamento</span><br>";
|
---|
| 187 |
|
---|
[357] | 188 | if(!controllo($prefix.'_ele_voti_lista','num_lista',++$num))
|
---|
| 189 | {
|
---|
| 190 | $sql="ALTER TABLE `".$prefix."_ele_voti_lista` ADD `num_lista` INT(2) UNSIGNED NOT NULL AFTER `id_sez`";
|
---|
| 191 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[363] | 192 | }else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_voti_lista non richiede questo aggiornamento</span><br>";
|
---|
[357] | 193 |
|
---|
| 194 | if(!controllo($prefix.'_ele_voti_ref','num_gruppo',++$num))
|
---|
| 195 | {
|
---|
| 196 | $sql="ALTER TABLE `".$prefix."_ele_voti_ref` ADD `num_gruppo` INT(2) UNSIGNED NOT NULL AFTER `id_sez`";
|
---|
| 197 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[363] | 198 | }else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_voti_ref non richiede questo aggiornamento</span><br>";
|
---|
[357] | 199 |
|
---|
| 200 | if(!controllo($prefix.'_ele_voti_candidati','num_cand',++$num))
|
---|
| 201 | {
|
---|
| 202 | $sql="ALTER TABLE `".$prefix."_ele_voti_candidati` ADD `num_cand` INT(2) UNSIGNED NOT NULL AFTER `id_sez`";
|
---|
| 203 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[363] | 204 | }else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_voti_candidati non richiede questo aggiornamento</span><br>";
|
---|
[357] | 205 |
|
---|
| 206 | if(!controllo($prefix.'_ele_candidati','num_lista',++$num))
|
---|
| 207 | {
|
---|
| 208 | $sql="ALTER TABLE `".$prefix."_ele_candidati` ADD `num_lista` INT(2) UNSIGNED NOT NULL AFTER `id_lista`";
|
---|
| 209 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[363] | 210 | }else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_candidati non richiede questo aggiornamento</span><br>";
|
---|
[357] | 211 |
|
---|
| 212 | if(!controllo($prefix.'_ele_sezioni','colore',++$num))
|
---|
| 213 | {
|
---|
[363] | 214 | $sql="ALTER TABLE `".$prefix."_ele_sezioni` ADD `colore` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '#FAFAD2' AFTER `solo_lista`";
|
---|
| 215 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
| 216 | }else{
|
---|
[364] | 217 | $sql="ALTER TABLE `".$prefix."_ele_sezioni` CHANGE `colore` `colore` VARCHAR(50) DEFAULT '#FAFAD2'";
|
---|
[363] | 218 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
| 219 | } echo "<br>";
|
---|
| 220 |
|
---|
[357] | 221 | echo "<br>Aggiornamento per nuovo sistema dei controlli di congruità ";
|
---|
| 222 |
|
---|
| 223 | if(!controllo($prefix.'_ele_controlli','id_cons',++$num))
|
---|
| 224 | {
|
---|
| 225 | $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";
|
---|
| 226 | echo "<br>".$num.") Creazione tabella dei controlli: ";
|
---|
| 227 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[363] | 228 | }else echo "<br><span style=\"color: green;\">- La tabella ".$prefix."_ele_controlli non richiede questo aggiornamento</span><br>";
|
---|
[357] | 229 |
|
---|
[363] | 230 | echo "<br>".++$num.") Eliminazione della vecchia tabella dei controlli: ";
|
---|
| 231 | if(controllo($prefix.'_ele_controllisez','',$num))
|
---|
[357] | 232 | {
|
---|
| 233 | $sql="DROP TABLE if exists `".$prefix."_ele_controllisez`";
|
---|
| 234 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[363] | 235 | } else echo "<br><span style=\"color: green;\">- Tabella non presente</span><br>";
|
---|
[357] | 236 |
|
---|
[363] | 237 | echo "<br>".++$num.") Aggiornamento tabella ".$prefix."_ele_voti_gruppo";
|
---|
[357] | 238 | $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;";
|
---|
[363] | 239 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[357] | 240 |
|
---|
[363] | 241 | echo "<br><br>".++$num.") Aggiornamento tabella ".$prefix."_ele_voti_lista";
|
---|
[357] | 242 | $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;";
|
---|
[363] | 243 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[357] | 244 | ##############################################
|
---|
| 245 |
|
---|
[363] | 246 | echo "<br><br>".++$num.") Aggiornamento dei valori di default";
|
---|
[357] | 247 | $sql="ALTER TABLE `".$prefix."_ele_gruppo` CHANGE `num_circ` `num_circ` INT(2) UNSIGNED NOT NULL DEFAULT '1';";
|
---|
[363] | 248 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[357] | 249 |
|
---|
[359] | 250 | $sql="ALTER TABLE `soraldo_authors` CHANGE `adminsuper` `adminsuper` TINYINT(2) NOT NULL DEFAULT '0';";
|
---|
[363] | 251 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[359] | 252 |
|
---|
[357] | 253 | $sql="ALTER TABLE `".$prefix."_ele_lista` CHANGE `num_gruppo` `num_gruppo` INT(2) UNSIGNED NOT NULL DEFAULT '0';";
|
---|
[363] | 254 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[357] | 255 |
|
---|
| 256 | $sql="ALTER TABLE `".$prefix."_ele_lista` CHANGE `num_circ` `num_circ` INT(2) UNSIGNED NOT NULL DEFAULT '1';";
|
---|
[363] | 257 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[357] | 258 |
|
---|
[363] | 259 | echo "<br><br>".++$num.") Ricostruzione della tabella ".$prefix."_ele_fasce`";
|
---|
[357] | 260 | $sql="DROP TABLE `".$prefix."_ele_fasce`";
|
---|
[363] | 261 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[357] | 262 |
|
---|
| 263 | $sql="CREATE TABLE `".$prefix."_ele_fasce` (
|
---|
| 264 | `id_fascia` int(2) NOT NULL,
|
---|
| 265 | `abitanti` int(11) NOT NULL,
|
---|
| 266 | `seggi` int(4) NOT NULL,
|
---|
| 267 | `id_conf` int(11) DEFAULT 1
|
---|
[363] | 268 | ) ENGINE=MyISAM DEFAULT CHARSET 'utf8';";
|
---|
[357] | 269 |
|
---|
| 270 |
|
---|
| 271 | $sql2="INSERT INTO `".$prefix."_ele_fasce` (`id_fascia`, `abitanti`, `seggi`, `id_conf`) VALUES
|
---|
| 272 | (1, 3000, 12, 1),
|
---|
| 273 | (2, 10000, 16, 1),
|
---|
| 274 | (3, 15000, 20, 1),
|
---|
| 275 | (4, 30000, 20, 1),
|
---|
| 276 | (5, 100000, 30, 1),
|
---|
| 277 | (6, 250000, 40, 1),
|
---|
| 278 | (7, 500000, 46, 1),
|
---|
| 279 | (8, 1000000, 50, 1),
|
---|
| 280 | (9, 100000000, 60, 1),
|
---|
| 281 | (1, 3000, 12, 2),
|
---|
| 282 | (2, 10000, 16, 2),
|
---|
| 283 | (3, 15000, 20, 2),
|
---|
| 284 | (4, 30000, 20, 2),
|
---|
| 285 | (5, 100000, 30, 2),
|
---|
| 286 | (6, 250000, 40, 2),
|
---|
| 287 | (7, 500000, 46, 2),
|
---|
| 288 | (8, 1000000, 50, 2),
|
---|
| 289 | (9, 100000000, 60, 2),
|
---|
| 290 | (1, 3000, 9, 3),
|
---|
| 291 | (2, 5000, 9, 3),
|
---|
| 292 | (4, 15000, 16, 3),
|
---|
| 293 | (3, 10000, 12, 3),
|
---|
| 294 | (5, 30000, 16, 3),
|
---|
| 295 | (6, 100000, 24, 3),
|
---|
| 296 | (7, 250000, 32, 3),
|
---|
| 297 | (8, 500000, 36, 3),
|
---|
| 298 | (9, 1000000, 40, 3),
|
---|
| 299 | (10, 100000000, 48, 3),
|
---|
| 300 | (1, 3000, 6, 4),
|
---|
| 301 | (2, 5000, 7, 4),
|
---|
| 302 | (3, 10000, 12, 4),
|
---|
| 303 | (4, 15000, 16, 4),
|
---|
| 304 | (5, 30000, 16, 4),
|
---|
| 305 | (6, 100000, 24, 4),
|
---|
| 306 | (7, 250000, 32, 4),
|
---|
| 307 | (8, 500000, 36, 4),
|
---|
| 308 | (9, 1000000, 40, 4),
|
---|
| 309 | (10, 100000000, 48, 4),
|
---|
| 310 | (1, 3000, 9, 5),
|
---|
| 311 | (2, 5000, 9, 5),
|
---|
| 312 | (3, 10000, 12, 5),
|
---|
| 313 | (4, 15000, 16, 5),
|
---|
| 314 | (5, 30000, 16, 5),
|
---|
| 315 | (6, 100000, 24, 5),
|
---|
| 316 | (7, 250000, 32, 5),
|
---|
| 317 | (8, 500000, 36, 5),
|
---|
| 318 | (9, 1000000, 40, 5),
|
---|
| 319 | (10, 100000000, 48, 5),
|
---|
| 320 | (1, 3000, 6, 6),
|
---|
| 321 | (2, 5000, 7, 6),
|
---|
| 322 | (3, 10000, 10, 6),
|
---|
| 323 | (4, 15000, 16, 6),
|
---|
| 324 | (5, 30000, 16, 6),
|
---|
| 325 | (6, 100000, 24, 6),
|
---|
| 326 | (7, 250000, 32, 6),
|
---|
| 327 | (8, 500000, 36, 6),
|
---|
| 328 | (9, 1000000, 40, 6),
|
---|
| 329 | (10, 100000000, 48, 6),
|
---|
| 330 | (1, 3000, 10, 7),
|
---|
| 331 | (2, 10000, 12, 7),
|
---|
| 332 | (3, 15000, 16, 7),
|
---|
| 333 | (4, 30000, 16, 7),
|
---|
| 334 | (5, 100000, 24, 7),
|
---|
| 335 | (6, 250000, 32, 7),
|
---|
| 336 | (7, 500000, 36, 7),
|
---|
| 337 | (8, 1000000, 40, 7),
|
---|
| 338 | (9, 100000000, 48, 7);";
|
---|
[363] | 339 | $ret=aggiorna($sql,$dbi,$sql2,$num);
|
---|
[324] | 340 | #if(!$ret) echo "<br>".$num++.") Fallito: $sql"; else echo "<br>".$num++.") Aggiornato<br>";
|
---|
[296] | 341 |
|
---|
[357] | 342 | $sql="ALTER TABLE `".$prefix."_ele_fasce`
|
---|
| 343 | ADD KEY `id_fascia` (`id_fascia`);";
|
---|
[363] | 344 | $ret=aggiorna($sql,$dbi,'',$num);
|
---|
[357] | 345 | #if(!$ret) echo "<br>".$num++.") Fallito: $sql"; else echo "<br>".$num++.") Aggiornato<br>";
|
---|
| 346 |
|
---|
| 347 |
|
---|
| 348 |
|
---|
| 349 | #if(!$ret)
|
---|
| 350 | # echo "<br>".$num++.") Fallito: $sql";
|
---|
| 351 | #elseif ($ret==1)
|
---|
| 352 | # echo "<br>".$num++.") Index eliminato";
|
---|
| 353 | #else
|
---|
| 354 | # echo "<br>".$num++.") Index aggiunto";
|
---|
[359] | 355 | #$sql="ALTER TABLE `".$prefix."_ele_voti_lista` DROP INDEX if exists `id_cons`";
|
---|
[363] | 356 | echo "<br><br>".++$num.") Ricostruzione e aggioramento indici";
|
---|
[359] | 357 | $tab=$prefix."_ele_voti_ref";
|
---|
| 358 | $ind="id_cons";
|
---|
| 359 | # $sql="ALTER TABLE `".$prefix."_ele_voti_ref` DROP INDEX `id_cons`; ";
|
---|
| 360 | $sql2="ALTER TABLE `".$prefix."_ele_voti_ref` ADD INDEX `id_cons` (`id_cons`, `id_gruppo`) USING BTREE";
|
---|
[363] | 361 | $ret=aggiorna_index($tab, $ind,$dbi,$sql2,$num);
|
---|
[359] | 362 |
|
---|
| 363 | $tab=$prefix."_ele_voti_lista";
|
---|
| 364 | $ind="id_cons";
|
---|
[357] | 365 | $sql2="ALTER TABLE `".$prefix."_ele_voti_lista` ADD INDEX `id_cons` (`id_cons`, `id_sez`, `id_lista`) USING BTREE";
|
---|
[363] | 366 | $ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
|
---|
[357] | 367 |
|
---|
[359] | 368 | $tab=$prefix."_ele_voti_gruppo";
|
---|
| 369 | $ind="id_cons";
|
---|
| 370 | #$sql="ALTER TABLE `".$prefix."_ele_voti_gruppo` DROP INDEX if exists `id_cons`";
|
---|
[357] | 371 | $sql2="ALTER TABLE `".$prefix."_ele_voti_gruppo` ADD INDEX `id_cons` (`id_cons`, `id_sez`, `id_gruppo`) USING BTREE";
|
---|
[363] | 372 | $ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
|
---|
[357] | 373 |
|
---|
[359] | 374 | $tab=$prefix."_ele_voti_candidati";
|
---|
| 375 | $ind="id_cons";
|
---|
| 376 | #$sql="ALTER TABLE `".$prefix."_ele_voti_candidati` DROP INDEX if exists `id_cons`";
|
---|
[357] | 377 | $sql2="ALTER TABLE `".$prefix."_ele_voti_candidati` ADD INDEX `id_cons` (`id_cons`, `id_sez`, `id_cand`) USING BTREE";
|
---|
[363] | 378 | $ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
|
---|
[357] | 379 |
|
---|
[359] | 380 | $tab=$prefix."_ele_lista";
|
---|
| 381 | $ind="id_cons";
|
---|
| 382 | #$sql="ALTER TABLE `".$prefix."_ele_lista` DROP INDEX if exists `id_cons`";
|
---|
[357] | 383 | $sql2="ALTER TABLE `".$prefix."_ele_lista` ADD INDEX `id_cons` (`id_cons`, `id_gruppo`) USING BTREE";
|
---|
[363] | 384 | $ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
|
---|
[357] | 385 |
|
---|
[359] | 386 | $tab=$prefix."_ele_lista";
|
---|
| 387 | $ind="PRIMARY";
|
---|
| 388 | #$sql="ALTER TABLE `".$prefix."_ele_lista` DROP INDEX if exists `PRIMARY`";
|
---|
[357] | 389 | $sql2="ALTER TABLE `".$prefix."_ele_lista` ADD PRIMARY KEY (`id_lista`) USING BTREE";
|
---|
[363] | 390 | $ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
|
---|
[357] | 391 |
|
---|
[359] | 392 | $tab=$prefix."_ele_gruppo";
|
---|
| 393 | $ind="id_cons";
|
---|
| 394 | #$sql="ALTER TABLE `".$prefix."_ele_gruppo` DROP INDEX if exists `id_cons`";
|
---|
[357] | 395 | $sql2="ALTER TABLE `".$prefix."_ele_gruppo` ADD INDEX `id_cons` (`id_cons`, `id_circ`) USING BTREE";
|
---|
[363] | 396 | $ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
|
---|
[357] | 397 |
|
---|
[359] | 398 | $tab=$prefix."_ele_gruppo";
|
---|
| 399 | $ind="PRIMARY";
|
---|
| 400 | #$sql="ALTER TABLE `".$prefix."_ele_gruppo` DROP INDEX if exists `PRIMARY`";
|
---|
[357] | 401 | $sql2="ALTER TABLE `".$prefix."_ele_gruppo` ADD PRIMARY KEY (`id_gruppo`) USING BTREE";
|
---|
[363] | 402 | $ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
|
---|
[357] | 403 |
|
---|
[359] | 404 | $tab=$prefix."_ele_candidati";
|
---|
| 405 | $ind="id_cons";
|
---|
| 406 | #$sql="ALTER TABLE `".$prefix."_ele_candidati` DROP INDEX if exists `id_cons`";
|
---|
[357] | 407 | $sql2="ALTER TABLE `".$prefix."_ele_candidati` ADD INDEX `id_cons` (`id_cons`, `id_lista`) USING BTREE";
|
---|
[363] | 408 | $ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
|
---|
[357] | 409 |
|
---|
[359] | 410 | $tab=$prefix."_ele_candidati";
|
---|
| 411 | $ind="PRIMARY";
|
---|
| 412 | #$sql="ALTER TABLE `".$prefix."_ele_candidati` DROP INDEX if exists `PRIMARY`";
|
---|
[357] | 413 | $sql2="ALTER TABLE `".$prefix."_ele_candidati` ADD PRIMARY KEY (`id_cand`) USING BTREE";
|
---|
[363] | 414 | $ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
|
---|
[357] | 415 |
|
---|
[359] | 416 | $tab=$prefix."_ele_consultazione";
|
---|
| 417 | $ind="descrizione";
|
---|
| 418 | #$sql="ALTER TABLE `".$prefix."_ele_consultazione` DROP INDEX if exists `descrizione`";
|
---|
| 419 | $sql2="ALTER TABLE `".$prefix."_ele_consultazione` ADD UNIQUE `descrizione` (`descrizione`(100))";
|
---|
[363] | 420 | $ret=aggiorna_index($tab,$ind,$dbi,$sql2,$num);
|
---|
[357] | 421 |
|
---|
[363] | 422 | echo "<br><br>".++$num.") Modifica Charset del database";
|
---|
[362] | 423 | if($newcs=='utf8') {
|
---|
| 424 | $cset='utf8';
|
---|
| 425 | $ccollate='utf8_general_ci';
|
---|
| 426 | $preset='latin1';
|
---|
| 427 | }else{
|
---|
| 428 | $cset='latin1';
|
---|
| 429 | $ccollate='latin1_swedish_ci';
|
---|
| 430 | $preset='utf8';
|
---|
| 431 | }
|
---|
| 432 | #$sql="ALTER DATABASE $dbname CHARACTER SET '$cset' COLLATE '$ccollate'";
|
---|
[361] | 433 | #$res = $dbi->prepare("$sql");
|
---|
| 434 | #$res->execute();
|
---|
[362] | 435 |
|
---|
| 436 | $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%')";
|
---|
[361] | 437 | $res = $dbi->prepare("$sql");
|
---|
| 438 | $res->execute();
|
---|
| 439 | $tab='';
|
---|
[363] | 440 | $agg=$res->rowCount();
|
---|
[362] | 441 |
|
---|
[361] | 442 | while(list($nometab,$campo,$def,$tipo,$nul)=$res->fetch(PDO::FETCH_NUM)) {
|
---|
| 443 | if($tab!=$nometab){
|
---|
[362] | 444 | $sql="alter table $nometab DEFAULT CHARSET=$cset COLLATE $ccollate";
|
---|
[361] | 445 | try{
|
---|
| 446 | $res2 = $dbi->prepare("$sql");
|
---|
| 447 | $res2->execute();
|
---|
| 448 | }
|
---|
| 449 | catch(PDOException $e)
|
---|
| 450 | {
|
---|
| 451 | die( $sql . "<br>" . $e->getMessage());
|
---|
| 452 | }
|
---|
[363] | 453 | $tab=$nometab; echo "<br><span style=\"color: green;\">- Tabella: $nometab</span>";
|
---|
[361] | 454 | }
|
---|
| 455 | if($def!='') $default="DEFAULT '$def'"; else $default='';
|
---|
| 456 | if($nul=='NO') $nullable='NOT NULL'; else $nullable='NULL';
|
---|
[362] | 457 | $sql="ALTER TABLE $nometab CHANGE $campo $campo $tipo CHARACTER SET '$cset' COLLATE '$ccollate' $nullable $default;";
|
---|
[361] | 458 | try{
|
---|
[363] | 459 | $res2 = $dbi->prepare("$sql");
|
---|
| 460 | $res2->execute();
|
---|
| 461 | }
|
---|
| 462 | catch(PDOException $e)
|
---|
| 463 | {
|
---|
| 464 | $default="DEFAULT $def";
|
---|
| 465 | $sql="ALTER TABLE $nometab CHANGE $campo $campo $tipo CHARACTER SET '$cset' COLLATE '$ccollate' $nullable $default;";
|
---|
| 466 | try{
|
---|
| 467 | $res2 = $dbi->prepare("$sql");
|
---|
| 468 | $res2->execute();
|
---|
| 469 | }
|
---|
| 470 | catch(PDOException $e)
|
---|
| 471 | {
|
---|
| 472 | die( $sql . "<br>" . $e->getMessage());
|
---|
| 473 | }
|
---|
| 474 | }
|
---|
| 475 | echo "<br><span style=\"color: green;\">-- $campo</span>";
|
---|
[361] | 476 | }
|
---|
[362] | 477 | $sql="SELECT table_name FROM INFORMATION_SCHEMA.tables WHERE TABLE_SCHEMA = '$dbname' and table_collation like '$preset%'";
|
---|
[361] | 478 | $res = $dbi->prepare("$sql");
|
---|
| 479 | $res->execute();
|
---|
| 480 | $tab='';
|
---|
[363] | 481 | if(!$agg) $agg=$res->rowCount();
|
---|
[361] | 482 | while(list($nometab)=$res->fetch(PDO::FETCH_NUM)) {
|
---|
[362] | 483 | $sql="alter table $nometab DEFAULT CHARSET=$cset COLLATE $ccollate";
|
---|
[361] | 484 | try{
|
---|
| 485 | $res2 = $dbi->prepare("$sql");
|
---|
| 486 | $res2->execute();
|
---|
| 487 | }
|
---|
| 488 | catch(PDOException $e)
|
---|
| 489 | {
|
---|
| 490 | die( $sql . "<br>" . $e->getMessage());
|
---|
| 491 | }
|
---|
[363] | 492 | echo "<br><span style=\"color: green;\">- Tabella: $nometab</span>";
|
---|
[361] | 493 | }
|
---|
[363] | 494 | if(!$agg) echo "<br><span style=\"color: green;\">- Nessuna tabella da aggiornare</span>";
|
---|
[361] | 495 | echo "<br><br>";
|
---|
[296] | 496 | ?>
|
---|