|
@@ 80-101 (lines=22) @@
|
| 77 |
|
$this->connection->exec($sql); |
| 78 |
|
} |
| 79 |
|
|
| 80 |
|
public function createInsertTrigger(Table $table) |
| 81 |
|
{ |
| 82 |
|
$triggerName = sprintf('TRG_%s_ONINSERT', $table->getName()); |
| 83 |
|
|
| 84 |
|
$sql = sprintf(' |
| 85 |
|
DROP TRIGGER IF EXISTS %s; |
| 86 |
|
|
| 87 |
|
CREATE TRIGGER %s AFTER INSERT ON `%s` |
| 88 |
|
FOR EACH ROW |
| 89 |
|
BEGIN |
| 90 |
|
IF (NEW.lastActivityTime IS NULL) THEN |
| 91 |
|
INSERT INTO local_insert VALUES (%s, NEW.uid); |
| 92 |
|
DELETE FROM local_delete WHERE table_name = %s AND uid = NEW.uid; |
| 93 |
|
DELETE FROM local_update WHERE table_name = %s AND uid = NEW.uid; |
| 94 |
|
END IF; |
| 95 |
|
END; |
| 96 |
|
|
| 97 |
|
', $triggerName, $triggerName, $table->getName(), $this->connection->quote($table->getName()), $this->connection->quote($table->getName()), $this->connection->quote($table->getName())); |
| 98 |
|
|
| 99 |
|
$this->connection->exec($sql); |
| 100 |
|
} |
| 101 |
|
|
| 102 |
|
public function createDeleteTrigger(Table $table) |
| 103 |
|
{ |
| 104 |
|
$triggerName = sprintf('TRG_%s_ONDELETE', $table->getName()); |
|
@@ 102-121 (lines=20) @@
|
| 99 |
|
$this->connection->exec($sql); |
| 100 |
|
} |
| 101 |
|
|
| 102 |
|
public function createDeleteTrigger(Table $table) |
| 103 |
|
{ |
| 104 |
|
$triggerName = sprintf('TRG_%s_ONDELETE', $table->getName()); |
| 105 |
|
|
| 106 |
|
$sql = sprintf(' |
| 107 |
|
DROP TRIGGER IF EXISTS %s; |
| 108 |
|
|
| 109 |
|
CREATE TRIGGER %s BEFORE DELETE ON `%s` |
| 110 |
|
FOR EACH ROW |
| 111 |
|
BEGIN |
| 112 |
|
IF (OLD.id IS NOT NULL) THEN |
| 113 |
|
INSERT INTO local_delete VALUES (%s, OLD.uid, OLD.id); |
| 114 |
|
END IF; |
| 115 |
|
DELETE FROM local_insert WHERE table_name = %s AND uid = OLD.uid; |
| 116 |
|
DELETE FROM local_update WHERE table_name = %s AND uid = OLD.uid; |
| 117 |
|
END; |
| 118 |
|
|
| 119 |
|
', $triggerName, $triggerName, $table->getName(), $this->connection->quote($table->getName()), $this->connection->quote($table->getName()), $this->connection->quote($table->getName())); |
| 120 |
|
|
| 121 |
|
$this->connection->exec($sql); |
| 122 |
|
} |
| 123 |
|
|
| 124 |
|
public function createUpdateTrigger(Table $table) |