1 | <?php |
||
8 | class OracleAutoIncrementHelper |
||
9 | { |
||
10 | /** |
||
11 | * @var \Illuminate\Database\Connection |
||
12 | */ |
||
13 | protected $connection; |
||
14 | |||
15 | /** |
||
16 | * @var \Yajra\Oci8\Schema\Trigger |
||
17 | */ |
||
18 | protected $trigger; |
||
19 | |||
20 | /** |
||
21 | * @var \Yajra\Oci8\Schema\Sequence |
||
22 | */ |
||
23 | protected $sequence; |
||
24 | |||
25 | /** |
||
26 | * @param \Illuminate\Database\Connection $connection |
||
27 | */ |
||
28 | public function __construct(Connection $connection) |
||
34 | |||
35 | /** |
||
36 | * create sequence and trigger for autoIncrement support |
||
37 | * |
||
38 | * @param Blueprint $blueprint |
||
39 | * @param string $table |
||
40 | * @return null |
||
41 | */ |
||
42 | public function createAutoIncrementObjects(Blueprint $blueprint, $table) |
||
65 | |||
66 | /** |
||
67 | * Get qualified autoincrement column. |
||
68 | * |
||
69 | * @param Blueprint $blueprint |
||
70 | * @return \Illuminate\Support\Fluent|null |
||
71 | */ |
||
72 | public function getQualifiedAutoIncrementColumn(Blueprint $blueprint) |
||
86 | |||
87 | /** |
||
88 | * Create an object name that limits to 30 chars. |
||
89 | * |
||
90 | * @param string $prefix |
||
91 | * @param string $table |
||
92 | * @param string $col |
||
93 | * @param string $type |
||
94 | * @return string |
||
95 | */ |
||
96 | private function createObjectName($prefix, $table, $col, $type) |
||
101 | |||
102 | /** |
||
103 | * Drop sequence and triggers if exists, autoincrement objects. |
||
104 | * |
||
105 | * @param string $table |
||
106 | * @return null |
||
107 | */ |
||
108 | public function dropAutoIncrementObjects($table) |
||
125 | |||
126 | /** |
||
127 | * Get table's primary key. |
||
128 | * |
||
129 | * @param string $table |
||
130 | * @return string |
||
131 | */ |
||
132 | public function getPrimaryKey($table) |
||
133 | { |
||
134 | if (! $table) { |
||
135 | return ''; |
||
136 | } |
||
137 | |||
138 | $sql = "SELECT cols.column_name |
||
139 | FROM all_constraints cons, all_cons_columns cols |
||
140 | WHERE upper(cols.table_name) = upper('{$table}') |
||
141 | AND cons.constraint_type = 'P' |
||
142 | AND cons.constraint_name = cols.constraint_name |
||
143 | AND cons.owner = cols.owner |
||
144 | AND cols.position = 1 |
||
145 | AND cons.owner = (select user from dual) |
||
146 | ORDER BY cols.table_name, cols.position"; |
||
147 | $data = $this->connection->selectOne($sql); |
||
148 | |||
149 | if (count($data)) { |
||
150 | return $data->column_name; |
||
151 | } |
||
152 | |||
153 | return ''; |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * Get sequence instance. |
||
158 | * |
||
159 | * @return Sequence |
||
160 | */ |
||
161 | public function getSequence() |
||
165 | |||
166 | /** |
||
167 | * Set sequence instance. |
||
168 | * |
||
169 | * @param Sequence $sequence |
||
170 | */ |
||
171 | public function setSequence($sequence) |
||
175 | |||
176 | /** |
||
177 | * Get trigger instance. |
||
178 | * |
||
179 | * @return Trigger |
||
180 | */ |
||
181 | public function getTrigger() |
||
185 | |||
186 | /** |
||
187 | * Set the trigger instance. |
||
188 | * |
||
189 | * @param Trigger $trigger |
||
190 | */ |
||
191 | public function setTrigger($trigger) |
||
195 | } |
||
196 |