@@ -32,7 +32,7 @@ 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 | 37 | $this->_info=$tableInfo; |
38 | 38 | $this->_primaryKeys=$primary; |
@@ -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,7 +64,7 @@ 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 | 69 | $this->_info[$name]=$value; |
70 | 70 | } |
@@ -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 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | public function getColumnNames() |
120 | 120 | { |
121 | 121 | foreach($this->getColumns() as $column) |
122 | - $names[] = $column->getColumnName(); |
|
122 | + $names[]=$column->getColumnName(); |
|
123 | 123 | return $names; |
124 | 124 | } |
125 | 125 | |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | { |
149 | 149 | $this->_lowercase=array(); |
150 | 150 | foreach($this->getColumns()->getKeys() as $key) |
151 | - $this->_lowercase[strtolower($key)] = $key; |
|
151 | + $this->_lowercase[strtolower($key)]=$key; |
|
152 | 152 | } |
153 | 153 | return $this->_lowercase; |
154 | 154 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * @var array |
29 | 29 | */ |
30 | - protected static $delimiterIdentifier = array('[', ']', '"', '`', "'"); |
|
30 | + protected static $delimiterIdentifier=array('[', ']', '"', '`', "'"); |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * @param TDbConnection database connection. |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | public static function getInstance($conn) |
54 | 54 | { |
55 | 55 | $conn->setActive(true); //must be connected before retrieving driver name |
56 | - $driver = $conn->getDriverName(); |
|
56 | + $driver=$conn->getDriverName(); |
|
57 | 57 | switch(strtolower($driver)) |
58 | 58 | { |
59 | 59 | case 'pgsql': |
@@ -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 | |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function getTableInfo($tableName=null) |
92 | 92 | { |
93 | - $key = $tableName===null?$this->getDbConnection()->getConnectionString():$tableName; |
|
93 | + $key=$tableName===null ? $this->getDbConnection()->getConnectionString() : $tableName; |
|
94 | 94 | if(!isset($this->_tableInfoCache[$key])) |
95 | 95 | { |
96 | - $class = $this->getTableInfoClass(); |
|
97 | - $tableInfo = $tableName===null ? new $class : $this->createTableInfo($tableName); |
|
98 | - $this->_tableInfoCache[$key] = $tableInfo; |
|
96 | + $class=$this->getTableInfoClass(); |
|
97 | + $tableInfo=$tableName===null ? new $class : $this->createTableInfo($tableName); |
|
98 | + $this->_tableInfoCache[$key]=$tableInfo; |
|
99 | 99 | } |
100 | 100 | return $this->_tableInfoCache[$key]; |
101 | 101 | } |
@@ -133,17 +133,17 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public function quoteTableName($name) |
135 | 135 | { |
136 | - $name = str_replace(self::$delimiterIdentifier, '', $name); |
|
136 | + $name=str_replace(self::$delimiterIdentifier, '', $name); |
|
137 | 137 | |
138 | - $args = func_get_args(); |
|
139 | - $rgt = $lft = isset($args[1]) ? $args[1] : ''; |
|
140 | - $rgt = isset($args[2]) ? $args[2] : $rgt; |
|
138 | + $args=func_get_args(); |
|
139 | + $rgt=$lft=isset($args[1]) ? $args[1] : ''; |
|
140 | + $rgt=isset($args[2]) ? $args[2] : $rgt; |
|
141 | 141 | |
142 | 142 | if(strpos($name, '.')===false) |
143 | - return $lft . $name . $rgt; |
|
143 | + return $lft.$name.$rgt; |
|
144 | 144 | $names=explode('.', $name); |
145 | 145 | foreach($names as &$n) |
146 | - $n = $lft . $n . $rgt; |
|
146 | + $n=$lft.$n.$rgt; |
|
147 | 147 | return implode('.', $names); |
148 | 148 | } |
149 | 149 | |
@@ -156,11 +156,11 @@ discard block |
||
156 | 156 | */ |
157 | 157 | public function quoteColumnName($name) |
158 | 158 | { |
159 | - $args = func_get_args(); |
|
160 | - $rgt = $lft = isset($args[1]) ? $args[1] : ''; |
|
161 | - $rgt = isset($args[2]) ? $args[2] : $rgt; |
|
159 | + $args=func_get_args(); |
|
160 | + $rgt=$lft=isset($args[1]) ? $args[1] : ''; |
|
161 | + $rgt=isset($args[2]) ? $args[2] : $rgt; |
|
162 | 162 | |
163 | - return $lft . str_replace(self::$delimiterIdentifier, '', $name) . $rgt; |
|
163 | + return $lft.str_replace(self::$delimiterIdentifier, '', $name).$rgt; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -172,11 +172,11 @@ discard block |
||
172 | 172 | */ |
173 | 173 | public function quoteColumnAlias($name) |
174 | 174 | { |
175 | - $args = func_get_args(); |
|
176 | - $rgt = $lft = isset($args[1]) ? $args[1] : ''; |
|
177 | - $rgt = isset($args[2]) ? $args[2] : $rgt; |
|
175 | + $args=func_get_args(); |
|
176 | + $rgt=$lft=isset($args[1]) ? $args[1] : ''; |
|
177 | + $rgt=isset($args[2]) ? $args[2] : $rgt; |
|
178 | 178 | |
179 | - return $lft . str_replace(self::$delimiterIdentifier, '', $name) . $rgt; |
|
179 | + return $lft.str_replace(self::$delimiterIdentifier, '', $name).$rgt; |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
@@ -50,7 +50,7 @@ |
||
50 | 50 | public function createCommandBuilder($connection) |
51 | 51 | { |
52 | 52 | Prado::using('System.Data.Common.Pgsql.TPgsqlCommandBuilder'); |
53 | - return new TPgsqlCommandBuilder($connection,$this); |
|
53 | + return new TPgsqlCommandBuilder($connection, $this); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | */ |
25 | 25 | class TPgsqlMetaData extends TDbMetaData |
26 | 26 | { |
27 | - private $_defaultSchema = 'public'; |
|
27 | + private $_defaultSchema='public'; |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * @return string TDbTableInfo class name. |
@@ -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,12 +99,12 @@ 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 |
106 | 106 | // sequence on the field. |
107 | - $sql = |
|
107 | + $sql= |
|
108 | 108 | <<<EOD |
109 | 109 | SELECT |
110 | 110 | a.attname, |
@@ -135,14 +135,14 @@ discard block |
||
135 | 135 | ORDER BY a.attnum |
136 | 136 | EOD; |
137 | 137 | $this->getDbConnection()->setActive(true); |
138 | - $command = $this->getDbConnection()->createCommand($sql); |
|
138 | + $command=$this->getDbConnection()->createCommand($sql); |
|
139 | 139 | $command->bindValue(':table', $tableName); |
140 | 140 | $command->bindValue(':schema', $schemaName); |
141 | - $tableInfo = $this->createNewTableInfo($schemaName, $tableName); |
|
141 | + $tableInfo=$this->createNewTableInfo($schemaName, $tableName); |
|
142 | 142 | $index=0; |
143 | 143 | foreach($command->query() as $col) |
144 | 144 | { |
145 | - $col['index'] = $index++; |
|
145 | + $col['index']=$index++; |
|
146 | 146 | $this->processColumn($tableInfo, $col); |
147 | 147 | } |
148 | 148 | if($index===0) |
@@ -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 | - $info['SchemaName'] = $this->assertIdentifier($schemaName); |
|
161 | - $info['TableName'] = $this->assertIdentifier($tableName); |
|
162 | - if($this->getIsView($schemaName,$tableName)) |
|
163 | - $info['IsView'] = true; |
|
164 | - list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName); |
|
165 | - $class = $this->getTableInfoClass(); |
|
166 | - return new $class($info,$primary,$foreign); |
|
160 | + $info['SchemaName']=$this->assertIdentifier($schemaName); |
|
161 | + $info['TableName']=$this->assertIdentifier($tableName); |
|
162 | + if($this->getIsView($schemaName, $tableName)) |
|
163 | + $info['IsView']=true; |
|
164 | + list($primary, $foreign)=$this->getConstraintKeys($schemaName, $tableName); |
|
165 | + $class=$this->getTableInfoClass(); |
|
166 | + return new $class($info, $primary, $foreign); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | { |
176 | 176 | if(strpos($name, '"')!==false) |
177 | 177 | { |
178 | - $ref = 'http://www.postgresql.org/docs/7.4/static/sql-syntax.html#SQL-SYNTAX-IDENTIFIERS'; |
|
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); |
180 | 180 | } |
181 | 181 | return $name; |
@@ -186,19 +186,19 @@ 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 | - $sql = |
|
191 | + $sql= |
|
192 | 192 | <<<EOD |
193 | 193 | SELECT count(c.relname) FROM pg_catalog.pg_class c |
194 | 194 | LEFT JOIN pg_catalog.pg_namespace n ON (n.oid = c.relnamespace) |
195 | 195 | WHERE (n.nspname=:schema) AND (c.relkind = 'v'::"char") AND c.relname = :table |
196 | 196 | EOD; |
197 | 197 | $this->getDbConnection()->setActive(true); |
198 | - $command = $this->getDbConnection()->createCommand($sql); |
|
199 | - $command->bindValue(':schema',$schemaName); |
|
198 | + $command=$this->getDbConnection()->createCommand($sql); |
|
199 | + $command->bindValue(':schema', $schemaName); |
|
200 | 200 | $command->bindValue(':table', $tableName); |
201 | - return intval($command->queryScalar()) === 1; |
|
201 | + return intval($command->queryScalar())===1; |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -207,56 +207,56 @@ discard block |
||
207 | 207 | */ |
208 | 208 | protected function processColumn($tableInfo, $col) |
209 | 209 | { |
210 | - $columnId = $col['attname']; //use column name as column Id |
|
210 | + $columnId=$col['attname']; //use column name as column Id |
|
211 | 211 | |
212 | - $info['ColumnName'] = '"'.$columnId.'"'; //quote the column names! |
|
213 | - $info['ColumnId'] = $columnId; |
|
214 | - $info['ColumnIndex'] = $col['index']; |
|
212 | + $info['ColumnName']='"'.$columnId.'"'; //quote the column names! |
|
213 | + $info['ColumnId']=$columnId; |
|
214 | + $info['ColumnIndex']=$col['index']; |
|
215 | 215 | if(!$col['attnotnull']) |
216 | - $info['AllowNull'] = true; |
|
216 | + $info['AllowNull']=true; |
|
217 | 217 | if(in_array($columnId, $tableInfo->getPrimaryKeys())) |
218 | - $info['IsPrimaryKey'] = true; |
|
218 | + $info['IsPrimaryKey']=true; |
|
219 | 219 | if($this->isForeignKeyColumn($columnId, $tableInfo)) |
220 | - $info['IsForeignKey'] = true; |
|
220 | + $info['IsForeignKey']=true; |
|
221 | 221 | |
222 | 222 | if($col['atttypmod'] > 0) |
223 | - $info['ColumnSize'] = $col['atttypmod'] - 4; |
|
223 | + $info['ColumnSize']=$col['atttypmod'] - 4; |
|
224 | 224 | if($col['atthasdef']) |
225 | - $info['DefaultValue'] = $col['adsrc']; |
|
226 | - if($col['attisserial'] || substr($col['adsrc'],0,8) === 'nextval(') |
|
225 | + $info['DefaultValue']=$col['adsrc']; |
|
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 | - $info['SequenceName'] = $sequence; |
|
230 | + $info['SequenceName']=$sequence; |
|
231 | 231 | unset($info['DefaultValue']); |
232 | 232 | } |
233 | 233 | } |
234 | - $matches = array(); |
|
234 | + $matches=array(); |
|
235 | 235 | if(preg_match('/\((\d+)(?:,(\d+))?+\)/', $col['type'], $matches)) |
236 | 236 | { |
237 | - $info['DbType'] = preg_replace('/\(\d+(?:,\d+)?\)/','',$col['type']); |
|
237 | + $info['DbType']=preg_replace('/\(\d+(?:,\d+)?\)/', '', $col['type']); |
|
238 | 238 | if($this->isPrecisionType($info['DbType'])) |
239 | 239 | { |
240 | - $info['NumericPrecision'] = intval($matches[1]); |
|
240 | + $info['NumericPrecision']=intval($matches[1]); |
|
241 | 241 | if(count($matches) > 2) |
242 | - $info['NumericScale'] = intval($matches[2]); |
|
242 | + $info['NumericScale']=intval($matches[2]); |
|
243 | 243 | } |
244 | 244 | else |
245 | - $info['ColumnSize'] = intval($matches[1]); |
|
245 | + $info['ColumnSize']=intval($matches[1]); |
|
246 | 246 | } |
247 | 247 | else |
248 | - $info['DbType'] = $col['type']; |
|
248 | + $info['DbType']=$col['type']; |
|
249 | 249 | |
250 | - $tableInfo->Columns[$columnId] = new TPgsqlTableColumn($info); |
|
250 | + $tableInfo->Columns[$columnId]=new TPgsqlTableColumn($info); |
|
251 | 251 | } |
252 | 252 | |
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 | - $matches = array(); |
|
259 | - if(preg_match('/nextval\([^\']*\'([^\']+)\'[^\)]*\)/i',$src,$matches)) |
|
258 | + $matches=array(); |
|
259 | + if(preg_match('/nextval\([^\']*\'([^\']+)\'[^\)]*\)/i', $src, $matches)) |
|
260 | 260 | { |
261 | 261 | if(is_int(strpos($matches[1], '.'))) |
262 | 262 | return $matches[1]; |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | */ |
271 | 271 | protected function isPrecisionType($type) |
272 | 272 | { |
273 | - $type = strtolower(trim($type)); |
|
273 | + $type=strtolower(trim($type)); |
|
274 | 274 | return $type==='numeric' || $type==='interval' || strpos($type, 'time')===0; |
275 | 275 | } |
276 | 276 | |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | */ |
283 | 283 | protected function getConstraintKeys($schemaName, $tableName) |
284 | 284 | { |
285 | - $sql = |
|
285 | + $sql= |
|
286 | 286 | <<<EOD |
287 | 287 | SELECT conname, consrc, contype, indkey, indisclustered FROM ( |
288 | 288 | SELECT |
@@ -330,25 +330,25 @@ discard block |
||
330 | 330 | 1 |
331 | 331 | EOD; |
332 | 332 | $this->getDbConnection()->setActive(true); |
333 | - $command = $this->getDbConnection()->createCommand($sql); |
|
333 | + $command=$this->getDbConnection()->createCommand($sql); |
|
334 | 334 | $command->bindValue(':table', $tableName); |
335 | 335 | $command->bindValue(':schema', $schemaName); |
336 | - $primary = array(); |
|
337 | - $foreign = array(); |
|
336 | + $primary=array(); |
|
337 | + $foreign=array(); |
|
338 | 338 | foreach($command->query() as $row) |
339 | 339 | { |
340 | 340 | switch($row['contype']) |
341 | 341 | { |
342 | 342 | case 'p': |
343 | - $primary = $this->getPrimaryKeys($tableName, $schemaName, $row['indkey']); |
|
343 | + $primary=$this->getPrimaryKeys($tableName, $schemaName, $row['indkey']); |
|
344 | 344 | break; |
345 | 345 | case 'f': |
346 | - if(($fkey = $this->getForeignKeys($row['consrc']))!==null) |
|
347 | - $foreign[] = $fkey; |
|
346 | + if(($fkey=$this->getForeignKeys($row['consrc']))!==null) |
|
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 | /** |
@@ -358,8 +358,8 @@ discard block |
||
358 | 358 | */ |
359 | 359 | protected function getPrimaryKeys($tableName, $schemaName, $columnIndex) |
360 | 360 | { |
361 | - $index = join(', ', explode(' ', $columnIndex)); |
|
362 | - $sql = |
|
361 | + $index=join(', ', explode(' ', $columnIndex)); |
|
362 | + $sql= |
|
363 | 363 | <<<EOD |
364 | 364 | SELECT attnum, attname FROM pg_catalog.pg_attribute WHERE |
365 | 365 | attrelid=( |
@@ -369,14 +369,14 @@ discard block |
||
369 | 369 | ) |
370 | 370 | AND attnum IN ({$index}) |
371 | 371 | EOD; |
372 | - $command = $this->getDbConnection()->createCommand($sql); |
|
372 | + $command=$this->getDbConnection()->createCommand($sql); |
|
373 | 373 | $command->bindValue(':table', $tableName); |
374 | 374 | $command->bindValue(':schema', $schemaName); |
375 | 375 | // $command->bindValue(':columnIndex', join(', ', explode(' ', $columnIndex))); |
376 | - $primary = array(); |
|
376 | + $primary=array(); |
|
377 | 377 | foreach($command->query() as $row) |
378 | 378 | { |
379 | - $primary[] = $row['attname']; |
|
379 | + $primary[]=$row['attname']; |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | return $primary; |
@@ -389,16 +389,16 @@ discard block |
||
389 | 389 | */ |
390 | 390 | protected function getForeignKeys($src) |
391 | 391 | { |
392 | - $matches = array(); |
|
393 | - $brackets = '\(([^\)]+)\)'; |
|
394 | - $find = "/FOREIGN\s+KEY\s+{$brackets}\s+REFERENCES\s+([^\(]+){$brackets}/i"; |
|
392 | + $matches=array(); |
|
393 | + $brackets='\(([^\)]+)\)'; |
|
394 | + $find="/FOREIGN\s+KEY\s+{$brackets}\s+REFERENCES\s+([^\(]+){$brackets}/i"; |
|
395 | 395 | if(preg_match($find, $src, $matches)) |
396 | 396 | { |
397 | - $keys = preg_split('/,\s+/', $matches[1]); |
|
398 | - $fkeys = array(); |
|
397 | + $keys=preg_split('/,\s+/', $matches[1]); |
|
398 | + $fkeys=array(); |
|
399 | 399 | foreach(preg_split('/,\s+/', $matches[3]) as $i => $fkey) |
400 | - $fkeys[$keys[$i]] = $fkey; |
|
401 | - return array('table' => str_replace('"','',$matches[2]), 'keys' => $fkeys); |
|
400 | + $fkeys[$keys[$i]]=$fkey; |
|
401 | + return array('table' => str_replace('"', '', $matches[2]), 'keys' => $fkeys); |
|
402 | 402 | } |
403 | 403 | } |
404 | 404 | |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | WHERE table_schema=:schema AND table_type='BASE TABLE' |
433 | 433 | EOD; |
434 | 434 | $command=$this->getDbConnection()->createCommand($sql); |
435 | - $command->bindParam(':schema',$schema); |
|
435 | + $command->bindParam(':schema', $schema); |
|
436 | 436 | $rows=$command->queryAll(); |
437 | 437 | $names=array(); |
438 | 438 | foreach($rows as $row) |
@@ -35,7 +35,7 @@ |
||
35 | 35 | */ |
36 | 36 | public function getPHPType() |
37 | 37 | { |
38 | - $dbtype = strtolower($this->getDbType()); |
|
38 | + $dbtype=strtolower($this->getDbType()); |
|
39 | 39 | foreach(self::$types as $type => $dbtypes) |
40 | 40 | { |
41 | 41 | if(in_array($dbtype, $dbtypes)) |
@@ -30,11 +30,11 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function getSearchExpression($fields, $keywords) |
32 | 32 | { |
33 | - $columns = array(); |
|
33 | + $columns=array(); |
|
34 | 34 | foreach($fields as $field) |
35 | 35 | { |
36 | 36 | if($this->isSearchableColumn($this->getTableInfo()->getColumn($field))) |
37 | - $columns[] = $field; |
|
37 | + $columns[]=$field; |
|
38 | 38 | } |
39 | 39 | return parent::getSearchExpression($columns, $keywords); |
40 | 40 | } |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | */ |
45 | 45 | protected function isSearchableColumn($column) |
46 | 46 | { |
47 | - $type = strtolower($column->getDbType()); |
|
48 | - return $type === 'character varying' || $type === 'varchar' || |
|
49 | - $type === 'character' || $type === 'char' || $type === 'text'; |
|
47 | + $type=strtolower($column->getDbType()); |
|
48 | + return $type==='character varying' || $type==='varchar' || |
|
49 | + $type==='character' || $type==='char' || $type==='text'; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | { |
60 | 60 | $conditions=array(); |
61 | 61 | foreach($words as $word) |
62 | - $conditions[] = $column.' ILIKE '.$this->getDbConnection()->quoteString('%'.$word.'%'); |
|
62 | + $conditions[]=$column.' ILIKE '.$this->getDbConnection()->quoteString('%'.$word.'%'); |
|
63 | 63 | return '('.implode(' AND ', $conditions).')'; |
64 | 64 | } |
65 | 65 |
@@ -88,10 +88,10 @@ discard block |
||
88 | 88 | */ |
89 | 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 : ''; |
|
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 | 95 | return $sql.$limitStr.$offsetStr; |
96 | 96 | } |
97 | 97 | |
@@ -105,18 +105,18 @@ discard block |
||
105 | 105 | $orders=array(); |
106 | 106 | foreach($ordering as $name => $direction) |
107 | 107 | { |
108 | - $direction = strtolower($direction) == 'desc' ? 'DESC' : 'ASC'; |
|
109 | - if(false !== strpos($name, '(') && false !== strpos($name, ')')) { |
|
108 | + $direction=strtolower($direction)=='desc' ? 'DESC' : 'ASC'; |
|
109 | + if(false!==strpos($name, '(') && false!==strpos($name, ')')) { |
|
110 | 110 | // key is a function (bad practice, but we need to handle it) |
111 | - $key = $name; |
|
111 | + $key=$name; |
|
112 | 112 | } else { |
113 | 113 | // key is a column |
114 | - $key = $this->getTableInfo()->getColumn($name)->getColumnName(); |
|
114 | + $key=$this->getTableInfo()->getColumn($name)->getColumnName(); |
|
115 | 115 | } |
116 | - $orders[] = $key.' '.$direction; |
|
116 | + $orders[]=$key.' '.$direction; |
|
117 | 117 | } |
118 | 118 | if(count($orders) > 0) |
119 | - $sql .= ' ORDER BY '.implode(', ', $orders); |
|
119 | + $sql.=' ORDER BY '.implode(', ', $orders); |
|
120 | 120 | return $sql; |
121 | 121 | } |
122 | 122 | |
@@ -130,13 +130,13 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function getSearchExpression($fields, $keywords) |
132 | 132 | { |
133 | - if(strlen(trim($keywords)) == 0) return ''; |
|
134 | - $words = preg_split('/\s/u', $keywords); |
|
135 | - $conditions = array(); |
|
133 | + if(strlen(trim($keywords))==0) return ''; |
|
134 | + $words=preg_split('/\s/u', $keywords); |
|
135 | + $conditions=array(); |
|
136 | 136 | foreach($fields as $field) |
137 | 137 | { |
138 | - $column = $this->getTableInfo()->getColumn($field)->getColumnName(); |
|
139 | - $conditions[] = $this->getSearchCondition($column, $words); |
|
138 | + $column=$this->getTableInfo()->getColumn($field)->getColumnName(); |
|
139 | + $conditions[]=$this->getSearchCondition($column, $words); |
|
140 | 140 | } |
141 | 141 | return '('.implode(' OR ', $conditions).')'; |
142 | 142 | } |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | { |
151 | 151 | $conditions=array(); |
152 | 152 | foreach($words as $word) |
153 | - $conditions[] = $column.' LIKE '.$this->getDbConnection()->quoteString('%'.$word.'%'); |
|
153 | + $conditions[]=$column.' LIKE '.$this->getDbConnection()->quoteString('%'.$word.'%'); |
|
154 | 154 | return '('.implode(' AND ', $conditions).')'; |
155 | 155 | } |
156 | 156 | |
@@ -195,102 +195,102 @@ discard block |
||
195 | 195 | */ |
196 | 196 | public function getSelectFieldList($data='*') { |
197 | 197 | if(is_scalar($data)) { |
198 | - $tmp = explode(',', $data); |
|
199 | - $result = array(); |
|
198 | + $tmp=explode(',', $data); |
|
199 | + $result=array(); |
|
200 | 200 | foreach($tmp as $v) |
201 | - $result[] = trim($v); |
|
201 | + $result[]=trim($v); |
|
202 | 202 | return $result; |
203 | 203 | } |
204 | 204 | |
205 | - $bHasWildcard = false; |
|
206 | - $result = array(); |
|
205 | + $bHasWildcard=false; |
|
206 | + $result=array(); |
|
207 | 207 | if(is_array($data) || $data instanceof Traversable) { |
208 | - $columns = $this->getTableInfo()->getColumns(); |
|
208 | + $columns=$this->getTableInfo()->getColumns(); |
|
209 | 209 | foreach($data as $key=>$value) { |
210 | 210 | if($key==='*' || $value==='*') { |
211 | - $bHasWildcard = true; |
|
211 | + $bHasWildcard=true; |
|
212 | 212 | continue; |
213 | 213 | } |
214 | 214 | |
215 | 215 | if(strToUpper($key)==='NULL') { |
216 | - $result[] = 'NULL'; |
|
216 | + $result[]='NULL'; |
|
217 | 217 | continue; |
218 | 218 | } |
219 | 219 | |
220 | 220 | if(strpos($key, '(')!==false && strpos($key, ')')!==false) { |
221 | - $result[] = $key; |
|
221 | + $result[]=$key; |
|
222 | 222 | continue; |
223 | 223 | } |
224 | 224 | |
225 | 225 | if(stripos($key, 'AS')!==false) { |
226 | - $result[] = $key; |
|
226 | + $result[]=$key; |
|
227 | 227 | continue; |
228 | 228 | } |
229 | 229 | |
230 | 230 | if(stripos($value, 'AS')!==false) { |
231 | - $result[] = $value; |
|
231 | + $result[]=$value; |
|
232 | 232 | continue; |
233 | 233 | } |
234 | 234 | |
235 | - $v = isset($columns[$value]); |
|
236 | - $k = isset($columns[$key]); |
|
235 | + $v=isset($columns[$value]); |
|
236 | + $k=isset($columns[$key]); |
|
237 | 237 | if(is_integer($key) && $v) { |
238 | - $key = $value; |
|
239 | - $k = $v; |
|
238 | + $key=$value; |
|
239 | + $k=$v; |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | if(strToUpper($value)==='NULL') { |
243 | 243 | if($k) |
244 | - $result[] = 'NULL AS ' . $columns[$key]->getColumnName(); |
|
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 | 250 | if(strpos($value, '(')!==false && strpos($value, ')')!==false) { |
251 | 251 | if($k) |
252 | - $result[] = $value . ' AS ' . $columns[$key]->getColumnName(); |
|
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 | 258 | if($v && $key==$value) { |
259 | - $result[] = $columns[$value]->getColumnName(); |
|
259 | + $result[]=$columns[$value]->getColumnName(); |
|
260 | 260 | continue; |
261 | 261 | } |
262 | 262 | |
263 | 263 | if($k && $value==null) { |
264 | - $result[] = $columns[$key]->getColumnName(); |
|
264 | + $result[]=$columns[$key]->getColumnName(); |
|
265 | 265 | continue; |
266 | 266 | } |
267 | 267 | |
268 | 268 | if(is_string($key) && $v) { |
269 | - $result[] = $columns[$value]->getColumnName() . ' AS ' . $key; |
|
269 | + $result[]=$columns[$value]->getColumnName().' AS '.$key; |
|
270 | 270 | continue; |
271 | 271 | } |
272 | 272 | |
273 | 273 | if(is_numeric($value) && $k) { |
274 | - $result[] = $value . ' AS ' . $columns[$key]->getColumnName(); |
|
274 | + $result[]=$value.' AS '.$columns[$key]->getColumnName(); |
|
275 | 275 | continue; |
276 | 276 | } |
277 | 277 | |
278 | 278 | if(is_string($value) && $k) { |
279 | - $result[] = $this->getDbConnection()->quoteString($value) . ' AS ' . $columns[$key]->getColumnName(); |
|
279 | + $result[]=$this->getDbConnection()->quoteString($value).' AS '.$columns[$key]->getColumnName(); |
|
280 | 280 | continue; |
281 | 281 | } |
282 | 282 | |
283 | 283 | if(!$v && !$k && is_integer($key)) { |
284 | - $result[] = is_numeric($value) ? $value : $this->getDbConnection()->quoteString((string)$value); |
|
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) |
|
293 | - $result = $result = array_merge($this->getTableInfo()->getColumnNames(), $result); |
|
292 | + if($data===null || count($result)==0 || $bHasWildcard) |
|
293 | + $result=$result=array_merge($this->getTableInfo()->getColumnNames(), $result); |
|
294 | 294 | |
295 | 295 | return $result; |
296 | 296 | } |
@@ -304,21 +304,21 @@ discard block |
||
304 | 304 | */ |
305 | 305 | public function createFindCommand($where='1=1', $parameters=array(), $ordering=array(), $limit=-1, $offset=-1, $select='*') |
306 | 306 | { |
307 | - $table = $this->getTableInfo()->getTableFullName(); |
|
308 | - $fields = implode(', ', $this -> getSelectFieldList($select)); |
|
309 | - $sql = "SELECT {$fields} FROM {$table}"; |
|
307 | + $table=$this->getTableInfo()->getTableFullName(); |
|
308 | + $fields=implode(', ', $this -> getSelectFieldList($select)); |
|
309 | + $sql="SELECT {$fields} FROM {$table}"; |
|
310 | 310 | if(!empty($where)) |
311 | - $sql .= " WHERE {$where}"; |
|
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 | 317 | if(count($ordering) > 0) |
318 | - $sql = $this->applyOrdering($sql, $ordering); |
|
319 | - if($limit>=0 || $offset>=0) |
|
320 | - $sql = $this->applyLimitOffset($sql, $limit, $offset); |
|
321 | - $command = $this->createCommand($sql); |
|
318 | + $sql=$this->applyOrdering($sql, $ordering); |
|
319 | + if($limit >= 0 || $offset >= 0) |
|
320 | + $sql=$this->applyLimitOffset($sql, $limit, $offset); |
|
321 | + $command=$this->createCommand($sql); |
|
322 | 322 | $this->bindArrayValues($command, $parameters); |
323 | 323 | return $command; |
324 | 324 | } |
@@ -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 | - $table = $this->getTableInfo()->getTableFullName(); |
|
348 | - if (!empty($where)) |
|
349 | - $where = ' WHERE '.$where; |
|
350 | - $command = $this->createCommand("DELETE FROM {$table}".$where); |
|
347 | + $table=$this->getTableInfo()->getTableFullName(); |
|
348 | + if(!empty($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 | } |
@@ -362,9 +362,9 @@ discard block |
||
362 | 362 | */ |
363 | 363 | public function createInsertCommand($data) |
364 | 364 | { |
365 | - $table = $this->getTableInfo()->getTableFullName(); |
|
366 | - list($fields, $bindings) = $this->getInsertFieldBindings($data); |
|
367 | - $command = $this->createCommand("INSERT INTO {$table}({$fields}) VALUES ($bindings)"); |
|
365 | + $table=$this->getTableInfo()->getTableFullName(); |
|
366 | + list($fields, $bindings)=$this->getInsertFieldBindings($data); |
|
367 | + $command=$this->createCommand("INSERT INTO {$table}({$fields}) VALUES ($bindings)"); |
|
368 | 368 | $this->bindColumnValues($command, $data); |
369 | 369 | return $command; |
370 | 370 | } |
@@ -379,15 +379,15 @@ discard block |
||
379 | 379 | */ |
380 | 380 | public function createUpdateCommand($data, $where, $parameters=array()) |
381 | 381 | { |
382 | - $table = $this->getTableInfo()->getTableFullName(); |
|
382 | + $table=$this->getTableInfo()->getTableFullName(); |
|
383 | 383 | if($this->hasIntegerKey($parameters)) |
384 | - $fields = implode(', ', $this->getColumnBindings($data, true)); |
|
384 | + $fields=implode(', ', $this->getColumnBindings($data, true)); |
|
385 | 385 | else |
386 | - $fields = implode(', ', $this->getColumnBindings($data)); |
|
386 | + $fields=implode(', ', $this->getColumnBindings($data)); |
|
387 | 387 | |
388 | - if (!empty($where)) |
|
389 | - $where = ' WHERE '.$where; |
|
390 | - $command = $this->createCommand("UPDATE {$table} SET {$fields}".$where); |
|
388 | + if(!empty($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(); |
|
402 | + $fields=array(); $bindings=array(); |
|
403 | 403 | foreach(array_keys($values) as $name) |
404 | 404 | { |
405 | - $fields[] = $this->getTableInfo()->getColumn($name)->getColumnName(); |
|
406 | - $bindings[] = ':'.$name; |
|
405 | + $fields[]=$this->getTableInfo()->getColumn($name)->getColumnName(); |
|
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 | /** |
@@ -419,8 +419,8 @@ discard block |
||
419 | 419 | $bindings=array(); |
420 | 420 | foreach(array_keys($values) as $name) |
421 | 421 | { |
422 | - $column = $this->getTableInfo()->getColumn($name)->getColumnName(); |
|
423 | - $bindings[] = $position ? $column.' = ?' : $column.' = :'.$name; |
|
422 | + $column=$this->getTableInfo()->getColumn($name)->getColumnName(); |
|
423 | + $bindings[]=$position ? $column.' = ?' : $column.' = :'.$name; |
|
424 | 424 | } |
425 | 425 | return $bindings; |
426 | 426 | } |
@@ -444,8 +444,8 @@ discard block |
||
444 | 444 | { |
445 | 445 | foreach($values as $name=>$value) |
446 | 446 | { |
447 | - $column = $this->getTableInfo()->getColumn($name); |
|
448 | - if($value === null && $column->getAllowNull()) |
|
447 | + $column=$this->getTableInfo()->getColumn($name); |
|
448 | + if($value===null && $column->getAllowNull()) |
|
449 | 449 | $command->bindValue(':'.$name, null, PDO::PARAM_NULL); |
450 | 450 | else |
451 | 451 | $command->bindValue(':'.$name, $value, $column->getPdoType()); |
@@ -460,15 +460,15 @@ discard block |
||
460 | 460 | { |
461 | 461 | if($this->hasIntegerKey($values)) |
462 | 462 | { |
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])); |
|
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])); |
|
466 | 466 | } |
467 | 467 | else |
468 | 468 | { |
469 | 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 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | */ |
19 | 19 | class TDbTableColumn extends TComponent |
20 | 20 | { |
21 | - const UNDEFINED_VALUE= INF; //use infinity for undefined value |
|
21 | + const UNDEFINED_VALUE=INF; //use infinity for undefined value |
|
22 | 22 | |
23 | 23 | private $_info=array(); |
24 | 24 | |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @param mixed default value if information array value is null |
37 | 37 | * @return mixed information array value. |
38 | 38 | */ |
39 | - protected function getInfo($name,$default=null) |
|
39 | + protected function getInfo($name, $default=null) |
|
40 | 40 | { |
41 | 41 | return isset($this->_info[$name]) ? $this->_info[$name] : $default; |
42 | 42 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * @param string information array key name |
46 | 46 | * @param mixed new information array value. |
47 | 47 | */ |
48 | - protected function setInfo($name,$value) |
|
48 | + protected function setInfo($name, $value) |
|
49 | 49 | { |
50 | 50 | $this->_info[$name]=$value; |
51 | 51 | } |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function getAllowNull() |
120 | 120 | { |
121 | - return $this->getInfo('AllowNull',false); |
|
121 | + return $this->getInfo('AllowNull', false); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | if(($precision=$this->getNumericPrecision())!==null) |
151 | 151 | { |
152 | 152 | $scale=$this->getNumericScale(); |
153 | - return $scale===null ? pow(10,$precision) : pow(10,$precision-$scale); |
|
153 | + return $scale===null ? pow(10, $precision) : pow(10, $precision - $scale); |
|
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | */ |
160 | 160 | public function getIsPrimaryKey() |
161 | 161 | { |
162 | - return $this->getInfo('IsPrimaryKey',false); |
|
162 | + return $this->getInfo('IsPrimaryKey', false); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function getIsForeignKey() |
169 | 169 | { |
170 | - return $this->getInfo('IsForeignKey',false); |
|
170 | + return $this->getInfo('IsForeignKey', false); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | { |
32 | 32 | if($column->hasSequence()) |
33 | 33 | { |
34 | - $command = $this->getDbConnection()->createCommand('SELECT @@Identity'); |
|
34 | + $command=$this->getDbConnection()->createCommand('SELECT @@Identity'); |
|
35 | 35 | return intval($command->queryScalar()); |
36 | 36 | } |
37 | 37 | } |
@@ -79,12 +79,12 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function applyLimitOffset($sql, $limit=-1, $offset=-1) |
81 | 81 | { |
82 | - $limit = $limit!==null ? intval($limit) : -1; |
|
83 | - $offset = $offset!==null ? intval($offset) : -1; |
|
84 | - if ($limit > 0 && $offset <= 0) //just limit |
|
85 | - $sql = preg_replace('/^([\s(])*SELECT( DISTINCT)?(?!\s*TOP\s*\()/i',"\\1SELECT\\2 TOP $limit", $sql); |
|
82 | + $limit=$limit!==null ? intval($limit) : -1; |
|
83 | + $offset=$offset!==null ? intval($offset) : -1; |
|
84 | + if($limit > 0 && $offset <= 0) //just limit |
|
85 | + $sql=preg_replace('/^([\s(])*SELECT( DISTINCT)?(?!\s*TOP\s*\()/i', "\\1SELECT\\2 TOP $limit", $sql); |
|
86 | 86 | else if($limit > 0 && $offset > 0) |
87 | - $sql = $this->rewriteLimitOffsetSql($sql, $limit,$offset); |
|
87 | + $sql=$this->rewriteLimitOffsetSql($sql, $limit, $offset); |
|
88 | 88 | return $sql; |
89 | 89 | } |
90 | 90 | |
@@ -98,13 +98,13 @@ discard block |
||
98 | 98 | */ |
99 | 99 | protected function rewriteLimitOffsetSql($sql, $limit, $offset) |
100 | 100 | { |
101 | - $fetch = $limit+$offset; |
|
102 | - $sql = preg_replace('/^([\s(])*SELECT( DISTINCT)?(?!\s*TOP\s*\()/i',"\\1SELECT\\2 TOP $fetch", $sql); |
|
103 | - $ordering = $this->findOrdering($sql); |
|
101 | + $fetch=$limit + $offset; |
|
102 | + $sql=preg_replace('/^([\s(])*SELECT( DISTINCT)?(?!\s*TOP\s*\()/i', "\\1SELECT\\2 TOP $fetch", $sql); |
|
103 | + $ordering=$this->findOrdering($sql); |
|
104 | 104 | |
105 | - $orginalOrdering = $this->joinOrdering($ordering); |
|
106 | - $reverseOrdering = $this->joinOrdering($this->reverseDirection($ordering)); |
|
107 | - $sql = "SELECT * FROM (SELECT TOP {$limit} * FROM ($sql) as [__inner top table__] {$reverseOrdering}) as [__outer top table__] {$orginalOrdering}"; |
|
105 | + $orginalOrdering=$this->joinOrdering($ordering); |
|
106 | + $reverseOrdering=$this->joinOrdering($this->reverseDirection($ordering)); |
|
107 | + $sql="SELECT * FROM (SELECT TOP {$limit} * FROM ($sql) as [__inner top table__] {$reverseOrdering}) as [__outer top table__] {$orginalOrdering}"; |
|
108 | 108 | return $sql; |
109 | 109 | } |
110 | 110 | |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | $matches=array(); |
122 | 122 | $ordering=array(); |
123 | 123 | preg_match_all('/(ORDER BY)[\s"\[](.*)(ASC|DESC)?(?:[\s"\[]|$|COMPUTE|FOR)/i', $sql, $matches); |
124 | - if(count($matches)>1 && count($matches[2]) > 0) |
|
124 | + if(count($matches) > 1 && count($matches[2]) > 0) |
|
125 | 125 | { |
126 | - $parts = explode(',', $matches[2][0]); |
|
126 | + $parts=explode(',', $matches[2][0]); |
|
127 | 127 | foreach($parts as $part) |
128 | 128 | { |
129 | 129 | $subs=array(); |
@@ -131,12 +131,12 @@ discard block |
||
131 | 131 | { |
132 | 132 | if(count($subs) > 1 && count($subs[2]) > 0) |
133 | 133 | { |
134 | - $ordering[$subs[1][0]] = $subs[2][0]; |
|
134 | + $ordering[$subs[1][0]]=$subs[2][0]; |
|
135 | 135 | } |
136 | 136 | //else what? |
137 | 137 | } |
138 | 138 | else |
139 | - $ordering[trim($part)] = 'ASC'; |
|
139 | + $ordering[trim($part)]='ASC'; |
|
140 | 140 | } |
141 | 141 | } |
142 | 142 | return $ordering; |
@@ -148,11 +148,11 @@ discard block |
||
148 | 148 | */ |
149 | 149 | protected function joinOrdering($orders) |
150 | 150 | { |
151 | - if(count($orders)>0) |
|
151 | + if(count($orders) > 0) |
|
152 | 152 | { |
153 | 153 | $str=array(); |
154 | 154 | foreach($orders as $column => $direction) |
155 | - $str[] = $column.' '.$direction; |
|
155 | + $str[]=$column.' '.$direction; |
|
156 | 156 | return 'ORDER BY '.implode(', ', $str); |
157 | 157 | } |
158 | 158 | } |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | protected function reverseDirection($orders) |
165 | 165 | { |
166 | 166 | foreach($orders as $column => $direction) |
167 | - $orders[$column] = strtolower(trim($direction))==='desc' ? 'ASC' : 'DESC'; |
|
167 | + $orders[$column]=strtolower(trim($direction))==='desc' ? 'ASC' : 'DESC'; |
|
168 | 168 | return $orders; |
169 | 169 | } |
170 | 170 | } |