Overview

Namespaces

  • None
  • Yajra
    • Oci8
      • Auth
      • Connectors
      • Eloquent
      • Query
        • Grammars
        • Processors
      • Schema
        • Grammars

Classes

  • Yajra\Oci8\Auth\OracleUserProvider
  • Yajra\Oci8\Connectors\OracleConnector
  • Yajra\Oci8\Eloquent\OracleEloquent
  • Yajra\Oci8\Oci8Connection
  • Yajra\Oci8\Oci8ServiceProvider
  • Yajra\Oci8\Query\Grammars\OracleGrammar
  • Yajra\Oci8\Query\OracleBuilder
  • Yajra\Oci8\Query\Processors\OracleProcessor
  • Yajra\Oci8\Schema\Comment
  • Yajra\Oci8\Schema\Grammars\OracleGrammar
  • Yajra\Oci8\Schema\OracleAutoIncrementHelper
  • Yajra\Oci8\Schema\OracleBlueprint
  • Yajra\Oci8\Schema\OracleBuilder
  • Yajra\Oci8\Schema\Sequence
  • Yajra\Oci8\Schema\Trigger

Traits

  • Yajra\Oci8\OracleReservedWords

Functions

  • config_path
  • Overview
  • Namespace
  • Class
 1: <?php
 2: 
 3: namespace Yajra\Oci8\Schema;
 4: 
 5: use Illuminate\Database\Connection;
 6: use Yajra\Oci8\OracleReservedWords;
 7: 
 8: class Trigger
 9: {
10:     use OracleReservedWords;
11: 
12:     /**
13:      * @var \Illuminate\Database\Connection|\Yajra\Oci8\Oci8Connection
14:      */
15:     protected $connection;
16: 
17:     /**
18:      * @param Connection $connection
19:      */
20:     public function __construct(Connection $connection)
21:     {
22:         $this->connection = $connection;
23:     }
24: 
25:     /**
26:      * Function to create auto increment trigger for a table.
27:      *
28:      * @param  string $table
29:      * @param  string $column
30:      * @param  string $triggerName
31:      * @param  string $sequenceName
32:      * @return boolean
33:      */
34:     public function autoIncrement($table, $column, $triggerName, $sequenceName)
35:     {
36:         if (! $table || ! $column || ! $triggerName || ! $sequenceName) {
37:             return false;
38:         }
39: 
40:         $table  = $this->wrapValue($table);
41:         $column = $this->wrapValue($column);
42: 
43:         return $this->connection->statement("
44:             create trigger $triggerName
45:             before insert on {$table}
46:             for each row
47:                 begin
48:             if :new.{$column} is null then
49:                 select {$sequenceName}.nextval into :new.{$column} from dual;
50:             end if;
51:             end;");
52:     }
53: 
54:     /**
55:      * Wrap value if reserved word.
56:      *
57:      * @param string $value
58:      * @return string
59:      */
60:     protected function wrapValue($value)
61:     {
62:         return $this->isReserved($value) ? '"' . $value . '"' : $value;
63:     }
64: 
65:     /**
66:      * Function to safely drop trigger db object.
67:      *
68:      * @param  string $name
69:      * @return boolean
70:      */
71:     public function drop($name)
72:     {
73:         if (! $name) {
74:             return false;
75:         }
76: 
77:         return $this->connection->statement("declare
78:                 e exception;
79:                 pragma exception_init(e,-4080);
80:             begin
81:                 execute immediate 'drop trigger {$name}';
82:             exception
83:             when e then
84:                 null;
85:             end;");
86:     }
87: }
88: 
API documentation generated by ApiGen