@@ -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; |
@@ -107,8 +107,9 @@ discard block |
||
| 107 | 107 | */ |
| 108 | 108 | public function getColumn($name) |
| 109 | 109 | { |
| 110 | - if(($column = $this->_columns->itemAt($name))!==null) |
|
| 111 | - return $column; |
|
| 110 | + if(($column = $this->_columns->itemAt($name))!==null) { |
|
| 111 | + return $column; |
|
| 112 | + } |
|
| 112 | 113 | throw new TDbException('dbtableinfo_invalid_column_name', $name, $this->getTableFullName()); |
| 113 | 114 | } |
| 114 | 115 | |
@@ -118,8 +119,9 @@ discard block |
||
| 118 | 119 | */ |
| 119 | 120 | public function getColumnNames() |
| 120 | 121 | { |
| 121 | - foreach($this->getColumns() as $column) |
|
| 122 | - $names[] = $column->getColumnName(); |
|
| 122 | + foreach($this->getColumns() as $column) { |
|
| 123 | + $names[] = $column->getColumnName(); |
|
| 124 | + } |
|
| 123 | 125 | return $names; |
| 124 | 126 | } |
| 125 | 127 | |
@@ -147,8 +149,9 @@ discard block |
||
| 147 | 149 | if($this->_lowercase===null) |
| 148 | 150 | { |
| 149 | 151 | $this->_lowercase=array(); |
| 150 | - foreach($this->getColumns()->getKeys() as $key) |
|
| 151 | - $this->_lowercase[strtolower($key)] = $key; |
|
| 152 | + foreach($this->getColumns()->getKeys() as $key) { |
|
| 153 | + $this->_lowercase[strtolower($key)] = $key; |
|
| 154 | + } |
|
| 152 | 155 | } |
| 153 | 156 | return $this->_lowercase; |
| 154 | 157 | } |
@@ -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 | } |
@@ -86,10 +86,11 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | protected function getSchemaTableName($table) |
| 88 | 88 | { |
| 89 | - if(count($parts= explode('.', str_replace('"','',$table))) > 1) |
|
| 90 | - return array($parts[0], $parts[1]); |
|
| 91 | - else |
|
| 92 | - return array($this->getDefaultSchema(),$parts[0]); |
|
| 89 | + if(count($parts= explode('.', str_replace('"','',$table))) > 1) { |
|
| 90 | + return array($parts[0], $parts[1]); |
|
| 91 | + } else { |
|
| 92 | + return array($this->getDefaultSchema(),$parts[0]); |
|
| 93 | + } |
|
| 93 | 94 | } |
| 94 | 95 | |
| 95 | 96 | /** |
@@ -145,8 +146,9 @@ discard block |
||
| 145 | 146 | $col['index'] = $index++; |
| 146 | 147 | $this->processColumn($tableInfo, $col); |
| 147 | 148 | } |
| 148 | - if($index===0) |
|
| 149 | - throw new TDbException('dbmetadata_invalid_table_view', $table); |
|
| 149 | + if($index===0) { |
|
| 150 | + throw new TDbException('dbmetadata_invalid_table_view', $table); |
|
| 151 | + } |
|
| 150 | 152 | return $tableInfo; |
| 151 | 153 | } |
| 152 | 154 | |
@@ -159,8 +161,9 @@ discard block |
||
| 159 | 161 | { |
| 160 | 162 | $info['SchemaName'] = $this->assertIdentifier($schemaName); |
| 161 | 163 | $info['TableName'] = $this->assertIdentifier($tableName); |
| 162 | - if($this->getIsView($schemaName,$tableName)) |
|
| 163 | - $info['IsView'] = true; |
|
| 164 | + if($this->getIsView($schemaName,$tableName)) { |
|
| 165 | + $info['IsView'] = true; |
|
| 166 | + } |
|
| 164 | 167 | list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName); |
| 165 | 168 | $class = $this->getTableInfoClass(); |
| 166 | 169 | return new $class($info,$primary,$foreign); |
@@ -212,17 +215,22 @@ discard block |
||
| 212 | 215 | $info['ColumnName'] = '"'.$columnId.'"'; //quote the column names! |
| 213 | 216 | $info['ColumnId'] = $columnId; |
| 214 | 217 | $info['ColumnIndex'] = $col['index']; |
| 215 | - if(!$col['attnotnull']) |
|
| 216 | - $info['AllowNull'] = true; |
|
| 217 | - if(in_array($columnId, $tableInfo->getPrimaryKeys())) |
|
| 218 | - $info['IsPrimaryKey'] = true; |
|
| 219 | - if($this->isForeignKeyColumn($columnId, $tableInfo)) |
|
| 220 | - $info['IsForeignKey'] = true; |
|
| 218 | + if(!$col['attnotnull']) { |
|
| 219 | + $info['AllowNull'] = true; |
|
| 220 | + } |
|
| 221 | + if(in_array($columnId, $tableInfo->getPrimaryKeys())) { |
|
| 222 | + $info['IsPrimaryKey'] = true; |
|
| 223 | + } |
|
| 224 | + if($this->isForeignKeyColumn($columnId, $tableInfo)) { |
|
| 225 | + $info['IsForeignKey'] = true; |
|
| 226 | + } |
|
| 221 | 227 | |
| 222 | - if($col['atttypmod'] > 0) |
|
| 223 | - $info['ColumnSize'] = $col['atttypmod'] - 4; |
|
| 224 | - if($col['atthasdef']) |
|
| 225 | - $info['DefaultValue'] = $col['adsrc']; |
|
| 228 | + if($col['atttypmod'] > 0) { |
|
| 229 | + $info['ColumnSize'] = $col['atttypmod'] - 4; |
|
| 230 | + } |
|
| 231 | + if($col['atthasdef']) { |
|
| 232 | + $info['DefaultValue'] = $col['adsrc']; |
|
| 233 | + } |
|
| 226 | 234 | if($col['attisserial'] || substr($col['adsrc'],0,8) === 'nextval(') |
| 227 | 235 | { |
| 228 | 236 | if(($sequence = $this->getSequenceName($tableInfo, $col['adsrc']))!==null) |
@@ -238,14 +246,15 @@ discard block |
||
| 238 | 246 | if($this->isPrecisionType($info['DbType'])) |
| 239 | 247 | { |
| 240 | 248 | $info['NumericPrecision'] = intval($matches[1]); |
| 241 | - if(count($matches) > 2) |
|
| 242 | - $info['NumericScale'] = intval($matches[2]); |
|
| 249 | + if(count($matches) > 2) { |
|
| 250 | + $info['NumericScale'] = intval($matches[2]); |
|
| 251 | + } |
|
| 252 | + } else { |
|
| 253 | + $info['ColumnSize'] = intval($matches[1]); |
|
| 243 | 254 | } |
| 244 | - else |
|
| 245 | - $info['ColumnSize'] = intval($matches[1]); |
|
| 255 | + } else { |
|
| 256 | + $info['DbType'] = $col['type']; |
|
| 246 | 257 | } |
| 247 | - else |
|
| 248 | - $info['DbType'] = $col['type']; |
|
| 249 | 258 | |
| 250 | 259 | $tableInfo->Columns[$columnId] = new TPgsqlTableColumn($info); |
| 251 | 260 | } |
@@ -258,10 +267,11 @@ discard block |
||
| 258 | 267 | $matches = array(); |
| 259 | 268 | if(preg_match('/nextval\([^\']*\'([^\']+)\'[^\)]*\)/i',$src,$matches)) |
| 260 | 269 | { |
| 261 | - if(is_int(strpos($matches[1], '.'))) |
|
| 262 | - return $matches[1]; |
|
| 263 | - else |
|
| 264 | - return $tableInfo->getSchemaName().'.'.$matches[1]; |
|
| 270 | + if(is_int(strpos($matches[1], '.'))) { |
|
| 271 | + return $matches[1]; |
|
| 272 | + } else { |
|
| 273 | + return $tableInfo->getSchemaName().'.'.$matches[1]; |
|
| 274 | + } |
|
| 265 | 275 | } |
| 266 | 276 | } |
| 267 | 277 | |
@@ -343,8 +353,9 @@ discard block |
||
| 343 | 353 | $primary = $this->getPrimaryKeys($tableName, $schemaName, $row['indkey']); |
| 344 | 354 | break; |
| 345 | 355 | case 'f': |
| 346 | - if(($fkey = $this->getForeignKeys($row['consrc']))!==null) |
|
| 347 | - $foreign[] = $fkey; |
|
| 356 | + if(($fkey = $this->getForeignKeys($row['consrc']))!==null) { |
|
| 357 | + $foreign[] = $fkey; |
|
| 358 | + } |
|
| 348 | 359 | break; |
| 349 | 360 | } |
| 350 | 361 | } |
@@ -396,8 +407,9 @@ discard block |
||
| 396 | 407 | { |
| 397 | 408 | $keys = preg_split('/,\s+/', $matches[1]); |
| 398 | 409 | $fkeys = array(); |
| 399 | - foreach(preg_split('/,\s+/', $matches[3]) as $i => $fkey) |
|
| 400 | - $fkeys[$keys[$i]] = $fkey; |
|
| 410 | + foreach(preg_split('/,\s+/', $matches[3]) as $i => $fkey) { |
|
| 411 | + $fkeys[$keys[$i]] = $fkey; |
|
| 412 | + } |
|
| 401 | 413 | return array('table' => str_replace('"','',$matches[2]), 'keys' => $fkeys); |
| 402 | 414 | } |
| 403 | 415 | } |
@@ -411,8 +423,9 @@ discard block |
||
| 411 | 423 | { |
| 412 | 424 | foreach($tableInfo->getForeignKeys() as $fk) |
| 413 | 425 | { |
| 414 | - if(in_array($columnId, array_keys($fk['keys']))) |
|
| 415 | - return true; |
|
| 426 | + if(in_array($columnId, array_keys($fk['keys']))) { |
|
| 427 | + return true; |
|
| 428 | + } |
|
| 416 | 429 | } |
| 417 | 430 | return false; |
| 418 | 431 | } |
@@ -425,8 +438,9 @@ discard block |
||
| 425 | 438 | */ |
| 426 | 439 | public function findTableNames($schema='public') |
| 427 | 440 | { |
| 428 | - if($schema==='') |
|
| 429 | - $schema=self::DEFAULT_SCHEMA; |
|
| 441 | + if($schema==='') { |
|
| 442 | + $schema=self::DEFAULT_SCHEMA; |
|
| 443 | + } |
|
| 430 | 444 | $sql=<<<EOD |
| 431 | 445 | SELECT table_name, table_schema FROM information_schema.tables |
| 432 | 446 | WHERE table_schema=:schema AND table_type='BASE TABLE' |
@@ -437,10 +451,11 @@ discard block |
||
| 437 | 451 | $names=array(); |
| 438 | 452 | foreach($rows as $row) |
| 439 | 453 | { |
| 440 | - if($schema===self::DEFAULT_SCHEMA) |
|
| 441 | - $names[]=$row['table_name']; |
|
| 442 | - else |
|
| 443 | - $names[]=$row['table_schema'].'.'.$row['table_name']; |
|
| 454 | + if($schema===self::DEFAULT_SCHEMA) { |
|
| 455 | + $names[]=$row['table_name']; |
|
| 456 | + } else { |
|
| 457 | + $names[]=$row['table_schema'].'.'.$row['table_name']; |
|
| 458 | + } |
|
| 444 | 459 | } |
| 445 | 460 | return $names; |
| 446 | 461 | } |
@@ -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 |
@@ -83,14 +83,17 @@ discard block |
||
| 83 | 83 | $col['index'] = $index++; |
| 84 | 84 | $column = $this->processColumn($col, $foreign); |
| 85 | 85 | $columns[$col['name']] = $column; |
| 86 | - if($column->getIsPrimaryKey()) |
|
| 87 | - $primary[] = $col['name']; |
|
| 86 | + if($column->getIsPrimaryKey()) { |
|
| 87 | + $primary[] = $col['name']; |
|
| 88 | + } |
|
| 88 | 89 | } |
| 89 | 90 | $info['TableName'] = $tableName; |
| 90 | - if($this->getIsView($tableName)) |
|
| 91 | - $info['IsView'] = true; |
|
| 92 | - if(count($columns)===0) |
|
| 93 | - throw new TDbException('dbmetadata_invalid_table_view', $tableName); |
|
| 91 | + if($this->getIsView($tableName)) { |
|
| 92 | + $info['IsView'] = true; |
|
| 93 | + } |
|
| 94 | + if(count($columns)===0) { |
|
| 95 | + throw new TDbException('dbmetadata_invalid_table_view', $tableName); |
|
| 96 | + } |
|
| 94 | 97 | $class = $this->getTableInfoClass(); |
| 95 | 98 | $tableInfo = new $class($info,$primary,$foreign); |
| 96 | 99 | $tableInfo->getColumns()->copyFrom($columns); |
@@ -123,16 +126,20 @@ discard block |
||
| 123 | 126 | $info['ColumnId'] = $columnId; |
| 124 | 127 | $info['ColumnIndex'] = $col['index']; |
| 125 | 128 | |
| 126 | - if($col['notnull']!=='99') |
|
| 127 | - $info['AllowNull'] = true; |
|
| 129 | + if($col['notnull']!=='99') { |
|
| 130 | + $info['AllowNull'] = true; |
|
| 131 | + } |
|
| 128 | 132 | |
| 129 | - if($col['pk']==='1') |
|
| 130 | - $info['IsPrimaryKey'] = true; |
|
| 131 | - if($this->isForeignKeyColumn($columnId, $foreign)) |
|
| 132 | - $info['IsForeignKey'] = true; |
|
| 133 | + if($col['pk']==='1') { |
|
| 134 | + $info['IsPrimaryKey'] = true; |
|
| 135 | + } |
|
| 136 | + if($this->isForeignKeyColumn($columnId, $foreign)) { |
|
| 137 | + $info['IsForeignKey'] = true; |
|
| 138 | + } |
|
| 133 | 139 | |
| 134 | - if($col['dflt_value']!==null) |
|
| 135 | - $info['DefaultValue'] = $col['dflt_value']; |
|
| 140 | + if($col['dflt_value']!==null) { |
|
| 141 | + $info['DefaultValue'] = $col['dflt_value']; |
|
| 142 | + } |
|
| 136 | 143 | |
| 137 | 144 | $type = strtolower($col['type']); |
| 138 | 145 | $info['AutoIncrement'] = $type==='integer' && $col['pk']==='1'; |
@@ -146,9 +153,9 @@ discard block |
||
| 146 | 153 | { |
| 147 | 154 | $info['NumericPrecision'] = intval($ps[0]); |
| 148 | 155 | $info['NumericScale'] = intval($ps[1]); |
| 156 | + } else { |
|
| 157 | + $info['ColumnSize']=intval($match[1]); |
|
| 149 | 158 | } |
| 150 | - else |
|
| 151 | - $info['ColumnSize']=intval($match[1]); |
|
| 152 | 159 | $info['DbType'] = substr($type,0,$pos); |
| 153 | 160 | } |
| 154 | 161 | |
@@ -183,8 +190,9 @@ discard block |
||
| 183 | 190 | { |
| 184 | 191 | foreach($foreign as $fk) |
| 185 | 192 | { |
| 186 | - if(in_array($columnId, array_keys($fk['keys']))) |
|
| 187 | - return true; |
|
| 193 | + if(in_array($columnId, array_keys($fk['keys']))) { |
|
| 194 | + return true; |
|
| 195 | + } |
|
| 188 | 196 | } |
| 189 | 197 | return false; |
| 190 | 198 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | /** |
| 68 | 68 | * Iterate through all the columns and returns the last insert id of the |
| 69 | 69 | * first column that has a sequence or serial. |
| 70 | - * @return mixed last insert id, null if none is found. |
|
| 70 | + * @return string|null last insert id, null if none is found. |
|
| 71 | 71 | */ |
| 72 | 72 | public function getLastInsertID() |
| 73 | 73 | { |
@@ -187,7 +187,6 @@ discard block |
||
| 187 | 187 | * array('col1' => 'NULL', '*') |
| 188 | 188 | * // SELECT `col1`, `col2`, `col3`, NULL AS `col1` FROM... |
| 189 | 189 | * </code> |
| 190 | - * @param mixed $value |
|
| 191 | 190 | * @return array of generated fields - use implode(', ', $selectfieldlist) to collapse field list for usage |
| 192 | 191 | * @since 3.1.7 |
| 193 | 192 | * @todo add support for table aliasing |
@@ -395,7 +394,7 @@ discard block |
||
| 395 | 394 | /** |
| 396 | 395 | * Returns a list of insert field name and a list of binding names. |
| 397 | 396 | * @param object array or object to be inserted. |
| 398 | - * @return array tuple ($fields, $bindings) |
|
| 397 | + * @return string[] tuple ($fields, $bindings) |
|
| 399 | 398 | */ |
| 400 | 399 | protected function getInsertFieldBindings($values) |
| 401 | 400 | { |
@@ -439,6 +438,7 @@ discard block |
||
| 439 | 438 | * Bind the name-value pairs of $values where the array keys correspond to column names. |
| 440 | 439 | * @param TDbCommand database command. |
| 441 | 440 | * @param array name-value pairs. |
| 441 | + * @param TDbCommand $command |
|
| 442 | 442 | */ |
| 443 | 443 | public function bindColumnValues($command, $values) |
| 444 | 444 | { |
@@ -455,6 +455,7 @@ discard block |
||
| 455 | 455 | /** |
| 456 | 456 | * @param TDbCommand database command |
| 457 | 457 | * @param array values for binding. |
| 458 | + * @param TDbCommand $command |
|
| 458 | 459 | */ |
| 459 | 460 | public function bindArrayValues($command, $values) |
| 460 | 461 | { |
@@ -1,13 +1,13 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * TDbCommandBuilder class 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.Common |
|
| 10 | - */ |
|
| 3 | + * TDbCommandBuilder class 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.Common |
|
| 10 | + */ |
|
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * TDbCommandBuilder provides basic methods to create query commands for tables |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * @param TDbConnection database connection. |
| 27 | 27 | * @param TDbTableInfo table information. |
| 28 | 28 | */ |
| 29 | - public function __construct($connection=null, $tableInfo=null) |
|
| 29 | + public function __construct($connection = null, $tableInfo = null) |
|
| 30 | 30 | { |
| 31 | 31 | $this->setDbConnection($connection); |
| 32 | 32 | $this->setTableInfo($tableInfo); |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function setDbConnection($value) |
| 47 | 47 | { |
| 48 | - $this->_connection=$value; |
|
| 48 | + $this->_connection = $value; |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public function setTableInfo($value) |
| 55 | 55 | { |
| 56 | - $this->_tableInfo=$value; |
|
| 56 | + $this->_tableInfo = $value; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -71,9 +71,9 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | public function getLastInsertID() |
| 73 | 73 | { |
| 74 | - foreach($this->getTableInfo()->getColumns() as $column) |
|
| 74 | + foreach ($this->getTableInfo()->getColumns() as $column) |
|
| 75 | 75 | { |
| 76 | - if($column->hasSequence()) |
|
| 76 | + if ($column->hasSequence()) |
|
| 77 | 77 | return $this->getDbConnection()->getLastInsertID($column->getSequenceName()); |
| 78 | 78 | } |
| 79 | 79 | } |
@@ -86,13 +86,13 @@ discard block |
||
| 86 | 86 | * @param integer row offset, -1 to ignore offset. |
| 87 | 87 | * @return string SQL with limit and offset. |
| 88 | 88 | */ |
| 89 | - public function applyLimitOffset($sql, $limit=-1, $offset=-1) |
|
| 89 | + public function applyLimitOffset($sql, $limit = -1, $offset = -1) |
|
| 90 | 90 | { |
| 91 | - $limit = $limit!==null ? (int)$limit : -1; |
|
| 92 | - $offset = $offset!==null ? (int)$offset : -1; |
|
| 93 | - $limitStr = $limit >= 0 ? ' LIMIT '.$limit : ''; |
|
| 94 | - $offsetStr = $offset >= 0 ? ' OFFSET '.$offset : ''; |
|
| 95 | - return $sql.$limitStr.$offsetStr; |
|
| 91 | + $limit = $limit !== null ? (int) $limit : -1; |
|
| 92 | + $offset = $offset !== null ? (int) $offset : -1; |
|
| 93 | + $limitStr = $limit >= 0 ? ' LIMIT ' . $limit : ''; |
|
| 94 | + $offsetStr = $offset >= 0 ? ' OFFSET ' . $offset : ''; |
|
| 95 | + return $sql . $limitStr . $offsetStr; |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -102,21 +102,21 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | public function applyOrdering($sql, $ordering) |
| 104 | 104 | { |
| 105 | - $orders=array(); |
|
| 106 | - foreach($ordering as $name => $direction) |
|
| 105 | + $orders = array(); |
|
| 106 | + foreach ($ordering as $name => $direction) |
|
| 107 | 107 | { |
| 108 | 108 | $direction = strtolower($direction) == 'desc' ? 'DESC' : 'ASC'; |
| 109 | - if(false !== strpos($name, '(') && false !== strpos($name, ')')) { |
|
| 109 | + if (false !== strpos($name, '(') && false !== strpos($name, ')')) { |
|
| 110 | 110 | // key is a function (bad practice, but we need to handle it) |
| 111 | 111 | $key = $name; |
| 112 | 112 | } else { |
| 113 | 113 | // key is a column |
| 114 | 114 | $key = $this->getTableInfo()->getColumn($name)->getColumnName(); |
| 115 | 115 | } |
| 116 | - $orders[] = $key.' '.$direction; |
|
| 116 | + $orders[] = $key . ' ' . $direction; |
|
| 117 | 117 | } |
| 118 | - if(count($orders) > 0) |
|
| 119 | - $sql .= ' ORDER BY '.implode(', ', $orders); |
|
| 118 | + if (count($orders) > 0) |
|
| 119 | + $sql .= ' ORDER BY ' . implode(', ', $orders); |
|
| 120 | 120 | return $sql; |
| 121 | 121 | } |
| 122 | 122 | |
@@ -130,15 +130,15 @@ discard block |
||
| 130 | 130 | */ |
| 131 | 131 | public function getSearchExpression($fields, $keywords) |
| 132 | 132 | { |
| 133 | - if(strlen(trim($keywords)) == 0) return ''; |
|
| 133 | + if (strlen(trim($keywords)) == 0) return ''; |
|
| 134 | 134 | $words = preg_split('/\s/u', $keywords); |
| 135 | 135 | $conditions = array(); |
| 136 | - foreach($fields as $field) |
|
| 136 | + foreach ($fields as $field) |
|
| 137 | 137 | { |
| 138 | 138 | $column = $this->getTableInfo()->getColumn($field)->getColumnName(); |
| 139 | 139 | $conditions[] = $this->getSearchCondition($column, $words); |
| 140 | 140 | } |
| 141 | - return '('.implode(' OR ', $conditions).')'; |
|
| 141 | + return '(' . implode(' OR ', $conditions) . ')'; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -148,10 +148,10 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | protected function getSearchCondition($column, $words) |
| 150 | 150 | { |
| 151 | - $conditions=array(); |
|
| 152 | - foreach($words as $word) |
|
| 153 | - $conditions[] = $column.' LIKE '.$this->getDbConnection()->quoteString('%'.$word.'%'); |
|
| 154 | - return '('.implode(' AND ', $conditions).')'; |
|
| 151 | + $conditions = array(); |
|
| 152 | + foreach ($words as $word) |
|
| 153 | + $conditions[] = $column . ' LIKE ' . $this->getDbConnection()->quoteString('%' . $word . '%'); |
|
| 154 | + return '(' . implode(' AND ', $conditions) . ')'; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -193,103 +193,103 @@ discard block |
||
| 193 | 193 | * @todo add support for table aliasing |
| 194 | 194 | * @todo add support for quoting of column aliasing |
| 195 | 195 | */ |
| 196 | - public function getSelectFieldList($data='*') { |
|
| 197 | - if(is_scalar($data)) { |
|
| 196 | + public function getSelectFieldList($data = '*') { |
|
| 197 | + if (is_scalar($data)) { |
|
| 198 | 198 | $tmp = explode(',', $data); |
| 199 | 199 | $result = array(); |
| 200 | - foreach($tmp as $v) |
|
| 200 | + foreach ($tmp as $v) |
|
| 201 | 201 | $result[] = trim($v); |
| 202 | 202 | return $result; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | $bHasWildcard = false; |
| 206 | 206 | $result = array(); |
| 207 | - if(is_array($data) || $data instanceof Traversable) { |
|
| 207 | + if (is_array($data) || $data instanceof Traversable) { |
|
| 208 | 208 | $columns = $this->getTableInfo()->getColumns(); |
| 209 | - foreach($data as $key=>$value) { |
|
| 210 | - if($key==='*' || $value==='*') { |
|
| 209 | + foreach ($data as $key=>$value) { |
|
| 210 | + if ($key === '*' || $value === '*') { |
|
| 211 | 211 | $bHasWildcard = true; |
| 212 | 212 | continue; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - if(strToUpper($key)==='NULL') { |
|
| 215 | + if (strToUpper($key) === 'NULL') { |
|
| 216 | 216 | $result[] = 'NULL'; |
| 217 | 217 | continue; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - if(strpos($key, '(')!==false && strpos($key, ')')!==false) { |
|
| 220 | + if (strpos($key, '(') !== false && strpos($key, ')') !== false) { |
|
| 221 | 221 | $result[] = $key; |
| 222 | 222 | continue; |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - if(stripos($key, 'AS')!==false) { |
|
| 225 | + if (stripos($key, 'AS') !== false) { |
|
| 226 | 226 | $result[] = $key; |
| 227 | 227 | continue; |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - if(stripos($value, 'AS')!==false) { |
|
| 230 | + if (stripos($value, 'AS') !== false) { |
|
| 231 | 231 | $result[] = $value; |
| 232 | 232 | continue; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | $v = isset($columns[$value]); |
| 236 | 236 | $k = isset($columns[$key]); |
| 237 | - if(is_integer($key) && $v) { |
|
| 237 | + if (is_integer($key) && $v) { |
|
| 238 | 238 | $key = $value; |
| 239 | 239 | $k = $v; |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - if(strToUpper($value)==='NULL') { |
|
| 243 | - if($k) |
|
| 242 | + if (strToUpper($value) === 'NULL') { |
|
| 243 | + if ($k) |
|
| 244 | 244 | $result[] = 'NULL AS ' . $columns[$key]->getColumnName(); |
| 245 | 245 | else |
| 246 | - $result[] = 'NULL' . (is_string($key) ? (' AS ' . (string)$key) : ''); |
|
| 246 | + $result[] = 'NULL' . (is_string($key) ? (' AS ' . (string) $key) : ''); |
|
| 247 | 247 | continue; |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - if(strpos($value, '(')!==false && strpos($value, ')')!==false) { |
|
| 251 | - if($k) |
|
| 250 | + if (strpos($value, '(') !== false && strpos($value, ')') !== false) { |
|
| 251 | + if ($k) |
|
| 252 | 252 | $result[] = $value . ' AS ' . $columns[$key]->getColumnName(); |
| 253 | 253 | else |
| 254 | - $result[] = $value . (is_string($key) ? (' AS ' . (string)$key) : ''); |
|
| 254 | + $result[] = $value . (is_string($key) ? (' AS ' . (string) $key) : ''); |
|
| 255 | 255 | continue; |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - if($v && $key==$value) { |
|
| 258 | + if ($v && $key == $value) { |
|
| 259 | 259 | $result[] = $columns[$value]->getColumnName(); |
| 260 | 260 | continue; |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - if($k && $value==null) { |
|
| 263 | + if ($k && $value == null) { |
|
| 264 | 264 | $result[] = $columns[$key]->getColumnName(); |
| 265 | 265 | continue; |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - if(is_string($key) && $v) { |
|
| 268 | + if (is_string($key) && $v) { |
|
| 269 | 269 | $result[] = $columns[$value]->getColumnName() . ' AS ' . $key; |
| 270 | 270 | continue; |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - if(is_numeric($value) && $k) { |
|
| 273 | + if (is_numeric($value) && $k) { |
|
| 274 | 274 | $result[] = $value . ' AS ' . $columns[$key]->getColumnName(); |
| 275 | 275 | continue; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - if(is_string($value) && $k) { |
|
| 278 | + if (is_string($value) && $k) { |
|
| 279 | 279 | $result[] = $this->getDbConnection()->quoteString($value) . ' AS ' . $columns[$key]->getColumnName(); |
| 280 | 280 | continue; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - if(!$v && !$k && is_integer($key)) { |
|
| 284 | - $result[] = is_numeric($value) ? $value : $this->getDbConnection()->quoteString((string)$value); |
|
| 283 | + if (!$v && !$k && is_integer($key)) { |
|
| 284 | + $result[] = is_numeric($value) ? $value : $this->getDbConnection()->quoteString((string) $value); |
|
| 285 | 285 | continue; |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - $result[] = (is_numeric($value) ? $value : $this->getDbConnection()->quoteString((string)$value)) . ' AS ' . $key; |
|
| 288 | + $result[] = (is_numeric($value) ? $value : $this->getDbConnection()->quoteString((string) $value)) . ' AS ' . $key; |
|
| 289 | 289 | } |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - if($data===null || count($result) == 0 || $bHasWildcard) |
|
| 292 | + if ($data === null || count($result) == 0 || $bHasWildcard) |
|
| 293 | 293 | $result = $result = array_merge($this->getTableInfo()->getColumnNames(), $result); |
| 294 | 294 | |
| 295 | 295 | return $result; |
@@ -302,21 +302,21 @@ discard block |
||
| 302 | 302 | * @param array condition parameters. |
| 303 | 303 | * @return TDbCommand query command. |
| 304 | 304 | */ |
| 305 | - public function createFindCommand($where='1=1', $parameters=array(), $ordering=array(), $limit=-1, $offset=-1, $select='*') |
|
| 305 | + public function createFindCommand($where = '1=1', $parameters = array(), $ordering = array(), $limit = -1, $offset = -1, $select = '*') |
|
| 306 | 306 | { |
| 307 | 307 | $table = $this->getTableInfo()->getTableFullName(); |
| 308 | 308 | $fields = implode(', ', $this -> getSelectFieldList($select)); |
| 309 | 309 | $sql = "SELECT {$fields} FROM {$table}"; |
| 310 | - if(!empty($where)) |
|
| 310 | + if (!empty($where)) |
|
| 311 | 311 | $sql .= " WHERE {$where}"; |
| 312 | 312 | return $this->applyCriterias($sql, $parameters, $ordering, $limit, $offset); |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - public function applyCriterias($sql, $parameters=array(),$ordering=array(), $limit=-1, $offset=-1) |
|
| 315 | + public function applyCriterias($sql, $parameters = array(), $ordering = array(), $limit = -1, $offset = -1) |
|
| 316 | 316 | { |
| 317 | - if(count($ordering) > 0) |
|
| 317 | + if (count($ordering) > 0) |
|
| 318 | 318 | $sql = $this->applyOrdering($sql, $ordering); |
| 319 | - if($limit>=0 || $offset>=0) |
|
| 319 | + if ($limit >= 0 || $offset >= 0) |
|
| 320 | 320 | $sql = $this->applyLimitOffset($sql, $limit, $offset); |
| 321 | 321 | $command = $this->createCommand($sql); |
| 322 | 322 | $this->bindArrayValues($command, $parameters); |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | * @param array binding parameters. |
| 330 | 330 | * @return TDbCommand count command. |
| 331 | 331 | */ |
| 332 | - public function createCountCommand($where='1=1', $parameters=array(),$ordering=array(), $limit=-1, $offset=-1) |
|
| 332 | + public function createCountCommand($where = '1=1', $parameters = array(), $ordering = array(), $limit = -1, $offset = -1) |
|
| 333 | 333 | { |
| 334 | 334 | return $this->createFindCommand($where, $parameters, $ordering, $limit, $offset, 'COUNT(*)'); |
| 335 | 335 | } |
@@ -342,12 +342,12 @@ discard block |
||
| 342 | 342 | * @param array delete parameters. |
| 343 | 343 | * @return TDbCommand delete command. |
| 344 | 344 | */ |
| 345 | - public function createDeleteCommand($where,$parameters=array()) |
|
| 345 | + public function createDeleteCommand($where, $parameters = array()) |
|
| 346 | 346 | { |
| 347 | 347 | $table = $this->getTableInfo()->getTableFullName(); |
| 348 | 348 | if (!empty($where)) |
| 349 | - $where = ' WHERE '.$where; |
|
| 350 | - $command = $this->createCommand("DELETE FROM {$table}".$where); |
|
| 349 | + $where = ' WHERE ' . $where; |
|
| 350 | + $command = $this->createCommand("DELETE FROM {$table}" . $where); |
|
| 351 | 351 | $this->bindArrayValues($command, $parameters); |
| 352 | 352 | return $command; |
| 353 | 353 | } |
@@ -377,17 +377,17 @@ discard block |
||
| 377 | 377 | * @param array update parameters. |
| 378 | 378 | * @return TDbCommand update command. |
| 379 | 379 | */ |
| 380 | - public function createUpdateCommand($data, $where, $parameters=array()) |
|
| 380 | + public function createUpdateCommand($data, $where, $parameters = array()) |
|
| 381 | 381 | { |
| 382 | 382 | $table = $this->getTableInfo()->getTableFullName(); |
| 383 | - if($this->hasIntegerKey($parameters)) |
|
| 383 | + if ($this->hasIntegerKey($parameters)) |
|
| 384 | 384 | $fields = implode(', ', $this->getColumnBindings($data, true)); |
| 385 | 385 | else |
| 386 | 386 | $fields = implode(', ', $this->getColumnBindings($data)); |
| 387 | 387 | |
| 388 | 388 | if (!empty($where)) |
| 389 | - $where = ' WHERE '.$where; |
|
| 390 | - $command = $this->createCommand("UPDATE {$table} SET {$fields}".$where); |
|
| 389 | + $where = ' WHERE ' . $where; |
|
| 390 | + $command = $this->createCommand("UPDATE {$table} SET {$fields}" . $where); |
|
| 391 | 391 | $this->bindArrayValues($command, array_merge($data, $parameters)); |
| 392 | 392 | return $command; |
| 393 | 393 | } |
@@ -399,13 +399,13 @@ discard block |
||
| 399 | 399 | */ |
| 400 | 400 | protected function getInsertFieldBindings($values) |
| 401 | 401 | { |
| 402 | - $fields = array(); $bindings=array(); |
|
| 403 | - foreach(array_keys($values) as $name) |
|
| 402 | + $fields = array(); $bindings = array(); |
|
| 403 | + foreach (array_keys($values) as $name) |
|
| 404 | 404 | { |
| 405 | 405 | $fields[] = $this->getTableInfo()->getColumn($name)->getColumnName(); |
| 406 | - $bindings[] = ':'.$name; |
|
| 406 | + $bindings[] = ':' . $name; |
|
| 407 | 407 | } |
| 408 | - return array(implode(', ',$fields), implode(', ', $bindings)); |
|
| 408 | + return array(implode(', ', $fields), implode(', ', $bindings)); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /** |
@@ -414,13 +414,13 @@ discard block |
||
| 414 | 414 | * @param boolean true to bind as position values. |
| 415 | 415 | * @return string update column names with corresponding binding substrings. |
| 416 | 416 | */ |
| 417 | - protected function getColumnBindings($values, $position=false) |
|
| 417 | + protected function getColumnBindings($values, $position = false) |
|
| 418 | 418 | { |
| 419 | - $bindings=array(); |
|
| 420 | - foreach(array_keys($values) as $name) |
|
| 419 | + $bindings = array(); |
|
| 420 | + foreach (array_keys($values) as $name) |
|
| 421 | 421 | { |
| 422 | 422 | $column = $this->getTableInfo()->getColumn($name)->getColumnName(); |
| 423 | - $bindings[] = $position ? $column.' = ?' : $column.' = :'.$name; |
|
| 423 | + $bindings[] = $position ? $column . ' = ?' : $column . ' = :' . $name; |
|
| 424 | 424 | } |
| 425 | 425 | return $bindings; |
| 426 | 426 | } |
@@ -442,13 +442,13 @@ discard block |
||
| 442 | 442 | */ |
| 443 | 443 | public function bindColumnValues($command, $values) |
| 444 | 444 | { |
| 445 | - foreach($values as $name=>$value) |
|
| 445 | + foreach ($values as $name=>$value) |
|
| 446 | 446 | { |
| 447 | 447 | $column = $this->getTableInfo()->getColumn($name); |
| 448 | - if($value === null && $column->getAllowNull()) |
|
| 449 | - $command->bindValue(':'.$name, null, PDO::PARAM_NULL); |
|
| 448 | + if ($value === null && $column->getAllowNull()) |
|
| 449 | + $command->bindValue(':' . $name, null, PDO::PARAM_NULL); |
|
| 450 | 450 | else |
| 451 | - $command->bindValue(':'.$name, $value, $column->getPdoType()); |
|
| 451 | + $command->bindValue(':' . $name, $value, $column->getPdoType()); |
|
| 452 | 452 | } |
| 453 | 453 | } |
| 454 | 454 | |
@@ -458,17 +458,17 @@ discard block |
||
| 458 | 458 | */ |
| 459 | 459 | public function bindArrayValues($command, $values) |
| 460 | 460 | { |
| 461 | - if($this->hasIntegerKey($values)) |
|
| 461 | + if ($this->hasIntegerKey($values)) |
|
| 462 | 462 | { |
| 463 | 463 | $values = array_values($values); |
| 464 | - for($i = 0, $max=count($values); $i<$max; $i++) |
|
| 465 | - $command->bindValue($i+1, $values[$i], $this->getPdoType($values[$i])); |
|
| 464 | + for ($i = 0, $max = count($values); $i < $max; $i++) |
|
| 465 | + $command->bindValue($i + 1, $values[$i], $this->getPdoType($values[$i])); |
|
| 466 | 466 | } |
| 467 | 467 | else |
| 468 | 468 | { |
| 469 | - foreach($values as $name=>$value) |
|
| 469 | + foreach ($values as $name=>$value) |
|
| 470 | 470 | { |
| 471 | - $prop = $name[0]===':' ? $name : ':'.$name; |
|
| 471 | + $prop = $name[0] === ':' ? $name : ':' . $name; |
|
| 472 | 472 | $command->bindValue($prop, $value, $this->getPdoType($value)); |
| 473 | 473 | } |
| 474 | 474 | } |
@@ -480,7 +480,7 @@ discard block |
||
| 480 | 480 | */ |
| 481 | 481 | public static function getPdoType($value) |
| 482 | 482 | { |
| 483 | - switch(gettype($value)) |
|
| 483 | + switch (gettype($value)) |
|
| 484 | 484 | { |
| 485 | 485 | case 'boolean': return PDO::PARAM_BOOL; |
| 486 | 486 | case 'integer': return PDO::PARAM_INT; |
@@ -495,9 +495,9 @@ discard block |
||
| 495 | 495 | */ |
| 496 | 496 | protected function hasIntegerKey($array) |
| 497 | 497 | { |
| 498 | - foreach($array as $k=>$v) |
|
| 498 | + foreach ($array as $k=>$v) |
|
| 499 | 499 | { |
| 500 | - if(gettype($k)==='integer') |
|
| 500 | + if (gettype($k) === 'integer') |
|
| 501 | 501 | return true; |
| 502 | 502 | } |
| 503 | 503 | return false; |
@@ -73,8 +73,9 @@ discard block |
||
| 73 | 73 | { |
| 74 | 74 | foreach($this->getTableInfo()->getColumns() as $column) |
| 75 | 75 | { |
| 76 | - if($column->hasSequence()) |
|
| 77 | - return $this->getDbConnection()->getLastInsertID($column->getSequenceName()); |
|
| 76 | + if($column->hasSequence()) { |
|
| 77 | + return $this->getDbConnection()->getLastInsertID($column->getSequenceName()); |
|
| 78 | + } |
|
| 78 | 79 | } |
| 79 | 80 | } |
| 80 | 81 | |
@@ -115,8 +116,9 @@ discard block |
||
| 115 | 116 | } |
| 116 | 117 | $orders[] = $key.' '.$direction; |
| 117 | 118 | } |
| 118 | - if(count($orders) > 0) |
|
| 119 | - $sql .= ' ORDER BY '.implode(', ', $orders); |
|
| 119 | + if(count($orders) > 0) { |
|
| 120 | + $sql .= ' ORDER BY '.implode(', ', $orders); |
|
| 121 | + } |
|
| 120 | 122 | return $sql; |
| 121 | 123 | } |
| 122 | 124 | |
@@ -130,7 +132,9 @@ discard block |
||
| 130 | 132 | */ |
| 131 | 133 | public function getSearchExpression($fields, $keywords) |
| 132 | 134 | { |
| 133 | - if(strlen(trim($keywords)) == 0) return ''; |
|
| 135 | + if(strlen(trim($keywords)) == 0) { |
|
| 136 | + return ''; |
|
| 137 | + } |
|
| 134 | 138 | $words = preg_split('/\s/u', $keywords); |
| 135 | 139 | $conditions = array(); |
| 136 | 140 | foreach($fields as $field) |
@@ -149,8 +153,9 @@ discard block |
||
| 149 | 153 | protected function getSearchCondition($column, $words) |
| 150 | 154 | { |
| 151 | 155 | $conditions=array(); |
| 152 | - foreach($words as $word) |
|
| 153 | - $conditions[] = $column.' LIKE '.$this->getDbConnection()->quoteString('%'.$word.'%'); |
|
| 156 | + foreach($words as $word) { |
|
| 157 | + $conditions[] = $column.' LIKE '.$this->getDbConnection()->quoteString('%'.$word.'%'); |
|
| 158 | + } |
|
| 154 | 159 | return '('.implode(' AND ', $conditions).')'; |
| 155 | 160 | } |
| 156 | 161 | |
@@ -197,8 +202,9 @@ discard block |
||
| 197 | 202 | if(is_scalar($data)) { |
| 198 | 203 | $tmp = explode(',', $data); |
| 199 | 204 | $result = array(); |
| 200 | - foreach($tmp as $v) |
|
| 201 | - $result[] = trim($v); |
|
| 205 | + foreach($tmp as $v) { |
|
| 206 | + $result[] = trim($v); |
|
| 207 | + } |
|
| 202 | 208 | return $result; |
| 203 | 209 | } |
| 204 | 210 | |
@@ -240,18 +246,20 @@ discard block |
||
| 240 | 246 | } |
| 241 | 247 | |
| 242 | 248 | if(strToUpper($value)==='NULL') { |
| 243 | - if($k) |
|
| 244 | - $result[] = 'NULL AS ' . $columns[$key]->getColumnName(); |
|
| 245 | - else |
|
| 246 | - $result[] = 'NULL' . (is_string($key) ? (' AS ' . (string)$key) : ''); |
|
| 249 | + if($k) { |
|
| 250 | + $result[] = 'NULL AS ' . $columns[$key]->getColumnName(); |
|
| 251 | + } else { |
|
| 252 | + $result[] = 'NULL' . (is_string($key) ? (' AS ' . (string)$key) : ''); |
|
| 253 | + } |
|
| 247 | 254 | continue; |
| 248 | 255 | } |
| 249 | 256 | |
| 250 | 257 | if(strpos($value, '(')!==false && strpos($value, ')')!==false) { |
| 251 | - if($k) |
|
| 252 | - $result[] = $value . ' AS ' . $columns[$key]->getColumnName(); |
|
| 253 | - else |
|
| 254 | - $result[] = $value . (is_string($key) ? (' AS ' . (string)$key) : ''); |
|
| 258 | + if($k) { |
|
| 259 | + $result[] = $value . ' AS ' . $columns[$key]->getColumnName(); |
|
| 260 | + } else { |
|
| 261 | + $result[] = $value . (is_string($key) ? (' AS ' . (string)$key) : ''); |
|
| 262 | + } |
|
| 255 | 263 | continue; |
| 256 | 264 | } |
| 257 | 265 | |
@@ -289,8 +297,9 @@ discard block |
||
| 289 | 297 | } |
| 290 | 298 | } |
| 291 | 299 | |
| 292 | - if($data===null || count($result) == 0 || $bHasWildcard) |
|
| 293 | - $result = $result = array_merge($this->getTableInfo()->getColumnNames(), $result); |
|
| 300 | + if($data===null || count($result) == 0 || $bHasWildcard) { |
|
| 301 | + $result = $result = array_merge($this->getTableInfo()->getColumnNames(), $result); |
|
| 302 | + } |
|
| 294 | 303 | |
| 295 | 304 | return $result; |
| 296 | 305 | } |
@@ -307,17 +316,20 @@ discard block |
||
| 307 | 316 | $table = $this->getTableInfo()->getTableFullName(); |
| 308 | 317 | $fields = implode(', ', $this -> getSelectFieldList($select)); |
| 309 | 318 | $sql = "SELECT {$fields} FROM {$table}"; |
| 310 | - if(!empty($where)) |
|
| 311 | - $sql .= " WHERE {$where}"; |
|
| 319 | + if(!empty($where)) { |
|
| 320 | + $sql .= " WHERE {$where}"; |
|
| 321 | + } |
|
| 312 | 322 | return $this->applyCriterias($sql, $parameters, $ordering, $limit, $offset); |
| 313 | 323 | } |
| 314 | 324 | |
| 315 | 325 | public function applyCriterias($sql, $parameters=array(),$ordering=array(), $limit=-1, $offset=-1) |
| 316 | 326 | { |
| 317 | - if(count($ordering) > 0) |
|
| 318 | - $sql = $this->applyOrdering($sql, $ordering); |
|
| 319 | - if($limit>=0 || $offset>=0) |
|
| 320 | - $sql = $this->applyLimitOffset($sql, $limit, $offset); |
|
| 327 | + if(count($ordering) > 0) { |
|
| 328 | + $sql = $this->applyOrdering($sql, $ordering); |
|
| 329 | + } |
|
| 330 | + if($limit>=0 || $offset>=0) { |
|
| 331 | + $sql = $this->applyLimitOffset($sql, $limit, $offset); |
|
| 332 | + } |
|
| 321 | 333 | $command = $this->createCommand($sql); |
| 322 | 334 | $this->bindArrayValues($command, $parameters); |
| 323 | 335 | return $command; |
@@ -345,8 +357,9 @@ discard block |
||
| 345 | 357 | public function createDeleteCommand($where,$parameters=array()) |
| 346 | 358 | { |
| 347 | 359 | $table = $this->getTableInfo()->getTableFullName(); |
| 348 | - if (!empty($where)) |
|
| 349 | - $where = ' WHERE '.$where; |
|
| 360 | + if (!empty($where)) { |
|
| 361 | + $where = ' WHERE '.$where; |
|
| 362 | + } |
|
| 350 | 363 | $command = $this->createCommand("DELETE FROM {$table}".$where); |
| 351 | 364 | $this->bindArrayValues($command, $parameters); |
| 352 | 365 | return $command; |
@@ -380,13 +393,15 @@ discard block |
||
| 380 | 393 | public function createUpdateCommand($data, $where, $parameters=array()) |
| 381 | 394 | { |
| 382 | 395 | $table = $this->getTableInfo()->getTableFullName(); |
| 383 | - if($this->hasIntegerKey($parameters)) |
|
| 384 | - $fields = implode(', ', $this->getColumnBindings($data, true)); |
|
| 385 | - else |
|
| 386 | - $fields = implode(', ', $this->getColumnBindings($data)); |
|
| 396 | + if($this->hasIntegerKey($parameters)) { |
|
| 397 | + $fields = implode(', ', $this->getColumnBindings($data, true)); |
|
| 398 | + } else { |
|
| 399 | + $fields = implode(', ', $this->getColumnBindings($data)); |
|
| 400 | + } |
|
| 387 | 401 | |
| 388 | - if (!empty($where)) |
|
| 389 | - $where = ' WHERE '.$where; |
|
| 402 | + if (!empty($where)) { |
|
| 403 | + $where = ' WHERE '.$where; |
|
| 404 | + } |
|
| 390 | 405 | $command = $this->createCommand("UPDATE {$table} SET {$fields}".$where); |
| 391 | 406 | $this->bindArrayValues($command, array_merge($data, $parameters)); |
| 392 | 407 | return $command; |
@@ -445,10 +460,11 @@ discard block |
||
| 445 | 460 | foreach($values as $name=>$value) |
| 446 | 461 | { |
| 447 | 462 | $column = $this->getTableInfo()->getColumn($name); |
| 448 | - if($value === null && $column->getAllowNull()) |
|
| 449 | - $command->bindValue(':'.$name, null, PDO::PARAM_NULL); |
|
| 450 | - else |
|
| 451 | - $command->bindValue(':'.$name, $value, $column->getPdoType()); |
|
| 463 | + if($value === null && $column->getAllowNull()) { |
|
| 464 | + $command->bindValue(':'.$name, null, PDO::PARAM_NULL); |
|
| 465 | + } else { |
|
| 466 | + $command->bindValue(':'.$name, $value, $column->getPdoType()); |
|
| 467 | + } |
|
| 452 | 468 | } |
| 453 | 469 | } |
| 454 | 470 | |
@@ -461,10 +477,10 @@ discard block |
||
| 461 | 477 | if($this->hasIntegerKey($values)) |
| 462 | 478 | { |
| 463 | 479 | $values = array_values($values); |
| 464 | - for($i = 0, $max=count($values); $i<$max; $i++) |
|
| 465 | - $command->bindValue($i+1, $values[$i], $this->getPdoType($values[$i])); |
|
| 466 | - } |
|
| 467 | - else |
|
| 480 | + for($i = 0, $max=count($values); $i<$max; $i++) { |
|
| 481 | + $command->bindValue($i+1, $values[$i], $this->getPdoType($values[$i])); |
|
| 482 | + } |
|
| 483 | + } else |
|
| 468 | 484 | { |
| 469 | 485 | foreach($values as $name=>$value) |
| 470 | 486 | { |
@@ -497,8 +513,9 @@ discard block |
||
| 497 | 513 | { |
| 498 | 514 | foreach($array as $k=>$v) |
| 499 | 515 | { |
| 500 | - if(gettype($k)==='integer') |
|
| 501 | - return true; |
|
| 516 | + if(gettype($k)==='integer') { |
|
| 517 | + return true; |
|
| 518 | + } |
|
| 502 | 519 | } |
| 503 | 520 | return false; |
| 504 | 521 | } |
@@ -127,8 +127,6 @@ discard block |
||
| 127 | 127 | /** |
| 128 | 128 | * Quotes a table name for use in a query. |
| 129 | 129 | * @param string $name table name |
| 130 | - * @param string $lft left delimiter |
|
| 131 | - * @param string $rgt right delimiter |
|
| 132 | 130 | * @return string the properly quoted table name |
| 133 | 131 | */ |
| 134 | 132 | public function quoteTableName($name) |
@@ -150,8 +148,6 @@ discard block |
||
| 150 | 148 | /** |
| 151 | 149 | * Quotes a column name for use in a query. |
| 152 | 150 | * @param string $name column name |
| 153 | - * @param string $lft left delimiter |
|
| 154 | - * @param string $rgt right delimiter |
|
| 155 | 151 | * @return string the properly quoted column name |
| 156 | 152 | */ |
| 157 | 153 | public function quoteColumnName($name) |
@@ -166,8 +162,6 @@ discard block |
||
| 166 | 162 | /** |
| 167 | 163 | * Quotes a column alias for use in a query. |
| 168 | 164 | * @param string $name column alias |
| 169 | - * @param string $lft left delimiter |
|
| 170 | - * @param string $rgt right delimiter |
|
| 171 | 165 | * @return string the properly quoted column alias |
| 172 | 166 | */ |
| 173 | 167 | public function quoteColumnAlias($name) |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | abstract class TDbMetaData extends TComponent |
| 23 | 23 | { |
| 24 | - private $_tableInfoCache=array(); |
|
| 24 | + private $_tableInfoCache = array(); |
|
| 25 | 25 | private $_connection; |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | public function __construct($conn) |
| 36 | 36 | { |
| 37 | - $this->_connection=$conn; |
|
| 37 | + $this->_connection = $conn; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | { |
| 55 | 55 | $conn->setActive(true); //must be connected before retrieving driver name |
| 56 | 56 | $driver = $conn->getDriverName(); |
| 57 | - switch(strtolower($driver)) |
|
| 57 | + switch (strtolower($driver)) |
|
| 58 | 58 | { |
| 59 | 59 | case 'pgsql': |
| 60 | 60 | Prado::using('System.Data.Common.Pgsql.TPgsqlMetaData'); |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | // Prado::using('System.Data.Common.IbmDb2.TIbmDb2MetaData'); |
| 80 | 80 | // return new TIbmDb2MetaData($conn); |
| 81 | 81 | default: |
| 82 | - throw new TDbException('ar_invalid_database_driver',$driver); |
|
| 82 | + throw new TDbException('ar_invalid_database_driver', $driver); |
|
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | |
@@ -88,13 +88,13 @@ discard block |
||
| 88 | 88 | * @param string table or view name |
| 89 | 89 | * @return TDbTableInfo table information. |
| 90 | 90 | */ |
| 91 | - public function getTableInfo($tableName=null) |
|
| 91 | + public function getTableInfo($tableName = null) |
|
| 92 | 92 | { |
| 93 | - $key = $tableName===null?$this->getDbConnection()->getConnectionString():$tableName; |
|
| 94 | - if(!isset($this->_tableInfoCache[$key])) |
|
| 93 | + $key = $tableName === null ? $this->getDbConnection()->getConnectionString() : $tableName; |
|
| 94 | + if (!isset($this->_tableInfoCache[$key])) |
|
| 95 | 95 | { |
| 96 | 96 | $class = $this->getTableInfoClass(); |
| 97 | - $tableInfo = $tableName===null ? new $class : $this->createTableInfo($tableName); |
|
| 97 | + $tableInfo = $tableName === null ? new $class : $this->createTableInfo($tableName); |
|
| 98 | 98 | $this->_tableInfoCache[$key] = $tableInfo; |
| 99 | 99 | } |
| 100 | 100 | return $this->_tableInfoCache[$key]; |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * @param string table name. |
| 106 | 106 | * @return TDbCommandBuilder command builder instance for the given table. |
| 107 | 107 | */ |
| 108 | - public function createCommandBuilder($tableName=null) |
|
| 108 | + public function createCommandBuilder($tableName = null) |
|
| 109 | 109 | { |
| 110 | 110 | return $this->getTableInfo($tableName)->createCommandBuilder($this->getDbConnection()); |
| 111 | 111 | } |
@@ -139,10 +139,10 @@ discard block |
||
| 139 | 139 | $rgt = $lft = isset($args[1]) ? $args[1] : ''; |
| 140 | 140 | $rgt = isset($args[2]) ? $args[2] : $rgt; |
| 141 | 141 | |
| 142 | - if(strpos($name, '.')===false) |
|
| 142 | + if (strpos($name, '.') === false) |
|
| 143 | 143 | return $lft . $name . $rgt; |
| 144 | - $names=explode('.', $name); |
|
| 145 | - foreach($names as &$n) |
|
| 144 | + $names = explode('.', $name); |
|
| 145 | + foreach ($names as &$n) |
|
| 146 | 146 | $n = $lft . $n . $rgt; |
| 147 | 147 | return implode('.', $names); |
| 148 | 148 | } |
@@ -187,6 +187,6 @@ discard block |
||
| 187 | 187 | * If not empty, the returned table names will be prefixed with the schema name. |
| 188 | 188 | * @return array all table names in the database. |
| 189 | 189 | */ |
| 190 | - abstract public function findTableNames($schema=''); |
|
| 190 | + abstract public function findTableNames($schema = ''); |
|
| 191 | 191 | } |
| 192 | 192 | |
@@ -139,11 +139,13 @@ |
||
| 139 | 139 | $rgt = $lft = isset($args[1]) ? $args[1] : ''; |
| 140 | 140 | $rgt = isset($args[2]) ? $args[2] : $rgt; |
| 141 | 141 | |
| 142 | - if(strpos($name, '.')===false) |
|
| 143 | - return $lft . $name . $rgt; |
|
| 142 | + if(strpos($name, '.')===false) { |
|
| 143 | + return $lft . $name . $rgt; |
|
| 144 | + } |
|
| 144 | 145 | $names=explode('.', $name); |
| 145 | - foreach($names as &$n) |
|
| 146 | - $n = $lft . $n . $rgt; |
|
| 146 | + foreach($names as &$n) { |
|
| 147 | + $n = $lft . $n . $rgt; |
|
| 148 | + } |
|
| 147 | 149 | return implode('.', $names); |
| 148 | 150 | } |
| 149 | 151 | |
@@ -1,13 +1,13 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * TDbMetaData class 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.Common |
|
| 10 | - */ |
|
| 3 | + * TDbMetaData class 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.Common |
|
| 10 | + */ |
|
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * TDbMetaData is the base class for retrieving metadata information, such as |
@@ -179,14 +179,14 @@ discard block |
||
| 179 | 179 | return $lft . str_replace(self::$delimiterIdentifier, '', $name) . $rgt; |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * Returns all table names in the database. |
|
| 184 | - * This method should be overridden by child classes in order to support this feature |
|
| 185 | - * because the default implementation simply throws an exception. |
|
| 186 | - * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema. |
|
| 187 | - * If not empty, the returned table names will be prefixed with the schema name. |
|
| 188 | - * @return array all table names in the database. |
|
| 189 | - */ |
|
| 182 | + /** |
|
| 183 | + * Returns all table names in the database. |
|
| 184 | + * This method should be overridden by child classes in order to support this feature |
|
| 185 | + * because the default implementation simply throws an exception. |
|
| 186 | + * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema. |
|
| 187 | + * If not empty, the returned table names will be prefixed with the schema name. |
|
| 188 | + * @return array all table names in the database. |
|
| 189 | + */ |
|
| 190 | 190 | abstract public function findTableNames($schema=''); |
| 191 | 191 | } |
| 192 | 192 | |
@@ -47,6 +47,7 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * @param TDbConnection database connection. |
| 50 | + * @param TDbConnection $connection |
|
| 50 | 51 | * @return TDbCommandBuilder new command builder |
| 51 | 52 | */ |
| 52 | 53 | public function createCommandBuilder($connection) |
@@ -58,6 +59,8 @@ discard block |
||
| 58 | 59 | /** |
| 59 | 60 | * @param string information array key name |
| 60 | 61 | * @param mixed default value if information array value is null |
| 62 | + * @param string $name |
|
| 63 | + * @param boolean $default |
|
| 61 | 64 | * @return mixed information array value. |
| 62 | 65 | */ |
| 63 | 66 | protected function getInfo($name,$default=null) |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | class TDbTableInfo extends TComponent |
| 20 | 20 | { |
| 21 | - private $_info=array(); |
|
| 21 | + private $_info = array(); |
|
| 22 | 22 | |
| 23 | 23 | private $_primaryKeys; |
| 24 | 24 | private $_foreignKeys; |
@@ -37,12 +37,12 @@ discard block |
||
| 37 | 37 | * Sets the database table meta data information. |
| 38 | 38 | * @param array table column information. |
| 39 | 39 | */ |
| 40 | - public function __construct($tableInfo=array(),$primary=array(),$foreign=array()) |
|
| 40 | + public function __construct($tableInfo = array(), $primary = array(), $foreign = array()) |
|
| 41 | 41 | { |
| 42 | - $this->_info=$tableInfo; |
|
| 43 | - $this->_primaryKeys=$primary; |
|
| 44 | - $this->_foreignKeys=$foreign; |
|
| 45 | - $this->_columns=new TMap; |
|
| 42 | + $this->_info = $tableInfo; |
|
| 43 | + $this->_primaryKeys = $primary; |
|
| 44 | + $this->_foreignKeys = $foreign; |
|
| 45 | + $this->_columns = new TMap; |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | public function createCommandBuilder($connection) |
| 53 | 53 | { |
| 54 | 54 | Prado::using('System.Data.Common.TDbCommandBuilder'); |
| 55 | - return new TDbCommandBuilder($connection,$this); |
|
| 55 | + return new TDbCommandBuilder($connection, $this); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @param mixed default value if information array value is null |
| 61 | 61 | * @return mixed information array value. |
| 62 | 62 | */ |
| 63 | - protected function getInfo($name,$default=null) |
|
| 63 | + protected function getInfo($name, $default = null) |
|
| 64 | 64 | { |
| 65 | 65 | return isset($this->_info[$name]) ? $this->_info[$name] : $default; |
| 66 | 66 | } |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | * @param string information array key name |
| 70 | 70 | * @param mixed new information array value. |
| 71 | 71 | */ |
| 72 | - protected function setInfo($name,$value) |
|
| 72 | + protected function setInfo($name, $value) |
|
| 73 | 73 | { |
| 74 | - $this->_info[$name]=$value; |
|
| 74 | + $this->_info[$name] = $value; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | public function getIsView() |
| 97 | 97 | { |
| 98 | - return $this->getInfo('IsView',false); |
|
| 98 | + return $this->getInfo('IsView', false); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | public function getColumn($name) |
| 114 | 114 | { |
| 115 | - if(($column = $this->_columns->itemAt($name))!==null) |
|
| 115 | + if (($column = $this->_columns->itemAt($name)) !== null) |
|
| 116 | 116 | return $column; |
| 117 | 117 | throw new TDbException('dbtableinfo_invalid_column_name', $name, $this->getTableFullName()); |
| 118 | 118 | } |
@@ -123,10 +123,10 @@ discard block |
||
| 123 | 123 | */ |
| 124 | 124 | public function getColumnNames() |
| 125 | 125 | { |
| 126 | - if($this->_names===null) |
|
| 126 | + if ($this->_names === null) |
|
| 127 | 127 | { |
| 128 | - $this->_names=array(); |
|
| 129 | - foreach($this->getColumns() as $column) |
|
| 128 | + $this->_names = array(); |
|
| 129 | + foreach ($this->getColumns() as $column) |
|
| 130 | 130 | $this->_names[] = $column->getColumnName(); |
| 131 | 131 | } |
| 132 | 132 | return $this->_names; |
@@ -153,10 +153,10 @@ discard block |
||
| 153 | 153 | */ |
| 154 | 154 | public function getLowerCaseColumnNames() |
| 155 | 155 | { |
| 156 | - if($this->_lowercase===null) |
|
| 156 | + if ($this->_lowercase === null) |
|
| 157 | 157 | { |
| 158 | - $this->_lowercase=array(); |
|
| 159 | - foreach($this->getColumns()->getKeys() as $key) |
|
| 158 | + $this->_lowercase = array(); |
|
| 159 | + foreach ($this->getColumns()->getKeys() as $key) |
|
| 160 | 160 | $this->_lowercase[strtolower($key)] = $key; |
| 161 | 161 | } |
| 162 | 162 | return $this->_lowercase; |
@@ -112,8 +112,9 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | public function getColumn($name) |
| 114 | 114 | { |
| 115 | - if(($column = $this->_columns->itemAt($name))!==null) |
|
| 116 | - return $column; |
|
| 115 | + if(($column = $this->_columns->itemAt($name))!==null) { |
|
| 116 | + return $column; |
|
| 117 | + } |
|
| 117 | 118 | throw new TDbException('dbtableinfo_invalid_column_name', $name, $this->getTableFullName()); |
| 118 | 119 | } |
| 119 | 120 | |
@@ -126,8 +127,9 @@ discard block |
||
| 126 | 127 | if($this->_names===null) |
| 127 | 128 | { |
| 128 | 129 | $this->_names=array(); |
| 129 | - foreach($this->getColumns() as $column) |
|
| 130 | - $this->_names[] = $column->getColumnName(); |
|
| 130 | + foreach($this->getColumns() as $column) { |
|
| 131 | + $this->_names[] = $column->getColumnName(); |
|
| 132 | + } |
|
| 131 | 133 | } |
| 132 | 134 | return $this->_names; |
| 133 | 135 | } |
@@ -156,8 +158,9 @@ discard block |
||
| 156 | 158 | if($this->_lowercase===null) |
| 157 | 159 | { |
| 158 | 160 | $this->_lowercase=array(); |
| 159 | - foreach($this->getColumns()->getKeys() as $key) |
|
| 160 | - $this->_lowercase[strtolower($key)] = $key; |
|
| 161 | + foreach($this->getColumns()->getKeys() as $key) { |
|
| 162 | + $this->_lowercase[strtolower($key)] = $key; |
|
| 163 | + } |
|
| 161 | 164 | } |
| 162 | 165 | return $this->_lowercase; |
| 163 | 166 | } |
@@ -89,6 +89,7 @@ discard block |
||
| 89 | 89 | * Updates the table with new data. |
| 90 | 90 | * @param array date for update. |
| 91 | 91 | * @param TSqlCriteria update conditions and parameters. |
| 92 | + * @param TSqlCriteria $criteria |
|
| 92 | 93 | * @return integer number of records affected. |
| 93 | 94 | */ |
| 94 | 95 | public function update($data, $criteria) |
@@ -207,6 +208,9 @@ discard block |
||
| 207 | 208 | return $this->onExecuteCommand($command,$command->execute()); |
| 208 | 209 | } |
| 209 | 210 | |
| 211 | + /** |
|
| 212 | + * @param TDbTableInfo $table |
|
| 213 | + */ |
|
| 210 | 214 | public function getIndexKeyCondition($table,$fields,$values) |
| 211 | 215 | { |
| 212 | 216 | if (!count($values)) |
@@ -351,7 +355,7 @@ discard block |
||
| 351 | 355 | * Inserts a new record into the table. Each array key must |
| 352 | 356 | * correspond to a column name in the table unless a null value is permitted. |
| 353 | 357 | * @param array new record data. |
| 354 | - * @return mixed last insert id if one column contains a serial or sequence, |
|
| 358 | + * @return string|boolean last insert id if one column contains a serial or sequence, |
|
| 355 | 359 | * otherwise true if command executes successfully and affected 1 or more rows. |
| 356 | 360 | */ |
| 357 | 361 | public function insert($data) |
@@ -370,7 +374,7 @@ discard block |
||
| 370 | 374 | /** |
| 371 | 375 | * Iterate through all the columns and returns the last insert id of the |
| 372 | 376 | * first column that has a sequence or serial. |
| 373 | - * @return mixed last insert id, null if none is found. |
|
| 377 | + * @return string|null last insert id, null if none is found. |
|
| 374 | 378 | */ |
| 375 | 379 | public function getLastInsertID() |
| 376 | 380 | { |
@@ -381,6 +385,7 @@ discard block |
||
| 381 | 385 | * @param string __call method name |
| 382 | 386 | * @param string criteria conditions |
| 383 | 387 | * @param array method arguments |
| 388 | + * @param string $condition |
|
| 384 | 389 | * @return TActiveRecordCriteria criteria created from the method name and its arguments. |
| 385 | 390 | */ |
| 386 | 391 | public function createCriteriaFromString($method, $condition, $args) |
@@ -434,6 +439,7 @@ discard block |
||
| 434 | 439 | * inspected to obtain the sql query to be executed. |
| 435 | 440 | * @param TDataGatewayCommand originator $sender |
| 436 | 441 | * @param TDataGatewayEventParameter |
| 442 | + * @param TDbCommand $command |
|
| 437 | 443 | */ |
| 438 | 444 | public function onCreateCommand($command, $criteria) |
| 439 | 445 | { |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | $where = $criteria->getCondition(); |
| 81 | 81 | $parameters = $criteria->getParameters()->toArray(); |
| 82 | 82 | $command = $this->getBuilder()->createDeleteCommand($where, $parameters); |
| 83 | - $this->onCreateCommand($command,$criteria); |
|
| 83 | + $this->onCreateCommand($command, $criteria); |
|
| 84 | 84 | $command->prepare(); |
| 85 | 85 | return $command->execute(); |
| 86 | 86 | } |
@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | { |
| 96 | 96 | $where = $criteria->getCondition(); |
| 97 | 97 | $parameters = $criteria->getParameters()->toArray(); |
| 98 | - $command = $this->getBuilder()->createUpdateCommand($data,$where, $parameters); |
|
| 99 | - $this->onCreateCommand($command,$criteria); |
|
| 98 | + $command = $this->getBuilder()->createUpdateCommand($data, $where, $parameters); |
|
| 99 | + $this->onCreateCommand($command, $criteria); |
|
| 100 | 100 | $command->prepare(); |
| 101 | 101 | return $this->onExecuteCommand($command, $command->execute()); |
| 102 | 102 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | public function updateByPk($data, $keys) |
| 110 | 110 | { |
| 111 | - list($where, $parameters) = $this->getPrimaryKeyCondition((array)$keys); |
|
| 111 | + list($where, $parameters) = $this->getPrimaryKeyCondition((array) $keys); |
|
| 112 | 112 | return $this->update($data, new TSqlCriteria($where, $parameters)); |
| 113 | 113 | } |
| 114 | 114 | |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | protected function getFindCommand($criteria) |
| 143 | 143 | { |
| 144 | - if($criteria===null) |
|
| 144 | + if ($criteria === null) |
|
| 145 | 145 | return $this->getBuilder()->createFindCommand(); |
| 146 | 146 | $where = $criteria->getCondition(); |
| 147 | 147 | $parameters = $criteria->getParameters()->toArray(); |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | $limit = $criteria->getLimit(); |
| 150 | 150 | $offset = $criteria->getOffset(); |
| 151 | 151 | $select = $criteria->getSelect(); |
| 152 | - $command = $this->getBuilder()->createFindCommand($where,$parameters,$ordering,$limit,$offset,$select); |
|
| 152 | + $command = $this->getBuilder()->createFindCommand($where, $parameters, $ordering, $limit, $offset, $select); |
|
| 153 | 153 | $this->onCreateCommand($command, $criteria); |
| 154 | 154 | return $command; |
| 155 | 155 | } |
@@ -160,11 +160,11 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | public function findByPk($keys) |
| 162 | 162 | { |
| 163 | - if($keys===null) |
|
| 163 | + if ($keys === null) |
|
| 164 | 164 | return null; |
| 165 | - list($where, $parameters) = $this->getPrimaryKeyCondition((array)$keys); |
|
| 165 | + list($where, $parameters) = $this->getPrimaryKeyCondition((array) $keys); |
|
| 166 | 166 | $command = $this->getBuilder()->createFindCommand($where, $parameters); |
| 167 | - $this->onCreateCommand($command, new TSqlCriteria($where,$parameters)); |
|
| 167 | + $this->onCreateCommand($command, new TSqlCriteria($where, $parameters)); |
|
| 168 | 168 | return $this->onExecuteCommand($command, $command->queryRow()); |
| 169 | 169 | } |
| 170 | 170 | |
@@ -174,22 +174,22 @@ discard block |
||
| 174 | 174 | */ |
| 175 | 175 | public function findAllByPk($keys) |
| 176 | 176 | { |
| 177 | - $where = $this->getCompositeKeyCondition((array)$keys); |
|
| 177 | + $where = $this->getCompositeKeyCondition((array) $keys); |
|
| 178 | 178 | $command = $this->getBuilder()->createFindCommand($where); |
| 179 | - $this->onCreateCommand($command, new TSqlCriteria($where,$keys)); |
|
| 180 | - return $this->onExecuteCommand($command,$command->query()); |
|
| 179 | + $this->onCreateCommand($command, new TSqlCriteria($where, $keys)); |
|
| 180 | + return $this->onExecuteCommand($command, $command->query()); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - public function findAllByIndex($criteria,$fields,$values) |
|
| 183 | + public function findAllByIndex($criteria, $fields, $values) |
|
| 184 | 184 | { |
| 185 | - $index = $this->getIndexKeyCondition($this->getTableInfo(),$fields,$values); |
|
| 186 | - if(strlen($where = $criteria->getCondition())>0) |
|
| 185 | + $index = $this->getIndexKeyCondition($this->getTableInfo(), $fields, $values); |
|
| 186 | + if (strlen($where = $criteria->getCondition()) > 0) |
|
| 187 | 187 | $criteria->setCondition("({$index}) AND ({$where})"); |
| 188 | 188 | else |
| 189 | 189 | $criteria->setCondition($index); |
| 190 | 190 | $command = $this->getFindCommand($criteria); |
| 191 | 191 | $this->onCreateCommand($command, $criteria); |
| 192 | - return $this->onExecuteCommand($command,$command->query()); |
|
| 192 | + return $this->onExecuteCommand($command, $command->query()); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -198,24 +198,24 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | public function deleteByPk($keys) |
| 200 | 200 | { |
| 201 | - if(count($keys)==0) |
|
| 201 | + if (count($keys) == 0) |
|
| 202 | 202 | return 0; |
| 203 | - $where = $this->getCompositeKeyCondition((array)$keys); |
|
| 203 | + $where = $this->getCompositeKeyCondition((array) $keys); |
|
| 204 | 204 | $command = $this->getBuilder()->createDeleteCommand($where); |
| 205 | - $this->onCreateCommand($command, new TSqlCriteria($where,$keys)); |
|
| 205 | + $this->onCreateCommand($command, new TSqlCriteria($where, $keys)); |
|
| 206 | 206 | $command->prepare(); |
| 207 | - return $this->onExecuteCommand($command,$command->execute()); |
|
| 207 | + return $this->onExecuteCommand($command, $command->execute()); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - public function getIndexKeyCondition($table,$fields,$values) |
|
| 210 | + public function getIndexKeyCondition($table, $fields, $values) |
|
| 211 | 211 | { |
| 212 | 212 | if (!count($values)) |
| 213 | 213 | return 'FALSE'; |
| 214 | 214 | $columns = array(); |
| 215 | 215 | $tableName = $table->getTableFullName(); |
| 216 | - foreach($fields as $field) |
|
| 217 | - $columns[] = $tableName.'.'.$table->getColumn($field)->getColumnName(); |
|
| 218 | - return '('.implode(', ',$columns).') IN '.$this->quoteTuple($values); |
|
| 216 | + foreach ($fields as $field) |
|
| 217 | + $columns[] = $tableName . '.' . $table->getColumn($field)->getColumnName(); |
|
| 218 | + return '(' . implode(', ', $columns) . ') IN ' . $this->quoteTuple($values); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -227,24 +227,24 @@ discard block |
||
| 227 | 227 | { |
| 228 | 228 | $primary = $this->getTableInfo()->getPrimaryKeys(); |
| 229 | 229 | $count = count($primary); |
| 230 | - if($count===0) |
|
| 230 | + if ($count === 0) |
|
| 231 | 231 | { |
| 232 | 232 | throw new TDbException('dbtablegateway_no_primary_key_found', |
| 233 | 233 | $this->getTableInfo()->getTableFullName()); |
| 234 | 234 | } |
| 235 | - if(!is_array($values) || count($values) === 0) |
|
| 235 | + if (!is_array($values) || count($values) === 0) |
|
| 236 | 236 | { |
| 237 | 237 | throw new TDbException('dbtablegateway_missing_pk_values', |
| 238 | 238 | $this->getTableInfo()->getTableFullName()); |
| 239 | 239 | } |
| 240 | - if($count>1 && (!isset($values[0]) || !is_array($values[0]))) |
|
| 240 | + if ($count > 1 && (!isset($values[0]) || !is_array($values[0]))) |
|
| 241 | 241 | $values = array($values); |
| 242 | - if($count > 1 && count($values[0]) !== $count) |
|
| 242 | + if ($count > 1 && count($values[0]) !== $count) |
|
| 243 | 243 | { |
| 244 | 244 | throw new TDbException('dbtablegateway_pk_value_count_mismatch', |
| 245 | 245 | $this->getTableInfo()->getTableFullName()); |
| 246 | 246 | } |
| 247 | - return $this->getIndexKeyCondition($this->getTableInfo(),$primary, $values); |
|
| 247 | + return $this->getIndexKeyCondition($this->getTableInfo(), $primary, $values); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | /** |
@@ -256,9 +256,9 @@ discard block |
||
| 256 | 256 | { |
| 257 | 257 | $conn = $this->getDbConnection(); |
| 258 | 258 | $data = array(); |
| 259 | - foreach($array as $k=>$v) |
|
| 259 | + foreach ($array as $k=>$v) |
|
| 260 | 260 | $data[] = is_array($v) ? $this->quoteTuple($v) : $conn->quoteString($v); |
| 261 | - return '('.implode(', ', $data).')'; |
|
| 261 | + return '(' . implode(', ', $data) . ')'; |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -269,19 +269,19 @@ discard block |
||
| 269 | 269 | protected function getPrimaryKeyCondition($values) |
| 270 | 270 | { |
| 271 | 271 | $primary = $this->getTableInfo()->getPrimaryKeys(); |
| 272 | - if(count($primary)===0) |
|
| 272 | + if (count($primary) === 0) |
|
| 273 | 273 | { |
| 274 | 274 | throw new TDbException('dbtablegateway_no_primary_key_found', |
| 275 | 275 | $this->getTableInfo()->getTableFullName()); |
| 276 | 276 | } |
| 277 | - $criteria=array(); |
|
| 278 | - $bindings=array(); |
|
| 277 | + $criteria = array(); |
|
| 278 | + $bindings = array(); |
|
| 279 | 279 | $i = 0; |
| 280 | - foreach($primary as $key) |
|
| 280 | + foreach ($primary as $key) |
|
| 281 | 281 | { |
| 282 | 282 | $column = $this->getTableInfo()->getColumn($key)->getColumnName(); |
| 283 | - $criteria[] = $column.' = :'.$key; |
|
| 284 | - $bindings[$key] = isset($values[$key])?$values[$key]:$values[$i++]; |
|
| 283 | + $criteria[] = $column . ' = :' . $key; |
|
| 284 | + $bindings[$key] = isset($values[$key]) ? $values[$key] : $values[$i++]; |
|
| 285 | 285 | } |
| 286 | 286 | return array(implode(' AND ', $criteria), $bindings); |
| 287 | 287 | } |
@@ -319,9 +319,9 @@ discard block |
||
| 319 | 319 | $ordering = $criteria->getOrdersBy(); |
| 320 | 320 | $limit = $criteria->getLimit(); |
| 321 | 321 | $offset = $criteria->getOffset(); |
| 322 | - if(count($ordering) > 0) |
|
| 322 | + if (count($ordering) > 0) |
|
| 323 | 323 | $sql = $this->getBuilder()->applyOrdering($sql, $ordering); |
| 324 | - if($limit>=0 || $offset>=0) |
|
| 324 | + if ($limit >= 0 || $offset >= 0) |
|
| 325 | 325 | $sql = $this->getBuilder()->applyLimitOffset($sql, $limit, $offset); |
| 326 | 326 | $command = $this->getBuilder()->createCommand($sql); |
| 327 | 327 | $this->getBuilder()->bindArrayValues($command, $criteria->getParameters()->toArray()); |
@@ -335,16 +335,16 @@ discard block |
||
| 335 | 335 | */ |
| 336 | 336 | public function count($criteria) |
| 337 | 337 | { |
| 338 | - if($criteria===null) |
|
| 339 | - return (int)$this->getBuilder()->createCountCommand()->queryScalar(); |
|
| 338 | + if ($criteria === null) |
|
| 339 | + return (int) $this->getBuilder()->createCountCommand()->queryScalar(); |
|
| 340 | 340 | $where = $criteria->getCondition(); |
| 341 | 341 | $parameters = $criteria->getParameters()->toArray(); |
| 342 | 342 | $ordering = $criteria->getOrdersBy(); |
| 343 | 343 | $limit = $criteria->getLimit(); |
| 344 | 344 | $offset = $criteria->getOffset(); |
| 345 | - $command = $this->getBuilder()->createCountCommand($where,$parameters,$ordering,$limit,$offset); |
|
| 345 | + $command = $this->getBuilder()->createCountCommand($where, $parameters, $ordering, $limit, $offset); |
|
| 346 | 346 | $this->onCreateCommand($command, $criteria); |
| 347 | - return $this->onExecuteCommand($command, (int)$command->queryScalar()); |
|
| 347 | + return $this->onExecuteCommand($command, (int) $command->queryScalar()); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
@@ -356,10 +356,10 @@ discard block |
||
| 356 | 356 | */ |
| 357 | 357 | public function insert($data) |
| 358 | 358 | { |
| 359 | - $command=$this->getBuilder()->createInsertCommand($data); |
|
| 360 | - $this->onCreateCommand($command, new TSqlCriteria(null,$data)); |
|
| 359 | + $command = $this->getBuilder()->createInsertCommand($data); |
|
| 360 | + $this->onCreateCommand($command, new TSqlCriteria(null, $data)); |
|
| 361 | 361 | $command->prepare(); |
| 362 | - if($this->onExecuteCommand($command, $command->execute()) > 0) |
|
| 362 | + if ($this->onExecuteCommand($command, $command->execute()) > 0) |
|
| 363 | 363 | { |
| 364 | 364 | $value = $this->getLastInsertId(); |
| 365 | 365 | return $value !== null ? $value : true; |
@@ -386,13 +386,13 @@ discard block |
||
| 386 | 386 | public function createCriteriaFromString($method, $condition, $args) |
| 387 | 387 | { |
| 388 | 388 | $fields = $this->extractMatchingConditions($method, $condition); |
| 389 | - $args=count($args) === 1 && is_array($args[0]) ? $args[0] : $args; |
|
| 390 | - if(count($fields)>count($args)) |
|
| 389 | + $args = count($args) === 1 && is_array($args[0]) ? $args[0] : $args; |
|
| 390 | + if (count($fields) > count($args)) |
|
| 391 | 391 | { |
| 392 | 392 | throw new TDbException('dbtablegateway_mismatch_args_exception', |
| 393 | - $method,count($fields),count($args)); |
|
| 393 | + $method, count($fields), count($args)); |
|
| 394 | 394 | } |
| 395 | - return new TSqlCriteria(implode(' ',$fields), $args); |
|
| 395 | + return new TSqlCriteria(implode(' ', $fields), $args); |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | /** |
@@ -406,21 +406,21 @@ discard block |
||
| 406 | 406 | { |
| 407 | 407 | $table = $this->getTableInfo(); |
| 408 | 408 | $columns = $table->getLowerCaseColumnNames(); |
| 409 | - $regexp = '/('.implode('|', array_keys($columns)).')(and|_and_|or|_or_)?/i'; |
|
| 409 | + $regexp = '/(' . implode('|', array_keys($columns)) . ')(and|_and_|or|_or_)?/i'; |
|
| 410 | 410 | $matches = array(); |
| 411 | - if(!preg_match_all($regexp, strtolower($condition), $matches,PREG_SET_ORDER)) |
|
| 411 | + if (!preg_match_all($regexp, strtolower($condition), $matches, PREG_SET_ORDER)) |
|
| 412 | 412 | { |
| 413 | 413 | throw new TDbException('dbtablegateway_mismatch_column_name', |
| 414 | 414 | $method, implode(', ', $columns), $table->getTableFullName()); |
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | $fields = array(); |
| 418 | - foreach($matches as $match) |
|
| 418 | + foreach ($matches as $match) |
|
| 419 | 419 | { |
| 420 | 420 | $key = $columns[$match[1]]; |
| 421 | 421 | $column = $table->getColumn($key)->getColumnName(); |
| 422 | 422 | $sql = $column . ' = ? '; |
| 423 | - if(count($match) > 2) |
|
| 423 | + if (count($match) > 2) |
|
| 424 | 424 | $sql .= strtoupper(str_replace('_', '', $match[2])); |
| 425 | 425 | $fields[] = $sql; |
| 426 | 426 | } |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | */ |
| 438 | 438 | public function onCreateCommand($command, $criteria) |
| 439 | 439 | { |
| 440 | - $this->raiseEvent('OnCreateCommand', $this, new TDataGatewayEventParameter($command,$criteria)); |
|
| 440 | + $this->raiseEvent('OnCreateCommand', $this, new TDataGatewayEventParameter($command, $criteria)); |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | /** |
@@ -471,10 +471,10 @@ discard block |
||
| 471 | 471 | private $_command; |
| 472 | 472 | private $_criteria; |
| 473 | 473 | |
| 474 | - public function __construct($command,$criteria) |
|
| 474 | + public function __construct($command, $criteria) |
|
| 475 | 475 | { |
| 476 | - $this->_command=$command; |
|
| 477 | - $this->_criteria=$criteria; |
|
| 476 | + $this->_command = $command; |
|
| 477 | + $this->_criteria = $criteria; |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | /** |
@@ -511,10 +511,10 @@ discard block |
||
| 511 | 511 | private $_command; |
| 512 | 512 | private $_result; |
| 513 | 513 | |
| 514 | - public function __construct($command,$result) |
|
| 514 | + public function __construct($command, $result) |
|
| 515 | 515 | { |
| 516 | - $this->_command=$command; |
|
| 517 | - $this->_result=$result; |
|
| 516 | + $this->_command = $command; |
|
| 517 | + $this->_result = $result; |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | */ |
| 539 | 539 | public function setResult($value) |
| 540 | 540 | { |
| 541 | - $this->_result=$value; |
|
| 541 | + $this->_result = $value; |
|
| 542 | 542 | } |
| 543 | 543 | } |
| 544 | 544 | |
@@ -141,8 +141,9 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | protected function getFindCommand($criteria) |
| 143 | 143 | { |
| 144 | - if($criteria===null) |
|
| 145 | - return $this->getBuilder()->createFindCommand(); |
|
| 144 | + if($criteria===null) { |
|
| 145 | + return $this->getBuilder()->createFindCommand(); |
|
| 146 | + } |
|
| 146 | 147 | $where = $criteria->getCondition(); |
| 147 | 148 | $parameters = $criteria->getParameters()->toArray(); |
| 148 | 149 | $ordering = $criteria->getOrdersBy(); |
@@ -160,8 +161,9 @@ discard block |
||
| 160 | 161 | */ |
| 161 | 162 | public function findByPk($keys) |
| 162 | 163 | { |
| 163 | - if($keys===null) |
|
| 164 | - return null; |
|
| 164 | + if($keys===null) { |
|
| 165 | + return null; |
|
| 166 | + } |
|
| 165 | 167 | list($where, $parameters) = $this->getPrimaryKeyCondition((array)$keys); |
| 166 | 168 | $command = $this->getBuilder()->createFindCommand($where, $parameters); |
| 167 | 169 | $this->onCreateCommand($command, new TSqlCriteria($where,$parameters)); |
@@ -183,10 +185,11 @@ discard block |
||
| 183 | 185 | public function findAllByIndex($criteria,$fields,$values) |
| 184 | 186 | { |
| 185 | 187 | $index = $this->getIndexKeyCondition($this->getTableInfo(),$fields,$values); |
| 186 | - if(strlen($where = $criteria->getCondition())>0) |
|
| 187 | - $criteria->setCondition("({$index}) AND ({$where})"); |
|
| 188 | - else |
|
| 189 | - $criteria->setCondition($index); |
|
| 188 | + if(strlen($where = $criteria->getCondition())>0) { |
|
| 189 | + $criteria->setCondition("({$index}) AND ({$where})"); |
|
| 190 | + } else { |
|
| 191 | + $criteria->setCondition($index); |
|
| 192 | + } |
|
| 190 | 193 | $command = $this->getFindCommand($criteria); |
| 191 | 194 | $this->onCreateCommand($command, $criteria); |
| 192 | 195 | return $this->onExecuteCommand($command,$command->query()); |
@@ -198,8 +201,9 @@ discard block |
||
| 198 | 201 | */ |
| 199 | 202 | public function deleteByPk($keys) |
| 200 | 203 | { |
| 201 | - if(count($keys)==0) |
|
| 202 | - return 0; |
|
| 204 | + if(count($keys)==0) { |
|
| 205 | + return 0; |
|
| 206 | + } |
|
| 203 | 207 | $where = $this->getCompositeKeyCondition((array)$keys); |
| 204 | 208 | $command = $this->getBuilder()->createDeleteCommand($where); |
| 205 | 209 | $this->onCreateCommand($command, new TSqlCriteria($where,$keys)); |
@@ -209,12 +213,14 @@ discard block |
||
| 209 | 213 | |
| 210 | 214 | public function getIndexKeyCondition($table,$fields,$values) |
| 211 | 215 | { |
| 212 | - if (!count($values)) |
|
| 213 | - return 'FALSE'; |
|
| 216 | + if (!count($values)) { |
|
| 217 | + return 'FALSE'; |
|
| 218 | + } |
|
| 214 | 219 | $columns = array(); |
| 215 | 220 | $tableName = $table->getTableFullName(); |
| 216 | - foreach($fields as $field) |
|
| 217 | - $columns[] = $tableName.'.'.$table->getColumn($field)->getColumnName(); |
|
| 221 | + foreach($fields as $field) { |
|
| 222 | + $columns[] = $tableName.'.'.$table->getColumn($field)->getColumnName(); |
|
| 223 | + } |
|
| 218 | 224 | return '('.implode(', ',$columns).') IN '.$this->quoteTuple($values); |
| 219 | 225 | } |
| 220 | 226 | |
@@ -237,8 +243,9 @@ discard block |
||
| 237 | 243 | throw new TDbException('dbtablegateway_missing_pk_values', |
| 238 | 244 | $this->getTableInfo()->getTableFullName()); |
| 239 | 245 | } |
| 240 | - if($count>1 && (!isset($values[0]) || !is_array($values[0]))) |
|
| 241 | - $values = array($values); |
|
| 246 | + if($count>1 && (!isset($values[0]) || !is_array($values[0]))) { |
|
| 247 | + $values = array($values); |
|
| 248 | + } |
|
| 242 | 249 | if($count > 1 && count($values[0]) !== $count) |
| 243 | 250 | { |
| 244 | 251 | throw new TDbException('dbtablegateway_pk_value_count_mismatch', |
@@ -256,8 +263,9 @@ discard block |
||
| 256 | 263 | { |
| 257 | 264 | $conn = $this->getDbConnection(); |
| 258 | 265 | $data = array(); |
| 259 | - foreach($array as $k=>$v) |
|
| 260 | - $data[] = is_array($v) ? $this->quoteTuple($v) : $conn->quoteString($v); |
|
| 266 | + foreach($array as $k=>$v) { |
|
| 267 | + $data[] = is_array($v) ? $this->quoteTuple($v) : $conn->quoteString($v); |
|
| 268 | + } |
|
| 261 | 269 | return '('.implode(', ', $data).')'; |
| 262 | 270 | } |
| 263 | 271 | |
@@ -319,10 +327,12 @@ discard block |
||
| 319 | 327 | $ordering = $criteria->getOrdersBy(); |
| 320 | 328 | $limit = $criteria->getLimit(); |
| 321 | 329 | $offset = $criteria->getOffset(); |
| 322 | - if(count($ordering) > 0) |
|
| 323 | - $sql = $this->getBuilder()->applyOrdering($sql, $ordering); |
|
| 324 | - if($limit>=0 || $offset>=0) |
|
| 325 | - $sql = $this->getBuilder()->applyLimitOffset($sql, $limit, $offset); |
|
| 330 | + if(count($ordering) > 0) { |
|
| 331 | + $sql = $this->getBuilder()->applyOrdering($sql, $ordering); |
|
| 332 | + } |
|
| 333 | + if($limit>=0 || $offset>=0) { |
|
| 334 | + $sql = $this->getBuilder()->applyLimitOffset($sql, $limit, $offset); |
|
| 335 | + } |
|
| 326 | 336 | $command = $this->getBuilder()->createCommand($sql); |
| 327 | 337 | $this->getBuilder()->bindArrayValues($command, $criteria->getParameters()->toArray()); |
| 328 | 338 | $this->onCreateCommand($command, $criteria); |
@@ -335,8 +345,9 @@ discard block |
||
| 335 | 345 | */ |
| 336 | 346 | public function count($criteria) |
| 337 | 347 | { |
| 338 | - if($criteria===null) |
|
| 339 | - return (int)$this->getBuilder()->createCountCommand()->queryScalar(); |
|
| 348 | + if($criteria===null) { |
|
| 349 | + return (int)$this->getBuilder()->createCountCommand()->queryScalar(); |
|
| 350 | + } |
|
| 340 | 351 | $where = $criteria->getCondition(); |
| 341 | 352 | $parameters = $criteria->getParameters()->toArray(); |
| 342 | 353 | $ordering = $criteria->getOrdersBy(); |
@@ -420,8 +431,9 @@ discard block |
||
| 420 | 431 | $key = $columns[$match[1]]; |
| 421 | 432 | $column = $table->getColumn($key)->getColumnName(); |
| 422 | 433 | $sql = $column . ' = ? '; |
| 423 | - if(count($match) > 2) |
|
| 424 | - $sql .= strtoupper(str_replace('_', '', $match[2])); |
|
| 434 | + if(count($match) > 2) { |
|
| 435 | + $sql .= strtoupper(str_replace('_', '', $match[2])); |
|
| 436 | + } |
|
| 425 | 437 | $fields[] = $sql; |
| 426 | 438 | } |
| 427 | 439 | return $fields; |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
| 191 | - * @return boolean true if the parameter index are string base, false otherwise. |
|
| 191 | + * @return boolean|null true if the parameter index are string base, false otherwise. |
|
| 192 | 192 | */ |
| 193 | 193 | public function getIsNamedParameters() |
| 194 | 194 | { |
@@ -206,6 +206,7 @@ discard block |
||
| 206 | 206 | |
| 207 | 207 | /** |
| 208 | 208 | * @param mixed ordering clause. |
| 209 | + * @param string $value |
|
| 209 | 210 | */ |
| 210 | 211 | public function setOrdersBy($value) |
| 211 | 212 | { |
@@ -250,6 +251,7 @@ discard block |
||
| 250 | 251 | |
| 251 | 252 | /** |
| 252 | 253 | * @param int record offset. |
| 254 | + * @param double $value |
|
| 253 | 255 | */ |
| 254 | 256 | public function setOffset($value) |
| 255 | 257 | { |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @var mixed |
| 34 | 34 | * @since 3.1.7 |
| 35 | 35 | */ |
| 36 | - private $_select='*'; |
|
| 36 | + private $_select = '*'; |
|
| 37 | 37 | private $_condition; |
| 38 | 38 | private $_parameters; |
| 39 | 39 | private $_ordersBy; |
@@ -45,14 +45,14 @@ discard block |
||
| 45 | 45 | * @param string sql string after the WHERE stanza |
| 46 | 46 | * @param mixed named or indexed parameters, accepts as multiple arguments. |
| 47 | 47 | */ |
| 48 | - public function __construct($condition=null, $parameters=array()) |
|
| 48 | + public function __construct($condition = null, $parameters = array()) |
|
| 49 | 49 | { |
| 50 | - if(!is_array($parameters) && func_num_args() > 1) |
|
| 51 | - $parameters = array_slice(func_get_args(),1); |
|
| 52 | - $this->_parameters=new TAttributeCollection; |
|
| 50 | + if (!is_array($parameters) && func_num_args() > 1) |
|
| 51 | + $parameters = array_slice(func_get_args(), 1); |
|
| 52 | + $this->_parameters = new TAttributeCollection; |
|
| 53 | 53 | $this->_parameters->setCaseSensitive(true); |
| 54 | - $this->_parameters->copyFrom((array)$parameters); |
|
| 55 | - $this->_ordersBy=new TAttributeCollection; |
|
| 54 | + $this->_parameters->copyFrom((array) $parameters); |
|
| 55 | + $this->_ordersBy = new TAttributeCollection; |
|
| 56 | 56 | $this->_ordersBy->setCaseSensitive(true); |
| 57 | 57 | |
| 58 | 58 | $this->setCondition($condition); |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | public function setCondition($value) |
| 128 | 128 | { |
| 129 | - if(empty($value)) { |
|
| 129 | + if (empty($value)) { |
|
| 130 | 130 | // reset the condition |
| 131 | 131 | $this->_condition = null; |
| 132 | 132 | return; |
@@ -138,32 +138,32 @@ discard block |
||
| 138 | 138 | // [LIMIT {[offset,] row_count | row_count OFFSET offset}] |
| 139 | 139 | // See: http://dev.mysql.com/doc/refman/5.0/en/select.html |
| 140 | 140 | |
| 141 | - if(preg_match('/ORDER\s+BY\s+(.*?)(?=LIMIT)|ORDER\s+BY\s+(.*?)$/i', $value, $matches) > 0) { |
|
| 141 | + if (preg_match('/ORDER\s+BY\s+(.*?)(?=LIMIT)|ORDER\s+BY\s+(.*?)$/i', $value, $matches) > 0) { |
|
| 142 | 142 | // condition contains ORDER BY |
| 143 | 143 | $value = str_replace($matches[0], '', $value); |
| 144 | - if(strlen($matches[1]) > 0) { |
|
| 144 | + if (strlen($matches[1]) > 0) { |
|
| 145 | 145 | $this->setOrdersBy($matches[1]); |
| 146 | - } else if(strlen($matches[2]) > 0) { |
|
| 146 | + } else if (strlen($matches[2]) > 0) { |
|
| 147 | 147 | $this->setOrdersBy($matches[2]); |
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - if(preg_match('/LIMIT\s+([\d\s,]+)/i', $value, $matches) > 0) { |
|
| 151 | + if (preg_match('/LIMIT\s+([\d\s,]+)/i', $value, $matches) > 0) { |
|
| 152 | 152 | // condition contains limit |
| 153 | 153 | $value = str_replace($matches[0], '', $value); // remove limit from query |
| 154 | - if(strpos($matches[1], ',')) { // both offset and limit given |
|
| 154 | + if (strpos($matches[1], ',')) { // both offset and limit given |
|
| 155 | 155 | list($offset, $limit) = explode(',', $matches[1]); |
| 156 | - $this->_limit = (int)$limit; |
|
| 157 | - $this->_offset = (int)$offset; |
|
| 156 | + $this->_limit = (int) $limit; |
|
| 157 | + $this->_offset = (int) $offset; |
|
| 158 | 158 | } else { // only limit given |
| 159 | - $this->_limit = (int)$matches[1]; |
|
| 159 | + $this->_limit = (int) $matches[1]; |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - if(preg_match('/OFFSET\s+(\d+)/i', $value, $matches) > 0) { |
|
| 163 | + if (preg_match('/OFFSET\s+(\d+)/i', $value, $matches) > 0) { |
|
| 164 | 164 | // condition contains offset |
| 165 | 165 | $value = str_replace($matches[0], '', $value); // remove offset from query |
| 166 | - $this->_offset = (int)$matches[1]; // set offset in criteria |
|
| 166 | + $this->_offset = (int) $matches[1]; // set offset in criteria |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | $this->_condition = trim($value); |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | */ |
| 183 | 183 | public function setParameters($value) |
| 184 | 184 | { |
| 185 | - if(!(is_array($value) || $value instanceof ArrayAccess)) |
|
| 185 | + if (!(is_array($value) || $value instanceof ArrayAccess)) |
|
| 186 | 186 | throw new TException('value must be array or ArrayAccess'); |
| 187 | 187 | $this->_parameters->copyFrom($value); |
| 188 | 188 | } |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | */ |
| 193 | 193 | public function getIsNamedParameters() |
| 194 | 194 | { |
| 195 | - foreach($this->getParameters() as $k=>$v) |
|
| 195 | + foreach ($this->getParameters() as $k=>$v) |
|
| 196 | 196 | return is_string($k); |
| 197 | 197 | } |
| 198 | 198 | |
@@ -209,16 +209,16 @@ discard block |
||
| 209 | 209 | */ |
| 210 | 210 | public function setOrdersBy($value) |
| 211 | 211 | { |
| 212 | - if(is_array($value) || $value instanceof Traversable) |
|
| 212 | + if (is_array($value) || $value instanceof Traversable) |
|
| 213 | 213 | $this->_ordersBy->copyFrom($value); |
| 214 | 214 | else |
| 215 | 215 | { |
| 216 | - $value=trim(preg_replace('/\s+/',' ',(string)$value)); |
|
| 217 | - $orderBys=array(); |
|
| 218 | - foreach(explode(',',$value) as $orderBy) |
|
| 216 | + $value = trim(preg_replace('/\s+/', ' ', (string) $value)); |
|
| 217 | + $orderBys = array(); |
|
| 218 | + foreach (explode(',', $value) as $orderBy) |
|
| 219 | 219 | { |
| 220 | - $vs=explode(' ',trim($orderBy)); |
|
| 221 | - $orderBys[$vs[0]]=isset($vs[1])?$vs[1]:'asc'; |
|
| 220 | + $vs = explode(' ', trim($orderBy)); |
|
| 221 | + $orderBys[$vs[0]] = isset($vs[1]) ? $vs[1] : 'asc'; |
|
| 222 | 222 | } |
| 223 | 223 | $this->_ordersBy->copyFrom($orderBys); |
| 224 | 224 | } |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | */ |
| 238 | 238 | public function setLimit($value) |
| 239 | 239 | { |
| 240 | - $this->_limit=$value; |
|
| 240 | + $this->_limit = $value; |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | /** |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | */ |
| 254 | 254 | public function setOffset($value) |
| 255 | 255 | { |
| 256 | - $this->_offset=$value; |
|
| 256 | + $this->_offset = $value; |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -262,22 +262,22 @@ discard block |
||
| 262 | 262 | public function __toString() |
| 263 | 263 | { |
| 264 | 264 | $str = ''; |
| 265 | - if(strlen((string)$this->getCondition()) > 0) |
|
| 266 | - $str .= '"'.(string)$this->getCondition().'"'; |
|
| 265 | + if (strlen((string) $this->getCondition()) > 0) |
|
| 266 | + $str .= '"' . (string) $this->getCondition() . '"'; |
|
| 267 | 267 | $params = array(); |
| 268 | - foreach($this->getParameters() as $k=>$v) |
|
| 268 | + foreach ($this->getParameters() as $k=>$v) |
|
| 269 | 269 | $params[] = "{$k} => ${v}"; |
| 270 | - if(count($params) > 0) |
|
| 271 | - $str .= ', "'.implode(', ',$params).'"'; |
|
| 270 | + if (count($params) > 0) |
|
| 271 | + $str .= ', "' . implode(', ', $params) . '"'; |
|
| 272 | 272 | $orders = array(); |
| 273 | - foreach($this->getOrdersBy() as $k=>$v) |
|
| 273 | + foreach ($this->getOrdersBy() as $k=>$v) |
|
| 274 | 274 | $orders[] = "{$k} => ${v}"; |
| 275 | - if(count($orders) > 0) |
|
| 276 | - $str .= ', "'.implode(', ',$orders).'"'; |
|
| 277 | - if($this->_limit !==null) |
|
| 278 | - $str .= ', '.$this->_limit; |
|
| 279 | - if($this->_offset !== null) |
|
| 280 | - $str .= ', '.$this->_offset; |
|
| 275 | + if (count($orders) > 0) |
|
| 276 | + $str .= ', "' . implode(', ', $orders) . '"'; |
|
| 277 | + if ($this->_limit !== null) |
|
| 278 | + $str .= ', ' . $this->_limit; |
|
| 279 | + if ($this->_offset !== null) |
|
| 280 | + $str .= ', ' . $this->_offset; |
|
| 281 | 281 | return $str; |
| 282 | 282 | } |
| 283 | 283 | } |
@@ -47,8 +47,9 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | public function __construct($condition=null, $parameters=array()) |
| 49 | 49 | { |
| 50 | - if(!is_array($parameters) && func_num_args() > 1) |
|
| 51 | - $parameters = array_slice(func_get_args(),1); |
|
| 50 | + if(!is_array($parameters) && func_num_args() > 1) { |
|
| 51 | + $parameters = array_slice(func_get_args(),1); |
|
| 52 | + } |
|
| 52 | 53 | $this->_parameters=new TAttributeCollection; |
| 53 | 54 | $this->_parameters->setCaseSensitive(true); |
| 54 | 55 | $this->_parameters->copyFrom((array)$parameters); |
@@ -182,8 +183,9 @@ discard block |
||
| 182 | 183 | */ |
| 183 | 184 | public function setParameters($value) |
| 184 | 185 | { |
| 185 | - if(!(is_array($value) || $value instanceof ArrayAccess)) |
|
| 186 | - throw new TException('value must be array or ArrayAccess'); |
|
| 186 | + if(!(is_array($value) || $value instanceof ArrayAccess)) { |
|
| 187 | + throw new TException('value must be array or ArrayAccess'); |
|
| 188 | + } |
|
| 187 | 189 | $this->_parameters->copyFrom($value); |
| 188 | 190 | } |
| 189 | 191 | |
@@ -192,8 +194,9 @@ discard block |
||
| 192 | 194 | */ |
| 193 | 195 | public function getIsNamedParameters() |
| 194 | 196 | { |
| 195 | - foreach($this->getParameters() as $k=>$v) |
|
| 196 | - return is_string($k); |
|
| 197 | + foreach($this->getParameters() as $k=>$v) { |
|
| 198 | + return is_string($k); |
|
| 199 | + } |
|
| 197 | 200 | } |
| 198 | 201 | |
| 199 | 202 | /** |
@@ -209,9 +212,9 @@ discard block |
||
| 209 | 212 | */ |
| 210 | 213 | public function setOrdersBy($value) |
| 211 | 214 | { |
| 212 | - if(is_array($value) || $value instanceof Traversable) |
|
| 213 | - $this->_ordersBy->copyFrom($value); |
|
| 214 | - else |
|
| 215 | + if(is_array($value) || $value instanceof Traversable) { |
|
| 216 | + $this->_ordersBy->copyFrom($value); |
|
| 217 | + } else |
|
| 215 | 218 | { |
| 216 | 219 | $value=trim(preg_replace('/\s+/',' ',(string)$value)); |
| 217 | 220 | $orderBys=array(); |
@@ -262,22 +265,29 @@ discard block |
||
| 262 | 265 | public function __toString() |
| 263 | 266 | { |
| 264 | 267 | $str = ''; |
| 265 | - if(strlen((string)$this->getCondition()) > 0) |
|
| 266 | - $str .= '"'.(string)$this->getCondition().'"'; |
|
| 268 | + if(strlen((string)$this->getCondition()) > 0) { |
|
| 269 | + $str .= '"'.(string)$this->getCondition().'"'; |
|
| 270 | + } |
|
| 267 | 271 | $params = array(); |
| 268 | - foreach($this->getParameters() as $k=>$v) |
|
| 269 | - $params[] = "{$k} => ${v}"; |
|
| 270 | - if(count($params) > 0) |
|
| 271 | - $str .= ', "'.implode(', ',$params).'"'; |
|
| 272 | + foreach($this->getParameters() as $k=>$v) { |
|
| 273 | + $params[] = "{$k} => ${v}"; |
|
| 274 | + } |
|
| 275 | + if(count($params) > 0) { |
|
| 276 | + $str .= ', "'.implode(', ',$params).'"'; |
|
| 277 | + } |
|
| 272 | 278 | $orders = array(); |
| 273 | - foreach($this->getOrdersBy() as $k=>$v) |
|
| 274 | - $orders[] = "{$k} => ${v}"; |
|
| 275 | - if(count($orders) > 0) |
|
| 276 | - $str .= ', "'.implode(', ',$orders).'"'; |
|
| 277 | - if($this->_limit !==null) |
|
| 278 | - $str .= ', '.$this->_limit; |
|
| 279 | - if($this->_offset !== null) |
|
| 280 | - $str .= ', '.$this->_offset; |
|
| 279 | + foreach($this->getOrdersBy() as $k=>$v) { |
|
| 280 | + $orders[] = "{$k} => ${v}"; |
|
| 281 | + } |
|
| 282 | + if(count($orders) > 0) { |
|
| 283 | + $str .= ', "'.implode(', ',$orders).'"'; |
|
| 284 | + } |
|
| 285 | + if($this->_limit !==null) { |
|
| 286 | + $str .= ', '.$this->_limit; |
|
| 287 | + } |
|
| 288 | + if($this->_offset !== null) { |
|
| 289 | + $str .= ', '.$this->_offset; |
|
| 290 | + } |
|
| 281 | 291 | return $str; |
| 282 | 292 | } |
| 283 | 293 | } |
@@ -86,6 +86,7 @@ discard block |
||
| 86 | 86 | * and a database connection. |
| 87 | 87 | * @param string|TDbTableInfo table or view name or table information. |
| 88 | 88 | * @param TDbConnection database connection. |
| 89 | + * @param TDbConnection $connection |
|
| 89 | 90 | */ |
| 90 | 91 | public function __construct($table,$connection) |
| 91 | 92 | { |
@@ -100,6 +101,7 @@ discard block |
||
| 100 | 101 | |
| 101 | 102 | /** |
| 102 | 103 | * @param TDbTableInfo table or view information. |
| 104 | + * @param TDbTableInfo $tableInfo |
|
| 103 | 105 | */ |
| 104 | 106 | protected function setTableInfo($tableInfo) |
| 105 | 107 | { |
@@ -110,6 +112,7 @@ discard block |
||
| 110 | 112 | /** |
| 111 | 113 | * Sets up the command builder for the given table. |
| 112 | 114 | * @param string table or view name. |
| 115 | + * @param string $tableName |
|
| 113 | 116 | */ |
| 114 | 117 | protected function setTableName($tableName) |
| 115 | 118 | { |
@@ -185,7 +188,7 @@ discard block |
||
| 185 | 188 | * Execute arbituary sql command with binding parameters. |
| 186 | 189 | * @param string SQL query string. |
| 187 | 190 | * @param array binding parameters, positional or named. |
| 188 | - * @return array query results. |
|
| 191 | + * @return TDbDataReader query results. |
|
| 189 | 192 | */ |
| 190 | 193 | public function findBySql($sql, $parameters=array()) |
| 191 | 194 | { |
@@ -198,6 +201,7 @@ discard block |
||
| 198 | 201 | * Execute arbituary sql command with binding parameters. |
| 199 | 202 | * @param string SQL query string. |
| 200 | 203 | * @param array binding parameters, positional or named. |
| 204 | + * @param string $sql |
|
| 201 | 205 | * @return TDbDataReader query results. |
| 202 | 206 | */ |
| 203 | 207 | public function findAllBySql($sql, $parameters=array()) |
@@ -279,6 +283,7 @@ discard block |
||
| 279 | 283 | * $table->findAllByPk(array(array($key1, $key2), array($key3, $key4), ...)); |
| 280 | 284 | * </code> |
| 281 | 285 | * @param mixed primary keys |
| 286 | + * @param integer[] $keys |
|
| 282 | 287 | * @return TDbDataReader data reader. |
| 283 | 288 | */ |
| 284 | 289 | public function findAllByPks($keys) |
@@ -350,6 +355,7 @@ discard block |
||
| 350 | 355 | * Find the number of records. |
| 351 | 356 | * @param string|TSqlCriteria SQL condition or criteria object. |
| 352 | 357 | * @param mixed parameter values. |
| 358 | + * @param string $criteria |
|
| 353 | 359 | * @return int number of records. |
| 354 | 360 | */ |
| 355 | 361 | public function count($criteria=null,$parameters=array()) |
@@ -372,6 +378,7 @@ discard block |
||
| 372 | 378 | * @param array new record data. |
| 373 | 379 | * @param string update condition |
| 374 | 380 | * @param array additional binding name-value pairs. |
| 381 | + * @param string $criteria |
|
| 375 | 382 | * @return integer number of records updated. |
| 376 | 383 | */ |
| 377 | 384 | public function update($data, $criteria, $parameters=array()) |
@@ -385,7 +392,7 @@ discard block |
||
| 385 | 392 | * Inserts a new record into the table. Each array key must |
| 386 | 393 | * correspond to a column name in the table unless a null value is permitted. |
| 387 | 394 | * @param array new record data. |
| 388 | - * @return mixed last insert id if one column contains a serial or sequence, |
|
| 395 | + * @return string|boolean last insert id if one column contains a serial or sequence, |
|
| 389 | 396 | * otherwise true if command executes successfully and affected 1 or more rows. |
| 390 | 397 | */ |
| 391 | 398 | public function insert($data) |
@@ -394,7 +401,7 @@ discard block |
||
| 394 | 401 | } |
| 395 | 402 | |
| 396 | 403 | /** |
| 397 | - * @return mixed last insert id, null if none is found. |
|
| 404 | + * @return string|null last insert id, null if none is found. |
|
| 398 | 405 | */ |
| 399 | 406 | public function getLastInsertId() |
| 400 | 407 | { |
@@ -87,12 +87,12 @@ discard block |
||
| 87 | 87 | * @param string|TDbTableInfo table or view name or table information. |
| 88 | 88 | * @param TDbConnection database connection. |
| 89 | 89 | */ |
| 90 | - public function __construct($table,$connection) |
|
| 90 | + public function __construct($table, $connection) |
|
| 91 | 91 | { |
| 92 | - $this->_connection=$connection; |
|
| 93 | - if(is_string($table)) |
|
| 92 | + $this->_connection = $connection; |
|
| 93 | + if (is_string($table)) |
|
| 94 | 94 | $this->setTableName($table); |
| 95 | - else if($table instanceof TDbTableInfo) |
|
| 95 | + else if ($table instanceof TDbTableInfo) |
|
| 96 | 96 | $this->setTableInfo($table); |
| 97 | 97 | else |
| 98 | 98 | throw new TDbException('dbtablegateway_invalid_table_info'); |
@@ -187,10 +187,10 @@ discard block |
||
| 187 | 187 | * @param array binding parameters, positional or named. |
| 188 | 188 | * @return array query results. |
| 189 | 189 | */ |
| 190 | - public function findBySql($sql, $parameters=array()) |
|
| 190 | + public function findBySql($sql, $parameters = array()) |
|
| 191 | 191 | { |
| 192 | - $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null; |
|
| 193 | - $criteria = $this->getCriteria($sql,$parameters, $args); |
|
| 192 | + $args = func_num_args() > 1 ? array_slice(func_get_args(), 1) : null; |
|
| 193 | + $criteria = $this->getCriteria($sql, $parameters, $args); |
|
| 194 | 194 | return $this->getCommand()->findBySql($criteria); |
| 195 | 195 | } |
| 196 | 196 | |
@@ -200,10 +200,10 @@ discard block |
||
| 200 | 200 | * @param array binding parameters, positional or named. |
| 201 | 201 | * @return TDbDataReader query results. |
| 202 | 202 | */ |
| 203 | - public function findAllBySql($sql, $parameters=array()) |
|
| 203 | + public function findAllBySql($sql, $parameters = array()) |
|
| 204 | 204 | { |
| 205 | - $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null; |
|
| 206 | - $criteria = $this->getCriteria($sql,$parameters, $args); |
|
| 205 | + $args = func_num_args() > 1 ? array_slice(func_get_args(), 1) : null; |
|
| 206 | + $criteria = $this->getCriteria($sql, $parameters, $args); |
|
| 207 | 207 | return $this->getCommand()->findAllBySql($criteria); |
| 208 | 208 | } |
| 209 | 209 | |
@@ -224,10 +224,10 @@ discard block |
||
| 224 | 224 | * @param mixed parameter values. |
| 225 | 225 | * @return array matching record object. |
| 226 | 226 | */ |
| 227 | - public function find($criteria, $parameters=array()) |
|
| 227 | + public function find($criteria, $parameters = array()) |
|
| 228 | 228 | { |
| 229 | - $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null; |
|
| 230 | - $criteria = $this->getCriteria($criteria,$parameters, $args); |
|
| 229 | + $args = func_num_args() > 1 ? array_slice(func_get_args(), 1) : null; |
|
| 230 | + $criteria = $this->getCriteria($criteria, $parameters, $args); |
|
| 231 | 231 | return $this->getCommand()->find($criteria); |
| 232 | 232 | } |
| 233 | 233 | |
@@ -237,11 +237,11 @@ discard block |
||
| 237 | 237 | * @param mixed parameter values. |
| 238 | 238 | * @return TDbDataReader matching records. |
| 239 | 239 | */ |
| 240 | - public function findAll($criteria=null, $parameters=array()) |
|
| 240 | + public function findAll($criteria = null, $parameters = array()) |
|
| 241 | 241 | { |
| 242 | - $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null; |
|
| 243 | - if($criteria!==null) |
|
| 244 | - $criteria = $this->getCriteria($criteria,$parameters, $args); |
|
| 242 | + $args = func_num_args() > 1 ? array_slice(func_get_args(), 1) : null; |
|
| 243 | + if ($criteria !== null) |
|
| 244 | + $criteria = $this->getCriteria($criteria, $parameters, $args); |
|
| 245 | 245 | return $this->getCommand()->findAll($criteria); |
| 246 | 246 | } |
| 247 | 247 | |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | */ |
| 260 | 260 | public function findByPk($keys) |
| 261 | 261 | { |
| 262 | - if(func_num_args() > 1) |
|
| 262 | + if (func_num_args() > 1) |
|
| 263 | 263 | $keys = func_get_args(); |
| 264 | 264 | return $this->getCommand()->findByPk($keys); |
| 265 | 265 | } |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | */ |
| 284 | 284 | public function findAllByPks($keys) |
| 285 | 285 | { |
| 286 | - if(func_num_args() > 1) |
|
| 286 | + if (func_num_args() > 1) |
|
| 287 | 287 | $keys = func_get_args(); |
| 288 | 288 | return $this->getCommand()->findAllByPk($keys); |
| 289 | 289 | } |
@@ -299,10 +299,10 @@ discard block |
||
| 299 | 299 | * @param array condition parameters. |
| 300 | 300 | * @return integer number of records deleted. |
| 301 | 301 | */ |
| 302 | - public function deleteAll($criteria, $parameters=array()) |
|
| 302 | + public function deleteAll($criteria, $parameters = array()) |
|
| 303 | 303 | { |
| 304 | - $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null; |
|
| 305 | - $criteria = $this->getCriteria($criteria,$parameters, $args); |
|
| 304 | + $args = func_num_args() > 1 ? array_slice(func_get_args(), 1) : null; |
|
| 305 | + $criteria = $this->getCriteria($criteria, $parameters, $args); |
|
| 306 | 306 | return $this->getCommand()->delete($criteria); |
| 307 | 307 | } |
| 308 | 308 | |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | */ |
| 332 | 332 | public function deleteByPk($keys) |
| 333 | 333 | { |
| 334 | - if(func_num_args() > 1) |
|
| 334 | + if (func_num_args() > 1) |
|
| 335 | 335 | $keys = func_get_args(); |
| 336 | 336 | return $this->getCommand()->deleteByPk($keys); |
| 337 | 337 | } |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | */ |
| 342 | 342 | public function deleteAllByPks($keys) |
| 343 | 343 | { |
| 344 | - if(func_num_args() > 1) |
|
| 344 | + if (func_num_args() > 1) |
|
| 345 | 345 | $keys = func_get_args(); |
| 346 | 346 | return $this->deleteByPk($keys); |
| 347 | 347 | } |
@@ -352,11 +352,11 @@ discard block |
||
| 352 | 352 | * @param mixed parameter values. |
| 353 | 353 | * @return int number of records. |
| 354 | 354 | */ |
| 355 | - public function count($criteria=null,$parameters=array()) |
|
| 355 | + public function count($criteria = null, $parameters = array()) |
|
| 356 | 356 | { |
| 357 | - $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null; |
|
| 358 | - if($criteria!==null) |
|
| 359 | - $criteria = $this->getCriteria($criteria,$parameters, $args); |
|
| 357 | + $args = func_num_args() > 1 ? array_slice(func_get_args(), 1) : null; |
|
| 358 | + if ($criteria !== null) |
|
| 359 | + $criteria = $this->getCriteria($criteria, $parameters, $args); |
|
| 360 | 360 | return $this->getCommand()->count($criteria); |
| 361 | 361 | } |
| 362 | 362 | |
@@ -374,10 +374,10 @@ discard block |
||
| 374 | 374 | * @param array additional binding name-value pairs. |
| 375 | 375 | * @return integer number of records updated. |
| 376 | 376 | */ |
| 377 | - public function update($data, $criteria, $parameters=array()) |
|
| 377 | + public function update($data, $criteria, $parameters = array()) |
|
| 378 | 378 | { |
| 379 | - $args = func_num_args() > 2 ? array_slice(func_get_args(),2) : null; |
|
| 380 | - $criteria = $this->getCriteria($criteria,$parameters, $args); |
|
| 379 | + $args = func_num_args() > 2 ? array_slice(func_get_args(), 2) : null; |
|
| 380 | + $criteria = $this->getCriteria($criteria, $parameters, $args); |
|
| 381 | 381 | return $this->getCommand()->update($data, $criteria); |
| 382 | 382 | } |
| 383 | 383 | |
@@ -412,12 +412,12 @@ discard block |
||
| 412 | 412 | */ |
| 413 | 413 | protected function getCriteria($criteria, $parameters, $args) |
| 414 | 414 | { |
| 415 | - if(is_string($criteria)) |
|
| 415 | + if (is_string($criteria)) |
|
| 416 | 416 | { |
| 417 | 417 | $useArgs = !is_array($parameters) && is_array($args); |
| 418 | - return new TSqlCriteria($criteria,$useArgs ? $args : $parameters); |
|
| 418 | + return new TSqlCriteria($criteria, $useArgs ? $args : $parameters); |
|
| 419 | 419 | } |
| 420 | - else if($criteria instanceof TSqlCriteria) |
|
| 420 | + else if ($criteria instanceof TSqlCriteria) |
|
| 421 | 421 | return $criteria; |
| 422 | 422 | else |
| 423 | 423 | throw new TDbException('dbtablegateway_invalid_criteria'); |
@@ -452,22 +452,22 @@ discard block |
||
| 452 | 452 | * @return mixed single record if method name starts with "findBy", 0 or more records |
| 453 | 453 | * if method name starts with "findAllBy" |
| 454 | 454 | */ |
| 455 | - public function __call($method,$args) |
|
| 455 | + public function __call($method, $args) |
|
| 456 | 456 | { |
| 457 | - $delete =false; |
|
| 458 | - if($findOne = substr(strtolower($method),0,6)==='findby') |
|
| 459 | - $condition = $method[6]==='_' ? substr($method,7) : substr($method,6); |
|
| 460 | - else if(substr(strtolower($method),0,9)==='findallby') |
|
| 461 | - $condition = $method[9]==='_' ? substr($method,10) : substr($method,9); |
|
| 462 | - else if($delete = substr(strtolower($method),0,8)==='deleteby') |
|
| 463 | - $condition = $method[8]==='_' ? substr($method,9) : substr($method,8); |
|
| 464 | - else if($delete = substr(strtolower($method),0,11)==='deleteallby') |
|
| 465 | - $condition = $method[11]==='_' ? substr($method,12) : substr($method,11); |
|
| 457 | + $delete = false; |
|
| 458 | + if ($findOne = substr(strtolower($method), 0, 6) === 'findby') |
|
| 459 | + $condition = $method[6] === '_' ? substr($method, 7) : substr($method, 6); |
|
| 460 | + else if (substr(strtolower($method), 0, 9) === 'findallby') |
|
| 461 | + $condition = $method[9] === '_' ? substr($method, 10) : substr($method, 9); |
|
| 462 | + else if ($delete = substr(strtolower($method), 0, 8) === 'deleteby') |
|
| 463 | + $condition = $method[8] === '_' ? substr($method, 9) : substr($method, 8); |
|
| 464 | + else if ($delete = substr(strtolower($method), 0, 11) === 'deleteallby') |
|
| 465 | + $condition = $method[11] === '_' ? substr($method, 12) : substr($method, 11); |
|
| 466 | 466 | else |
| 467 | 467 | return null; |
| 468 | 468 | |
| 469 | 469 | $criteria = $this->getCommand()->createCriteriaFromString($method, $condition, $args); |
| 470 | - if($delete) |
|
| 470 | + if ($delete) |
|
| 471 | 471 | return $this->deleteAll($criteria); |
| 472 | 472 | else |
| 473 | 473 | return $findOne ? $this->find($criteria) : $this->findAll($criteria); |
@@ -90,12 +90,13 @@ discard block |
||
| 90 | 90 | public function __construct($table,$connection) |
| 91 | 91 | { |
| 92 | 92 | $this->_connection=$connection; |
| 93 | - if(is_string($table)) |
|
| 94 | - $this->setTableName($table); |
|
| 95 | - else if($table instanceof TDbTableInfo) |
|
| 96 | - $this->setTableInfo($table); |
|
| 97 | - else |
|
| 98 | - throw new TDbException('dbtablegateway_invalid_table_info'); |
|
| 93 | + if(is_string($table)) { |
|
| 94 | + $this->setTableName($table); |
|
| 95 | + } else if($table instanceof TDbTableInfo) { |
|
| 96 | + $this->setTableInfo($table); |
|
| 97 | + } else { |
|
| 98 | + throw new TDbException('dbtablegateway_invalid_table_info'); |
|
| 99 | + } |
|
| 99 | 100 | } |
| 100 | 101 | |
| 101 | 102 | /** |
@@ -240,8 +241,9 @@ discard block |
||
| 240 | 241 | public function findAll($criteria=null, $parameters=array()) |
| 241 | 242 | { |
| 242 | 243 | $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null; |
| 243 | - if($criteria!==null) |
|
| 244 | - $criteria = $this->getCriteria($criteria,$parameters, $args); |
|
| 244 | + if($criteria!==null) { |
|
| 245 | + $criteria = $this->getCriteria($criteria,$parameters, $args); |
|
| 246 | + } |
|
| 245 | 247 | return $this->getCommand()->findAll($criteria); |
| 246 | 248 | } |
| 247 | 249 | |
@@ -259,8 +261,9 @@ discard block |
||
| 259 | 261 | */ |
| 260 | 262 | public function findByPk($keys) |
| 261 | 263 | { |
| 262 | - if(func_num_args() > 1) |
|
| 263 | - $keys = func_get_args(); |
|
| 264 | + if(func_num_args() > 1) { |
|
| 265 | + $keys = func_get_args(); |
|
| 266 | + } |
|
| 264 | 267 | return $this->getCommand()->findByPk($keys); |
| 265 | 268 | } |
| 266 | 269 | |
@@ -283,8 +286,9 @@ discard block |
||
| 283 | 286 | */ |
| 284 | 287 | public function findAllByPks($keys) |
| 285 | 288 | { |
| 286 | - if(func_num_args() > 1) |
|
| 287 | - $keys = func_get_args(); |
|
| 289 | + if(func_num_args() > 1) { |
|
| 290 | + $keys = func_get_args(); |
|
| 291 | + } |
|
| 288 | 292 | return $this->getCommand()->findAllByPk($keys); |
| 289 | 293 | } |
| 290 | 294 | |
@@ -331,8 +335,9 @@ discard block |
||
| 331 | 335 | */ |
| 332 | 336 | public function deleteByPk($keys) |
| 333 | 337 | { |
| 334 | - if(func_num_args() > 1) |
|
| 335 | - $keys = func_get_args(); |
|
| 338 | + if(func_num_args() > 1) { |
|
| 339 | + $keys = func_get_args(); |
|
| 340 | + } |
|
| 336 | 341 | return $this->getCommand()->deleteByPk($keys); |
| 337 | 342 | } |
| 338 | 343 | |
@@ -341,8 +346,9 @@ discard block |
||
| 341 | 346 | */ |
| 342 | 347 | public function deleteAllByPks($keys) |
| 343 | 348 | { |
| 344 | - if(func_num_args() > 1) |
|
| 345 | - $keys = func_get_args(); |
|
| 349 | + if(func_num_args() > 1) { |
|
| 350 | + $keys = func_get_args(); |
|
| 351 | + } |
|
| 346 | 352 | return $this->deleteByPk($keys); |
| 347 | 353 | } |
| 348 | 354 | |
@@ -355,8 +361,9 @@ discard block |
||
| 355 | 361 | public function count($criteria=null,$parameters=array()) |
| 356 | 362 | { |
| 357 | 363 | $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null; |
| 358 | - if($criteria!==null) |
|
| 359 | - $criteria = $this->getCriteria($criteria,$parameters, $args); |
|
| 364 | + if($criteria!==null) { |
|
| 365 | + $criteria = $this->getCriteria($criteria,$parameters, $args); |
|
| 366 | + } |
|
| 360 | 367 | return $this->getCommand()->count($criteria); |
| 361 | 368 | } |
| 362 | 369 | |
@@ -416,11 +423,11 @@ discard block |
||
| 416 | 423 | { |
| 417 | 424 | $useArgs = !is_array($parameters) && is_array($args); |
| 418 | 425 | return new TSqlCriteria($criteria,$useArgs ? $args : $parameters); |
| 426 | + } else if($criteria instanceof TSqlCriteria) { |
|
| 427 | + return $criteria; |
|
| 428 | + } else { |
|
| 429 | + throw new TDbException('dbtablegateway_invalid_criteria'); |
|
| 419 | 430 | } |
| 420 | - else if($criteria instanceof TSqlCriteria) |
|
| 421 | - return $criteria; |
|
| 422 | - else |
|
| 423 | - throw new TDbException('dbtablegateway_invalid_criteria'); |
|
| 424 | 431 | } |
| 425 | 432 | |
| 426 | 433 | /** |
@@ -455,22 +462,24 @@ discard block |
||
| 455 | 462 | public function __call($method,$args) |
| 456 | 463 | { |
| 457 | 464 | $delete =false; |
| 458 | - if($findOne = substr(strtolower($method),0,6)==='findby') |
|
| 459 | - $condition = $method[6]==='_' ? substr($method,7) : substr($method,6); |
|
| 460 | - else if(substr(strtolower($method),0,9)==='findallby') |
|
| 461 | - $condition = $method[9]==='_' ? substr($method,10) : substr($method,9); |
|
| 462 | - else if($delete = substr(strtolower($method),0,8)==='deleteby') |
|
| 463 | - $condition = $method[8]==='_' ? substr($method,9) : substr($method,8); |
|
| 464 | - else if($delete = substr(strtolower($method),0,11)==='deleteallby') |
|
| 465 | - $condition = $method[11]==='_' ? substr($method,12) : substr($method,11); |
|
| 466 | - else |
|
| 467 | - return null; |
|
| 465 | + if($findOne = substr(strtolower($method),0,6)==='findby') { |
|
| 466 | + $condition = $method[6]==='_' ? substr($method,7) : substr($method,6); |
|
| 467 | + } else if(substr(strtolower($method),0,9)==='findallby') { |
|
| 468 | + $condition = $method[9]==='_' ? substr($method,10) : substr($method,9); |
|
| 469 | + } else if($delete = substr(strtolower($method),0,8)==='deleteby') { |
|
| 470 | + $condition = $method[8]==='_' ? substr($method,9) : substr($method,8); |
|
| 471 | + } else if($delete = substr(strtolower($method),0,11)==='deleteallby') { |
|
| 472 | + $condition = $method[11]==='_' ? substr($method,12) : substr($method,11); |
|
| 473 | + } else { |
|
| 474 | + return null; |
|
| 475 | + } |
|
| 468 | 476 | |
| 469 | 477 | $criteria = $this->getCommand()->createCriteriaFromString($method, $condition, $args); |
| 470 | - if($delete) |
|
| 471 | - return $this->deleteAll($criteria); |
|
| 472 | - else |
|
| 473 | - return $findOne ? $this->find($criteria) : $this->findAll($criteria); |
|
| 478 | + if($delete) { |
|
| 479 | + return $this->deleteAll($criteria); |
|
| 480 | + } else { |
|
| 481 | + return $findOne ? $this->find($criteria) : $this->findAll($criteria); |
|
| 482 | + } |
|
| 474 | 483 | } |
| 475 | 484 | } |
| 476 | 485 | |
@@ -1,14 +1,14 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * TTableGateway class 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 | - * @version $Id$ |
|
| 10 | - * @package System.Data.DataGateway |
|
| 11 | - */ |
|
| 3 | + * TTableGateway class 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 | + * @version $Id$ |
|
| 10 | + * @package System.Data.DataGateway |
|
| 11 | + */ |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Loads the data gateway command builder and sql criteria. |