1: <?php
2:
3: namespace Yajra\Oci8\Schema;
4:
5: use Illuminate\Database\Connection;
6:
7: class Trigger
8: {
9: 10: 11:
12: protected $connection;
13:
14: 15: 16:
17: public function __construct(Connection $connection)
18: {
19: $this->connection = $connection;
20: }
21:
22: 23: 24: 25: 26: 27: 28: 29: 30:
31: public function autoIncrement($table, $column, $triggerName, $sequenceName)
32: {
33: if (! $table or ! $column or ! $triggerName or ! $sequenceName) {
34: return false;
35: }
36:
37: return $this->connection->statement("
38: create trigger $triggerName
39: before insert on {$table}
40: for each row
41: begin
42: if :new.{$column} is null then
43: select {$sequenceName}.nextval into :new.{$column} from dual;
44: end if;
45: end;");
46: }
47:
48: 49: 50: 51: 52: 53:
54: public function drop($name)
55: {
56: if (! $name) {
57: return false;
58: }
59:
60: return $this->connection->statement("
61: declare
62: e exception;
63: pragma exception_init(e,-4080);
64: begin
65: execute immediate 'drop trigger {$name}';
66: exception
67: when e then
68: null;
69: end;");
70: }
71: }
72: