if (!isset($this->schema[$tbl])) {
- echo "Skip $tbl\n";
+ echo "Skip $tbl = table does not exist in schema\n";
return;
}
return;
}
+ echo "$fkstr \n $tbl";
+
$q = DB_DAtaObject::factory('core_enum');
$q->query("ALTER TABLE $tbl COMMENT = '{$q->escape($fkstr)}'");
// create a list of source/targets from $this->links
+
$revmap = array();
foreach($this->links as $tbl => $map) {
if (!isset($this->schema[$tbl])) {
}
+
+
foreach($revmap as $target_table => $sources) {
// throw example.. UPDATE `Error: invalid_id_test` SET x=1;
+ if (!isset($this->schema[$target_table])) {
+ echo "Skip $target_table = table does not exist in schema\n";
+ continue;
+ }
+
+
+
$q = DB_DataObject::factory('core_enum');
$q->query("
DROP TRIGGER IF EXISTS `{$target_table}_before_delete` ;
$err = substr("Failed Delete {$target_table} refs {$source_table}:{$source_col}", 0, 64);
$trigger .="
SET mid = 0;
- SELECT count(*) into mid FROM {$source_table} WHERE {$source_col} = OLD.{$target_col};
- IF mid > 0 THEN
-
- UPDATE `$err` SET x = 1;
-
+ IF OLD.{$target_col} > 0 THEN
+ SELECT count(*) into mid FROM {$source_table} WHERE {$source_col} = OLD.{$target_col} LIMIT 1;
+ IF mid > 0 THEN
+ UPDATE `$err` SET x = 1;
+ END IF;
END IF;
";
}
//DB_DAtaObject::debugLevel(1);
$q = DB_DataObject::factory('core_enum');
$q->query($trigger);
-
+ echo "CREATED TRIGGER {$target_table}_before_delete\n";
}
$source_tbl = $tbl;
list($target_table , $target_col) = explode(':', $target);
+
+ if (!isset($this->schema[$target_table])) {
+ // skip... target table does not exist
+ continue;
+ }
+
+
$err = substr("Fail: INSERT referenced {$tbl}:{$source_col}", 0, 64);
$trigger .="
SET mid = 0;
if NEW.{$source_col} > 0 THEN
- SELECT {$target_col} into mid FROM {$target_table} WHERE {$target_col} = NEW.{$source_col};
+ SELECT {$target_col} into mid FROM {$target_table} WHERE {$target_col} = NEW.{$source_col} LIMIT 1;
IF mid < 1 THEN
UPDATE `$err` SET x = 1;
END IF;
//DB_DAtaObject::debugLevel(1);
$q = DB_DataObject::factory('core_enum');
$q->query($trigger);
-
+ echo "CREATED TRIGGER {$tbl}_before_insert\n";
$source_tbl = $tbl;
list($target_table , $target_col) = explode(':', $target);
+
+ if (!isset($this->schema[$target_table])) {
+ // skip... target table does not exist
+ continue;
+ }
+
$err = substr("Fail: UPDATE referenced {$tbl}:$source_col", 0, 64);
$trigger .="
SET mid = 0;
if NEW.{$source_col} > 0 THEN
- SELECT {$target_col} into mid FROM {$target_table} WHERE {$target_col} = NEW.{$source_col};
+ SELECT {$target_col} into mid FROM {$target_table} WHERE {$target_col} = NEW.{$source_col} LIMIT 1;
IF mid < 1 THEN
UPDATE `$err` SET x = 1;
END IF;
//DB_DAtaObject::debugLevel(1);
$q = DB_DataObject::factory('core_enum');
$q->query($trigger);
-
+ echo "CREATED TRIGGER {$tbl}_before_update\n";
");
while ($q->fetch()) {
- $cache[$table] = $q->SPECIFIC_NAME;
- }
- if ($table == 'core_notify_recur') {
- print_r($cache[$table]);
+ $cache[$table][] = $q->SPECIFIC_NAME;
}
+
}
// now see which of the procedures match the specification..
$ret = array();