| 1 | <?php |
||
| 7 | class Trigger |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var \Illuminate\Database\Connection |
||
| 11 | */ |
||
| 12 | protected $connection; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @param Connection $connection |
||
| 16 | */ |
||
| 17 | public function __construct(Connection $connection) |
||
| 21 | |||
| 22 | /** |
||
| 23 | * function to create auto increment trigger for a table |
||
| 24 | * |
||
| 25 | * @param string $table |
||
| 26 | * @param string $column |
||
| 27 | * @param string $triggerName |
||
| 28 | * @param string $sequenceName |
||
| 29 | * @return boolean |
||
| 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 | * function to safely drop trigger db object |
||
| 50 | * |
||
| 51 | * @param string $name |
||
| 52 | * @return boolean |
||
| 53 | */ |
||
| 54 | public function drop($name) |
||
| 71 | } |
||
| 72 |