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