PhpLabWare version 0.3 
/dd/ -> 0_1007_inc.php

1  <?php
2  // updates some table description columns to type int
3 
4  $db->debug=true;
5  $r1007=$db->Execute("SELECT id,table_desc_name FROM tableoftables");
6  while ($r1007 && !$r1007->EOF) {
7     if ($r1007->fields[1]) {
8 
9        // rename old columns and create new ones
10        $db->Execute ("ALTER TABLE {$r1007->fields[1]} RENAME COLUMN associated_table TO at_old");
11        $db->Execute ("ALTER TABLE {$r1007->fields[1]} RENAME COLUMN associated_column TO ac_old");
12        $db->Execute ("ALTER TABLE {$r1007->fields[1]} RENAME COLUMN associated_local_key TO alk_old");
13 
14        $rb1007=$db->Execute("ALTER TABLE {$r1007->fields[1]} ADD COLUMN associated_table int");
15        $rb1007=$db->Execute("ALTER TABLE {$r1007->fields[1]} ADD COLUMN associated_column int");
16        $rb1007=$db->Execute("ALTER TABLE {$r1007->fields[1]} ADD COLUMN associated_local_key int");
17        
18        // copy data from old to new columns
19        $rc1007=$db->Execute("SELECT id,at_old,ac_old,alk_old FROM {$r1007->fields[1]}");
20        $rc1007->MoveFirst();
21        while ($rc1007 && !$rc1007->EOF) {
22           $at=(int)$rc1007->fields[1];
23           if($at)
24              $db->Execute("UPDATE {$r1007->fields[1]} SET associated_table=$at WHERE id={$r1007->fields[0]}");
25           $ac=(int)$rc1007->fields[2];
26           if($ac)
27              $db->Execute("UPDATE {$r1007->fields[1]} SET associated_column=$ac WHERE id={$r1007->fields[0]}");
28           $alt=(int)$rc1007->fields[3];
29           if($alt)
30              $db->Execute("UPDATE {$r1007->fields[1]} SET associated_local_key=$alt WHERE id={$r1007->fields[0]");
31           $rc1007->MoveNext();
32        }
33        
34        // drop the old columns
35        $db->Execute ("ALTER TABLE {$r1007->fields[1]} DROP COLUMN at_old");
36        $db->Execute ("ALTER TABLE {$r1007->fields[1]} DROP COLUMN ac_old");
37        $db->Execute ("ALTER TABLE {$r1007->fields[1]} DROP COLUMN alk_old");
38        
39     }
40     else echo "poep.<br>";
41     $r1007->MoveNext();
42  }
43 
44  $db->debug=false;
45 
46  ?>
47 


Generated: Sun Oct 5 21:17:35 2003 SourceForge Logo Generated by PHPXref 0.2