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

1  <?php
2 
3  // Adds columns gw, gr, ow, or to each table
4  // Adodb datadictionary is used to add these plus indices
5 
6  // This might take a while:
7  ini_set("max_execution_time","0");
8 
9  $ra=$db->Execute("SELECT real_tablename,table_desc_name,shortname FROM tableoftables");
10  $dict=NewDataDictionary($db);
11  $fields="
12     gr L,
13     gw L,
14     er L,
15     ew L
16  ";
17  $fieldstring="id,label,columnname,sortkey,display_table,display_record, required, type, datatype, associated_table, associated_column, modifiable";
18  while (!($ra->EOF)) {
19     if($ra->fields['table_desc_name']) {
20        $shortname=$ra->fields['shortname'];
21        // add the new columns
22        $sqlArray=$dict->AddColumnSQL($ra->fields['real_tablename'],$fields);
23        $dict->ExecuteSQLArray($sqlArray);
24        // and make indices on them
25        $sqlArray=$dict->CreateIndexSQL($shortname.'_gr_index',$ra->fields['real_tablename'],'gr');
26        $dict->ExecuteSQLArray($sqlArray);
27        $sqlArray=$dict->CreateIndexSQL($shortname.'_gw_index',$ra->fields['real_tablename'],'gw');
28        $dict->ExecuteSQLArray($sqlArray);
29        $sqlArray=$dict->CreateIndexSQL($shortname.'_er_index',$ra->fields['real_tablename'],'er');
30        $dict->ExecuteSQLArray($sqlArray);
31        $sqlArray=$dict->CreateIndexSQL($shortname.'_ew_index',$ra->fields['real_tablename'],'ew');
32        $dict->ExecuteSQLArray($sqlArray);
33 
34        // update description tables
35        $desc=$ra->fields['table_desc_name'];
36        // check that $desc_id (sequence) is in sync with the table, and get it in sync if it was not:
37        $rt=$db->Execute("SELECT max(id) FROM $desc");
38        $max=$rt->fields[0];
39        if ($max) {
40           while ($descid <=$max)
41              $descid=$db->GenId("$desc"."_id");
42        }
43        else
44           $descid=$db->GenId("$desc"."_id");
45        // now let's be sure we did not do this already:
46        unset($rt);
47        $rt=$db->Execute ("SELECT id FROM $desc WHERE columnname='gr'");
48        if (!$rt->fields[0]) {
49           $db->Execute("INSERT INTO $desc ($fieldstring) Values($descid,'group read','gr','111','N','N','N','smallint','int',NULL,NULL,'Y')");
50           $descid=$db->GenId("$desc"."_id");
51           $db->Execute("INSERT INTO $desc ($fieldstring) Values($descid,'group write','gw','112','N','N','N','smallint','int',NULL,NULL,'Y')");
52           $descid=$db->GenId("$desc"."_id");
53           $db->Execute("INSERT INTO $desc ($fieldstring) Values($descid,'everyone read','er','113','N','N','N','smallint','int',NULL,NULL,'Y')");
54           $descid=$db->GenId("$desc"."_id");
55           $db->Execute("INSERT INTO $desc ($fieldstring) Values($descid,'everyone write','ew','114','N','N','N','smallint','int',NULL,NULL,'Y')");
56        }
57     }
58     $ra->MoveNext();
59  }


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