@@ -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 | } |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | protected function createTableInfo($table) |
| 71 | 71 | { |
| 72 | - list($catalogName,$schemaName,$tableName) = $this->getCatalogSchemaTableName($table); |
|
| 72 | + list($catalogName, $schemaName, $tableName)=$this->getCatalogSchemaTableName($table); |
|
| 73 | 73 | $this->getDbConnection()->setActive(true); |
| 74 | - $sql = <<<EOD |
|
| 74 | + $sql=<<<EOD |
|
| 75 | 75 | SELECT t.*, |
| 76 | 76 | c.*, |
| 77 | 77 | columnproperty(object_id(c.table_schema + '.' + c.table_name), c.column_name,'IsIdentity') as IsIdentity |
@@ -81,11 +81,11 @@ discard block |
||
| 81 | 81 | AND t.table_name = :table |
| 82 | 82 | EOD; |
| 83 | 83 | if($schemaName!==null) |
| 84 | - $sql .= ' AND t.table_schema = :schema'; |
|
| 84 | + $sql.=' AND t.table_schema = :schema'; |
|
| 85 | 85 | if($catalogName!==null) |
| 86 | - $sql .= ' AND t.table_catalog = :catalog'; |
|
| 86 | + $sql.=' AND t.table_catalog = :catalog'; |
|
| 87 | 87 | |
| 88 | - $command = $this->getDbConnection()->createCommand($sql); |
|
| 88 | + $command=$this->getDbConnection()->createCommand($sql); |
|
| 89 | 89 | $command->bindValue(':table', $tableName); |
| 90 | 90 | if($schemaName!==null) |
| 91 | 91 | $command->bindValue(':schema', $schemaName); |
@@ -96,8 +96,8 @@ discard block |
||
| 96 | 96 | foreach($command->query() as $col) |
| 97 | 97 | { |
| 98 | 98 | if($tableInfo===null) |
| 99 | - $tableInfo = $this->createNewTableInfo($col); |
|
| 100 | - $this->processColumn($tableInfo,$col); |
|
| 99 | + $tableInfo=$this->createNewTableInfo($col); |
|
| 100 | + $this->processColumn($tableInfo, $col); |
|
| 101 | 101 | } |
| 102 | 102 | if($tableInfo===null) |
| 103 | 103 | throw new TDbException('dbmetadata_invalid_table_view', $table); |
@@ -111,13 +111,13 @@ discard block |
||
| 111 | 111 | protected function getCatalogSchemaTableName($table) |
| 112 | 112 | { |
| 113 | 113 | //remove possible delimiters |
| 114 | - $result = explode('.', preg_replace('/\[|\]|"/', '', $table)); |
|
| 114 | + $result=explode('.', preg_replace('/\[|\]|"/', '', $table)); |
|
| 115 | 115 | if(count($result)===1) |
| 116 | - return array(null,null,$result[0]); |
|
| 116 | + return array(null, null, $result[0]); |
|
| 117 | 117 | if(count($result)===2) |
| 118 | - return array(null,$result[0],$result[1]); |
|
| 119 | - if(count($result)>2) |
|
| 120 | - return array($result[0],$result[1],$result[2]); |
|
| 118 | + return array(null, $result[0], $result[1]); |
|
| 119 | + if(count($result) > 2) |
|
| 120 | + return array($result[0], $result[1], $result[2]); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -126,31 +126,31 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | protected function processColumn($tableInfo, $col) |
| 128 | 128 | { |
| 129 | - $columnId = $col['COLUMN_NAME']; |
|
| 129 | + $columnId=$col['COLUMN_NAME']; |
|
| 130 | 130 | |
| 131 | - $info['ColumnName'] = "[$columnId]"; //quote the column names! |
|
| 132 | - $info['ColumnId'] = $columnId; |
|
| 133 | - $info['ColumnIndex'] = intval($col['ORDINAL_POSITION'])-1; //zero-based index |
|
| 131 | + $info['ColumnName']="[$columnId]"; //quote the column names! |
|
| 132 | + $info['ColumnId']=$columnId; |
|
| 133 | + $info['ColumnIndex']=intval($col['ORDINAL_POSITION']) - 1; //zero-based index |
|
| 134 | 134 | if($col['IS_NULLABLE']!=='NO') |
| 135 | - $info['AllowNull'] = true; |
|
| 135 | + $info['AllowNull']=true; |
|
| 136 | 136 | if($col['COLUMN_DEFAULT']!==null) |
| 137 | - $info['DefaultValue'] = $col['COLUMN_DEFAULT']; |
|
| 137 | + $info['DefaultValue']=$col['COLUMN_DEFAULT']; |
|
| 138 | 138 | |
| 139 | 139 | if(in_array($columnId, $tableInfo->getPrimaryKeys())) |
| 140 | - $info['IsPrimaryKey'] = true; |
|
| 140 | + $info['IsPrimaryKey']=true; |
|
| 141 | 141 | if($this->isForeignKeyColumn($columnId, $tableInfo)) |
| 142 | - $info['IsForeignKey'] = true; |
|
| 142 | + $info['IsForeignKey']=true; |
|
| 143 | 143 | |
| 144 | 144 | if($col['IsIdentity']==='1') |
| 145 | - $info['AutoIncrement'] = true; |
|
| 146 | - $info['DbType'] = $col['DATA_TYPE']; |
|
| 145 | + $info['AutoIncrement']=true; |
|
| 146 | + $info['DbType']=$col['DATA_TYPE']; |
|
| 147 | 147 | if($col['CHARACTER_MAXIMUM_LENGTH']!==null) |
| 148 | - $info['ColumnSize'] = intval($col['CHARACTER_MAXIMUM_LENGTH']); |
|
| 149 | - if($col['NUMERIC_PRECISION'] !== null) |
|
| 150 | - $info['NumericPrecision'] = intval($col['NUMERIC_PRECISION']); |
|
| 148 | + $info['ColumnSize']=intval($col['CHARACTER_MAXIMUM_LENGTH']); |
|
| 149 | + if($col['NUMERIC_PRECISION']!==null) |
|
| 150 | + $info['NumericPrecision']=intval($col['NUMERIC_PRECISION']); |
|
| 151 | 151 | if($col['NUMERIC_SCALE']!==null) |
| 152 | - $info['NumericScale'] = intval($col['NUMERIC_SCALE']); |
|
| 153 | - $tableInfo->Columns[$columnId] = new TMssqlTableColumn($info); |
|
| 152 | + $info['NumericScale']=intval($col['NUMERIC_SCALE']); |
|
| 153 | + $tableInfo->Columns[$columnId]=new TMssqlTableColumn($info); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -160,14 +160,14 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | protected function createNewTableInfo($col) |
| 162 | 162 | { |
| 163 | - $info['CatalogName'] = $col['TABLE_CATALOG']; |
|
| 164 | - $info['SchemaName'] = $col['TABLE_SCHEMA']; |
|
| 165 | - $info['TableName'] = $col['TABLE_NAME']; |
|
| 163 | + $info['CatalogName']=$col['TABLE_CATALOG']; |
|
| 164 | + $info['SchemaName']=$col['TABLE_SCHEMA']; |
|
| 165 | + $info['TableName']=$col['TABLE_NAME']; |
|
| 166 | 166 | if($col['TABLE_TYPE']==='VIEW') |
| 167 | - $info['IsView'] = true; |
|
| 168 | - list($primary, $foreign) = $this->getConstraintKeys($col); |
|
| 169 | - $class = $this->getTableInfoClass(); |
|
| 170 | - return new $class($info,$primary,$foreign); |
|
| 167 | + $info['IsView']=true; |
|
| 168 | + list($primary, $foreign)=$this->getConstraintKeys($col); |
|
| 169 | + $class=$this->getTableInfoClass(); |
|
| 170 | + return new $class($info, $primary, $foreign); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | protected function getConstraintKeys($col) |
| 180 | 180 | { |
| 181 | - $sql = <<<EOD |
|
| 181 | + $sql=<<<EOD |
|
| 182 | 182 | SELECT k.column_name field_name |
| 183 | 183 | FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE k |
| 184 | 184 | LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS c |
@@ -189,13 +189,13 @@ discard block |
||
| 189 | 189 | c.constraint_type ='PRIMARY KEY' |
| 190 | 190 | AND k.table_name = :table |
| 191 | 191 | EOD; |
| 192 | - $command = $this->getDbConnection()->createCommand($sql); |
|
| 192 | + $command=$this->getDbConnection()->createCommand($sql); |
|
| 193 | 193 | $command->bindValue(':table', $col['TABLE_NAME']); |
| 194 | - $primary = array(); |
|
| 194 | + $primary=array(); |
|
| 195 | 195 | foreach($command->query()->readAll() as $field) |
| 196 | - $primary[] = $field['field_name']; |
|
| 197 | - $foreign = $this->getForeignConstraints($col); |
|
| 198 | - return array($primary,$foreign); |
|
| 196 | + $primary[]=$field['field_name']; |
|
| 197 | + $foreign=$this->getForeignConstraints($col); |
|
| 198 | + return array($primary, $foreign); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | protected function getForeignConstraints($col) |
| 208 | 208 | { |
| 209 | 209 | //From http://msdn2.microsoft.com/en-us/library/aa175805(SQL.80).aspx |
| 210 | - $sql = <<<EOD |
|
| 210 | + $sql=<<<EOD |
|
| 211 | 211 | SELECT |
| 212 | 212 | KCU1.CONSTRAINT_NAME AS 'FK_CONSTRAINT_NAME' |
| 213 | 213 | , KCU1.TABLE_NAME AS 'FK_TABLE_NAME' |
@@ -232,14 +232,14 @@ discard block |
||
| 232 | 232 | AND KCU2.ORDINAL_POSITION = KCU1.ORDINAL_POSITION |
| 233 | 233 | WHERE KCU1.TABLE_NAME = :table |
| 234 | 234 | EOD; |
| 235 | - $command = $this->getDbConnection()->createCommand($sql); |
|
| 235 | + $command=$this->getDbConnection()->createCommand($sql); |
|
| 236 | 236 | $command->bindValue(':table', $col['TABLE_NAME']); |
| 237 | 237 | $fkeys=array(); |
| 238 | - $catalogSchema = "[{$col['TABLE_CATALOG']}].[{$col['TABLE_SCHEMA']}]"; |
|
| 238 | + $catalogSchema="[{$col['TABLE_CATALOG']}].[{$col['TABLE_SCHEMA']}]"; |
|
| 239 | 239 | foreach($command->query() as $info) |
| 240 | 240 | { |
| 241 | - $fkeys[$info['FK_CONSTRAINT_NAME']]['keys'][$info['FK_COLUMN_NAME']] = $info['UQ_COLUMN_NAME']; |
|
| 242 | - $fkeys[$info['FK_CONSTRAINT_NAME']]['table'] = $info['UQ_TABLE_NAME']; |
|
| 241 | + $fkeys[$info['FK_CONSTRAINT_NAME']]['keys'][$info['FK_COLUMN_NAME']]=$info['UQ_COLUMN_NAME']; |
|
| 242 | + $fkeys[$info['FK_CONSTRAINT_NAME']]['table']=$info['UQ_TABLE_NAME']; |
|
| 243 | 243 | } |
| 244 | 244 | return count($fkeys) > 0 ? array_values($fkeys) : $fkeys; |
| 245 | 245 | } |
@@ -276,9 +276,9 @@ discard block |
||
| 276 | 276 | $command->bindParam(":schema", $schema); |
| 277 | 277 | $rows=$command->queryAll(); |
| 278 | 278 | $names=array(); |
| 279 | - foreach ($rows as $row) |
|
| 279 | + foreach($rows as $row) |
|
| 280 | 280 | { |
| 281 | - if ($schema == self::DEFAULT_SCHEMA) |
|
| 281 | + if($schema==self::DEFAULT_SCHEMA) |
|
| 282 | 282 | $names[]=$row['TABLE_NAME']; |
| 283 | 283 | else |
| 284 | 284 | $names[]=$schema.'.'.$row['TABLE_SCHEMA'].'.'.$row['TABLE_NAME']; |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | class TMssqlTableColumn extends TDbTableColumn |
| 25 | 25 | { |
| 26 | - private static $types = array(); |
|
| 26 | + private static $types=array(); |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * Overrides parent implementation, returns PHP type from the db type. |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | public function getAutoIncrement() |
| 42 | 42 | { |
| 43 | - return $this->getInfo('AutoIncrement',false); |
|
| 43 | + return $this->getInfo('AutoIncrement', false); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | class TMysqlTableColumn extends TDbTableColumn |
| 25 | 25 | { |
| 26 | - private static $types = array( |
|
| 26 | + private static $types=array( |
|
| 27 | 27 | 'integer' => array('bit', 'tinyint', 'smallint', 'mediumint', 'int', 'integer', 'bigint'), |
| 28 | 28 | 'boolean' => array('boolean', 'bool'), |
| 29 | 29 | 'float' => array('float', 'double', 'double precision', 'decimal', 'dec', 'numeric', 'fixed') |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function getPHPType() |
| 37 | 37 | { |
| 38 | - $dbtype = trim(str_replace(array('unsigned', 'zerofill'),array('','',),strtolower($this->getDbType()))); |
|
| 38 | + $dbtype=trim(str_replace(array('unsigned', 'zerofill'), array('', '',), strtolower($this->getDbType()))); |
|
| 39 | 39 | if($dbtype==='tinyint' && $this->getColumnSize()===1) |
| 40 | 40 | return 'boolean'; |
| 41 | 41 | foreach(self::$types as $type => $dbtypes) |
@@ -74,24 +74,24 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | protected function createTableInfo($table) |
| 76 | 76 | { |
| 77 | - list($schemaName,$tableName) = $this->getSchemaTableName($table); |
|
| 78 | - $find = $schemaName===null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`"; |
|
| 79 | - $colCase = $this->getDbConnection()->getColumnCase(); |
|
| 80 | - if($colCase != TDbColumnCaseMode::Preserved) |
|
| 77 | + list($schemaName, $tableName)=$this->getSchemaTableName($table); |
|
| 78 | + $find=$schemaName===null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`"; |
|
| 79 | + $colCase=$this->getDbConnection()->getColumnCase(); |
|
| 80 | + if($colCase!=TDbColumnCaseMode::Preserved) |
|
| 81 | 81 | $this->getDbConnection()->setColumnCase('Preserved'); |
| 82 | 82 | $this->getDbConnection()->setActive(true); |
| 83 | - $sql = "SHOW FULL FIELDS FROM {$find}"; |
|
| 84 | - $command = $this->getDbConnection()->createCommand($sql); |
|
| 85 | - $tableInfo = $this->createNewTableInfo($table); |
|
| 83 | + $sql="SHOW FULL FIELDS FROM {$find}"; |
|
| 84 | + $command=$this->getDbConnection()->createCommand($sql); |
|
| 85 | + $tableInfo=$this->createNewTableInfo($table); |
|
| 86 | 86 | $index=0; |
| 87 | 87 | foreach($command->query() as $col) |
| 88 | 88 | { |
| 89 | - $col['index'] = $index++; |
|
| 90 | - $this->processColumn($tableInfo,$col); |
|
| 89 | + $col['index']=$index++; |
|
| 90 | + $this->processColumn($tableInfo, $col); |
|
| 91 | 91 | } |
| 92 | 92 | if($index===0) |
| 93 | 93 | throw new TDbException('dbmetadata_invalid_table_view', $table); |
| 94 | - if($colCase != TDbColumnCaseMode::Preserved) |
|
| 94 | + if($colCase!=TDbColumnCaseMode::Preserved) |
|
| 95 | 95 | $this->getDbConnection()->setColumnCase($colCase); |
| 96 | 96 | return $tableInfo; |
| 97 | 97 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | { |
| 104 | 104 | if(!$this->_serverVersion) |
| 105 | 105 | { |
| 106 | - $version = $this->getDbConnection()->getAttribute(PDO::ATTR_SERVER_VERSION); |
|
| 106 | + $version=$this->getDbConnection()->getAttribute(PDO::ATTR_SERVER_VERSION); |
|
| 107 | 107 | $digits=array(); |
| 108 | 108 | preg_match('/(\d+)\.(\d+)\.(\d+)/', $version, $digits); |
| 109 | 109 | $this->_serverVersion=floatval($digits[1].'.'.$digits[2].$digits[3]); |
@@ -117,50 +117,50 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | protected function processColumn($tableInfo, $col) |
| 119 | 119 | { |
| 120 | - $columnId = $col['Field']; |
|
| 120 | + $columnId=$col['Field']; |
|
| 121 | 121 | |
| 122 | - $info['ColumnName'] = "`$columnId`"; //quote the column names! |
|
| 123 | - $info['ColumnId'] = $columnId; |
|
| 124 | - $info['ColumnIndex'] = $col['index']; |
|
| 122 | + $info['ColumnName']="`$columnId`"; //quote the column names! |
|
| 123 | + $info['ColumnId']=$columnId; |
|
| 124 | + $info['ColumnIndex']=$col['index']; |
|
| 125 | 125 | if($col['Null']==='YES') |
| 126 | - $info['AllowNull'] = true; |
|
| 126 | + $info['AllowNull']=true; |
|
| 127 | 127 | if(is_int(strpos(strtolower($col['Extra']), 'auto_increment'))) |
| 128 | 128 | $info['AutoIncrement']=true; |
| 129 | 129 | if($col['Default']!=="") |
| 130 | - $info['DefaultValue'] = $col['Default']; |
|
| 130 | + $info['DefaultValue']=$col['Default']; |
|
| 131 | 131 | |
| 132 | 132 | if($col['Key']==='PRI' || in_array($columnId, $tableInfo->getPrimaryKeys())) |
| 133 | - $info['IsPrimaryKey'] = true; |
|
| 133 | + $info['IsPrimaryKey']=true; |
|
| 134 | 134 | if($this->isForeignKeyColumn($columnId, $tableInfo)) |
| 135 | - $info['IsForeignKey'] = true; |
|
| 135 | + $info['IsForeignKey']=true; |
|
| 136 | 136 | |
| 137 | - $info['DbType'] = $col['Type']; |
|
| 137 | + $info['DbType']=$col['Type']; |
|
| 138 | 138 | $match=array(); |
| 139 | 139 | //find SET/ENUM values, column size, precision, and scale |
| 140 | 140 | if(preg_match('/\((.*)\)/', $col['Type'], $match)) |
| 141 | 141 | { |
| 142 | - $info['DbType']= preg_replace('/\(.*\)/', '', $col['Type']); |
|
| 142 | + $info['DbType']=preg_replace('/\(.*\)/', '', $col['Type']); |
|
| 143 | 143 | |
| 144 | 144 | //find SET/ENUM values |
| 145 | 145 | if($this->isEnumSetType($info['DbType'])) |
| 146 | - $info['DbTypeValues'] = preg_split("/[',]/S", $match[1], -1, PREG_SPLIT_NO_EMPTY); |
|
| 146 | + $info['DbTypeValues']=preg_split("/[',]/S", $match[1], -1, PREG_SPLIT_NO_EMPTY); |
|
| 147 | 147 | |
| 148 | 148 | //find column size, precision and scale |
| 149 | - $pscale = array(); |
|
| 149 | + $pscale=array(); |
|
| 150 | 150 | if(preg_match('/(\d+)(?:,(\d+))?+/', $match[1], $pscale)) |
| 151 | 151 | { |
| 152 | 152 | if($this->isPrecisionType($info['DbType'])) |
| 153 | 153 | { |
| 154 | - $info['NumericPrecision'] = intval($pscale[1]); |
|
| 154 | + $info['NumericPrecision']=intval($pscale[1]); |
|
| 155 | 155 | if(count($pscale) > 2) |
| 156 | - $info['NumericScale'] = intval($pscale[2]); |
|
| 156 | + $info['NumericScale']=intval($pscale[2]); |
|
| 157 | 157 | } |
| 158 | 158 | else |
| 159 | - $info['ColumnSize'] = intval($pscale[1]); |
|
| 159 | + $info['ColumnSize']=intval($pscale[1]); |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - $tableInfo->Columns[$columnId] = new TMysqlTableColumn($info); |
|
| 163 | + $tableInfo->Columns[$columnId]=new TMysqlTableColumn($info); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | */ |
| 169 | 169 | protected function isPrecisionType($type) |
| 170 | 170 | { |
| 171 | - $type = strtolower(trim($type)); |
|
| 171 | + $type=strtolower(trim($type)); |
|
| 172 | 172 | return $type==='decimal' || $type==='dec' |
| 173 | 173 | || $type==='float' || $type==='double' |
| 174 | 174 | || $type==='double precision' || $type==='real'; |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | */ |
| 180 | 180 | protected function isEnumSetType($type) |
| 181 | 181 | { |
| 182 | - $type = strtolower(trim($type)); |
|
| 182 | + $type=strtolower(trim($type)); |
|
| 183 | 183 | return $type==='set' || $type==='enum'; |
| 184 | 184 | } |
| 185 | 185 | |
@@ -191,12 +191,12 @@ discard block |
||
| 191 | 191 | protected function getSchemaTableName($table) |
| 192 | 192 | { |
| 193 | 193 | //remove the back ticks and separate out the "database.table" |
| 194 | - $result = explode('.', str_replace('`', '', $table)); |
|
| 194 | + $result=explode('.', str_replace('`', '', $table)); |
|
| 195 | 195 | foreach($result as $name) |
| 196 | 196 | { |
| 197 | 197 | if(!$this->isValidIdentifier($name)) |
| 198 | 198 | { |
| 199 | - $ref = 'http://dev.mysql.com/doc/refman/5.0/en/identifiers.html'; |
|
| 199 | + $ref='http://dev.mysql.com/doc/refman/5.0/en/identifiers.html'; |
|
| 200 | 200 | throw new TDbException('dbcommon_invalid_identifier_name', $table, $ref); |
| 201 | 201 | } |
| 202 | 202 | } |
@@ -220,14 +220,14 @@ discard block |
||
| 220 | 220 | */ |
| 221 | 221 | protected function createNewTableInfo($table) |
| 222 | 222 | { |
| 223 | - list($schemaName,$tableName) = $this->getSchemaTableName($table); |
|
| 224 | - $info['SchemaName'] = $schemaName; |
|
| 225 | - $info['TableName'] = $tableName; |
|
| 226 | - if($this->getIsView($schemaName,$tableName)) |
|
| 227 | - $info['IsView'] = true; |
|
| 228 | - list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName); |
|
| 229 | - $class = $this->getTableInfoClass(); |
|
| 230 | - return new $class($info,$primary,$foreign); |
|
| 223 | + list($schemaName, $tableName)=$this->getSchemaTableName($table); |
|
| 224 | + $info['SchemaName']=$schemaName; |
|
| 225 | + $info['TableName']=$tableName; |
|
| 226 | + if($this->getIsView($schemaName, $tableName)) |
|
| 227 | + $info['IsView']=true; |
|
| 228 | + list($primary, $foreign)=$this->getConstraintKeys($schemaName, $tableName); |
|
| 229 | + $class=$this->getTableInfoClass(); |
|
| 230 | + return new $class($info, $primary, $foreign); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -240,25 +240,25 @@ discard block |
||
| 240 | 240 | * @return boolean true if is view, false otherwise. |
| 241 | 241 | * @throws TDbException if table or view does not exist. |
| 242 | 242 | */ |
| 243 | - protected function getIsView($schemaName,$tableName) |
|
| 243 | + protected function getIsView($schemaName, $tableName) |
|
| 244 | 244 | { |
| 245 | - if($this->getServerVersion()<5.01) |
|
| 245 | + if($this->getServerVersion() < 5.01) |
|
| 246 | 246 | return false; |
| 247 | 247 | if($schemaName!==null) |
| 248 | - $sql = "SHOW FULL TABLES FROM `{$schemaName}` LIKE :table"; |
|
| 248 | + $sql="SHOW FULL TABLES FROM `{$schemaName}` LIKE :table"; |
|
| 249 | 249 | else |
| 250 | - $sql = "SHOW FULL TABLES LIKE :table"; |
|
| 250 | + $sql="SHOW FULL TABLES LIKE :table"; |
|
| 251 | 251 | |
| 252 | - $command = $this->getDbConnection()->createCommand($sql); |
|
| 252 | + $command=$this->getDbConnection()->createCommand($sql); |
|
| 253 | 253 | $command->bindValue(':table', $tableName); |
| 254 | 254 | try |
| 255 | 255 | { |
| 256 | - return count($result = $command->queryRow()) > 0 && $result['Table_type']==='VIEW'; |
|
| 256 | + return count($result=$command->queryRow()) > 0 && $result['Table_type']==='VIEW'; |
|
| 257 | 257 | } |
| 258 | 258 | catch(TDbException $e) |
| 259 | 259 | { |
| 260 | - $table = $schemaName===null?$tableName:$schemaName.'.'.$tableName; |
|
| 261 | - throw new TDbException('dbcommon_invalid_table_name',$table,$e->getMessage()); |
|
| 260 | + $table=$schemaName===null ? $tableName : $schemaName.'.'.$tableName; |
|
| 261 | + throw new TDbException('dbcommon_invalid_table_name', $table, $e->getMessage()); |
|
| 262 | 262 | } |
| 263 | 263 | } |
| 264 | 264 | |
@@ -270,22 +270,22 @@ discard block |
||
| 270 | 270 | */ |
| 271 | 271 | protected function getConstraintKeys($schemaName, $tableName) |
| 272 | 272 | { |
| 273 | - $table = $schemaName===null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`"; |
|
| 274 | - $sql = "SHOW INDEX FROM {$table}"; |
|
| 275 | - $command = $this->getDbConnection()->createCommand($sql); |
|
| 276 | - $primary = array(); |
|
| 273 | + $table=$schemaName===null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`"; |
|
| 274 | + $sql="SHOW INDEX FROM {$table}"; |
|
| 275 | + $command=$this->getDbConnection()->createCommand($sql); |
|
| 276 | + $primary=array(); |
|
| 277 | 277 | foreach($command->query() as $row) |
| 278 | 278 | { |
| 279 | 279 | if($row['Key_name']==='PRIMARY') |
| 280 | - $primary[] = $row['Column_name']; |
|
| 280 | + $primary[]=$row['Column_name']; |
|
| 281 | 281 | } |
| 282 | 282 | // MySQL version was increased to >=5.1.21 instead of 5.x |
| 283 | 283 | // due to a MySQL bug (http://bugs.mysql.com/bug.php?id=19588) |
| 284 | 284 | if($this->getServerVersion() >= 5.121) |
| 285 | - $foreign = $this->getForeignConstraints($schemaName,$tableName); |
|
| 285 | + $foreign=$this->getForeignConstraints($schemaName, $tableName); |
|
| 286 | 286 | else |
| 287 | - $foreign = $this->findForeignConstraints($schemaName,$tableName); |
|
| 288 | - return array($primary,$foreign); |
|
| 287 | + $foreign=$this->findForeignConstraints($schemaName, $tableName); |
|
| 288 | + return array($primary, $foreign); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
@@ -296,8 +296,8 @@ discard block |
||
| 296 | 296 | */ |
| 297 | 297 | protected function getForeignConstraints($schemaName, $tableName) |
| 298 | 298 | { |
| 299 | - $andSchema = $schemaName !== null ? 'AND TABLE_SCHEMA LIKE :schema' : 'AND TABLE_SCHEMA LIKE DATABASE()'; |
|
| 300 | - $sql = <<<EOD |
|
| 299 | + $andSchema=$schemaName!==null ? 'AND TABLE_SCHEMA LIKE :schema' : 'AND TABLE_SCHEMA LIKE DATABASE()'; |
|
| 300 | + $sql=<<<EOD |
|
| 301 | 301 | SELECT |
| 302 | 302 | CONSTRAINT_NAME as con, |
| 303 | 303 | COLUMN_NAME as col, |
@@ -311,15 +311,15 @@ discard block |
||
| 311 | 311 | AND TABLE_NAME LIKE :table |
| 312 | 312 | $andSchema |
| 313 | 313 | EOD; |
| 314 | - $command = $this->getDbConnection()->createCommand($sql); |
|
| 314 | + $command=$this->getDbConnection()->createCommand($sql); |
|
| 315 | 315 | $command->bindValue(':table', $tableName); |
| 316 | 316 | if($schemaName!==null) |
| 317 | 317 | $command->bindValue(':schema', $schemaName); |
| 318 | 318 | $fkeys=array(); |
| 319 | 319 | foreach($command->query() as $col) |
| 320 | 320 | { |
| 321 | - $fkeys[$col['con']]['keys'][$col['col']] = $col['fkcol']; |
|
| 322 | - $fkeys[$col['con']]['table'] = $col['fktable']; |
|
| 321 | + $fkeys[$col['con']]['keys'][$col['col']]=$col['fkcol']; |
|
| 322 | + $fkeys[$col['con']]['table']=$col['fktable']; |
|
| 323 | 323 | } |
| 324 | 324 | return count($fkeys) > 0 ? array_values($fkeys) : $fkeys; |
| 325 | 325 | } |
@@ -332,17 +332,17 @@ discard block |
||
| 332 | 332 | */ |
| 333 | 333 | protected function getShowCreateTable($schemaName, $tableName) |
| 334 | 334 | { |
| 335 | - if(version_compare(PHP_VERSION,'5.1.3','<')) |
|
| 335 | + if(version_compare(PHP_VERSION, '5.1.3', '<')) |
|
| 336 | 336 | throw new TDbException('dbmetadata_requires_php_version', 'Mysql 4.1.x', '5.1.3'); |
| 337 | 337 | |
| 338 | 338 | //See http://netevil.org/node.php?nid=795&SC=1 |
| 339 | 339 | $this->getDbConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); |
| 340 | 340 | if($schemaName!==null) |
| 341 | - $sql = "SHOW CREATE TABLE `{$schemaName}`.`{$tableName}`"; |
|
| 341 | + $sql="SHOW CREATE TABLE `{$schemaName}`.`{$tableName}`"; |
|
| 342 | 342 | else |
| 343 | - $sql = "SHOW CREATE TABLE `{$tableName}`"; |
|
| 344 | - $command = $this->getDbConnection()->createCommand($sql); |
|
| 345 | - $result = $command->queryRow(); |
|
| 343 | + $sql="SHOW CREATE TABLE `{$tableName}`"; |
|
| 344 | + $command=$this->getDbConnection()->createCommand($sql); |
|
| 345 | + $result=$command->queryRow(); |
|
| 346 | 346 | return isset($result['Create Table']) ? $result['Create Table'] : (isset($result['Create View']) ? $result['Create View'] : ''); |
| 347 | 347 | } |
| 348 | 348 | |
@@ -354,19 +354,19 @@ discard block |
||
| 354 | 354 | */ |
| 355 | 355 | protected function findForeignConstraints($schemaName, $tableName) |
| 356 | 356 | { |
| 357 | - $sql = $this->getShowCreateTable($schemaName, $tableName); |
|
| 358 | - $matches =array(); |
|
| 359 | - $regexp = '/FOREIGN KEY\s+\(([^\)]+)\)\s+REFERENCES\s+`?([^`]+)`?\s\(([^\)]+)\)/mi'; |
|
| 360 | - preg_match_all($regexp,$sql,$matches,PREG_SET_ORDER); |
|
| 361 | - $foreign = array(); |
|
| 357 | + $sql=$this->getShowCreateTable($schemaName, $tableName); |
|
| 358 | + $matches=array(); |
|
| 359 | + $regexp='/FOREIGN KEY\s+\(([^\)]+)\)\s+REFERENCES\s+`?([^`]+)`?\s\(([^\)]+)\)/mi'; |
|
| 360 | + preg_match_all($regexp, $sql, $matches, PREG_SET_ORDER); |
|
| 361 | + $foreign=array(); |
|
| 362 | 362 | foreach($matches as $match) |
| 363 | 363 | { |
| 364 | - $fields = array_map('trim',explode(',',str_replace('`','',$match[1]))); |
|
| 365 | - $fk_fields = array_map('trim',explode(',',str_replace('`','',$match[3]))); |
|
| 364 | + $fields=array_map('trim', explode(',', str_replace('`', '', $match[1]))); |
|
| 365 | + $fk_fields=array_map('trim', explode(',', str_replace('`', '', $match[3]))); |
|
| 366 | 366 | $keys=array(); |
| 367 | 367 | foreach($fields as $k=>$v) |
| 368 | - $keys[$v] = $fk_fields[$k]; |
|
| 369 | - $foreign[] = array('keys' => $keys, 'table' => trim($match[2])); |
|
| 368 | + $keys[$v]=$fk_fields[$k]; |
|
| 369 | + $foreign[]=array('keys' => $keys, 'table' => trim($match[2])); |
|
| 370 | 370 | } |
| 371 | 371 | return $foreign; |
| 372 | 372 | } |
@@ -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 | - $table = $this->getDbConnection()->quoteString($tableName); |
|
| 75 | - $sql = "PRAGMA table_info({$table})"; |
|
| 76 | - $command = $this->getDbConnection()->createCommand($sql); |
|
| 77 | - $foreign = $this->getForeignKeys($table); |
|
| 74 | + $table=$this->getDbConnection()->quoteString($tableName); |
|
| 75 | + $sql="PRAGMA table_info({$table})"; |
|
| 76 | + $command=$this->getDbConnection()->createCommand($sql); |
|
| 77 | + $foreign=$this->getForeignKeys($table); |
|
| 78 | 78 | $index=0; |
| 79 | 79 | $columns=array(); |
| 80 | 80 | $primary=array(); |
| 81 | 81 | foreach($command->query() as $col) |
| 82 | 82 | { |
| 83 | - $col['index'] = $index++; |
|
| 84 | - $column = $this->processColumn($col, $foreign); |
|
| 85 | - $columns[$col['name']] = $column; |
|
| 83 | + $col['index']=$index++; |
|
| 84 | + $column=$this->processColumn($col, $foreign); |
|
| 85 | + $columns[$col['name']]=$column; |
|
| 86 | 86 | if($column->getIsPrimaryKey()) |
| 87 | - $primary[] = $col['name']; |
|
| 87 | + $primary[]=$col['name']; |
|
| 88 | 88 | } |
| 89 | - $info['TableName'] = $tableName; |
|
| 89 | + $info['TableName']=$tableName; |
|
| 90 | 90 | if($this->getIsView($tableName)) |
| 91 | - $info['IsView'] = true; |
|
| 91 | + $info['IsView']=true; |
|
| 92 | 92 | if(count($columns)===0) |
| 93 | 93 | throw new TDbException('dbmetadata_invalid_table_view', $tableName); |
| 94 | - $class = $this->getTableInfoClass(); |
|
| 95 | - $tableInfo = new $class($info,$primary,$foreign); |
|
| 94 | + $class=$this->getTableInfoClass(); |
|
| 95 | + $tableInfo=new $class($info, $primary, $foreign); |
|
| 96 | 96 | $tableInfo->getColumns()->copyFrom($columns); |
| 97 | 97 | return $tableInfo; |
| 98 | 98 | } |
@@ -103,11 +103,11 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | protected function getIsView($tableName) |
| 105 | 105 | { |
| 106 | - $sql = 'SELECT count(*) FROM sqlite_master WHERE type="view" AND name= :table'; |
|
| 106 | + $sql='SELECT count(*) FROM sqlite_master WHERE type="view" AND name= :table'; |
|
| 107 | 107 | $this->getDbConnection()->setActive(true); |
| 108 | - $command = $this->getDbConnection()->createCommand($sql); |
|
| 108 | + $command=$this->getDbConnection()->createCommand($sql); |
|
| 109 | 109 | $command->bindValue(':table', $tableName); |
| 110 | - return intval($command->queryScalar()) === 1; |
|
| 110 | + return intval($command->queryScalar())===1; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -117,39 +117,39 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | protected function processColumn($col, $foreign) |
| 119 | 119 | { |
| 120 | - $columnId = $col['name']; //use column name as column Id |
|
| 120 | + $columnId=$col['name']; //use column name as column Id |
|
| 121 | 121 | |
| 122 | - $info['ColumnName'] = '"'.$columnId.'"'; //quote the column names! |
|
| 123 | - $info['ColumnId'] = $columnId; |
|
| 124 | - $info['ColumnIndex'] = $col['index']; |
|
| 122 | + $info['ColumnName']='"'.$columnId.'"'; //quote the column names! |
|
| 123 | + $info['ColumnId']=$columnId; |
|
| 124 | + $info['ColumnIndex']=$col['index']; |
|
| 125 | 125 | |
| 126 | 126 | if($col['notnull']!=='99') |
| 127 | - $info['AllowNull'] = true; |
|
| 127 | + $info['AllowNull']=true; |
|
| 128 | 128 | |
| 129 | 129 | if($col['pk']==='1') |
| 130 | - $info['IsPrimaryKey'] = true; |
|
| 130 | + $info['IsPrimaryKey']=true; |
|
| 131 | 131 | if($this->isForeignKeyColumn($columnId, $foreign)) |
| 132 | - $info['IsForeignKey'] = true; |
|
| 132 | + $info['IsForeignKey']=true; |
|
| 133 | 133 | |
| 134 | 134 | if($col['dflt_value']!==null) |
| 135 | - $info['DefaultValue'] = $col['dflt_value']; |
|
| 135 | + $info['DefaultValue']=$col['dflt_value']; |
|
| 136 | 136 | |
| 137 | - $type = strtolower($col['type']); |
|
| 138 | - $info['AutoIncrement'] = $type==='integer' && $col['pk']==='1'; |
|
| 137 | + $type=strtolower($col['type']); |
|
| 138 | + $info['AutoIncrement']=$type==='integer' && $col['pk']==='1'; |
|
| 139 | 139 | |
| 140 | - $info['DbType'] = $type; |
|
| 140 | + $info['DbType']=$type; |
|
| 141 | 141 | $match=array(); |
| 142 | 142 | if(is_int($pos=strpos($type, '(')) && preg_match('/\((.*)\)/', $type, $match)) |
| 143 | 143 | { |
| 144 | - $ps = explode(',', $match[1]); |
|
| 144 | + $ps=explode(',', $match[1]); |
|
| 145 | 145 | if(count($ps)===2) |
| 146 | 146 | { |
| 147 | - $info['NumericPrecision'] = intval($ps[0]); |
|
| 148 | - $info['NumericScale'] = intval($ps[1]); |
|
| 147 | + $info['NumericPrecision']=intval($ps[0]); |
|
| 148 | + $info['NumericScale']=intval($ps[1]); |
|
| 149 | 149 | } |
| 150 | 150 | else |
| 151 | 151 | $info['ColumnSize']=intval($match[1]); |
| 152 | - $info['DbType'] = substr($type,0,$pos); |
|
| 152 | + $info['DbType']=substr($type, 0, $pos); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | return new TSqliteTableColumn($info); |
@@ -163,13 +163,13 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | protected function getForeignKeys($table) |
| 165 | 165 | { |
| 166 | - $sql = "PRAGMA foreign_key_list({$table})"; |
|
| 167 | - $command = $this->getDbConnection()->createCommand($sql); |
|
| 168 | - $fkeys = array(); |
|
| 166 | + $sql="PRAGMA foreign_key_list({$table})"; |
|
| 167 | + $command=$this->getDbConnection()->createCommand($sql); |
|
| 168 | + $fkeys=array(); |
|
| 169 | 169 | foreach($command->query() as $col) |
| 170 | 170 | { |
| 171 | - $fkeys[$col['table']]['keys'][$col['from']] = $col['to']; |
|
| 172 | - $fkeys[$col['table']]['table'] = $col['table']; |
|
| 171 | + $fkeys[$col['table']]['keys'][$col['from']]=$col['to']; |
|
| 172 | + $fkeys[$col['table']]['table']=$col['table']; |
|
| 173 | 173 | } |
| 174 | 174 | return count($fkeys) > 0 ? array_values($fkeys) : $fkeys; |
| 175 | 175 | } |
@@ -30,12 +30,12 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | public function applyLimitOffset($sql, $limit=-1, $offset=-1) |
| 32 | 32 | { |
| 33 | - $limit = $limit!==null ? intval($limit) : -1; |
|
| 34 | - $offset = $offset!==null ? intval($offset) : -1; |
|
| 33 | + $limit=$limit!==null ? intval($limit) : -1; |
|
| 34 | + $offset=$offset!==null ? intval($offset) : -1; |
|
| 35 | 35 | if($limit > 0 || $offset > 0) |
| 36 | 36 | { |
| 37 | - $limitStr = ' LIMIT '.$limit; |
|
| 38 | - $offsetStr = $offset >= 0 ? ' OFFSET '.$offset : ''; |
|
| 37 | + $limitStr=' LIMIT '.$limit; |
|
| 38 | + $offsetStr=$offset >= 0 ? ' OFFSET '.$offset : ''; |
|
| 39 | 39 | return $sql.$limitStr.$offsetStr; |
| 40 | 40 | } |
| 41 | 41 | else |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | /** |
| 27 | 27 | * @TODO add sqlite types. |
| 28 | 28 | */ |
| 29 | - private static $types = array(); |
|
| 29 | + private static $types=array(); |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Overrides parent implementation, returns PHP type from the db type. |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | public function getPHPType() |
| 36 | 36 | { |
| 37 | - $dbtype = strtolower($this->getDbType()); |
|
| 37 | + $dbtype=strtolower($this->getDbType()); |
|
| 38 | 38 | foreach(self::$types as $type => $dbtypes) |
| 39 | 39 | { |
| 40 | 40 | if(in_array($dbtype, $dbtypes)) |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | { |
| 63 | 63 | $db=$this->getDbConnection(); |
| 64 | 64 | foreach($xml['database'] as $name=>$value) |
| 65 | - $db->setSubProperty($name,$value); |
|
| 65 | + $db->setSubProperty($name, $value); |
|
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | else |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | { |
| 72 | 72 | $db=$this->getDbConnection(); |
| 73 | 73 | foreach($prop->getAttributes() as $name=>$value) |
| 74 | - $db->setSubproperty($name,$value); |
|
| 74 | + $db->setSubproperty($name, $value); |
|
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | } |
@@ -106,9 +106,9 @@ discard block |
||
| 106 | 106 | if($this->_conn===null) |
| 107 | 107 | { |
| 108 | 108 | if($this->_connID!=='') |
| 109 | - $this->_conn = $this->findConnectionByID($this->getConnectionID()); |
|
| 109 | + $this->_conn=$this->findConnectionByID($this->getConnectionID()); |
|
| 110 | 110 | else |
| 111 | - $this->_conn = Prado::createComponent($this->getConnectionClass()); |
|
| 111 | + $this->_conn=Prado::createComponent($this->getConnectionClass()); |
|
| 112 | 112 | } |
| 113 | 113 | return $this->_conn; |
| 114 | 114 | } |
@@ -154,12 +154,12 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | protected function findConnectionByID($id) |
| 156 | 156 | { |
| 157 | - $conn = $this->getApplication()->getModule($id); |
|
| 157 | + $conn=$this->getApplication()->getModule($id); |
|
| 158 | 158 | if($conn instanceof TDbConnection) |
| 159 | 159 | return $conn; |
| 160 | 160 | else if($conn instanceof TDataSourceConfig) |
| 161 | 161 | return $conn->getDbConnection(); |
| 162 | 162 | else |
| 163 | - throw new TConfigurationException('datasource_dbconnection_invalid',$id); |
|
| 163 | + throw new TConfigurationException('datasource_dbconnection_invalid', $id); |
|
| 164 | 164 | } |
| 165 | 165 | } |