@@ -121,6 +121,7 @@ |
||
121 | 121 | |
122 | 122 | /** |
123 | 123 | * @param string search condition, the SQL string after the WHERE clause. |
124 | + * @param string|null $value |
|
124 | 125 | */ |
125 | 126 | public function setSearchCondition($value) |
126 | 127 | { |
@@ -54,14 +54,14 @@ discard block |
||
54 | 54 | protected function initializeSort() |
55 | 55 | { |
56 | 56 | $table = $this->getTableInfo(); |
57 | - $sorts = array('Sort By', str_repeat('-',15)); |
|
57 | + $sorts = array('Sort By', str_repeat('-', 15)); |
|
58 | 58 | $headers = array(); |
59 | - foreach($table->getColumns() as $name=>$colum) |
|
59 | + foreach ($table->getColumns() as $name=>$colum) |
|
60 | 60 | { |
61 | 61 | $fname = ucwords(str_replace('_', ' ', $name)); |
62 | - $sorts[$name.' ASC'] = $fname .' Ascending'; |
|
63 | - $sorts[$name.' DESC'] = $fname .' Descending'; |
|
64 | - $headers[] = $fname ; |
|
62 | + $sorts[$name . ' ASC'] = $fname . ' Ascending'; |
|
63 | + $sorts[$name . ' DESC'] = $fname . ' Descending'; |
|
64 | + $headers[] = $fname; |
|
65 | 65 | } |
66 | 66 | $this->_sort->setDataSource($sorts); |
67 | 67 | $this->_sort->dataBind(); |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | public function onPreRender($param) |
76 | 76 | { |
77 | 77 | parent::onPreRender($param); |
78 | - if(!$this->getPage()->getIsPostBack() || $this->getViewState('CurrentClass')!=$this->getRecordClass()) |
|
78 | + if (!$this->getPage()->getIsPostBack() || $this->getViewState('CurrentClass') != $this->getRecordClass()) |
|
79 | 79 | { |
80 | 80 | $this->initializeSort(); |
81 | 81 | $this->setViewState('CurrentClass', $this->getRecordClass()); |
@@ -103,18 +103,18 @@ discard block |
||
103 | 103 | { |
104 | 104 | $total = $this->_list->getVirtualItemCount(); |
105 | 105 | $limit = $this->_list->getPageSize(); |
106 | - $offset = $this->_list->getCurrentPageIndex()*$limit; |
|
107 | - if($offset + $limit > $total) |
|
106 | + $offset = $this->_list->getCurrentPageIndex() * $limit; |
|
107 | + if ($offset + $limit > $total) |
|
108 | 108 | $limit = $total - $offset; |
109 | 109 | $criteria = new TActiveRecordCriteria($this->getSearchCondition(), $this->getSearchParameters()); |
110 | - if($limit > 0) |
|
110 | + if ($limit > 0) |
|
111 | 111 | { |
112 | 112 | $criteria->setLimit($limit); |
113 | - if($offset <= $total) |
|
113 | + if ($offset <= $total) |
|
114 | 114 | $criteria->setOffset($offset); |
115 | 115 | } |
116 | - $order = explode(' ',$this->_sort->getSelectedValue(), 2); |
|
117 | - if(is_array($order) && count($order) === 2) |
|
116 | + $order = explode(' ', $this->_sort->getSelectedValue(), 2); |
|
117 | + if (is_array($order) && count($order) === 2) |
|
118 | 118 | $criteria->OrdersBy[$order[0]] = $order[1]; |
119 | 119 | return $criteria; |
120 | 120 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | */ |
141 | 141 | public function setSearchParameters($value) |
142 | 142 | { |
143 | - $this->setViewState('SearchParameters', TPropertyValue::ensureArray($value),array()); |
|
143 | + $this->setViewState('SearchParameters', TPropertyValue::ensureArray($value), array()); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | */ |
157 | 157 | public function bubbleEvent($sender, $param) |
158 | 158 | { |
159 | - switch(strtolower($param->getCommandName())) |
|
159 | + switch (strtolower($param->getCommandName())) |
|
160 | 160 | { |
161 | 161 | case 'delete': |
162 | 162 | return $this->deleteRecord($sender, $param); |
@@ -172,9 +172,9 @@ discard block |
||
172 | 172 | */ |
173 | 173 | protected function initializeEdit($sender, $param) |
174 | 174 | { |
175 | - if(($ctrl=$this->getEditViewControl())!==null) |
|
175 | + if (($ctrl = $this->getEditViewControl()) !== null) |
|
176 | 176 | { |
177 | - if($param instanceof TRepeaterCommandEventParameter) |
|
177 | + if ($param instanceof TRepeaterCommandEventParameter) |
|
178 | 178 | { |
179 | 179 | $pk = $param->getItem()->getCustomData(); |
180 | 180 | $ctrl->setRecordPk($pk); |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | */ |
189 | 189 | protected function deleteRecord($sender, $param) |
190 | 190 | { |
191 | - if($param instanceof TRepeaterCommandEventParameter) |
|
191 | + if ($param instanceof TRepeaterCommandEventParameter) |
|
192 | 192 | { |
193 | 193 | $pk = $param->getItem()->getCustomData(); |
194 | 194 | $this->getRecordFinder()->deleteByPk($pk); |
@@ -201,10 +201,10 @@ discard block |
||
201 | 201 | protected function listItemCreated($sender, $param) |
202 | 202 | { |
203 | 203 | $item = $param->getItem(); |
204 | - if($item instanceof IItemDataRenderer) |
|
204 | + if ($item instanceof IItemDataRenderer) |
|
205 | 205 | { |
206 | 206 | $type = $item->getItemType(); |
207 | - if($type==TListItemType::Item || $type==TListItemType::AlternatingItem) |
|
207 | + if ($type == TListItemType::Item || $type == TListItemType::AlternatingItem) |
|
208 | 208 | $this->populateField($sender, $param); |
209 | 209 | } |
210 | 210 | } |
@@ -216,10 +216,10 @@ discard block |
||
216 | 216 | protected function populateField($sender, $param) |
217 | 217 | { |
218 | 218 | $item = $param->getItem(); |
219 | - if(($data = $item->getData()) !== null) |
|
219 | + if (($data = $item->getData()) !== null) |
|
220 | 220 | { |
221 | 221 | $item->setCustomData($this->getRecordPkValues($data)); |
222 | - if(($prop = $item->findControl('_properties'))!==null) |
|
222 | + if (($prop = $item->findControl('_properties')) !== null) |
|
223 | 223 | { |
224 | 224 | $item->_properties->setDataSource($this->getRecordPropertyValues($data)); |
225 | 225 | $item->_properties->dataBind(); |
@@ -292,10 +292,10 @@ discard block |
||
292 | 292 | */ |
293 | 293 | protected function getEditViewControl() |
294 | 294 | { |
295 | - if(($id=$this->getEditViewID())!==null) |
|
295 | + if (($id = $this->getEditViewID()) !== null) |
|
296 | 296 | { |
297 | 297 | $ctrl = $this->getParent()->findControl($id); |
298 | - if($ctrl===null) |
|
298 | + if ($ctrl === null) |
|
299 | 299 | throw new TConfigurationException('scaffold_unable_to_find_edit_view', $id); |
300 | 300 | return $ctrl; |
301 | 301 | } |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * Returns records matching the list of given primary keys. |
202 | 202 | * @param TActiveRecord active record instance. |
203 | 203 | * @param array list of primary name value pairs |
204 | - * @return array matching data. |
|
204 | + * @return TDbDataReader matching data. |
|
205 | 205 | */ |
206 | 206 | public function findRecordsByPks(TActiveRecord $record, $keys) |
207 | 207 | { |
@@ -227,7 +227,8 @@ discard block |
||
227 | 227 | * Return record data from sql query. |
228 | 228 | * @param TActiveRecord active record finder instance. |
229 | 229 | * @param TActiveRecordCriteria sql query |
230 | - * @return array result. |
|
230 | + * @param TSqlCriteria $criteria |
|
231 | + * @return TDbDataReader result. |
|
231 | 232 | */ |
232 | 233 | public function findRecordBySql(TActiveRecord $record, $criteria) |
233 | 234 | { |
@@ -238,6 +239,7 @@ discard block |
||
238 | 239 | * Return record data from sql query. |
239 | 240 | * @param TActiveRecord active record finder instance. |
240 | 241 | * @param TActiveRecordCriteria sql query |
242 | + * @param TSqlCriteria $criteria |
|
241 | 243 | * @return TDbDataReader result iterator. |
242 | 244 | */ |
243 | 245 | public function findRecordsBySql(TActiveRecord $record, $criteria) |
@@ -264,7 +266,7 @@ discard block |
||
264 | 266 | /** |
265 | 267 | * Insert a new record. |
266 | 268 | * @param TActiveRecord new record. |
267 | - * @return int number of rows affected. |
|
269 | + * @return string|boolean number of rows affected. |
|
268 | 270 | */ |
269 | 271 | public function insert(TActiveRecord $record) |
270 | 272 | { |
@@ -279,6 +281,7 @@ discard block |
||
279 | 281 | /** |
280 | 282 | * Sets the last insert ID to the corresponding property of the record if available. |
281 | 283 | * @param TActiveRecord record for insertion |
284 | + * @param TActiveRecord $record |
|
282 | 285 | */ |
283 | 286 | protected function updatePostInsert($record) |
284 | 287 | { |
@@ -396,6 +399,7 @@ discard block |
||
396 | 399 | * Delete multiple records by criteria. |
397 | 400 | * @param TActiveRecord active record finder instance. |
398 | 401 | * @param TActiveRecordCriteria search criteria |
402 | + * @param TSqlCriteria $criteria |
|
399 | 403 | * @return int number of records. |
400 | 404 | */ |
401 | 405 | public function deleteRecordsByCriteria(TActiveRecord $record, $criteria) |
@@ -20,19 +20,19 @@ discard block |
||
20 | 20 | class TActiveRecordGateway extends TComponent |
21 | 21 | { |
22 | 22 | private $_manager; |
23 | - private $_tables=array(); //table cache |
|
24 | - private $_meta=array(); //meta data cache. |
|
25 | - private $_commandBuilders=array(); |
|
23 | + private $_tables = array(); //table cache |
|
24 | + private $_meta = array(); //meta data cache. |
|
25 | + private $_commandBuilders = array(); |
|
26 | 26 | private $_currentRecord; |
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Constant name for specifying optional table name in TActiveRecord. |
30 | 30 | */ |
31 | - const TABLE_CONST='TABLE'; |
|
31 | + const TABLE_CONST = 'TABLE'; |
|
32 | 32 | /** |
33 | 33 | * Method name for returning optional table name in in TActiveRecord |
34 | 34 | */ |
35 | - const TABLE_METHOD='table'; |
|
35 | + const TABLE_METHOD = 'table'; |
|
36 | 36 | |
37 | 37 | /** |
38 | 38 | * Record gateway constructor. |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function __construct(TActiveRecordManager $manager) |
42 | 42 | { |
43 | - $this->_manager=$manager; |
|
43 | + $this->_manager = $manager; |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -60,20 +60,20 @@ discard block |
||
60 | 60 | protected function getRecordTableName(TActiveRecord $record) |
61 | 61 | { |
62 | 62 | $class = new ReflectionClass($record); |
63 | - if($class->hasConstant(self::TABLE_CONST)) |
|
63 | + if ($class->hasConstant(self::TABLE_CONST)) |
|
64 | 64 | { |
65 | 65 | $value = $class->getConstant(self::TABLE_CONST); |
66 | - if(empty($value)) |
|
66 | + if (empty($value)) |
|
67 | 67 | throw new TActiveRecordException('ar_invalid_tablename_property', |
68 | - get_class($record),self::TABLE_CONST); |
|
68 | + get_class($record), self::TABLE_CONST); |
|
69 | 69 | return $value; |
70 | 70 | } |
71 | 71 | elseif ($class->hasMethod(self::TABLE_METHOD)) |
72 | 72 | { |
73 | 73 | $value = $record->{self::TABLE_METHOD}(); |
74 | - if(empty($value)) |
|
74 | + if (empty($value)) |
|
75 | 75 | throw new TActiveRecordException('ar_invalid_tablename_method', |
76 | - get_class($record),self::TABLE_METHOD); |
|
76 | + get_class($record), self::TABLE_METHOD); |
|
77 | 77 | return $value; |
78 | 78 | } |
79 | 79 | else |
@@ -100,24 +100,24 @@ discard block |
||
100 | 100 | public function getTableInfo(TDbConnection $connection, $tableName) |
101 | 101 | { |
102 | 102 | $connStr = $connection->getConnectionString(); |
103 | - $key = $connStr.$tableName; |
|
104 | - if(!isset($this->_tables[$key])) |
|
103 | + $key = $connStr . $tableName; |
|
104 | + if (!isset($this->_tables[$key])) |
|
105 | 105 | { |
106 | 106 | //call this first to ensure that unserializing the cache |
107 | 107 | //will find the correct driver dependent classes. |
108 | - if(!isset($this->_meta[$connStr])) |
|
108 | + if (!isset($this->_meta[$connStr])) |
|
109 | 109 | { |
110 | 110 | Prado::using('System.Data.Common.TDbMetaData'); |
111 | 111 | $this->_meta[$connStr] = TDbMetaData::getInstance($connection); |
112 | 112 | } |
113 | 113 | |
114 | 114 | $tableInfo = null; |
115 | - if(($cache=$this->getManager()->getCache())!==null) |
|
115 | + if (($cache = $this->getManager()->getCache()) !== null) |
|
116 | 116 | $tableInfo = $cache->get($key); |
117 | - if(empty($tableInfo)) |
|
117 | + if (empty($tableInfo)) |
|
118 | 118 | { |
119 | 119 | $tableInfo = $this->_meta[$connStr]->getTableInfo($tableName); |
120 | - if($cache!==null) |
|
120 | + if ($cache !== null) |
|
121 | 121 | $cache->set($key, $tableInfo); |
122 | 122 | } |
123 | 123 | $this->_tables[$key] = $tableInfo; |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | $conn = $record->getDbConnection(); |
135 | 135 | $connStr = $conn->getConnectionString(); |
136 | 136 | $tableInfo = $this->getRecordTableInfo($record); |
137 | - if(!isset($this->_commandBuilders[$connStr])) |
|
137 | + if (!isset($this->_commandBuilders[$connStr])) |
|
138 | 138 | { |
139 | 139 | $builder = $tableInfo->createCommandBuilder($record->getDbConnection()); |
140 | 140 | Prado::using('System.Data.DataGateway.TDataGatewayCommand'); |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | |
146 | 146 | } |
147 | 147 | $this->_commandBuilders[$connStr]->getBuilder()->setTableInfo($tableInfo); |
148 | - $this->_currentRecord=$record; |
|
148 | + $this->_currentRecord = $record; |
|
149 | 149 | return $this->_commandBuilders[$connStr]; |
150 | 150 | } |
151 | 151 | |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | public function onCreateCommand($sender, $param) |
163 | 163 | { |
164 | 164 | $this->raiseEvent('OnCreateCommand', $this, $param); |
165 | - if($this->_currentRecord!==null) |
|
165 | + if ($this->_currentRecord !== null) |
|
166 | 166 | $this->_currentRecord->onCreateCommand($param); |
167 | 167 | } |
168 | 168 | |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | public function onExecuteCommand($sender, $param) |
181 | 181 | { |
182 | 182 | $this->raiseEvent('OnExecuteCommand', $this, $param); |
183 | - if($this->_currentRecord!==null) |
|
183 | + if ($this->_currentRecord !== null) |
|
184 | 184 | $this->_currentRecord->onExecuteCommand($param); |
185 | 185 | } |
186 | 186 | |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * @param array primary name value pairs |
192 | 192 | * @return array record data |
193 | 193 | */ |
194 | - public function findRecordByPK(TActiveRecord $record,$keys) |
|
194 | + public function findRecordByPK(TActiveRecord $record, $keys) |
|
195 | 195 | { |
196 | 196 | $command = $this->getCommand($record); |
197 | 197 | return $command->findByPk($keys); |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * @param boolean true to return multiple rows as iterator, false returns first row. |
218 | 218 | * @return mixed matching data. |
219 | 219 | */ |
220 | - public function findRecordsByCriteria(TActiveRecord $record, $criteria, $iterator=false) |
|
220 | + public function findRecordsByCriteria(TActiveRecord $record, $criteria, $iterator = false) |
|
221 | 221 | { |
222 | 222 | $command = $this->getCommand($record); |
223 | 223 | return $iterator ? $command->findAll($criteria) : $command->find($criteria); |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | |
248 | 248 | public function findRecordsByIndex(TActiveRecord $record, $criteria, $fields, $values) |
249 | 249 | { |
250 | - return $this->getCommand($record)->findAllByIndex($criteria,$fields,$values); |
|
250 | + return $this->getCommand($record)->findAllByIndex($criteria, $fields, $values); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | { |
271 | 271 | //$this->updateAssociatedRecords($record,true); |
272 | 272 | $result = $this->getCommand($record)->insert($this->getInsertValues($record)); |
273 | - if($result) |
|
273 | + if ($result) |
|
274 | 274 | $this->updatePostInsert($record); |
275 | 275 | //$this->updateAssociatedRecords($record); |
276 | 276 | return $result; |
@@ -284,10 +284,10 @@ discard block |
||
284 | 284 | { |
285 | 285 | $command = $this->getCommand($record); |
286 | 286 | $tableInfo = $command->getTableInfo(); |
287 | - foreach($tableInfo->getColumns() as $name => $column) |
|
287 | + foreach ($tableInfo->getColumns() as $name => $column) |
|
288 | 288 | { |
289 | - if($column->hasSequence()) |
|
290 | - $record->setColumnValue($name,$command->getLastInsertID($column->getSequenceName())); |
|
289 | + if ($column->hasSequence()) |
|
290 | + $record->setColumnValue($name, $command->getLastInsertID($column->getSequenceName())); |
|
291 | 291 | } |
292 | 292 | } |
293 | 293 | |
@@ -297,20 +297,20 @@ discard block |
||
297 | 297 | */ |
298 | 298 | protected function getInsertValues(TActiveRecord $record) |
299 | 299 | { |
300 | - $values=array(); |
|
300 | + $values = array(); |
|
301 | 301 | $tableInfo = $this->getCommand($record)->getTableInfo(); |
302 | - foreach($tableInfo->getColumns() as $name=>$column) |
|
302 | + foreach ($tableInfo->getColumns() as $name=>$column) |
|
303 | 303 | { |
304 | - if($column->getIsExcluded()) |
|
304 | + if ($column->getIsExcluded()) |
|
305 | 305 | continue; |
306 | 306 | $value = $record->getColumnValue($name); |
307 | - if(!$column->getAllowNull() && $value===null && !$column->hasSequence() && ($column->getDefaultValue() === TDbTableColumn::UNDEFINED_VALUE)) |
|
307 | + if (!$column->getAllowNull() && $value === null && !$column->hasSequence() && ($column->getDefaultValue() === TDbTableColumn::UNDEFINED_VALUE)) |
|
308 | 308 | { |
309 | 309 | throw new TActiveRecordException( |
310 | 310 | 'ar_value_must_not_be_null', get_class($record), |
311 | 311 | $tableInfo->getTableFullName(), $name); |
312 | 312 | } |
313 | - if($value!==null) |
|
313 | + if ($value !== null) |
|
314 | 314 | $values[$name] = $value; |
315 | 315 | } |
316 | 316 | return $values; |
@@ -332,29 +332,29 @@ discard block |
||
332 | 332 | |
333 | 333 | protected function getUpdateValues(TActiveRecord $record) |
334 | 334 | { |
335 | - $values=array(); |
|
335 | + $values = array(); |
|
336 | 336 | $tableInfo = $this->getCommand($record)->getTableInfo(); |
337 | - $primary=array(); |
|
338 | - foreach($tableInfo->getColumns() as $name=>$column) |
|
337 | + $primary = array(); |
|
338 | + foreach ($tableInfo->getColumns() as $name=>$column) |
|
339 | 339 | { |
340 | - if($column->getIsExcluded()) |
|
340 | + if ($column->getIsExcluded()) |
|
341 | 341 | continue; |
342 | 342 | $value = $record->getColumnValue($name); |
343 | - if(!$column->getAllowNull() && $value===null && ($column->getDefaultValue() === TDbTableColumn::UNDEFINED_VALUE)) |
|
343 | + if (!$column->getAllowNull() && $value === null && ($column->getDefaultValue() === TDbTableColumn::UNDEFINED_VALUE)) |
|
344 | 344 | { |
345 | 345 | throw new TActiveRecordException( |
346 | 346 | 'ar_value_must_not_be_null', get_class($record), |
347 | 347 | $tableInfo->getTableFullName(), $name); |
348 | 348 | } |
349 | - if($column->getIsPrimaryKey()) |
|
349 | + if ($column->getIsPrimaryKey()) |
|
350 | 350 | $primary[$name] = $value; |
351 | 351 | else |
352 | 352 | $values[$name] = $value; |
353 | 353 | } |
354 | - return array($values,$primary); |
|
354 | + return array($values, $primary); |
|
355 | 355 | } |
356 | 356 | |
357 | - protected function updateAssociatedRecords(TActiveRecord $record,$updateBelongsTo=false) |
|
357 | + protected function updateAssociatedRecords(TActiveRecord $record, $updateBelongsTo = false) |
|
358 | 358 | { |
359 | 359 | $context = new TActiveRecordRelationContext($record); |
360 | 360 | return $context->updateAssociatedRecords($updateBelongsTo); |
@@ -373,10 +373,10 @@ discard block |
||
373 | 373 | protected function getPrimaryKeyValues(TActiveRecord $record) |
374 | 374 | { |
375 | 375 | $tableInfo = $this->getCommand($record)->getTableInfo(); |
376 | - $primary=array(); |
|
377 | - foreach($tableInfo->getColumns() as $name=>$column) |
|
376 | + $primary = array(); |
|
377 | + foreach ($tableInfo->getColumns() as $name=>$column) |
|
378 | 378 | { |
379 | - if($column->getIsPrimaryKey()) |
|
379 | + if ($column->getIsPrimaryKey()) |
|
380 | 380 | $primary[$name] = $record->getColumnValue($name); |
381 | 381 | } |
382 | 382 | return $primary; |
@@ -410,11 +410,11 @@ discard block |
||
410 | 410 | * @param TActiveRecord active record |
411 | 411 | * @param TActiveRecordCriteria data for the command. |
412 | 412 | */ |
413 | - protected function raiseCommandEvent($event,$command,$record,$criteria) |
|
413 | + protected function raiseCommandEvent($event, $command, $record, $criteria) |
|
414 | 414 | { |
415 | - if(!($criteria instanceof TSqlCriteria)) |
|
416 | - $criteria = new TActiveRecordCriteria(null,$criteria); |
|
417 | - $param = new TActiveRecordEventParameter($command,$record,$criteria); |
|
415 | + if (!($criteria instanceof TSqlCriteria)) |
|
416 | + $criteria = new TActiveRecordCriteria(null, $criteria); |
|
417 | + $param = new TActiveRecordEventParameter($command, $record, $criteria); |
|
418 | 418 | $manager = $record->getRecordManager(); |
419 | 419 | $manager->{$event}($param); |
420 | 420 | $record->{$event}($param); |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * TActiveRecordGateway, TActiveRecordStatementType, TActiveRecordEventParameter classes file. |
|
4 | - * |
|
5 | - * @author Wei Zhuo <weizhuo[at]gmail[dot]com> |
|
6 | - * @link https://github.com/pradosoft/prado |
|
7 | - * @copyright Copyright © 2005-2015 The PRADO Group |
|
8 | - * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
9 | - * @package System.Data.ActiveRecord |
|
10 | - */ |
|
3 | + * TActiveRecordGateway, TActiveRecordStatementType, TActiveRecordEventParameter classes file. |
|
4 | + * |
|
5 | + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> |
|
6 | + * @link https://github.com/pradosoft/prado |
|
7 | + * @copyright Copyright © 2005-2015 The PRADO Group |
|
8 | + * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
9 | + * @package System.Data.ActiveRecord |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * TActiveRecordGateway excutes the SQL command queries and returns the data |
@@ -67,16 +67,14 @@ |
||
67 | 67 | throw new TActiveRecordException('ar_invalid_tablename_property', |
68 | 68 | get_class($record),self::TABLE_CONST); |
69 | 69 | return $value; |
70 | - } |
|
71 | - elseif ($class->hasMethod(self::TABLE_METHOD)) |
|
70 | + } elseif ($class->hasMethod(self::TABLE_METHOD)) |
|
72 | 71 | { |
73 | 72 | $value = $record->{self::TABLE_METHOD}(); |
74 | 73 | if(empty($value)) |
75 | 74 | throw new TActiveRecordException('ar_invalid_tablename_method', |
76 | 75 | get_class($record),self::TABLE_METHOD); |
77 | 76 | return $value; |
78 | - } |
|
79 | - else |
|
77 | + } else |
|
80 | 78 | return strtolower(get_class($record)); |
81 | 79 | } |
82 | 80 |
@@ -123,6 +123,7 @@ |
||
123 | 123 | /** |
124 | 124 | * @param TMssqlTableInfo table information. |
125 | 125 | * @param array column information. |
126 | + * @param TMssqlTableInfo $tableInfo |
|
126 | 127 | */ |
127 | 128 | protected function processColumn($tableInfo, $col) |
128 | 129 | { |
@@ -259,15 +259,15 @@ |
||
259 | 259 | return false; |
260 | 260 | } |
261 | 261 | |
262 | - /** |
|
263 | - * Returns all table names in the database. |
|
264 | - * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema. |
|
265 | - * If not empty, the returned table names will be prefixed with the schema name. |
|
266 | - * @return array all table names in the database. |
|
267 | - */ |
|
262 | + /** |
|
263 | + * Returns all table names in the database. |
|
264 | + * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema. |
|
265 | + * If not empty, the returned table names will be prefixed with the schema name. |
|
266 | + * @return array all table names in the database. |
|
267 | + */ |
|
268 | 268 | public function findTableNames($schema='dbo') |
269 | 269 | { |
270 | - $condition="TABLE_TYPE='BASE TABLE'"; |
|
270 | + $condition="TABLE_TYPE='BASE TABLE'"; |
|
271 | 271 | $sql=<<<EOD |
272 | 272 | SELECT TABLE_NAME, TABLE_SCHEMA FROM [INFORMATION_SCHEMA].[TABLES] |
273 | 273 | WHERE TABLE_SCHEMA=:schema AND $condition |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | protected function createTableInfo($table) |
71 | 71 | { |
72 | - list($catalogName,$schemaName,$tableName) = $this->getCatalogSchemaTableName($table); |
|
72 | + list($catalogName, $schemaName, $tableName) = $this->getCatalogSchemaTableName($table); |
|
73 | 73 | $this->getDbConnection()->setActive(true); |
74 | 74 | $sql = <<<EOD |
75 | 75 | SELECT t.*, |
@@ -80,26 +80,26 @@ discard block |
||
80 | 80 | WHERE t.table_name = c.table_name |
81 | 81 | AND t.table_name = :table |
82 | 82 | EOD; |
83 | - if($schemaName!==null) |
|
83 | + if ($schemaName !== null) |
|
84 | 84 | $sql .= ' AND t.table_schema = :schema'; |
85 | - if($catalogName!==null) |
|
85 | + if ($catalogName !== null) |
|
86 | 86 | $sql .= ' AND t.table_catalog = :catalog'; |
87 | 87 | |
88 | 88 | $command = $this->getDbConnection()->createCommand($sql); |
89 | 89 | $command->bindValue(':table', $tableName); |
90 | - if($schemaName!==null) |
|
90 | + if ($schemaName !== null) |
|
91 | 91 | $command->bindValue(':schema', $schemaName); |
92 | - if($catalogName!==null) |
|
92 | + if ($catalogName !== null) |
|
93 | 93 | $command->bindValue(':catalog', $catalogName); |
94 | 94 | |
95 | - $tableInfo=null; |
|
96 | - foreach($command->query() as $col) |
|
95 | + $tableInfo = null; |
|
96 | + foreach ($command->query() as $col) |
|
97 | 97 | { |
98 | - if($tableInfo===null) |
|
98 | + if ($tableInfo === null) |
|
99 | 99 | $tableInfo = $this->createNewTableInfo($col); |
100 | - $this->processColumn($tableInfo,$col); |
|
100 | + $this->processColumn($tableInfo, $col); |
|
101 | 101 | } |
102 | - if($tableInfo===null) |
|
102 | + if ($tableInfo === null) |
|
103 | 103 | throw new TDbException('dbmetadata_invalid_table_view', $table); |
104 | 104 | return $tableInfo; |
105 | 105 | } |
@@ -112,12 +112,12 @@ discard block |
||
112 | 112 | { |
113 | 113 | //remove possible delimiters |
114 | 114 | $result = explode('.', preg_replace('/\[|\]|"/', '', $table)); |
115 | - if(count($result)===1) |
|
116 | - return array(null,null,$result[0]); |
|
117 | - if(count($result)===2) |
|
118 | - return array(null,$result[0],$result[1]); |
|
119 | - if(count($result)>2) |
|
120 | - return array($result[0],$result[1],$result[2]); |
|
115 | + if (count($result) === 1) |
|
116 | + return array(null, null, $result[0]); |
|
117 | + if (count($result) === 2) |
|
118 | + return array(null, $result[0], $result[1]); |
|
119 | + if (count($result) > 2) |
|
120 | + return array($result[0], $result[1], $result[2]); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -130,25 +130,25 @@ discard block |
||
130 | 130 | |
131 | 131 | $info['ColumnName'] = "[$columnId]"; //quote the column names! |
132 | 132 | $info['ColumnId'] = $columnId; |
133 | - $info['ColumnIndex'] = intval($col['ORDINAL_POSITION'])-1; //zero-based index |
|
134 | - if($col['IS_NULLABLE']!=='NO') |
|
133 | + $info['ColumnIndex'] = intval($col['ORDINAL_POSITION']) - 1; //zero-based index |
|
134 | + if ($col['IS_NULLABLE'] !== 'NO') |
|
135 | 135 | $info['AllowNull'] = true; |
136 | - if($col['COLUMN_DEFAULT']!==null) |
|
136 | + if ($col['COLUMN_DEFAULT'] !== null) |
|
137 | 137 | $info['DefaultValue'] = $col['COLUMN_DEFAULT']; |
138 | 138 | |
139 | - if(in_array($columnId, $tableInfo->getPrimaryKeys())) |
|
139 | + if (in_array($columnId, $tableInfo->getPrimaryKeys())) |
|
140 | 140 | $info['IsPrimaryKey'] = true; |
141 | - if($this->isForeignKeyColumn($columnId, $tableInfo)) |
|
141 | + if ($this->isForeignKeyColumn($columnId, $tableInfo)) |
|
142 | 142 | $info['IsForeignKey'] = true; |
143 | 143 | |
144 | - if($col['IsIdentity']==='1') |
|
144 | + if ($col['IsIdentity'] === '1') |
|
145 | 145 | $info['AutoIncrement'] = true; |
146 | 146 | $info['DbType'] = $col['DATA_TYPE']; |
147 | - if($col['CHARACTER_MAXIMUM_LENGTH']!==null) |
|
147 | + if ($col['CHARACTER_MAXIMUM_LENGTH'] !== null) |
|
148 | 148 | $info['ColumnSize'] = intval($col['CHARACTER_MAXIMUM_LENGTH']); |
149 | - if($col['NUMERIC_PRECISION'] !== null) |
|
149 | + if ($col['NUMERIC_PRECISION'] !== null) |
|
150 | 150 | $info['NumericPrecision'] = intval($col['NUMERIC_PRECISION']); |
151 | - if($col['NUMERIC_SCALE']!==null) |
|
151 | + if ($col['NUMERIC_SCALE'] !== null) |
|
152 | 152 | $info['NumericScale'] = intval($col['NUMERIC_SCALE']); |
153 | 153 | $tableInfo->Columns[$columnId] = new TMssqlTableColumn($info); |
154 | 154 | } |
@@ -163,11 +163,11 @@ discard block |
||
163 | 163 | $info['CatalogName'] = $col['TABLE_CATALOG']; |
164 | 164 | $info['SchemaName'] = $col['TABLE_SCHEMA']; |
165 | 165 | $info['TableName'] = $col['TABLE_NAME']; |
166 | - if($col['TABLE_TYPE']==='VIEW') |
|
166 | + if ($col['TABLE_TYPE'] === 'VIEW') |
|
167 | 167 | $info['IsView'] = true; |
168 | 168 | list($primary, $foreign) = $this->getConstraintKeys($col); |
169 | 169 | $class = $this->getTableInfoClass(); |
170 | - return new $class($info,$primary,$foreign); |
|
170 | + return new $class($info, $primary, $foreign); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
@@ -192,10 +192,10 @@ discard block |
||
192 | 192 | $command = $this->getDbConnection()->createCommand($sql); |
193 | 193 | $command->bindValue(':table', $col['TABLE_NAME']); |
194 | 194 | $primary = array(); |
195 | - foreach($command->query()->readAll() as $field) |
|
195 | + foreach ($command->query()->readAll() as $field) |
|
196 | 196 | $primary[] = $field['field_name']; |
197 | 197 | $foreign = $this->getForeignConstraints($col); |
198 | - return array($primary,$foreign); |
|
198 | + return array($primary, $foreign); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
@@ -234,9 +234,9 @@ discard block |
||
234 | 234 | EOD; |
235 | 235 | $command = $this->getDbConnection()->createCommand($sql); |
236 | 236 | $command->bindValue(':table', $col['TABLE_NAME']); |
237 | - $fkeys=array(); |
|
237 | + $fkeys = array(); |
|
238 | 238 | $catalogSchema = "[{$col['TABLE_CATALOG']}].[{$col['TABLE_SCHEMA']}]"; |
239 | - foreach($command->query() as $info) |
|
239 | + foreach ($command->query() as $info) |
|
240 | 240 | { |
241 | 241 | $fkeys[$info['FK_CONSTRAINT_NAME']]['keys'][$info['FK_COLUMN_NAME']] = $info['UQ_COLUMN_NAME']; |
242 | 242 | $fkeys[$info['FK_CONSTRAINT_NAME']]['table'] = $info['UQ_TABLE_NAME']; |
@@ -251,9 +251,9 @@ discard block |
||
251 | 251 | */ |
252 | 252 | protected function isForeignKeyColumn($columnId, $tableInfo) |
253 | 253 | { |
254 | - foreach($tableInfo->getForeignKeys() as $fk) |
|
254 | + foreach ($tableInfo->getForeignKeys() as $fk) |
|
255 | 255 | { |
256 | - if(in_array($columnId, array_keys($fk['keys']))) |
|
256 | + if (in_array($columnId, array_keys($fk['keys']))) |
|
257 | 257 | return true; |
258 | 258 | } |
259 | 259 | return false; |
@@ -265,23 +265,23 @@ discard block |
||
265 | 265 | * If not empty, the returned table names will be prefixed with the schema name. |
266 | 266 | * @return array all table names in the database. |
267 | 267 | */ |
268 | - public function findTableNames($schema='dbo') |
|
268 | + public function findTableNames($schema = 'dbo') |
|
269 | 269 | { |
270 | - $condition="TABLE_TYPE='BASE TABLE'"; |
|
271 | - $sql=<<<EOD |
|
270 | + $condition = "TABLE_TYPE='BASE TABLE'"; |
|
271 | + $sql = <<<EOD |
|
272 | 272 | SELECT TABLE_NAME, TABLE_SCHEMA FROM [INFORMATION_SCHEMA].[TABLES] |
273 | 273 | WHERE TABLE_SCHEMA=:schema AND $condition |
274 | 274 | EOD; |
275 | - $command=$this->getDbConnection()->createCommand($sql); |
|
275 | + $command = $this->getDbConnection()->createCommand($sql); |
|
276 | 276 | $command->bindParam(":schema", $schema); |
277 | - $rows=$command->queryAll(); |
|
278 | - $names=array(); |
|
277 | + $rows = $command->queryAll(); |
|
278 | + $names = array(); |
|
279 | 279 | foreach ($rows as $row) |
280 | 280 | { |
281 | 281 | if ($schema == self::DEFAULT_SCHEMA) |
282 | - $names[]=$row['TABLE_NAME']; |
|
282 | + $names[] = $row['TABLE_NAME']; |
|
283 | 283 | else |
284 | - $names[]=$schema.'.'.$row['TABLE_SCHEMA'].'.'.$row['TABLE_NAME']; |
|
284 | + $names[] = $schema . '.' . $row['TABLE_SCHEMA'] . '.' . $row['TABLE_NAME']; |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | return $names; |
@@ -192,8 +192,9 @@ |
||
192 | 192 | $command = $this->getDbConnection()->createCommand($sql); |
193 | 193 | $command->bindValue(':table', $col['TABLE_NAME']); |
194 | 194 | $primary = array(); |
195 | - foreach($command->query()->readAll() as $field) |
|
196 | - $primary[] = $field['field_name']; |
|
195 | + foreach($command->query()->readAll() as $field) { |
|
196 | + $primary[] = $field['field_name']; |
|
197 | + } |
|
197 | 198 | $foreign = $this->getForeignConstraints($col); |
198 | 199 | return array($primary,$foreign); |
199 | 200 | } |
@@ -27,7 +27,7 @@ |
||
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Overrides parent implementation, returns PHP type from the db type. |
30 | - * @return boolean derived PHP primitive type from the column db type. |
|
30 | + * @return string derived PHP primitive type from the column db type. |
|
31 | 31 | */ |
32 | 32 | public function getPHPType() |
33 | 33 | { |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function getAutoIncrement() |
42 | 42 | { |
43 | - return $this->getInfo('AutoIncrement',false); |
|
43 | + return $this->getInfo('AutoIncrement', false); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function getIsExcluded() |
58 | 58 | { |
59 | - return strtolower($this->getDbType())==='timestamp'; |
|
59 | + return strtolower($this->getDbType()) === 'timestamp'; |
|
60 | 60 | } |
61 | 61 | } |
62 | 62 |
@@ -114,6 +114,7 @@ |
||
114 | 114 | /** |
115 | 115 | * @param TMysqlTableInfo table information. |
116 | 116 | * @param array column information. |
117 | + * @param TMysqlTableInfo $tableInfo |
|
117 | 118 | */ |
118 | 119 | protected function processColumn($tableInfo, $col) |
119 | 120 | { |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | */ |
28 | 28 | class TMysqlMetaData extends TDbMetaData |
29 | 29 | { |
30 | - private $_serverVersion=0; |
|
30 | + private $_serverVersion = 0; |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * @return string TDbTableInfo class name. |
@@ -74,24 +74,24 @@ discard block |
||
74 | 74 | */ |
75 | 75 | protected function createTableInfo($table) |
76 | 76 | { |
77 | - list($schemaName,$tableName) = $this->getSchemaTableName($table); |
|
78 | - $find = $schemaName===null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`"; |
|
77 | + list($schemaName, $tableName) = $this->getSchemaTableName($table); |
|
78 | + $find = $schemaName === null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`"; |
|
79 | 79 | $colCase = $this->getDbConnection()->getColumnCase(); |
80 | - if($colCase != TDbColumnCaseMode::Preserved) |
|
80 | + if ($colCase != TDbColumnCaseMode::Preserved) |
|
81 | 81 | $this->getDbConnection()->setColumnCase('Preserved'); |
82 | 82 | $this->getDbConnection()->setActive(true); |
83 | 83 | $sql = "SHOW FULL FIELDS FROM {$find}"; |
84 | 84 | $command = $this->getDbConnection()->createCommand($sql); |
85 | 85 | $tableInfo = $this->createNewTableInfo($table); |
86 | - $index=0; |
|
87 | - foreach($command->query() as $col) |
|
86 | + $index = 0; |
|
87 | + foreach ($command->query() as $col) |
|
88 | 88 | { |
89 | 89 | $col['index'] = $index++; |
90 | - $this->processColumn($tableInfo,$col); |
|
90 | + $this->processColumn($tableInfo, $col); |
|
91 | 91 | } |
92 | - if($index===0) |
|
92 | + if ($index === 0) |
|
93 | 93 | throw new TDbException('dbmetadata_invalid_table_view', $table); |
94 | - if($colCase != TDbColumnCaseMode::Preserved) |
|
94 | + if ($colCase != TDbColumnCaseMode::Preserved) |
|
95 | 95 | $this->getDbConnection()->setColumnCase($colCase); |
96 | 96 | return $tableInfo; |
97 | 97 | } |
@@ -101,12 +101,12 @@ discard block |
||
101 | 101 | */ |
102 | 102 | protected function getServerVersion() |
103 | 103 | { |
104 | - if(!$this->_serverVersion) |
|
104 | + if (!$this->_serverVersion) |
|
105 | 105 | { |
106 | 106 | $version = $this->getDbConnection()->getAttribute(PDO::ATTR_SERVER_VERSION); |
107 | - $digits=array(); |
|
107 | + $digits = array(); |
|
108 | 108 | preg_match('/(\d+)\.(\d+)\.(\d+)/', $version, $digits); |
109 | - $this->_serverVersion=floatval($digits[1].'.'.$digits[2].$digits[3]); |
|
109 | + $this->_serverVersion = floatval($digits[1] . '.' . $digits[2] . $digits[3]); |
|
110 | 110 | } |
111 | 111 | return $this->_serverVersion; |
112 | 112 | } |
@@ -122,37 +122,37 @@ discard block |
||
122 | 122 | $info['ColumnName'] = "`$columnId`"; //quote the column names! |
123 | 123 | $info['ColumnId'] = $columnId; |
124 | 124 | $info['ColumnIndex'] = $col['index']; |
125 | - if($col['Null']==='YES') |
|
125 | + if ($col['Null'] === 'YES') |
|
126 | 126 | $info['AllowNull'] = true; |
127 | - if(is_int(strpos(strtolower($col['Extra']), 'auto_increment'))) |
|
128 | - $info['AutoIncrement']=true; |
|
129 | - if($col['Default']!=="") |
|
127 | + if (is_int(strpos(strtolower($col['Extra']), 'auto_increment'))) |
|
128 | + $info['AutoIncrement'] = true; |
|
129 | + if ($col['Default'] !== "") |
|
130 | 130 | $info['DefaultValue'] = $col['Default']; |
131 | 131 | |
132 | - if($col['Key']==='PRI' || in_array($columnId, $tableInfo->getPrimaryKeys())) |
|
132 | + if ($col['Key'] === 'PRI' || in_array($columnId, $tableInfo->getPrimaryKeys())) |
|
133 | 133 | $info['IsPrimaryKey'] = true; |
134 | - if($this->isForeignKeyColumn($columnId, $tableInfo)) |
|
134 | + if ($this->isForeignKeyColumn($columnId, $tableInfo)) |
|
135 | 135 | $info['IsForeignKey'] = true; |
136 | 136 | |
137 | 137 | $info['DbType'] = $col['Type']; |
138 | - $match=array(); |
|
138 | + $match = array(); |
|
139 | 139 | //find SET/ENUM values, column size, precision, and scale |
140 | - if(preg_match('/\((.*)\)/', $col['Type'], $match)) |
|
140 | + if (preg_match('/\((.*)\)/', $col['Type'], $match)) |
|
141 | 141 | { |
142 | - $info['DbType']= preg_replace('/\(.*\)/', '', $col['Type']); |
|
142 | + $info['DbType'] = preg_replace('/\(.*\)/', '', $col['Type']); |
|
143 | 143 | |
144 | 144 | //find SET/ENUM values |
145 | - if($this->isEnumSetType($info['DbType'])) |
|
145 | + if ($this->isEnumSetType($info['DbType'])) |
|
146 | 146 | $info['DbTypeValues'] = preg_split("/[',]/S", $match[1], -1, PREG_SPLIT_NO_EMPTY); |
147 | 147 | |
148 | 148 | //find column size, precision and scale |
149 | 149 | $pscale = array(); |
150 | - if(preg_match('/(\d+)(?:,(\d+))?+/', $match[1], $pscale)) |
|
150 | + if (preg_match('/(\d+)(?:,(\d+))?+/', $match[1], $pscale)) |
|
151 | 151 | { |
152 | - if($this->isPrecisionType($info['DbType'])) |
|
152 | + if ($this->isPrecisionType($info['DbType'])) |
|
153 | 153 | { |
154 | 154 | $info['NumericPrecision'] = intval($pscale[1]); |
155 | - if(count($pscale) > 2) |
|
155 | + if (count($pscale) > 2) |
|
156 | 156 | $info['NumericScale'] = intval($pscale[2]); |
157 | 157 | } |
158 | 158 | else |
@@ -169,9 +169,9 @@ discard block |
||
169 | 169 | protected function isPrecisionType($type) |
170 | 170 | { |
171 | 171 | $type = strtolower(trim($type)); |
172 | - return $type==='decimal' || $type==='dec' |
|
173 | - || $type==='float' || $type==='double' |
|
174 | - || $type==='double precision' || $type==='real'; |
|
172 | + return $type === 'decimal' || $type === 'dec' |
|
173 | + || $type === 'float' || $type === 'double' |
|
174 | + || $type === 'double precision' || $type === 'real'; |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | protected function isEnumSetType($type) |
181 | 181 | { |
182 | 182 | $type = strtolower(trim($type)); |
183 | - return $type==='set' || $type==='enum'; |
|
183 | + return $type === 'set' || $type === 'enum'; |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -192,9 +192,9 @@ discard block |
||
192 | 192 | { |
193 | 193 | //remove the back ticks and separate out the "database.table" |
194 | 194 | $result = explode('.', str_replace('`', '', $table)); |
195 | - foreach($result as $name) |
|
195 | + foreach ($result as $name) |
|
196 | 196 | { |
197 | - if(!$this->isValidIdentifier($name)) |
|
197 | + if (!$this->isValidIdentifier($name)) |
|
198 | 198 | { |
199 | 199 | $ref = 'http://dev.mysql.com/doc/refman/5.0/en/identifiers.html'; |
200 | 200 | throw new TDbException('dbcommon_invalid_identifier_name', $table, $ref); |
@@ -220,14 +220,14 @@ discard block |
||
220 | 220 | */ |
221 | 221 | protected function createNewTableInfo($table) |
222 | 222 | { |
223 | - list($schemaName,$tableName) = $this->getSchemaTableName($table); |
|
223 | + list($schemaName, $tableName) = $this->getSchemaTableName($table); |
|
224 | 224 | $info['SchemaName'] = $schemaName; |
225 | 225 | $info['TableName'] = $tableName; |
226 | - if($this->getIsView($schemaName,$tableName)) |
|
226 | + if ($this->getIsView($schemaName, $tableName)) |
|
227 | 227 | $info['IsView'] = true; |
228 | 228 | list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName); |
229 | 229 | $class = $this->getTableInfoClass(); |
230 | - return new $class($info,$primary,$foreign); |
|
230 | + return new $class($info, $primary, $foreign); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -240,11 +240,11 @@ discard block |
||
240 | 240 | * @return boolean true if is view, false otherwise. |
241 | 241 | * @throws TDbException if table or view does not exist. |
242 | 242 | */ |
243 | - protected function getIsView($schemaName,$tableName) |
|
243 | + protected function getIsView($schemaName, $tableName) |
|
244 | 244 | { |
245 | - if($this->getServerVersion()<5.01) |
|
245 | + if ($this->getServerVersion() < 5.01) |
|
246 | 246 | return false; |
247 | - if($schemaName!==null) |
|
247 | + if ($schemaName !== null) |
|
248 | 248 | $sql = "SHOW FULL TABLES FROM `{$schemaName}` LIKE :table"; |
249 | 249 | else |
250 | 250 | $sql = "SHOW FULL TABLES LIKE :table"; |
@@ -253,12 +253,12 @@ discard block |
||
253 | 253 | $command->bindValue(':table', $tableName); |
254 | 254 | try |
255 | 255 | { |
256 | - return count($result = $command->queryRow()) > 0 && $result['Table_type']==='VIEW'; |
|
256 | + return count($result = $command->queryRow()) > 0 && $result['Table_type'] === 'VIEW'; |
|
257 | 257 | } |
258 | - catch(TDbException $e) |
|
258 | + catch (TDbException $e) |
|
259 | 259 | { |
260 | - $table = $schemaName===null?$tableName:$schemaName.'.'.$tableName; |
|
261 | - throw new TDbException('dbcommon_invalid_table_name',$table,$e->getMessage()); |
|
260 | + $table = $schemaName === null ? $tableName : $schemaName . '.' . $tableName; |
|
261 | + throw new TDbException('dbcommon_invalid_table_name', $table, $e->getMessage()); |
|
262 | 262 | } |
263 | 263 | } |
264 | 264 | |
@@ -270,22 +270,22 @@ discard block |
||
270 | 270 | */ |
271 | 271 | protected function getConstraintKeys($schemaName, $tableName) |
272 | 272 | { |
273 | - $table = $schemaName===null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`"; |
|
273 | + $table = $schemaName === null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`"; |
|
274 | 274 | $sql = "SHOW INDEX FROM {$table}"; |
275 | 275 | $command = $this->getDbConnection()->createCommand($sql); |
276 | 276 | $primary = array(); |
277 | - foreach($command->query() as $row) |
|
277 | + foreach ($command->query() as $row) |
|
278 | 278 | { |
279 | - if($row['Key_name']==='PRIMARY') |
|
279 | + if ($row['Key_name'] === 'PRIMARY') |
|
280 | 280 | $primary[] = $row['Column_name']; |
281 | 281 | } |
282 | 282 | // MySQL version was increased to >=5.1.21 instead of 5.x |
283 | 283 | // due to a MySQL bug (http://bugs.mysql.com/bug.php?id=19588) |
284 | - if($this->getServerVersion() >= 5.121) |
|
285 | - $foreign = $this->getForeignConstraints($schemaName,$tableName); |
|
284 | + if ($this->getServerVersion() >= 5.121) |
|
285 | + $foreign = $this->getForeignConstraints($schemaName, $tableName); |
|
286 | 286 | else |
287 | - $foreign = $this->findForeignConstraints($schemaName,$tableName); |
|
288 | - return array($primary,$foreign); |
|
287 | + $foreign = $this->findForeignConstraints($schemaName, $tableName); |
|
288 | + return array($primary, $foreign); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -313,10 +313,10 @@ discard block |
||
313 | 313 | EOD; |
314 | 314 | $command = $this->getDbConnection()->createCommand($sql); |
315 | 315 | $command->bindValue(':table', $tableName); |
316 | - if($schemaName!==null) |
|
316 | + if ($schemaName !== null) |
|
317 | 317 | $command->bindValue(':schema', $schemaName); |
318 | - $fkeys=array(); |
|
319 | - foreach($command->query() as $col) |
|
318 | + $fkeys = array(); |
|
319 | + foreach ($command->query() as $col) |
|
320 | 320 | { |
321 | 321 | $fkeys[$col['con']]['keys'][$col['col']] = $col['fkcol']; |
322 | 322 | $fkeys[$col['con']]['table'] = $col['fktable']; |
@@ -332,12 +332,12 @@ discard block |
||
332 | 332 | */ |
333 | 333 | protected function getShowCreateTable($schemaName, $tableName) |
334 | 334 | { |
335 | - if(version_compare(PHP_VERSION,'5.1.3','<')) |
|
335 | + if (version_compare(PHP_VERSION, '5.1.3', '<')) |
|
336 | 336 | throw new TDbException('dbmetadata_requires_php_version', 'Mysql 4.1.x', '5.1.3'); |
337 | 337 | |
338 | 338 | //See http://netevil.org/node.php?nid=795&SC=1 |
339 | 339 | $this->getDbConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); |
340 | - if($schemaName!==null) |
|
340 | + if ($schemaName !== null) |
|
341 | 341 | $sql = "SHOW CREATE TABLE `{$schemaName}`.`{$tableName}`"; |
342 | 342 | else |
343 | 343 | $sql = "SHOW CREATE TABLE `{$tableName}`"; |
@@ -355,16 +355,16 @@ discard block |
||
355 | 355 | protected function findForeignConstraints($schemaName, $tableName) |
356 | 356 | { |
357 | 357 | $sql = $this->getShowCreateTable($schemaName, $tableName); |
358 | - $matches =array(); |
|
358 | + $matches = array(); |
|
359 | 359 | $regexp = '/FOREIGN KEY\s+\(([^\)]+)\)\s+REFERENCES\s+`?([^`]+)`?\s\(([^\)]+)\)/mi'; |
360 | - preg_match_all($regexp,$sql,$matches,PREG_SET_ORDER); |
|
360 | + preg_match_all($regexp, $sql, $matches, PREG_SET_ORDER); |
|
361 | 361 | $foreign = array(); |
362 | - foreach($matches as $match) |
|
362 | + foreach ($matches as $match) |
|
363 | 363 | { |
364 | - $fields = array_map('trim',explode(',',str_replace('`','',$match[1]))); |
|
365 | - $fk_fields = array_map('trim',explode(',',str_replace('`','',$match[3]))); |
|
366 | - $keys=array(); |
|
367 | - foreach($fields as $k=>$v) |
|
364 | + $fields = array_map('trim', explode(',', str_replace('`', '', $match[1]))); |
|
365 | + $fk_fields = array_map('trim', explode(',', str_replace('`', '', $match[3]))); |
|
366 | + $keys = array(); |
|
367 | + foreach ($fields as $k=>$v) |
|
368 | 368 | $keys[$v] = $fk_fields[$k]; |
369 | 369 | $foreign[] = array('keys' => $keys, 'table' => trim($match[2])); |
370 | 370 | } |
@@ -378,9 +378,9 @@ discard block |
||
378 | 378 | */ |
379 | 379 | protected function isForeignKeyColumn($columnId, $tableInfo) |
380 | 380 | { |
381 | - foreach($tableInfo->getForeignKeys() as $fk) |
|
381 | + foreach ($tableInfo->getForeignKeys() as $fk) |
|
382 | 382 | { |
383 | - if(in_array($columnId, array_keys($fk['keys']))) |
|
383 | + if (in_array($columnId, array_keys($fk['keys']))) |
|
384 | 384 | return true; |
385 | 385 | } |
386 | 386 | return false; |
@@ -392,13 +392,13 @@ discard block |
||
392 | 392 | * If not empty, the returned table names will be prefixed with the schema name. |
393 | 393 | * @return array all table names in the database. |
394 | 394 | */ |
395 | - public function findTableNames($schema='') |
|
395 | + public function findTableNames($schema = '') |
|
396 | 396 | { |
397 | - if($schema==='') |
|
397 | + if ($schema === '') |
|
398 | 398 | return $this->getDbConnection()->createCommand('SHOW TABLES')->queryColumn(); |
399 | - $names=$this->getDbConnection()->createCommand('SHOW TABLES FROM '.$this->quoteTableName($schema))->queryColumn(); |
|
400 | - foreach($names as &$name) |
|
401 | - $name=$schema.'.'.$name; |
|
399 | + $names = $this->getDbConnection()->createCommand('SHOW TABLES FROM ' . $this->quoteTableName($schema))->queryColumn(); |
|
400 | + foreach ($names as &$name) |
|
401 | + $name = $schema . '.' . $name; |
|
402 | 402 | return $names; |
403 | 403 | } |
404 | 404 | } |
@@ -417,12 +417,12 @@ |
||
417 | 417 | return false; |
418 | 418 | } |
419 | 419 | |
420 | - /** |
|
421 | - * Returns all table names in the database. |
|
422 | - * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema. |
|
423 | - * If not empty, the returned table names will be prefixed with the schema name. |
|
424 | - * @return array all table names in the database. |
|
425 | - */ |
|
420 | + /** |
|
421 | + * Returns all table names in the database. |
|
422 | + * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema. |
|
423 | + * If not empty, the returned table names will be prefixed with the schema name. |
|
424 | + * @return array all table names in the database. |
|
425 | + */ |
|
426 | 426 | public function findTableNames($schema='public') |
427 | 427 | { |
428 | 428 | if($schema==='') |
@@ -154,8 +154,7 @@ discard block |
||
154 | 154 | $info['NumericPrecision'] = intval($pscale[1]); |
155 | 155 | if(count($pscale) > 2) |
156 | 156 | $info['NumericScale'] = intval($pscale[2]); |
157 | - } |
|
158 | - else |
|
157 | + } else |
|
159 | 158 | $info['ColumnSize'] = intval($pscale[1]); |
160 | 159 | } |
161 | 160 | } |
@@ -254,8 +253,7 @@ discard block |
||
254 | 253 | try |
255 | 254 | { |
256 | 255 | return count($result = $command->queryRow()) > 0 && $result['Table_type']==='VIEW'; |
257 | - } |
|
258 | - catch(TDbException $e) |
|
256 | + } catch(TDbException $e) |
|
259 | 257 | { |
260 | 258 | $table = $schemaName===null?$tableName:$schemaName.'.'.$tableName; |
261 | 259 | throw new TDbException('dbcommon_invalid_table_name',$table,$e->getMessage()); |
@@ -364,8 +362,9 @@ discard block |
||
364 | 362 | $fields = array_map('trim',explode(',',str_replace('`','',$match[1]))); |
365 | 363 | $fk_fields = array_map('trim',explode(',',str_replace('`','',$match[3]))); |
366 | 364 | $keys=array(); |
367 | - foreach($fields as $k=>$v) |
|
368 | - $keys[$v] = $fk_fields[$k]; |
|
365 | + foreach($fields as $k=>$v) { |
|
366 | + $keys[$v] = $fk_fields[$k]; |
|
367 | + } |
|
369 | 368 | $foreign[] = array('keys' => $keys, 'table' => trim($match[2])); |
370 | 369 | } |
371 | 370 | return $foreign; |
@@ -397,8 +396,9 @@ discard block |
||
397 | 396 | if($schema==='') |
398 | 397 | return $this->getDbConnection()->createCommand('SHOW TABLES')->queryColumn(); |
399 | 398 | $names=$this->getDbConnection()->createCommand('SHOW TABLES FROM '.$this->quoteTableName($schema))->queryColumn(); |
400 | - foreach($names as &$name) |
|
401 | - $name=$schema.'.'.$name; |
|
399 | + foreach($names as &$name) { |
|
400 | + $name=$schema.'.'.$name; |
|
401 | + } |
|
402 | 402 | return $names; |
403 | 403 | } |
404 | 404 | } |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | /** |
146 | 146 | * @param string table schema name |
147 | 147 | * @param string table name. |
148 | - * @return boolean true if the table is a view. |
|
148 | + * @return integer true if the table is a view. |
|
149 | 149 | */ |
150 | 150 | protected function getIsView($schemaName,$tableName) |
151 | 151 | { |
@@ -167,6 +167,7 @@ discard block |
||
167 | 167 | /** |
168 | 168 | * @param TOracleTableInfo table information. |
169 | 169 | * @param array column information. |
170 | + * @param TOracleTableInfo $tableInfo |
|
170 | 171 | */ |
171 | 172 | protected function processColumn($tableInfo, $col) |
172 | 173 | { |
@@ -322,6 +323,7 @@ discard block |
||
322 | 323 | /** |
323 | 324 | * @param string column name. |
324 | 325 | * @param TOracleTableInfo table information. |
326 | + * @param string $columnId |
|
325 | 327 | * @return boolean true if column is a foreign key. |
326 | 328 | */ |
327 | 329 | protected function isForeignKeyColumn($columnId, $tableInfo) |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function setDefaultSchema($schema) |
43 | 43 | { |
44 | - $this->_defaultSchema=$schema; |
|
44 | + $this->_defaultSchema = $schema; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -58,10 +58,10 @@ discard block |
||
58 | 58 | */ |
59 | 59 | protected function getSchemaTableName($table) |
60 | 60 | { |
61 | - if(count($parts= explode('.', str_replace('"','',$table))) > 1) |
|
61 | + if (count($parts = explode('.', str_replace('"', '', $table))) > 1) |
|
62 | 62 | return array($parts[0], $parts[1]); |
63 | 63 | else |
64 | - return array($this->getDefaultSchema(),$parts[0]); |
|
64 | + return array($this->getDefaultSchema(), $parts[0]); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | protected function createTableInfo($table) |
73 | 73 | { |
74 | - list($schemaName,$tableName) = $this->getSchemaTableName($table); |
|
74 | + list($schemaName, $tableName) = $this->getSchemaTableName($table); |
|
75 | 75 | |
76 | 76 | // This query is made much more complex by the addition of the 'attisserial' field. |
77 | 77 | // The subquery to get that field checks to see if there is an internally dependent |
@@ -100,13 +100,13 @@ discard block |
||
100 | 100 | //$command->bindValue(':table', $tableName); |
101 | 101 | //$command->bindValue(':schema', $schemaName); |
102 | 102 | $tableInfo = $this->createNewTableInfo($schemaName, $tableName); |
103 | - $index=0; |
|
104 | - foreach($command->query() as $col) |
|
103 | + $index = 0; |
|
104 | + foreach ($command->query() as $col) |
|
105 | 105 | { |
106 | 106 | $col['index'] = $index++; |
107 | 107 | $this->processColumn($tableInfo, $col); |
108 | 108 | } |
109 | - if($index===0) |
|
109 | + if ($index === 0) |
|
110 | 110 | throw new TDbException('dbmetadata_invalid_table_view', $table); |
111 | 111 | return $tableInfo; |
112 | 112 | } |
@@ -116,15 +116,15 @@ discard block |
||
116 | 116 | * @param string table name. |
117 | 117 | * @return TOracleTableInfo |
118 | 118 | */ |
119 | - protected function createNewTableInfo($schemaName,$tableName) |
|
119 | + protected function createNewTableInfo($schemaName, $tableName) |
|
120 | 120 | { |
121 | 121 | $info['SchemaName'] = $this->assertIdentifier($schemaName); |
122 | - $info['TableName'] = $this->assertIdentifier($tableName); |
|
123 | - $info['IsView'] = false; |
|
124 | - if($this->getIsView($schemaName,$tableName)) $info['IsView'] = true; |
|
122 | + $info['TableName'] = $this->assertIdentifier($tableName); |
|
123 | + $info['IsView'] = false; |
|
124 | + if ($this->getIsView($schemaName, $tableName)) $info['IsView'] = true; |
|
125 | 125 | list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName); |
126 | 126 | $class = $this->getTableInfoClass(); |
127 | - return new $class($info,$primary,$foreign); |
|
127 | + return new $class($info, $primary, $foreign); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | */ |
135 | 135 | protected function assertIdentifier($name) |
136 | 136 | { |
137 | - if(strpos($name, '"')!==false) |
|
137 | + if (strpos($name, '"') !== false) |
|
138 | 138 | { |
139 | 139 | $ref = 'http://www.oracle.com'; |
140 | 140 | throw new TDbException('dbcommon_invalid_identifier_name', $name, $ref); |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | * @param string table name. |
148 | 148 | * @return boolean true if the table is a view. |
149 | 149 | */ |
150 | - protected function getIsView($schemaName,$tableName) |
|
150 | + protected function getIsView($schemaName, $tableName) |
|
151 | 151 | { |
152 | 152 | $this->getDbConnection()->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); |
153 | 153 | $sql = |
@@ -173,14 +173,14 @@ discard block |
||
173 | 173 | $columnId = strtolower($col['attname']); //use column name as column Id |
174 | 174 | |
175 | 175 | //$info['ColumnName'] = '"'.$columnId.'"'; //quote the column names! |
176 | - $info['ColumnName'] = $columnId; //NOT quote the column names! |
|
177 | - $info['ColumnId'] = $columnId; |
|
178 | - $info['ColumnIndex'] = $col['index']; |
|
179 | - if(! (bool)$col['attnotnull'] ) $info['AllowNull'] = true; |
|
180 | - if(in_array($columnId, $tableInfo->getPrimaryKeys())) $info['IsPrimaryKey'] = true; |
|
181 | - if($this->isForeignKeyColumn($columnId, $tableInfo)) $info['IsForeignKey'] = true; |
|
182 | - if( (int)$col['atttypmod'] > 0 ) $info['ColumnSize'] = $col['atttypmod']; // - 4; |
|
183 | - if( (bool)$col['atthasdef'] ) $info['DefaultValue'] = $col['adsrc']; |
|
176 | + $info['ColumnName'] = $columnId; //NOT quote the column names! |
|
177 | + $info['ColumnId'] = $columnId; |
|
178 | + $info['ColumnIndex'] = $col['index']; |
|
179 | + if (!(bool) $col['attnotnull']) $info['AllowNull'] = true; |
|
180 | + if (in_array($columnId, $tableInfo->getPrimaryKeys())) $info['IsPrimaryKey'] = true; |
|
181 | + if ($this->isForeignKeyColumn($columnId, $tableInfo)) $info['IsForeignKey'] = true; |
|
182 | + if ((int) $col['atttypmod'] > 0) $info['ColumnSize'] = $col['atttypmod']; // - 4; |
|
183 | + if ((bool) $col['atthasdef']) $info['DefaultValue'] = $col['adsrc']; |
|
184 | 184 | // |
185 | 185 | // For a while Oracle Tables has no associated AutoIncrement Triggers |
186 | 186 | // |
@@ -195,13 +195,13 @@ discard block |
||
195 | 195 | } |
196 | 196 | */ |
197 | 197 | $matches = array(); |
198 | - if(preg_match('/\((\d+)(?:,(\d+))?+\)/', $col['type'], $matches)) |
|
198 | + if (preg_match('/\((\d+)(?:,(\d+))?+\)/', $col['type'], $matches)) |
|
199 | 199 | { |
200 | - $info['DbType'] = preg_replace('/\(\d+(?:,\d+)?\)/','',$col['type']); |
|
201 | - if($this->isPrecisionType($info['DbType'])) |
|
200 | + $info['DbType'] = preg_replace('/\(\d+(?:,\d+)?\)/', '', $col['type']); |
|
201 | + if ($this->isPrecisionType($info['DbType'])) |
|
202 | 202 | { |
203 | 203 | $info['NumericPrecision'] = intval($matches[1]); |
204 | - if(count($matches) > 2) |
|
204 | + if (count($matches) > 2) |
|
205 | 205 | $info['NumericScale'] = intval($matches[2]); |
206 | 206 | } |
207 | 207 | else |
@@ -215,15 +215,15 @@ discard block |
||
215 | 215 | /** |
216 | 216 | * @return string serial name if found, null otherwise. |
217 | 217 | */ |
218 | - protected function getSequenceName($tableInfo,$src) |
|
218 | + protected function getSequenceName($tableInfo, $src) |
|
219 | 219 | { |
220 | 220 | $matches = array(); |
221 | - if(preg_match('/nextval\([^\']*\'([^\']+)\'[^\)]*\)/i',$src,$matches)) |
|
221 | + if (preg_match('/nextval\([^\']*\'([^\']+)\'[^\)]*\)/i', $src, $matches)) |
|
222 | 222 | { |
223 | - if(is_int(strpos($matches[1], '.'))) |
|
223 | + if (is_int(strpos($matches[1], '.'))) |
|
224 | 224 | return $matches[1]; |
225 | 225 | else |
226 | - return $tableInfo->getSchemaName().'.'.$matches[1]; |
|
226 | + return $tableInfo->getSchemaName() . '.' . $matches[1]; |
|
227 | 227 | } |
228 | 228 | } |
229 | 229 | |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | protected function isPrecisionType($type) |
234 | 234 | { |
235 | 235 | $type = strtolower(trim($type)); |
236 | - return $type==='number'; // || $type==='interval' || strpos($type, 'time')===0; |
|
236 | + return $type === 'number'; // || $type==='interval' || strpos($type, 'time')===0; |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
@@ -262,19 +262,19 @@ discard block |
||
262 | 262 | //$command->bindValue(':schema', $schemaName); |
263 | 263 | $primary = array(); |
264 | 264 | $foreign = array(); |
265 | - foreach($command->query() as $row) |
|
265 | + foreach ($command->query() as $row) |
|
266 | 266 | { |
267 | - switch( strtolower( $row['contype'] ) ) |
|
267 | + switch (strtolower($row['contype'])) |
|
268 | 268 | { |
269 | 269 | case 'p': |
270 | - $primary = array_merge( $primary, array(strtolower( $row['consrc'] )) ); |
|
270 | + $primary = array_merge($primary, array(strtolower($row['consrc']))); |
|
271 | 271 | /* |
272 | 272 | $arr = $this->getPrimaryKeys($row['consrc']); |
273 | 273 | $primary = array_merge( $primary, array(strtolower( $arr[0] )) ); |
274 | 274 | */ |
275 | 275 | break; |
276 | 276 | case 'r': |
277 | - $foreign = array_merge( $foreign, array(strtolower( $row['consrc'] )) ); |
|
277 | + $foreign = array_merge($foreign, array(strtolower($row['consrc']))); |
|
278 | 278 | /* |
279 | 279 | // if(($fkey = $this->getForeignKeys($row['consrc']))!==null) |
280 | 280 | $fkey = $this->getForeignKeys( $row['consrc'] ); |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | break; |
284 | 284 | } |
285 | 285 | } |
286 | - return array($primary,$foreign); |
|
286 | + return array($primary, $foreign); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | /** |
@@ -294,8 +294,8 @@ discard block |
||
294 | 294 | protected function getPrimaryKeys($src) |
295 | 295 | { |
296 | 296 | $matches = array(); |
297 | - if(preg_match('/PRIMARY\s+KEY\s+\(([^\)]+)\)/i', $src, $matches)) |
|
298 | - return preg_split('/,\s+/',$matches[1]); |
|
297 | + if (preg_match('/PRIMARY\s+KEY\s+\(([^\)]+)\)/i', $src, $matches)) |
|
298 | + return preg_split('/,\s+/', $matches[1]); |
|
299 | 299 | return array(); |
300 | 300 | } |
301 | 301 | |
@@ -309,13 +309,13 @@ discard block |
||
309 | 309 | $matches = array(); |
310 | 310 | $brackets = '\(([^\)]+)\)'; |
311 | 311 | $find = "/FOREIGN\s+KEY\s+{$brackets}\s+REFERENCES\s+([^\(]+){$brackets}/i"; |
312 | - if(preg_match($find, $src, $matches)) |
|
312 | + if (preg_match($find, $src, $matches)) |
|
313 | 313 | { |
314 | 314 | $keys = preg_split('/,\s+/', $matches[1]); |
315 | 315 | $fkeys = array(); |
316 | - foreach(preg_split('/,\s+/', $matches[3]) as $i => $fkey) |
|
316 | + foreach (preg_split('/,\s+/', $matches[3]) as $i => $fkey) |
|
317 | 317 | $fkeys[$keys[$i]] = $fkey; |
318 | - return array('table' => str_replace('"','',$matches[2]), 'keys' => $fkeys); |
|
318 | + return array('table' => str_replace('"', '', $matches[2]), 'keys' => $fkeys); |
|
319 | 319 | } |
320 | 320 | } |
321 | 321 | |
@@ -326,9 +326,9 @@ discard block |
||
326 | 326 | */ |
327 | 327 | protected function isForeignKeyColumn($columnId, $tableInfo) |
328 | 328 | { |
329 | - foreach($tableInfo->getForeignKeys() as $fk) |
|
329 | + foreach ($tableInfo->getForeignKeys() as $fk) |
|
330 | 330 | { |
331 | - if( $fk==$columnId ) |
|
331 | + if ($fk == $columnId) |
|
332 | 332 | //if(in_array($columnId, array_keys($fk['keys']))) |
333 | 333 | return true; |
334 | 334 | } |
@@ -341,33 +341,33 @@ discard block |
||
341 | 341 | * If not empty, the returned table names will be prefixed with the schema name. |
342 | 342 | * @return array all table names in the database. |
343 | 343 | */ |
344 | - public function findTableNames($schema='') |
|
344 | + public function findTableNames($schema = '') |
|
345 | 345 | { |
346 | - if($schema==='') |
|
346 | + if ($schema === '') |
|
347 | 347 | { |
348 | - $sql=<<<EOD |
|
348 | + $sql = <<<EOD |
|
349 | 349 | SELECT table_name, '{$schema}' as table_schema FROM user_tables |
350 | 350 | EOD; |
351 | - $command=$this->getDbConnection()->createCommand($sql); |
|
351 | + $command = $this->getDbConnection()->createCommand($sql); |
|
352 | 352 | } |
353 | 353 | else |
354 | 354 | { |
355 | - $sql=<<<EOD |
|
355 | + $sql = <<<EOD |
|
356 | 356 | SELECT object_name as table_name, owner as table_schema FROM all_objects |
357 | 357 | WHERE object_type = 'TABLE' AND owner=:schema |
358 | 358 | EOD; |
359 | - $command=$this->getDbConnection()->createCommand($sql); |
|
360 | - $command->bindParam(':schema',$schema); |
|
359 | + $command = $this->getDbConnection()->createCommand($sql); |
|
360 | + $command->bindParam(':schema', $schema); |
|
361 | 361 | } |
362 | 362 | |
363 | - $rows=$command->queryAll(); |
|
364 | - $names=array(); |
|
365 | - foreach($rows as $row) |
|
363 | + $rows = $command->queryAll(); |
|
364 | + $names = array(); |
|
365 | + foreach ($rows as $row) |
|
366 | 366 | { |
367 | - if($schema===$this->getDefaultSchema() || $schema==='') |
|
368 | - $names[]=$row['TABLE_NAME']; |
|
367 | + if ($schema === $this->getDefaultSchema() || $schema === '') |
|
368 | + $names[] = $row['TABLE_NAME']; |
|
369 | 369 | else |
370 | - $names[]=$row['TABLE_SCHEMA'].'.'.$row['TABLE_NAME']; |
|
370 | + $names[] = $row['TABLE_SCHEMA'] . '.' . $row['TABLE_NAME']; |
|
371 | 371 | } |
372 | 372 | return $names; |
373 | 373 | } |
@@ -417,12 +417,12 @@ |
||
417 | 417 | return false; |
418 | 418 | } |
419 | 419 | |
420 | - /** |
|
421 | - * Returns all table names in the database. |
|
422 | - * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema. |
|
423 | - * If not empty, the returned table names will be prefixed with the schema name. |
|
424 | - * @return array all table names in the database. |
|
425 | - */ |
|
420 | + /** |
|
421 | + * Returns all table names in the database. |
|
422 | + * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema. |
|
423 | + * If not empty, the returned table names will be prefixed with the schema name. |
|
424 | + * @return array all table names in the database. |
|
425 | + */ |
|
426 | 426 | public function findTableNames($schema='public') |
427 | 427 | { |
428 | 428 | if($schema==='') |
@@ -203,11 +203,9 @@ discard block |
||
203 | 203 | $info['NumericPrecision'] = intval($matches[1]); |
204 | 204 | if(count($matches) > 2) |
205 | 205 | $info['NumericScale'] = intval($matches[2]); |
206 | - } |
|
207 | - else |
|
206 | + } else |
|
208 | 207 | $info['ColumnSize'] = intval($matches[1]); |
209 | - } |
|
210 | - else |
|
208 | + } else |
|
211 | 209 | $info['DbType'] = $col['type']; |
212 | 210 | $tableInfo->Columns[$columnId] = new TOracleTableColumn($info); |
213 | 211 | } |
@@ -313,8 +311,9 @@ discard block |
||
313 | 311 | { |
314 | 312 | $keys = preg_split('/,\s+/', $matches[1]); |
315 | 313 | $fkeys = array(); |
316 | - foreach(preg_split('/,\s+/', $matches[3]) as $i => $fkey) |
|
317 | - $fkeys[$keys[$i]] = $fkey; |
|
314 | + foreach(preg_split('/,\s+/', $matches[3]) as $i => $fkey) { |
|
315 | + $fkeys[$keys[$i]] = $fkey; |
|
316 | + } |
|
318 | 317 | return array('table' => str_replace('"','',$matches[2]), 'keys' => $fkeys); |
319 | 318 | } |
320 | 319 | } |
@@ -349,8 +348,7 @@ discard block |
||
349 | 348 | SELECT table_name, '{$schema}' as table_schema FROM user_tables |
350 | 349 | EOD; |
351 | 350 | $command=$this->getDbConnection()->createCommand($sql); |
352 | - } |
|
353 | - else |
|
351 | + } else |
|
354 | 352 | { |
355 | 353 | $sql=<<<EOD |
356 | 354 | SELECT object_name as table_name, owner as table_schema FROM all_objects |
@@ -53,6 +53,8 @@ |
||
53 | 53 | /** |
54 | 54 | * @param string information array key name |
55 | 55 | * @param mixed default value if information array value is null |
56 | + * @param string $name |
|
57 | + * @param boolean $default |
|
56 | 58 | * @return mixed information array value. |
57 | 59 | */ |
58 | 60 | public function getInfo($name,$default=null) |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | */ |
20 | 20 | class TOracleTableInfo extends TComponent |
21 | 21 | { |
22 | - private $_info=array(); |
|
22 | + private $_info = array(); |
|
23 | 23 | |
24 | 24 | private $_primaryKeys; |
25 | 25 | private $_foreignKeys; |
@@ -32,12 +32,12 @@ discard block |
||
32 | 32 | * Sets the database table meta data information. |
33 | 33 | * @param array table column information. |
34 | 34 | */ |
35 | - public function __construct($tableInfo=array(),$primary=array(),$foreign=array()) |
|
35 | + public function __construct($tableInfo = array(), $primary = array(), $foreign = array()) |
|
36 | 36 | { |
37 | - $this->_info=$tableInfo; |
|
38 | - $this->_primaryKeys=$primary; |
|
39 | - $this->_foreignKeys=$foreign; |
|
40 | - $this->_columns=new TMap; |
|
37 | + $this->_info = $tableInfo; |
|
38 | + $this->_primaryKeys = $primary; |
|
39 | + $this->_foreignKeys = $foreign; |
|
40 | + $this->_columns = new TMap; |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | public function createCommandBuilder($connection) |
48 | 48 | { |
49 | 49 | Prado::using('System.Data.Common.Oracle.TOracleCommandBuilder'); |
50 | - return new TOracleCommandBuilder($connection,$this); |
|
50 | + return new TOracleCommandBuilder($connection, $this); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @param mixed default value if information array value is null |
56 | 56 | * @return mixed information array value. |
57 | 57 | */ |
58 | - public function getInfo($name,$default=null) |
|
58 | + public function getInfo($name, $default = null) |
|
59 | 59 | { |
60 | 60 | return isset($this->_info[$name]) ? $this->_info[$name] : $default; |
61 | 61 | } |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | * @param string information array key name |
65 | 65 | * @param mixed new information array value. |
66 | 66 | */ |
67 | - protected function setInfo($name,$value) |
|
67 | + protected function setInfo($name, $value) |
|
68 | 68 | { |
69 | - $this->_info[$name]=$value; |
|
69 | + $this->_info[$name] = $value; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function getTableFullName() |
84 | 84 | { |
85 | - return $this->_info['SchemaName'].'.'.$this->getTableName(); |
|
85 | + return $this->_info['SchemaName'] . '.' . $this->getTableName(); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function getIsView() |
92 | 92 | { |
93 | - return $this->getInfo('IsView',false); |
|
93 | + return $this->getInfo('IsView', false); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public function getColumn($name) |
109 | 109 | { |
110 | - if(($column = $this->_columns->itemAt($name))!==null) |
|
110 | + if (($column = $this->_columns->itemAt($name)) !== null) |
|
111 | 111 | return $column; |
112 | 112 | throw new TDbException('dbtableinfo_invalid_column_name', $name, $this->getTableFullName()); |
113 | 113 | } |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function getColumnNames() |
120 | 120 | { |
121 | - foreach($this->getColumns() as $column) |
|
121 | + foreach ($this->getColumns() as $column) |
|
122 | 122 | $names[] = $column->getColumnName(); |
123 | 123 | return $names; |
124 | 124 | } |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public function getLowerCaseColumnNames() |
146 | 146 | { |
147 | - if($this->_lowercase===null) |
|
147 | + if ($this->_lowercase === null) |
|
148 | 148 | { |
149 | - $this->_lowercase=array(); |
|
150 | - foreach($this->getColumns()->getKeys() as $key) |
|
149 | + $this->_lowercase = array(); |
|
150 | + foreach ($this->getColumns()->getKeys() as $key) |
|
151 | 151 | $this->_lowercase[strtolower($key)] = $key; |
152 | 152 | } |
153 | 153 | return $this->_lowercase; |
@@ -118,8 +118,9 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function getColumnNames() |
120 | 120 | { |
121 | - foreach($this->getColumns() as $column) |
|
122 | - $names[] = $column->getColumnName(); |
|
121 | + foreach($this->getColumns() as $column) { |
|
122 | + $names[] = $column->getColumnName(); |
|
123 | + } |
|
123 | 124 | return $names; |
124 | 125 | } |
125 | 126 | |
@@ -147,8 +148,9 @@ discard block |
||
147 | 148 | if($this->_lowercase===null) |
148 | 149 | { |
149 | 150 | $this->_lowercase=array(); |
150 | - foreach($this->getColumns()->getKeys() as $key) |
|
151 | - $this->_lowercase[strtolower($key)] = $key; |
|
151 | + foreach($this->getColumns()->getKeys() as $key) { |
|
152 | + $this->_lowercase[strtolower($key)] = $key; |
|
153 | + } |
|
152 | 154 | } |
153 | 155 | return $this->_lowercase; |
154 | 156 | } |
@@ -204,6 +204,7 @@ |
||
204 | 204 | /** |
205 | 205 | * @param TPgsqlTableInfo table information. |
206 | 206 | * @param array column information. |
207 | + * @param TPgsqlTableInfo $tableInfo |
|
207 | 208 | */ |
208 | 209 | protected function processColumn($tableInfo, $col) |
209 | 210 | { |
@@ -417,12 +417,12 @@ |
||
417 | 417 | return false; |
418 | 418 | } |
419 | 419 | |
420 | - /** |
|
421 | - * Returns all table names in the database. |
|
422 | - * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema. |
|
423 | - * If not empty, the returned table names will be prefixed with the schema name. |
|
424 | - * @return array all table names in the database. |
|
425 | - */ |
|
420 | + /** |
|
421 | + * Returns all table names in the database. |
|
422 | + * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema. |
|
423 | + * If not empty, the returned table names will be prefixed with the schema name. |
|
424 | + * @return array all table names in the database. |
|
425 | + */ |
|
426 | 426 | public function findTableNames($schema='public') |
427 | 427 | { |
428 | 428 | if($schema==='') |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function setDefaultSchema($schema) |
71 | 71 | { |
72 | - $this->_defaultSchema=$schema; |
|
72 | + $this->_defaultSchema = $schema; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -86,10 +86,10 @@ discard block |
||
86 | 86 | */ |
87 | 87 | protected function getSchemaTableName($table) |
88 | 88 | { |
89 | - if(count($parts= explode('.', str_replace('"','',$table))) > 1) |
|
89 | + if (count($parts = explode('.', str_replace('"', '', $table))) > 1) |
|
90 | 90 | return array($parts[0], $parts[1]); |
91 | 91 | else |
92 | - return array($this->getDefaultSchema(),$parts[0]); |
|
92 | + return array($this->getDefaultSchema(), $parts[0]); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | */ |
100 | 100 | protected function createTableInfo($table) |
101 | 101 | { |
102 | - list($schemaName,$tableName) = $this->getSchemaTableName($table); |
|
102 | + list($schemaName, $tableName) = $this->getSchemaTableName($table); |
|
103 | 103 | |
104 | 104 | // This query is made much more complex by the addition of the 'attisserial' field. |
105 | 105 | // The subquery to get that field checks to see if there is an internally dependent |
@@ -139,13 +139,13 @@ discard block |
||
139 | 139 | $command->bindValue(':table', $tableName); |
140 | 140 | $command->bindValue(':schema', $schemaName); |
141 | 141 | $tableInfo = $this->createNewTableInfo($schemaName, $tableName); |
142 | - $index=0; |
|
143 | - foreach($command->query() as $col) |
|
142 | + $index = 0; |
|
143 | + foreach ($command->query() as $col) |
|
144 | 144 | { |
145 | 145 | $col['index'] = $index++; |
146 | 146 | $this->processColumn($tableInfo, $col); |
147 | 147 | } |
148 | - if($index===0) |
|
148 | + if ($index === 0) |
|
149 | 149 | throw new TDbException('dbmetadata_invalid_table_view', $table); |
150 | 150 | return $tableInfo; |
151 | 151 | } |
@@ -155,15 +155,15 @@ discard block |
||
155 | 155 | * @param string table name. |
156 | 156 | * @return TPgsqlTableInfo |
157 | 157 | */ |
158 | - protected function createNewTableInfo($schemaName,$tableName) |
|
158 | + protected function createNewTableInfo($schemaName, $tableName) |
|
159 | 159 | { |
160 | 160 | $info['SchemaName'] = $this->assertIdentifier($schemaName); |
161 | 161 | $info['TableName'] = $this->assertIdentifier($tableName); |
162 | - if($this->getIsView($schemaName,$tableName)) |
|
162 | + if ($this->getIsView($schemaName, $tableName)) |
|
163 | 163 | $info['IsView'] = true; |
164 | 164 | list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName); |
165 | 165 | $class = $this->getTableInfoClass(); |
166 | - return new $class($info,$primary,$foreign); |
|
166 | + return new $class($info, $primary, $foreign); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | */ |
174 | 174 | protected function assertIdentifier($name) |
175 | 175 | { |
176 | - if(strpos($name, '"')!==false) |
|
176 | + if (strpos($name, '"') !== false) |
|
177 | 177 | { |
178 | 178 | $ref = 'http://www.postgresql.org/docs/7.4/static/sql-syntax.html#SQL-SYNTAX-IDENTIFIERS'; |
179 | 179 | throw new TDbException('dbcommon_invalid_identifier_name', $name, $ref); |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | * @param string table name. |
187 | 187 | * @return boolean true if the table is a view. |
188 | 188 | */ |
189 | - protected function getIsView($schemaName,$tableName) |
|
189 | + protected function getIsView($schemaName, $tableName) |
|
190 | 190 | { |
191 | 191 | $sql = |
192 | 192 | <<<EOD |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | EOD; |
197 | 197 | $this->getDbConnection()->setActive(true); |
198 | 198 | $command = $this->getDbConnection()->createCommand($sql); |
199 | - $command->bindValue(':schema',$schemaName); |
|
199 | + $command->bindValue(':schema', $schemaName); |
|
200 | 200 | $command->bindValue(':table', $tableName); |
201 | 201 | return intval($command->queryScalar()) === 1; |
202 | 202 | } |
@@ -209,36 +209,36 @@ discard block |
||
209 | 209 | { |
210 | 210 | $columnId = $col['attname']; //use column name as column Id |
211 | 211 | |
212 | - $info['ColumnName'] = '"'.$columnId.'"'; //quote the column names! |
|
212 | + $info['ColumnName'] = '"' . $columnId . '"'; //quote the column names! |
|
213 | 213 | $info['ColumnId'] = $columnId; |
214 | 214 | $info['ColumnIndex'] = $col['index']; |
215 | - if(!$col['attnotnull']) |
|
215 | + if (!$col['attnotnull']) |
|
216 | 216 | $info['AllowNull'] = true; |
217 | - if(in_array($columnId, $tableInfo->getPrimaryKeys())) |
|
217 | + if (in_array($columnId, $tableInfo->getPrimaryKeys())) |
|
218 | 218 | $info['IsPrimaryKey'] = true; |
219 | - if($this->isForeignKeyColumn($columnId, $tableInfo)) |
|
219 | + if ($this->isForeignKeyColumn($columnId, $tableInfo)) |
|
220 | 220 | $info['IsForeignKey'] = true; |
221 | 221 | |
222 | - if($col['atttypmod'] > 0) |
|
223 | - $info['ColumnSize'] = $col['atttypmod'] - 4; |
|
224 | - if($col['atthasdef']) |
|
222 | + if ($col['atttypmod'] > 0) |
|
223 | + $info['ColumnSize'] = $col['atttypmod'] - 4; |
|
224 | + if ($col['atthasdef']) |
|
225 | 225 | $info['DefaultValue'] = $col['adsrc']; |
226 | - if($col['attisserial'] || substr($col['adsrc'],0,8) === 'nextval(') |
|
226 | + if ($col['attisserial'] || substr($col['adsrc'], 0, 8) === 'nextval(') |
|
227 | 227 | { |
228 | - if(($sequence = $this->getSequenceName($tableInfo, $col['adsrc']))!==null) |
|
228 | + if (($sequence = $this->getSequenceName($tableInfo, $col['adsrc'])) !== null) |
|
229 | 229 | { |
230 | 230 | $info['SequenceName'] = $sequence; |
231 | 231 | unset($info['DefaultValue']); |
232 | 232 | } |
233 | 233 | } |
234 | 234 | $matches = array(); |
235 | - if(preg_match('/\((\d+)(?:,(\d+))?+\)/', $col['type'], $matches)) |
|
235 | + if (preg_match('/\((\d+)(?:,(\d+))?+\)/', $col['type'], $matches)) |
|
236 | 236 | { |
237 | - $info['DbType'] = preg_replace('/\(\d+(?:,\d+)?\)/','',$col['type']); |
|
238 | - if($this->isPrecisionType($info['DbType'])) |
|
237 | + $info['DbType'] = preg_replace('/\(\d+(?:,\d+)?\)/', '', $col['type']); |
|
238 | + if ($this->isPrecisionType($info['DbType'])) |
|
239 | 239 | { |
240 | 240 | $info['NumericPrecision'] = intval($matches[1]); |
241 | - if(count($matches) > 2) |
|
241 | + if (count($matches) > 2) |
|
242 | 242 | $info['NumericScale'] = intval($matches[2]); |
243 | 243 | } |
244 | 244 | else |
@@ -253,15 +253,15 @@ discard block |
||
253 | 253 | /** |
254 | 254 | * @return string serial name if found, null otherwise. |
255 | 255 | */ |
256 | - protected function getSequenceName($tableInfo,$src) |
|
256 | + protected function getSequenceName($tableInfo, $src) |
|
257 | 257 | { |
258 | 258 | $matches = array(); |
259 | - if(preg_match('/nextval\([^\']*\'([^\']+)\'[^\)]*\)/i',$src,$matches)) |
|
259 | + if (preg_match('/nextval\([^\']*\'([^\']+)\'[^\)]*\)/i', $src, $matches)) |
|
260 | 260 | { |
261 | - if(is_int(strpos($matches[1], '.'))) |
|
261 | + if (is_int(strpos($matches[1], '.'))) |
|
262 | 262 | return $matches[1]; |
263 | 263 | else |
264 | - return $tableInfo->getSchemaName().'.'.$matches[1]; |
|
264 | + return $tableInfo->getSchemaName() . '.' . $matches[1]; |
|
265 | 265 | } |
266 | 266 | } |
267 | 267 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | protected function isPrecisionType($type) |
272 | 272 | { |
273 | 273 | $type = strtolower(trim($type)); |
274 | - return $type==='numeric' || $type==='interval' || strpos($type, 'time')===0; |
|
274 | + return $type === 'numeric' || $type === 'interval' || strpos($type, 'time') === 0; |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -335,20 +335,20 @@ discard block |
||
335 | 335 | $command->bindValue(':schema', $schemaName); |
336 | 336 | $primary = array(); |
337 | 337 | $foreign = array(); |
338 | - foreach($command->query() as $row) |
|
338 | + foreach ($command->query() as $row) |
|
339 | 339 | { |
340 | - switch($row['contype']) |
|
340 | + switch ($row['contype']) |
|
341 | 341 | { |
342 | 342 | case 'p': |
343 | 343 | $primary = $this->getPrimaryKeys($tableName, $schemaName, $row['indkey']); |
344 | 344 | break; |
345 | 345 | case 'f': |
346 | - if(($fkey = $this->getForeignKeys($row['consrc']))!==null) |
|
346 | + if (($fkey = $this->getForeignKeys($row['consrc'])) !== null) |
|
347 | 347 | $foreign[] = $fkey; |
348 | 348 | break; |
349 | 349 | } |
350 | 350 | } |
351 | - return array($primary,$foreign); |
|
351 | + return array($primary, $foreign); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | $command->bindValue(':schema', $schemaName); |
375 | 375 | // $command->bindValue(':columnIndex', join(', ', explode(' ', $columnIndex))); |
376 | 376 | $primary = array(); |
377 | - foreach($command->query() as $row) |
|
377 | + foreach ($command->query() as $row) |
|
378 | 378 | { |
379 | 379 | $primary[] = $row['attname']; |
380 | 380 | } |
@@ -392,13 +392,13 @@ discard block |
||
392 | 392 | $matches = array(); |
393 | 393 | $brackets = '\(([^\)]+)\)'; |
394 | 394 | $find = "/FOREIGN\s+KEY\s+{$brackets}\s+REFERENCES\s+([^\(]+){$brackets}/i"; |
395 | - if(preg_match($find, $src, $matches)) |
|
395 | + if (preg_match($find, $src, $matches)) |
|
396 | 396 | { |
397 | 397 | $keys = preg_split('/,\s+/', $matches[1]); |
398 | 398 | $fkeys = array(); |
399 | - foreach(preg_split('/,\s+/', $matches[3]) as $i => $fkey) |
|
399 | + foreach (preg_split('/,\s+/', $matches[3]) as $i => $fkey) |
|
400 | 400 | $fkeys[$keys[$i]] = $fkey; |
401 | - return array('table' => str_replace('"','',$matches[2]), 'keys' => $fkeys); |
|
401 | + return array('table' => str_replace('"', '', $matches[2]), 'keys' => $fkeys); |
|
402 | 402 | } |
403 | 403 | } |
404 | 404 | |
@@ -409,9 +409,9 @@ discard block |
||
409 | 409 | */ |
410 | 410 | protected function isForeignKeyColumn($columnId, $tableInfo) |
411 | 411 | { |
412 | - foreach($tableInfo->getForeignKeys() as $fk) |
|
412 | + foreach ($tableInfo->getForeignKeys() as $fk) |
|
413 | 413 | { |
414 | - if(in_array($columnId, array_keys($fk['keys']))) |
|
414 | + if (in_array($columnId, array_keys($fk['keys']))) |
|
415 | 415 | return true; |
416 | 416 | } |
417 | 417 | return false; |
@@ -423,24 +423,24 @@ discard block |
||
423 | 423 | * If not empty, the returned table names will be prefixed with the schema name. |
424 | 424 | * @return array all table names in the database. |
425 | 425 | */ |
426 | - public function findTableNames($schema='public') |
|
426 | + public function findTableNames($schema = 'public') |
|
427 | 427 | { |
428 | - if($schema==='') |
|
429 | - $schema=self::DEFAULT_SCHEMA; |
|
430 | - $sql=<<<EOD |
|
428 | + if ($schema === '') |
|
429 | + $schema = self::DEFAULT_SCHEMA; |
|
430 | + $sql = <<<EOD |
|
431 | 431 | SELECT table_name, table_schema FROM information_schema.tables |
432 | 432 | WHERE table_schema=:schema AND table_type='BASE TABLE' |
433 | 433 | EOD; |
434 | - $command=$this->getDbConnection()->createCommand($sql); |
|
435 | - $command->bindParam(':schema',$schema); |
|
436 | - $rows=$command->queryAll(); |
|
437 | - $names=array(); |
|
438 | - foreach($rows as $row) |
|
434 | + $command = $this->getDbConnection()->createCommand($sql); |
|
435 | + $command->bindParam(':schema', $schema); |
|
436 | + $rows = $command->queryAll(); |
|
437 | + $names = array(); |
|
438 | + foreach ($rows as $row) |
|
439 | 439 | { |
440 | - if($schema===self::DEFAULT_SCHEMA) |
|
441 | - $names[]=$row['table_name']; |
|
440 | + if ($schema === self::DEFAULT_SCHEMA) |
|
441 | + $names[] = $row['table_name']; |
|
442 | 442 | else |
443 | - $names[]=$row['table_schema'].'.'.$row['table_name']; |
|
443 | + $names[] = $row['table_schema'] . '.' . $row['table_name']; |
|
444 | 444 | } |
445 | 445 | return $names; |
446 | 446 | } |
@@ -240,11 +240,9 @@ discard block |
||
240 | 240 | $info['NumericPrecision'] = intval($matches[1]); |
241 | 241 | if(count($matches) > 2) |
242 | 242 | $info['NumericScale'] = intval($matches[2]); |
243 | - } |
|
244 | - else |
|
243 | + } else |
|
245 | 244 | $info['ColumnSize'] = intval($matches[1]); |
246 | - } |
|
247 | - else |
|
245 | + } else |
|
248 | 246 | $info['DbType'] = $col['type']; |
249 | 247 | |
250 | 248 | $tableInfo->Columns[$columnId] = new TPgsqlTableColumn($info); |
@@ -396,8 +394,9 @@ discard block |
||
396 | 394 | { |
397 | 395 | $keys = preg_split('/,\s+/', $matches[1]); |
398 | 396 | $fkeys = array(); |
399 | - foreach(preg_split('/,\s+/', $matches[3]) as $i => $fkey) |
|
400 | - $fkeys[$keys[$i]] = $fkey; |
|
397 | + foreach(preg_split('/,\s+/', $matches[3]) as $i => $fkey) { |
|
398 | + $fkeys[$keys[$i]] = $fkey; |
|
399 | + } |
|
401 | 400 | return array('table' => str_replace('"','',$matches[2]), 'keys' => $fkeys); |
402 | 401 | } |
403 | 402 | } |
@@ -159,6 +159,7 @@ |
||
159 | 159 | * |
160 | 160 | * |
161 | 161 | * @param string quoted table name. |
162 | + * @param string $table |
|
162 | 163 | * @return array foreign key details. |
163 | 164 | */ |
164 | 165 | protected function getForeignKeys($table) |
@@ -189,11 +189,11 @@ |
||
189 | 189 | return false; |
190 | 190 | } |
191 | 191 | |
192 | - /** |
|
193 | - * Returns all table names in the database. |
|
194 | - * @param string $schema the schema of the tables. This is not used for sqlite database. |
|
195 | - * @return array all table names in the database. |
|
196 | - */ |
|
192 | + /** |
|
193 | + * Returns all table names in the database. |
|
194 | + * @param string $schema the schema of the tables. This is not used for sqlite database. |
|
195 | + * @return array all table names in the database. |
|
196 | + */ |
|
197 | 197 | public function findTableNames($schema='') |
198 | 198 | { |
199 | 199 | $sql="SELECT DISTINCT tbl_name FROM sqlite_master WHERE tbl_name<>'sqlite_sequence'"; |
@@ -69,30 +69,30 @@ discard block |
||
69 | 69 | */ |
70 | 70 | protected function createTableInfo($tableName) |
71 | 71 | { |
72 | - $tableName = str_replace("'",'',$tableName); |
|
72 | + $tableName = str_replace("'", '', $tableName); |
|
73 | 73 | $this->getDbConnection()->setActive(true); |
74 | 74 | $table = $this->getDbConnection()->quoteString($tableName); |
75 | 75 | $sql = "PRAGMA table_info({$table})"; |
76 | 76 | $command = $this->getDbConnection()->createCommand($sql); |
77 | 77 | $foreign = $this->getForeignKeys($table); |
78 | - $index=0; |
|
79 | - $columns=array(); |
|
80 | - $primary=array(); |
|
81 | - foreach($command->query() as $col) |
|
78 | + $index = 0; |
|
79 | + $columns = array(); |
|
80 | + $primary = array(); |
|
81 | + foreach ($command->query() as $col) |
|
82 | 82 | { |
83 | 83 | $col['index'] = $index++; |
84 | 84 | $column = $this->processColumn($col, $foreign); |
85 | 85 | $columns[$col['name']] = $column; |
86 | - if($column->getIsPrimaryKey()) |
|
86 | + if ($column->getIsPrimaryKey()) |
|
87 | 87 | $primary[] = $col['name']; |
88 | 88 | } |
89 | 89 | $info['TableName'] = $tableName; |
90 | - if($this->getIsView($tableName)) |
|
90 | + if ($this->getIsView($tableName)) |
|
91 | 91 | $info['IsView'] = true; |
92 | - if(count($columns)===0) |
|
92 | + if (count($columns) === 0) |
|
93 | 93 | throw new TDbException('dbmetadata_invalid_table_view', $tableName); |
94 | 94 | $class = $this->getTableInfoClass(); |
95 | - $tableInfo = new $class($info,$primary,$foreign); |
|
95 | + $tableInfo = new $class($info, $primary, $foreign); |
|
96 | 96 | $tableInfo->getColumns()->copyFrom($columns); |
97 | 97 | return $tableInfo; |
98 | 98 | } |
@@ -119,37 +119,37 @@ discard block |
||
119 | 119 | { |
120 | 120 | $columnId = $col['name']; //use column name as column Id |
121 | 121 | |
122 | - $info['ColumnName'] = '"'.$columnId.'"'; //quote the column names! |
|
122 | + $info['ColumnName'] = '"' . $columnId . '"'; //quote the column names! |
|
123 | 123 | $info['ColumnId'] = $columnId; |
124 | 124 | $info['ColumnIndex'] = $col['index']; |
125 | 125 | |
126 | - if($col['notnull']!=='99') |
|
126 | + if ($col['notnull'] !== '99') |
|
127 | 127 | $info['AllowNull'] = true; |
128 | 128 | |
129 | - if($col['pk']==='1') |
|
129 | + if ($col['pk'] === '1') |
|
130 | 130 | $info['IsPrimaryKey'] = true; |
131 | - if($this->isForeignKeyColumn($columnId, $foreign)) |
|
131 | + if ($this->isForeignKeyColumn($columnId, $foreign)) |
|
132 | 132 | $info['IsForeignKey'] = true; |
133 | 133 | |
134 | - if($col['dflt_value']!==null) |
|
134 | + if ($col['dflt_value'] !== null) |
|
135 | 135 | $info['DefaultValue'] = $col['dflt_value']; |
136 | 136 | |
137 | 137 | $type = strtolower($col['type']); |
138 | - $info['AutoIncrement'] = $type==='integer' && $col['pk']==='1'; |
|
138 | + $info['AutoIncrement'] = $type === 'integer' && $col['pk'] === '1'; |
|
139 | 139 | |
140 | 140 | $info['DbType'] = $type; |
141 | - $match=array(); |
|
142 | - if(is_int($pos=strpos($type, '(')) && preg_match('/\((.*)\)/', $type, $match)) |
|
141 | + $match = array(); |
|
142 | + if (is_int($pos = strpos($type, '(')) && preg_match('/\((.*)\)/', $type, $match)) |
|
143 | 143 | { |
144 | 144 | $ps = explode(',', $match[1]); |
145 | - if(count($ps)===2) |
|
145 | + if (count($ps) === 2) |
|
146 | 146 | { |
147 | 147 | $info['NumericPrecision'] = intval($ps[0]); |
148 | 148 | $info['NumericScale'] = intval($ps[1]); |
149 | 149 | } |
150 | 150 | else |
151 | - $info['ColumnSize']=intval($match[1]); |
|
152 | - $info['DbType'] = substr($type,0,$pos); |
|
151 | + $info['ColumnSize'] = intval($match[1]); |
|
152 | + $info['DbType'] = substr($type, 0, $pos); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | return new TSqliteTableColumn($info); |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | $sql = "PRAGMA foreign_key_list({$table})"; |
167 | 167 | $command = $this->getDbConnection()->createCommand($sql); |
168 | 168 | $fkeys = array(); |
169 | - foreach($command->query() as $col) |
|
169 | + foreach ($command->query() as $col) |
|
170 | 170 | { |
171 | 171 | $fkeys[$col['table']]['keys'][$col['from']] = $col['to']; |
172 | 172 | $fkeys[$col['table']]['table'] = $col['table']; |
@@ -181,9 +181,9 @@ discard block |
||
181 | 181 | */ |
182 | 182 | protected function isForeignKeyColumn($columnId, $foreign) |
183 | 183 | { |
184 | - foreach($foreign as $fk) |
|
184 | + foreach ($foreign as $fk) |
|
185 | 185 | { |
186 | - if(in_array($columnId, array_keys($fk['keys']))) |
|
186 | + if (in_array($columnId, array_keys($fk['keys']))) |
|
187 | 187 | return true; |
188 | 188 | } |
189 | 189 | return false; |
@@ -194,9 +194,9 @@ discard block |
||
194 | 194 | * @param string $schema the schema of the tables. This is not used for sqlite database. |
195 | 195 | * @return array all table names in the database. |
196 | 196 | */ |
197 | - public function findTableNames($schema='') |
|
197 | + public function findTableNames($schema = '') |
|
198 | 198 | { |
199 | - $sql="SELECT DISTINCT tbl_name FROM sqlite_master WHERE tbl_name<>'sqlite_sequence'"; |
|
199 | + $sql = "SELECT DISTINCT tbl_name FROM sqlite_master WHERE tbl_name<>'sqlite_sequence'"; |
|
200 | 200 | return $this->getDbConnection()->createCommand($sql)->queryColumn(); |
201 | 201 | } |
202 | 202 | } |
203 | 203 | \ No newline at end of file |
@@ -146,8 +146,7 @@ |
||
146 | 146 | { |
147 | 147 | $info['NumericPrecision'] = intval($ps[0]); |
148 | 148 | $info['NumericScale'] = intval($ps[1]); |
149 | - } |
|
150 | - else |
|
149 | + } else |
|
151 | 150 | $info['ColumnSize']=intval($match[1]); |
152 | 151 | $info['DbType'] = substr($type,0,$pos); |
153 | 152 | } |