11
11
12
12
namespace CodeIgniter \Database \OCI8 ;
13
13
14
+ use CodeIgniter \Database \Exceptions \DatabaseException ;
14
15
use CodeIgniter \Database \BaseBuilder ;
15
16
16
17
/**
@@ -73,24 +74,24 @@ class Builder extends BaseBuilder
73
74
protected function _insertBatch (string $ table , array $ keys , array $ values ): string
74
75
{
75
76
$ keys = implode (', ' , $ keys );
76
- $ has_primary_key = in_array ('PRIMARY ' , array_column ($ this ->db ->getIndexData ($ table ), 'type ' ), true );
77
+ $ hasPrimaryKey = in_array ('PRIMARY ' , array_column ($ this ->db ->getIndexData ($ table ), 'type ' ), true );
77
78
78
79
// ORA-00001 measures
79
- if ($ has_primary_key ) {
80
+ if ($ hasPrimaryKey ) {
80
81
$ sql = 'INSERT INTO ' . $ table . ' ( ' . $ keys . ") \n SELECT * FROM ( \n" ;
81
- $ select_query_values = [];
82
+ $ selectQueryValues = [];
82
83
83
- for ($ i = 0 , $ c = count ( $ values); $ i < $ c ; $ i ++ ) {
84
- $ select_query_values [] = 'SELECT ' . substr (substr ($ values [ $ i ] , 1 ), 0 , -1 ) . ' FROM DUAL ' ;
84
+ foreach ($ values as $ value ) {
85
+ $ selectQueryValues [] = 'SELECT ' . substr (substr ($ value , 1 ), 0 , -1 ) . ' FROM DUAL ' ;
85
86
}
86
87
87
- return $ sql . implode ("\n UNION ALL \n" , $ select_query_values ) . "\n) " ;
88
+ return $ sql . implode ("\n UNION ALL \n" , $ selectQueryValues ) . "\n) " ;
88
89
}
89
90
90
91
$ sql = "INSERT ALL \n" ;
91
92
92
- for ($ i = 0 , $ c = count ( $ values); $ i < $ c ; $ i ++ ) {
93
- $ sql .= ' INTO ' . $ table . ' ( ' . $ keys . ') VALUES ' . $ values [ $ i ] . "\n" ;
93
+ foreach ($ values as $ value ) {
94
+ $ sql .= ' INTO ' . $ table . ' ( ' . $ keys . ') VALUES ' . $ value . "\n" ;
94
95
}
95
96
96
97
return $ sql . 'SELECT * FROM dual ' ;
@@ -107,18 +108,18 @@ protected function _insertBatch(string $table, array $keys, array $values): stri
107
108
*/
108
109
protected function _replace (string $ table , array $ keys , array $ values ): string
109
110
{
110
- $ field_names = array_map (static function ($ column_name ) {
111
- return trim ($ column_name , '" ' );
111
+ $ fieldNames = array_map (static function ($ columnName ) {
112
+ return trim ($ columnName , '" ' );
112
113
}, $ keys );
113
114
114
- $ unique_indexes = array_filter ($ this ->db ->getIndexData ($ table ), static function ($ index ) use ($ field_names ) {
115
- $ has_all_fields = count (array_intersect ($ index ->fields , $ field_names )) === count ($ index ->fields );
115
+ $ uniqueIndexes = array_filter ($ this ->db ->getIndexData ($ table ), static function ($ index ) use ($ fieldNames ) {
116
+ $ hasAllFields = count (array_intersect ($ index ->fields , $ fieldNames )) === count ($ index ->fields );
116
117
117
- return ($ index ->type === 'PRIMARY ' ) && $ has_all_fields ;
118
+ return ($ index ->type === 'PRIMARY ' ) && $ hasAllFields ;
118
119
});
119
- $ replaceable_fields = array_filter ($ keys , static function ($ column_name ) use ($ unique_indexes ) {
120
- foreach ($ unique_indexes as $ index ) {
121
- if (in_array (trim ($ column_name , '" ' ), $ index ->fields , true )) {
120
+ $ replaceableFields = array_filter ($ keys , static function ($ columnName ) use ($ uniqueIndexes ) {
121
+ foreach ($ uniqueIndexes as $ index ) {
122
+ if (in_array (trim ($ columnName , '" ' ), $ index ->fields , true )) {
122
123
return false ;
123
124
}
124
125
}
@@ -128,31 +129,31 @@ protected function _replace(string $table, array $keys, array $values): string
128
129
129
130
$ sql = 'MERGE INTO ' . $ table . "\n USING (SELECT " ;
130
131
131
- $ sql .= implode (', ' , array_map (static function ($ column_name , $ value ) {
132
- return $ value . ' ' . $ column_name ;
132
+ $ sql .= implode (', ' , array_map (static function ($ columnName , $ value ) {
133
+ return $ value . ' ' . $ columnName ;
133
134
}, $ keys , $ values ));
134
135
135
136
$ sql .= ' FROM DUAL) "_replace" ON ( ' ;
136
137
137
- $ on_list = [];
138
- $ on_list [] = '1 != 1 ' ;
138
+ $ onList = [];
139
+ $ onList [] = '1 != 1 ' ;
139
140
140
- foreach ($ unique_indexes as $ index ) {
141
- $ on_list [] = '( ' . implode (' AND ' , array_map (static function ($ column_name ) use ($ table ) {
142
- return $ table . '." ' . $ column_name . '" = "_replace"." ' . $ column_name . '" ' ;
141
+ foreach ($ uniqueIndexes as $ index ) {
142
+ $ onList [] = '( ' . implode (' AND ' , array_map (static function ($ columnName ) use ($ table ) {
143
+ return $ table . '." ' . $ columnName . '" = "_replace"." ' . $ columnName . '" ' ;
143
144
}, $ index ->fields )) . ') ' ;
144
145
}
145
146
146
- $ sql .= implode (' OR ' , $ on_list ) . ') WHEN MATCHED THEN UPDATE SET ' ;
147
+ $ sql .= implode (' OR ' , $ onList ) . ') WHEN MATCHED THEN UPDATE SET ' ;
147
148
148
- $ sql .= implode (', ' , array_map (static function ($ column_name ) {
149
- return $ column_name . ' = "_replace". ' . $ column_name ;
150
- }, $ replaceable_fields ));
149
+ $ sql .= implode (', ' , array_map (static function ($ columnName ) {
150
+ return $ columnName . ' = "_replace". ' . $ columnName ;
151
+ }, $ replaceableFields ));
151
152
152
- $ sql .= ' WHEN NOT MATCHED THEN INSERT ( ' . implode (', ' , $ replaceable_fields ) . ') VALUES ' ;
153
- $ sql .= ' ( ' . implode (', ' , array_map (static function ($ column_name ) {
154
- return '"_replace". ' . $ column_name ;
155
- }, $ replaceable_fields )) . ') ' ;
153
+ $ sql .= ' WHEN NOT MATCHED THEN INSERT ( ' . implode (', ' , $ replaceableFields ) . ') VALUES ' ;
154
+ $ sql .= ' ( ' . implode (', ' , array_map (static function ($ columnName ) {
155
+ return '"_replace". ' . $ columnName ;
156
+ }, $ replaceableFields )) . ') ' ;
156
157
157
158
return $ sql ;
158
159
}
@@ -180,17 +181,17 @@ protected function _truncate(string $table): string
180
181
* @param mixed $where The where clause
181
182
* @param int $limit The limit clause
182
183
*
183
- * @throws \CodeIgniter\Database\Exceptions\ DatabaseException
184
+ * @throws DatabaseException
184
185
*
185
186
* @return mixed
186
187
*/
187
- public function delete ($ where = '' , ?int $ limit = null , bool $ reset_data = true )
188
+ public function delete ($ where = '' , ?int $ limit = null , bool $ resetData = true )
188
189
{
189
190
if (! empty ($ limit )) {
190
191
$ this ->QBLimit = $ limit ;
191
192
}
192
193
193
- return parent ::delete ($ where , null , $ reset_data );
194
+ return parent ::delete ($ where , null , $ resetData );
194
195
}
195
196
196
197
/**
0 commit comments