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