@@ -92,6 +92,7 @@ discard block |
||
92 | 92 | |
93 | 93 | /** |
94 | 94 | * Fetch results for current relationship. |
95 | + * @param TActiveRecord $obj |
|
95 | 96 | * @return boolean always true. |
96 | 97 | */ |
97 | 98 | public function fetchResultsInto($obj) |
@@ -104,7 +105,6 @@ discard block |
||
104 | 105 | * Returns foreign keys in $fromRecord with source column names as key |
105 | 106 | * and foreign column names in the corresponding $matchesRecord as value. |
106 | 107 | * The method returns the first matching foreign key between these 2 records. |
107 | - * @param TActiveRecord $fromRecord |
|
108 | 108 | * @param TActiveRecord $matchesRecord |
109 | 109 | * @return array foreign keys with source column names as key and foreign column names as value. |
110 | 110 | */ |
@@ -212,6 +212,7 @@ discard block |
||
212 | 212 | * @param array source property names |
213 | 213 | * @param array foreign objects |
214 | 214 | * @param array foreign object field names. |
215 | + * @param TActiveRecord[] $fkObjects |
|
215 | 216 | */ |
216 | 217 | protected function populateResult(&$results,$properties,&$fkObjects,$fields) |
217 | 218 | { |
@@ -30,8 +30,8 @@ discard block |
||
30 | 30 | |
31 | 31 | public function __construct(TActiveRecordRelationContext $context, $criteria) |
32 | 32 | { |
33 | - $this->_context = $context; |
|
34 | - $this->_criteria = $criteria; |
|
33 | + $this->_context=$context; |
|
34 | + $this->_criteria=$criteria; |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -71,22 +71,22 @@ discard block |
||
71 | 71 | * @param array method arguments |
72 | 72 | * @return mixed TActiveRecord or array of TActiveRecord results depending on the method called. |
73 | 73 | */ |
74 | - public function __call($method,$args) |
|
74 | + public function __call($method, $args) |
|
75 | 75 | { |
76 | 76 | static $stack=array(); |
77 | 77 | |
78 | - $results = call_user_func_array(array($this->getSourceRecord(),$method),$args); |
|
79 | - $validArray = is_array($results) && count($results) > 0; |
|
78 | + $results=call_user_func_array(array($this->getSourceRecord(), $method), $args); |
|
79 | + $validArray=is_array($results) && count($results) > 0; |
|
80 | 80 | if($validArray || $results instanceof ArrayAccess || $results instanceof TActiveRecord) |
81 | 81 | { |
82 | 82 | $this->collectForeignObjects($results); |
83 | - while($obj = array_pop($stack)) |
|
83 | + while($obj=array_pop($stack)) |
|
84 | 84 | $obj->collectForeignObjects($results); |
85 | 85 | } |
86 | 86 | else if($results instanceof TActiveRecordRelation) |
87 | - $stack[] = $this; //call it later |
|
88 | - else if($results === null || !$validArray) |
|
89 | - $stack = array(); |
|
87 | + $stack[]=$this; //call it later |
|
88 | + else if($results===null || !$validArray) |
|
89 | + $stack=array(); |
|
90 | 90 | return $results; |
91 | 91 | } |
92 | 92 | |
@@ -110,28 +110,28 @@ discard block |
||
110 | 110 | */ |
111 | 111 | protected function findForeignKeys($from, $matchesRecord, $loose=false) |
112 | 112 | { |
113 | - $gateway = $matchesRecord->getRecordGateway(); |
|
114 | - $recordTableInfo = $gateway->getRecordTableInfo($matchesRecord); |
|
115 | - $matchingTableName = strtolower($recordTableInfo->getTableName()); |
|
116 | - $matchingFullTableName = strtolower($recordTableInfo->getTableFullName()); |
|
113 | + $gateway=$matchesRecord->getRecordGateway(); |
|
114 | + $recordTableInfo=$gateway->getRecordTableInfo($matchesRecord); |
|
115 | + $matchingTableName=strtolower($recordTableInfo->getTableName()); |
|
116 | + $matchingFullTableName=strtolower($recordTableInfo->getTableFullName()); |
|
117 | 117 | $tableInfo=$from; |
118 | 118 | if($from instanceof TActiveRecord) |
119 | - $tableInfo = $gateway->getRecordTableInfo($from); |
|
119 | + $tableInfo=$gateway->getRecordTableInfo($from); |
|
120 | 120 | //find first non-empty FK |
121 | 121 | foreach($tableInfo->getForeignKeys() as $fkeys) |
122 | 122 | { |
123 | - $fkTable = strtolower($fkeys['table']); |
|
123 | + $fkTable=strtolower($fkeys['table']); |
|
124 | 124 | if($fkTable===$matchingTableName || $fkTable===$matchingFullTableName) |
125 | 125 | { |
126 | - $hasFkField = !$loose && $this->getContext()->hasFkField(); |
|
127 | - $key = $hasFkField ? $this->getFkFields($fkeys['keys']) : $fkeys['keys']; |
|
126 | + $hasFkField=!$loose && $this->getContext()->hasFkField(); |
|
127 | + $key=$hasFkField ? $this->getFkFields($fkeys['keys']) : $fkeys['keys']; |
|
128 | 128 | if(!empty($key)) |
129 | 129 | return $key; |
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | 133 | //none found |
134 | - $matching = $gateway->getRecordTableInfo($matchesRecord)->getTableFullName(); |
|
134 | + $matching=$gateway->getRecordTableInfo($matchesRecord)->getTableFullName(); |
|
135 | 135 | throw new TActiveRecordException('ar_relations_missing_fk', |
136 | 136 | $tableInfo->getTableFullName(), $matching); |
137 | 137 | } |
@@ -149,13 +149,13 @@ discard block |
||
149 | 149 | */ |
150 | 150 | private function getFkFields($fkeys) |
151 | 151 | { |
152 | - $matching = array(); |
|
152 | + $matching=array(); |
|
153 | 153 | preg_match_all('/\s*(\S+\.)?([\w-]+)\s*/', $this->getContext()->getFkField(), $matching); |
154 | - $fields = array(); |
|
154 | + $fields=array(); |
|
155 | 155 | foreach($fkeys as $fkName => $field) |
156 | 156 | { |
157 | 157 | if(in_array($fkName, $matching[2])) |
158 | - $fields[$fkName] = $field; |
|
158 | + $fields[$fkName]=$field; |
|
159 | 159 | } |
160 | 160 | return $fields; |
161 | 161 | } |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | { |
170 | 170 | $ids=array(); |
171 | 171 | foreach($properties as $property) |
172 | - $ids[] = is_object($obj) ? (string)$obj->getColumnValue($property) : (string)$obj[$property]; |
|
172 | + $ids[]=is_object($obj) ? (string) $obj->getColumnValue($property) : (string) $obj[$property]; |
|
173 | 173 | return serialize($ids); |
174 | 174 | } |
175 | 175 | |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | */ |
182 | 182 | protected function findForeignObjects($fields, $indexValues) |
183 | 183 | { |
184 | - $finder = $this->getContext()->getForeignRecordFinder(); |
|
184 | + $finder=$this->getContext()->getForeignRecordFinder(); |
|
185 | 185 | return $finder->findAllByIndex($this->_criteria, $fields, $indexValues); |
186 | 186 | } |
187 | 187 | |
@@ -194,14 +194,14 @@ discard block |
||
194 | 194 | protected function getIndexValues($keys, $results) |
195 | 195 | { |
196 | 196 | if(!is_array($results) && !$results instanceof ArrayAccess) |
197 | - $results = array($results); |
|
197 | + $results=array($results); |
|
198 | 198 | $values=array(); |
199 | 199 | foreach($results as $result) |
200 | 200 | { |
201 | - $value = array(); |
|
201 | + $value=array(); |
|
202 | 202 | foreach($keys as $name) |
203 | - $value[] = $result->getColumnValue($name); |
|
204 | - $values[] = $value; |
|
203 | + $value[]=$result->getColumnValue($name); |
|
204 | + $values[]=$value; |
|
205 | 205 | } |
206 | 206 | return $values; |
207 | 207 | } |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | * @param array foreign objects |
214 | 214 | * @param array foreign object field names. |
215 | 215 | */ |
216 | - protected function populateResult(&$results,$properties,&$fkObjects,$fields) |
|
216 | + protected function populateResult(&$results, $properties, &$fkObjects, $fields) |
|
217 | 217 | { |
218 | 218 | $collections=array(); |
219 | 219 | foreach($fkObjects as $fkObject) |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | { |
232 | 232 | if(is_array($results) || $results instanceof ArrayAccess) |
233 | 233 | { |
234 | - for($i=0,$k=count($results);$i<$k;$i++) |
|
234 | + for($i=0, $k=count($results); $i < $k; $i++) |
|
235 | 235 | $this->setObjectProperty($results[$i], $properties, $collections); |
236 | 236 | } |
237 | 237 | else |
@@ -246,8 +246,8 @@ discard block |
||
246 | 246 | */ |
247 | 247 | protected function setObjectProperty($source, $properties, &$collections) |
248 | 248 | { |
249 | - $hash = $this->getObjectHash($source, $properties); |
|
250 | - $prop = $this->getContext()->getProperty(); |
|
249 | + $hash=$this->getObjectHash($source, $properties); |
|
250 | + $prop=$this->getContext()->getProperty(); |
|
251 | 251 | $source->$prop=isset($collections[$hash]) ? $collections[$hash] : array(); |
252 | 252 | } |
253 | 253 | } |
@@ -80,10 +80,10 @@ discard block |
||
80 | 80 | if($validArray || $results instanceof ArrayAccess || $results instanceof TActiveRecord) |
81 | 81 | { |
82 | 82 | $this->collectForeignObjects($results); |
83 | - while($obj = array_pop($stack)) |
|
84 | - $obj->collectForeignObjects($results); |
|
85 | - } |
|
86 | - else if($results instanceof TActiveRecordRelation) |
|
83 | + while($obj = array_pop($stack)) { |
|
84 | + $obj->collectForeignObjects($results); |
|
85 | + } |
|
86 | + } else if($results instanceof TActiveRecordRelation) |
|
87 | 87 | $stack[] = $this; //call it later |
88 | 88 | else if($results === null || !$validArray) |
89 | 89 | $stack = array(); |
@@ -233,8 +233,7 @@ discard block |
||
233 | 233 | { |
234 | 234 | for($i=0,$k=count($results);$i<$k;$i++) |
235 | 235 | $this->setObjectProperty($results[$i], $properties, $collections); |
236 | - } |
|
237 | - else |
|
236 | + } else |
|
238 | 237 | $this->setObjectProperty($results, $properties, $collections); |
239 | 238 | } |
240 | 239 |
@@ -47,6 +47,9 @@ |
||
47 | 47 | return $control; |
48 | 48 | } |
49 | 49 | |
50 | + /** |
|
51 | + * @return string |
|
52 | + */ |
|
50 | 53 | protected function getDefaultControlValue($container,$column, $record) |
51 | 54 | { |
52 | 55 | $control = $container->findControl(self::DEFAULT_ID); |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | { |
16 | 16 | $control->setID(self::DEFAULT_ID); |
17 | 17 | $control->setEnabled($this->getIsEnabled($column, $record)); |
18 | - $container->Controls[] = $control; |
|
18 | + $container->Controls[]=$control; |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | protected function setNotNullProperty($container, $control, $column, $record) |
@@ -27,8 +27,8 @@ discard block |
||
27 | 27 | |
28 | 28 | protected function createBooleanControl($container, $column, $record) |
29 | 29 | { |
30 | - $value = $this->getRecordPropertyValue($column, $record); |
|
31 | - $control = new TCheckBox(); |
|
30 | + $value=$this->getRecordPropertyValue($column, $record); |
|
31 | + $control=new TCheckBox(); |
|
32 | 32 | $control->setChecked(TPropertyValue::ensureBoolean($value)); |
33 | 33 | $control->setCssClass('boolean-checkbox'); |
34 | 34 | $this->setDefaultProperty($container, $control, $column, $record); |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | |
38 | 38 | protected function createDefaultControl($container, $column, $record) |
39 | 39 | { |
40 | - $value = $this->getRecordPropertyValue($column, $record); |
|
41 | - $control = new TTextBox(); |
|
40 | + $value=$this->getRecordPropertyValue($column, $record); |
|
41 | + $control=new TTextBox(); |
|
42 | 42 | $control->setText($value); |
43 | 43 | $control->setCssClass('default-textbox scaffold_input'); |
44 | 44 | if(($len=$column->getColumnSize())!==null) |
@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | return $control; |
48 | 48 | } |
49 | 49 | |
50 | - protected function getDefaultControlValue($container,$column, $record) |
|
50 | + protected function getDefaultControlValue($container, $column, $record) |
|
51 | 51 | { |
52 | - $control = $container->findControl(self::DEFAULT_ID); |
|
52 | + $control=$container->findControl(self::DEFAULT_ID); |
|
53 | 53 | if($control instanceof TCheckBox) |
54 | 54 | return $control->getChecked(); |
55 | 55 | else if($control instanceof TControl) |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | |
59 | 59 | protected function createMultiLineControl($container, $column, $record) |
60 | 60 | { |
61 | - $value = $this->getRecordPropertyValue($column, $record); |
|
62 | - $control = new TTextBox(); |
|
61 | + $value=$this->getRecordPropertyValue($column, $record); |
|
62 | + $control=new TTextBox(); |
|
63 | 63 | $control->setText($value); |
64 | 64 | $control->setTextMode(TTextBoxMode::MultiLine); |
65 | 65 | $control->setCssClass('multiline-textbox scaffold_input'); |
@@ -69,13 +69,13 @@ discard block |
||
69 | 69 | |
70 | 70 | protected function createYearControl($container, $column, $record) |
71 | 71 | { |
72 | - $value = $this->getRecordPropertyValue($column, $record); |
|
73 | - $control = new TDropDownList(); |
|
74 | - $years = array(); |
|
75 | - $current = intval(@date('Y')); |
|
76 | - $from = $current-10; $to=$current+10; |
|
77 | - for($i = $from; $i <= $to; $i++) |
|
78 | - $years[$i] = $i; |
|
72 | + $value=$this->getRecordPropertyValue($column, $record); |
|
73 | + $control=new TDropDownList(); |
|
74 | + $years=array(); |
|
75 | + $current=intval(@date('Y')); |
|
76 | + $from=$current - 10; $to=$current + 10; |
|
77 | + for($i=$from; $i <= $to; $i++) |
|
78 | + $years[$i]=$i; |
|
79 | 79 | $control->setDataSource($years); |
80 | 80 | $control->setSelectedValue(empty($value) ? $current : $value); |
81 | 81 | $control->setCssClass('year-dropdown'); |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | |
86 | 86 | protected function createIntegerControl($container, $column, $record) |
87 | 87 | { |
88 | - $control = $this->createDefaultControl($container, $column, $record); |
|
89 | - $val = $this->createTypeValidator($container, $column, $record); |
|
88 | + $control=$this->createDefaultControl($container, $column, $record); |
|
89 | + $val=$this->createTypeValidator($container, $column, $record); |
|
90 | 90 | $val->setDataType(TValidationDataType::Integer); |
91 | 91 | $val->setErrorMessage('Please entery an integer.'); |
92 | 92 | return $control; |
@@ -94,13 +94,13 @@ discard block |
||
94 | 94 | |
95 | 95 | protected function createFloatControl($container, $column, $record) |
96 | 96 | { |
97 | - $control = $this->createDefaultControl($container, $column, $record); |
|
98 | - $val = $this->createTypeValidator($container, $column, $record); |
|
97 | + $control=$this->createDefaultControl($container, $column, $record); |
|
98 | + $val=$this->createTypeValidator($container, $column, $record); |
|
99 | 99 | $val->setDataType(TValidationDataType::Float); |
100 | 100 | $val->setErrorMessage('Please entery a decimal number.'); |
101 | - if(($max= $column->getMaxiumNumericConstraint())!==null) |
|
101 | + if(($max=$column->getMaxiumNumericConstraint())!==null) |
|
102 | 102 | { |
103 | - $val = $this->createRangeValidator($container,$column,$record); |
|
103 | + $val=$this->createRangeValidator($container, $column, $record); |
|
104 | 104 | $val->setDataType(TValidationDataType::Float); |
105 | 105 | $val->setMaxValue($max); |
106 | 106 | $val->setStrictComparison(true); |
@@ -111,99 +111,99 @@ discard block |
||
111 | 111 | |
112 | 112 | protected function createRequiredValidator($container, $column, $record) |
113 | 113 | { |
114 | - $val = new TRequiredFieldValidator(); |
|
114 | + $val=new TRequiredFieldValidator(); |
|
115 | 115 | $val->setErrorMessage('*'); |
116 | 116 | $val->setControlCssClass('required-input'); |
117 | 117 | $val->setCssClass('required'); |
118 | 118 | $val->setControlToValidate(self::DEFAULT_ID); |
119 | 119 | $val->setValidationGroup($this->getParent()->getValidationGroup()); |
120 | 120 | $val->setDisplay(TValidatorDisplayStyle::Dynamic); |
121 | - $container->Controls[] = $val; |
|
121 | + $container->Controls[]=$val; |
|
122 | 122 | return $val; |
123 | 123 | } |
124 | 124 | |
125 | 125 | protected function createTypeValidator($container, $column, $record) |
126 | 126 | { |
127 | - $val = new TDataTypeValidator(); |
|
127 | + $val=new TDataTypeValidator(); |
|
128 | 128 | $val->setControlCssClass('required-input2'); |
129 | 129 | $val->setCssClass('required'); |
130 | 130 | $val->setControlToValidate(self::DEFAULT_ID); |
131 | 131 | $val->setValidationGroup($this->getParent()->getValidationGroup()); |
132 | 132 | $val->setDisplay(TValidatorDisplayStyle::Dynamic); |
133 | - $container->Controls[] = $val; |
|
133 | + $container->Controls[]=$val; |
|
134 | 134 | return $val; |
135 | 135 | } |
136 | 136 | |
137 | 137 | protected function createRangeValidator($container, $column, $record) |
138 | 138 | { |
139 | - $val = new TRangeValidator(); |
|
139 | + $val=new TRangeValidator(); |
|
140 | 140 | $val->setControlCssClass('required-input3'); |
141 | 141 | $val->setCssClass('required'); |
142 | 142 | $val->setControlToValidate(self::DEFAULT_ID); |
143 | 143 | $val->setValidationGroup($this->getParent()->getValidationGroup()); |
144 | 144 | $val->setDisplay(TValidatorDisplayStyle::Dynamic); |
145 | - $container->Controls[] = $val; |
|
145 | + $container->Controls[]=$val; |
|
146 | 146 | return $val; |
147 | 147 | } |
148 | 148 | |
149 | 149 | protected function createTimeControl($container, $column, $record) |
150 | 150 | { |
151 | - $value = $this->getRecordPropertyValue($column, $record); |
|
151 | + $value=$this->getRecordPropertyValue($column, $record); |
|
152 | 152 | $hours=array(); |
153 | - for($i=0;$i<24;$i++) $hours[] = str_pad($i,2,'0',STR_PAD_LEFT); |
|
153 | + for($i=0; $i < 24; $i++) $hours[]=str_pad($i, 2, '0', STR_PAD_LEFT); |
|
154 | 154 | $mins=array(); |
155 | - for($i=0;$i<60;$i++) $mins[] = str_pad($i,2,'0',STR_PAD_LEFT); |
|
156 | - $hour = intval(@date('H')); |
|
157 | - $min = intval(@date('i')); |
|
158 | - $sec = intval(@date('s')); |
|
155 | + for($i=0; $i < 60; $i++) $mins[]=str_pad($i, 2, '0', STR_PAD_LEFT); |
|
156 | + $hour=intval(@date('H')); |
|
157 | + $min=intval(@date('i')); |
|
158 | + $sec=intval(@date('s')); |
|
159 | 159 | if(!empty($value)) |
160 | 160 | { |
161 | 161 | $match=array(); |
162 | 162 | if(preg_match('/(\d+):(\d+):?(\d+)?/', $value, $match)) |
163 | 163 | { |
164 | - $hour = $match[1]; |
|
165 | - $min = $match[2]; |
|
164 | + $hour=$match[1]; |
|
165 | + $min=$match[2]; |
|
166 | 166 | if(isset($match[3])) |
167 | 167 | $sec=$match[3]; |
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
171 | - $hcontrol = new TDropDownList(); |
|
171 | + $hcontrol=new TDropDownList(); |
|
172 | 172 | $hcontrol->setDataSource($hours); |
173 | 173 | $hcontrol->setID(self::DEFAULT_ID); |
174 | 174 | $hcontrol->dataBind(); |
175 | 175 | $hcontrol->setSelectedValue(intval($hour)); |
176 | - $container->Controls[] = $hcontrol; |
|
177 | - $container->Controls[] = ' : '; |
|
176 | + $container->Controls[]=$hcontrol; |
|
177 | + $container->Controls[]=' : '; |
|
178 | 178 | |
179 | - $mcontrol = new TDropDownList(); |
|
179 | + $mcontrol=new TDropDownList(); |
|
180 | 180 | $mcontrol->setDataSource($mins); |
181 | 181 | $mcontrol->dataBind(); |
182 | 182 | $mcontrol->setID('scaffold_time_min'); |
183 | 183 | $mcontrol->setSelectedValue(intval($min)); |
184 | - $container->Controls[] = $mcontrol; |
|
185 | - $container->Controls[] = ' : '; |
|
184 | + $container->Controls[]=$mcontrol; |
|
185 | + $container->Controls[]=' : '; |
|
186 | 186 | |
187 | - $scontrol = new TDropDownList(); |
|
187 | + $scontrol=new TDropDownList(); |
|
188 | 188 | $scontrol->setDataSource($mins); |
189 | 189 | $scontrol->dataBind(); |
190 | 190 | $scontrol->setID('scaffold_time_sec'); |
191 | 191 | $scontrol->setSelectedValue(intval($sec)); |
192 | - $container->Controls[] = $scontrol; |
|
192 | + $container->Controls[]=$scontrol; |
|
193 | 193 | |
194 | - return array($hcontrol,$mcontrol,$scontrol); |
|
194 | + return array($hcontrol, $mcontrol, $scontrol); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | |
198 | 198 | protected function createDateControl($container, $column, $record) |
199 | 199 | { |
200 | - $value = $this->getRecordPropertyValue($column, $record); |
|
201 | - $control = new TDatePicker(); |
|
200 | + $value=$this->getRecordPropertyValue($column, $record); |
|
201 | + $control=new TDatePicker(); |
|
202 | 202 | $control->setFromYear(1900); |
203 | 203 | $control->setInputMode(TDatePickerInputMode::DropDownList); |
204 | 204 | $control->setDateFormat('yyyy-MM-dd'); |
205 | 205 | if(!empty($value)) |
206 | - $control->setDate(substr($value,0,10)); |
|
206 | + $control->setDate(substr($value, 0, 10)); |
|
207 | 207 | $control->setCssClass('date-dropdown'); |
208 | 208 | $this->setNotNullProperty($container, $control, $column, $record); |
209 | 209 | return $control; |
@@ -211,10 +211,10 @@ discard block |
||
211 | 211 | |
212 | 212 | protected function createDateTimeControl($container, $column, $record) |
213 | 213 | { |
214 | - $value = $this->getRecordPropertyValue($column, $record); |
|
215 | - $control = $this->createDateControl($container, $column, $record); |
|
216 | - $container->Controls[] = ' @ '; |
|
217 | - $time = $this->createTimeControl($container, $column, $record); |
|
214 | + $value=$this->getRecordPropertyValue($column, $record); |
|
215 | + $control=$this->createDateControl($container, $column, $record); |
|
216 | + $container->Controls[]=' @ '; |
|
217 | + $time=$this->createTimeControl($container, $column, $record); |
|
218 | 218 | if(!empty($value)) |
219 | 219 | { |
220 | 220 | $match=array(); |
@@ -232,30 +232,30 @@ discard block |
||
232 | 232 | |
233 | 233 | protected function getDateTimeValue($container, $column, $record) |
234 | 234 | { |
235 | - $date = $container->findControl(self::DEFAULT_ID)->getDate(); |
|
236 | - $hour = $container->findControl('scaffold_time_hour')->getSelectedValue(); |
|
237 | - $mins = $container->findControl('scaffold_time_min')->getSelectedValue(); |
|
238 | - $secs = $container->findControl('scaffold_time_sec')->getSelectedValue(); |
|
235 | + $date=$container->findControl(self::DEFAULT_ID)->getDate(); |
|
236 | + $hour=$container->findControl('scaffold_time_hour')->getSelectedValue(); |
|
237 | + $mins=$container->findControl('scaffold_time_min')->getSelectedValue(); |
|
238 | + $secs=$container->findControl('scaffold_time_sec')->getSelectedValue(); |
|
239 | 239 | return "{$date} {$hour}:{$mins}:{$secs}"; |
240 | 240 | } |
241 | 241 | |
242 | 242 | protected function getTimeValue($container, $column, $record) |
243 | 243 | { |
244 | - $hour = $container->findControl(self::DEFAULT_ID)->getSelectedValue(); |
|
245 | - $mins = $container->findControl('scaffold_time_min')->getSelectedValue(); |
|
246 | - $secs = $container->findControl('scaffold_time_sec')->getSelectedValue(); |
|
244 | + $hour=$container->findControl(self::DEFAULT_ID)->getSelectedValue(); |
|
245 | + $mins=$container->findControl('scaffold_time_min')->getSelectedValue(); |
|
246 | + $secs=$container->findControl('scaffold_time_sec')->getSelectedValue(); |
|
247 | 247 | return "{$hour}:{$mins}:{$secs}"; |
248 | 248 | } |
249 | 249 | |
250 | 250 | protected function createSetControl($container, $column, $record) |
251 | 251 | { |
252 | - $value = $this->getRecordPropertyValue($column, $record); |
|
253 | - $selectedValues = preg_split('/\s*,\s*/', $value); |
|
254 | - $control = new TCheckBoxList(); |
|
255 | - $values = $column->getDbTypeValues(); |
|
252 | + $value=$this->getRecordPropertyValue($column, $record); |
|
253 | + $selectedValues=preg_split('/\s*,\s*/', $value); |
|
254 | + $control=new TCheckBoxList(); |
|
255 | + $values=$column->getDbTypeValues(); |
|
256 | 256 | $control->setDataSource($values); |
257 | 257 | $control->dataBind(); |
258 | - $control->setSelectedIndices($this->getMatchingIndices($values,$selectedValues)); |
|
258 | + $control->setSelectedIndices($this->getMatchingIndices($values, $selectedValues)); |
|
259 | 259 | $control->setID(self::DEFAULT_ID); |
260 | 260 | $control->setCssClass('set-checkboxes'); |
261 | 261 | $this->setNotNullProperty($container, $control, $column, $record); |
@@ -265,23 +265,23 @@ discard block |
||
265 | 265 | protected function getMatchingIndices($checks, $values) |
266 | 266 | { |
267 | 267 | $index=array(); |
268 | - for($i=0, $k=count($checks); $i<$k; $i++) |
|
268 | + for($i=0, $k=count($checks); $i < $k; $i++) |
|
269 | 269 | { |
270 | 270 | if(in_array($checks[$i], $values)) |
271 | - $index[] = $i; |
|
271 | + $index[]=$i; |
|
272 | 272 | } |
273 | 273 | return $index; |
274 | 274 | } |
275 | 275 | |
276 | 276 | protected function createEnumControl($container, $column, $record) |
277 | 277 | { |
278 | - $value = $this->getRecordPropertyValue($column, $record); |
|
279 | - $selectedValues = preg_split('/\s*,\s*/', $value); |
|
280 | - $control = new TRadioButtonList(); |
|
281 | - $values = $column->getDbTypeValues(); |
|
278 | + $value=$this->getRecordPropertyValue($column, $record); |
|
279 | + $selectedValues=preg_split('/\s*,\s*/', $value); |
|
280 | + $control=new TRadioButtonList(); |
|
281 | + $values=$column->getDbTypeValues(); |
|
282 | 282 | $control->setDataSource($values); |
283 | 283 | $control->dataBind(); |
284 | - $index = $this->getMatchingIndices($values,$selectedValues); |
|
284 | + $index=$this->getMatchingIndices($values, $selectedValues); |
|
285 | 285 | if(count($index) > 0) |
286 | 286 | $control->setSelectedIndex($index[0]); |
287 | 287 | $control->setID(self::DEFAULT_ID); |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | foreach($container->findControl(self::DEFAULT_ID)->getItems() as $item) |
297 | 297 | { |
298 | 298 | if($item->getSelected()) |
299 | - $value[] = $item->getText(); |
|
299 | + $value[]=$item->getText(); |
|
300 | 300 | } |
301 | 301 | return implode(',', $value); |
302 | 302 | } |
@@ -123,6 +123,7 @@ |
||
123 | 123 | /** |
124 | 124 | * @param TMssqlTableInfo table information. |
125 | 125 | * @param array column information. |
126 | + * @param TMssqlTableInfo $tableInfo |
|
126 | 127 | */ |
127 | 128 | protected function processColumn($tableInfo, $col) |
128 | 129 | { |
@@ -259,15 +259,15 @@ |
||
259 | 259 | return false; |
260 | 260 | } |
261 | 261 | |
262 | - /** |
|
263 | - * Returns all table names in the database. |
|
264 | - * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema. |
|
265 | - * If not empty, the returned table names will be prefixed with the schema name. |
|
266 | - * @return array all table names in the database. |
|
267 | - */ |
|
262 | + /** |
|
263 | + * Returns all table names in the database. |
|
264 | + * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema. |
|
265 | + * If not empty, the returned table names will be prefixed with the schema name. |
|
266 | + * @return array all table names in the database. |
|
267 | + */ |
|
268 | 268 | public function findTableNames($schema='dbo') |
269 | 269 | { |
270 | - $condition="TABLE_TYPE='BASE TABLE'"; |
|
270 | + $condition="TABLE_TYPE='BASE TABLE'"; |
|
271 | 271 | $sql=<<<EOD |
272 | 272 | SELECT TABLE_NAME, TABLE_SCHEMA FROM [INFORMATION_SCHEMA].[TABLES] |
273 | 273 | WHERE TABLE_SCHEMA=:schema AND $condition |
@@ -69,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']; |
@@ -27,7 +27,7 @@ |
||
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Overrides parent implementation, returns PHP type from the db type. |
30 | - * @return boolean derived PHP primitive type from the column db type. |
|
30 | + * @return string derived PHP primitive type from the column db type. |
|
31 | 31 | */ |
32 | 32 | public function getPHPType() |
33 | 33 | { |
@@ -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 | /** |
@@ -114,6 +114,7 @@ |
||
114 | 114 | /** |
115 | 115 | * @param TMysqlTableInfo table information. |
116 | 116 | * @param array column information. |
117 | + * @param TMysqlTableInfo $tableInfo |
|
117 | 118 | */ |
118 | 119 | protected function processColumn($tableInfo, $col) |
119 | 120 | { |
@@ -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==='') |
@@ -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 | } |
@@ -154,8 +154,7 @@ discard block |
||
154 | 154 | $info['NumericPrecision'] = intval($pscale[1]); |
155 | 155 | if(count($pscale) > 2) |
156 | 156 | $info['NumericScale'] = intval($pscale[2]); |
157 | - } |
|
158 | - else |
|
157 | + } else |
|
159 | 158 | $info['ColumnSize'] = intval($pscale[1]); |
160 | 159 | } |
161 | 160 | } |
@@ -254,8 +253,7 @@ discard block |
||
254 | 253 | try |
255 | 254 | { |
256 | 255 | return count($result = $command->queryRow()) > 0 && $result['Table_type']==='VIEW'; |
257 | - } |
|
258 | - catch(TDbException $e) |
|
256 | + } catch(TDbException $e) |
|
259 | 257 | { |
260 | 258 | $table = $schemaName===null?$tableName:$schemaName.'.'.$tableName; |
261 | 259 | throw new TDbException('dbcommon_invalid_table_name',$table,$e->getMessage()); |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | /** |
146 | 146 | * @param string table schema name |
147 | 147 | * @param string table name. |
148 | - * @return boolean true if the table is a view. |
|
148 | + * @return integer true if the table is a view. |
|
149 | 149 | */ |
150 | 150 | protected function getIsView($schemaName,$tableName) |
151 | 151 | { |
@@ -167,6 +167,7 @@ discard block |
||
167 | 167 | /** |
168 | 168 | * @param TOracleTableInfo table information. |
169 | 169 | * @param array column information. |
170 | + * @param TOracleTableInfo $tableInfo |
|
170 | 171 | */ |
171 | 172 | protected function processColumn($tableInfo, $col) |
172 | 173 | { |
@@ -322,6 +323,7 @@ discard block |
||
322 | 323 | /** |
323 | 324 | * @param string column name. |
324 | 325 | * @param TOracleTableInfo table information. |
326 | + * @param string $columnId |
|
325 | 327 | * @return boolean true if column is a foreign key. |
326 | 328 | */ |
327 | 329 | protected function isForeignKeyColumn($columnId, $tableInfo) |
@@ -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==='') |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | */ |
26 | 26 | class TOracleMetaData extends TDbMetaData |
27 | 27 | { |
28 | - private $_defaultSchema = 'system'; |
|
28 | + private $_defaultSchema='system'; |
|
29 | 29 | |
30 | 30 | |
31 | 31 | /** |
@@ -58,10 +58,10 @@ discard block |
||
58 | 58 | */ |
59 | 59 | protected function getSchemaTableName($table) |
60 | 60 | { |
61 | - if(count($parts= explode('.', str_replace('"','',$table))) > 1) |
|
61 | + if(count($parts=explode('.', str_replace('"', '', $table))) > 1) |
|
62 | 62 | return array($parts[0], $parts[1]); |
63 | 63 | else |
64 | - return array($this->getDefaultSchema(),$parts[0]); |
|
64 | + return array($this->getDefaultSchema(), $parts[0]); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -71,12 +71,12 @@ discard block |
||
71 | 71 | */ |
72 | 72 | protected function createTableInfo($table) |
73 | 73 | { |
74 | - list($schemaName,$tableName) = $this->getSchemaTableName($table); |
|
74 | + list($schemaName, $tableName)=$this->getSchemaTableName($table); |
|
75 | 75 | |
76 | 76 | // This query is made much more complex by the addition of the 'attisserial' field. |
77 | 77 | // The subquery to get that field checks to see if there is an internally dependent |
78 | 78 | // sequence on the field. |
79 | - $sql = |
|
79 | + $sql= |
|
80 | 80 | <<<EOD |
81 | 81 | SELECT |
82 | 82 | a.COLUMN_ID, |
@@ -96,14 +96,14 @@ discard block |
||
96 | 96 | EOD; |
97 | 97 | $this->getDbConnection()->setActive(true); |
98 | 98 | $this->getDbConnection()->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); |
99 | - $command = $this->getDbConnection()->createCommand($sql); |
|
99 | + $command=$this->getDbConnection()->createCommand($sql); |
|
100 | 100 | //$command->bindValue(':table', $tableName); |
101 | 101 | //$command->bindValue(':schema', $schemaName); |
102 | - $tableInfo = $this->createNewTableInfo($schemaName, $tableName); |
|
102 | + $tableInfo=$this->createNewTableInfo($schemaName, $tableName); |
|
103 | 103 | $index=0; |
104 | 104 | foreach($command->query() as $col) |
105 | 105 | { |
106 | - $col['index'] = $index++; |
|
106 | + $col['index']=$index++; |
|
107 | 107 | $this->processColumn($tableInfo, $col); |
108 | 108 | } |
109 | 109 | if($index===0) |
@@ -116,15 +116,15 @@ discard block |
||
116 | 116 | * @param string table name. |
117 | 117 | * @return TOracleTableInfo |
118 | 118 | */ |
119 | - protected function createNewTableInfo($schemaName,$tableName) |
|
119 | + protected function createNewTableInfo($schemaName, $tableName) |
|
120 | 120 | { |
121 | - $info['SchemaName'] = $this->assertIdentifier($schemaName); |
|
122 | - $info['TableName'] = $this->assertIdentifier($tableName); |
|
123 | - $info['IsView'] = false; |
|
124 | - if($this->getIsView($schemaName,$tableName)) $info['IsView'] = true; |
|
125 | - list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName); |
|
126 | - $class = $this->getTableInfoClass(); |
|
127 | - return new $class($info,$primary,$foreign); |
|
121 | + $info['SchemaName']=$this->assertIdentifier($schemaName); |
|
122 | + $info['TableName']=$this->assertIdentifier($tableName); |
|
123 | + $info['IsView']=false; |
|
124 | + if($this->getIsView($schemaName, $tableName)) $info['IsView']=true; |
|
125 | + list($primary, $foreign)=$this->getConstraintKeys($schemaName, $tableName); |
|
126 | + $class=$this->getTableInfoClass(); |
|
127 | + return new $class($info, $primary, $foreign); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | { |
137 | 137 | if(strpos($name, '"')!==false) |
138 | 138 | { |
139 | - $ref = 'http://www.oracle.com'; |
|
139 | + $ref='http://www.oracle.com'; |
|
140 | 140 | throw new TDbException('dbcommon_invalid_identifier_name', $name, $ref); |
141 | 141 | } |
142 | 142 | return $name; |
@@ -147,10 +147,10 @@ discard block |
||
147 | 147 | * @param string table name. |
148 | 148 | * @return boolean true if the table is a view. |
149 | 149 | */ |
150 | - protected function getIsView($schemaName,$tableName) |
|
150 | + protected function getIsView($schemaName, $tableName) |
|
151 | 151 | { |
152 | 152 | $this->getDbConnection()->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); |
153 | - $sql = |
|
153 | + $sql= |
|
154 | 154 | <<<EOD |
155 | 155 | select OBJECT_TYPE |
156 | 156 | from ALL_OBJECTS |
@@ -158,10 +158,10 @@ discard block |
||
158 | 158 | and OWNER = '{$schemaName}' |
159 | 159 | EOD; |
160 | 160 | $this->getDbConnection()->setActive(true); |
161 | - $command = $this->getDbConnection()->createCommand($sql); |
|
161 | + $command=$this->getDbConnection()->createCommand($sql); |
|
162 | 162 | //$command->bindValue(':schema',$schemaName); |
163 | 163 | //$command->bindValue(':table', $tableName); |
164 | - return intval($command->queryScalar() === 'VIEW'); |
|
164 | + return intval($command->queryScalar()==='VIEW'); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -170,17 +170,17 @@ discard block |
||
170 | 170 | */ |
171 | 171 | protected function processColumn($tableInfo, $col) |
172 | 172 | { |
173 | - $columnId = strtolower($col['attname']); //use column name as column Id |
|
173 | + $columnId=strtolower($col['attname']); //use column name as column Id |
|
174 | 174 | |
175 | 175 | //$info['ColumnName'] = '"'.$columnId.'"'; //quote the column names! |
176 | - $info['ColumnName'] = $columnId; //NOT quote the column names! |
|
177 | - $info['ColumnId'] = $columnId; |
|
178 | - $info['ColumnIndex'] = $col['index']; |
|
179 | - if(! (bool)$col['attnotnull'] ) $info['AllowNull'] = true; |
|
180 | - if(in_array($columnId, $tableInfo->getPrimaryKeys())) $info['IsPrimaryKey'] = true; |
|
181 | - if($this->isForeignKeyColumn($columnId, $tableInfo)) $info['IsForeignKey'] = true; |
|
182 | - if( (int)$col['atttypmod'] > 0 ) $info['ColumnSize'] = $col['atttypmod']; // - 4; |
|
183 | - if( (bool)$col['atthasdef'] ) $info['DefaultValue'] = $col['adsrc']; |
|
176 | + $info['ColumnName']=$columnId; //NOT quote the column names! |
|
177 | + $info['ColumnId']=$columnId; |
|
178 | + $info['ColumnIndex']=$col['index']; |
|
179 | + if(!(bool) $col['attnotnull']) $info['AllowNull']=true; |
|
180 | + if(in_array($columnId, $tableInfo->getPrimaryKeys())) $info['IsPrimaryKey']=true; |
|
181 | + if($this->isForeignKeyColumn($columnId, $tableInfo)) $info['IsForeignKey']=true; |
|
182 | + if((int) $col['atttypmod'] > 0) $info['ColumnSize']=$col['atttypmod']; // - 4; |
|
183 | + if((bool) $col['atthasdef']) $info['DefaultValue']=$col['adsrc']; |
|
184 | 184 | // |
185 | 185 | // For a while Oracle Tables has no associated AutoIncrement Triggers |
186 | 186 | // |
@@ -194,31 +194,31 @@ discard block |
||
194 | 194 | } |
195 | 195 | } |
196 | 196 | */ |
197 | - $matches = array(); |
|
197 | + $matches=array(); |
|
198 | 198 | if(preg_match('/\((\d+)(?:,(\d+))?+\)/', $col['type'], $matches)) |
199 | 199 | { |
200 | - $info['DbType'] = preg_replace('/\(\d+(?:,\d+)?\)/','',$col['type']); |
|
200 | + $info['DbType']=preg_replace('/\(\d+(?:,\d+)?\)/', '', $col['type']); |
|
201 | 201 | if($this->isPrecisionType($info['DbType'])) |
202 | 202 | { |
203 | - $info['NumericPrecision'] = intval($matches[1]); |
|
203 | + $info['NumericPrecision']=intval($matches[1]); |
|
204 | 204 | if(count($matches) > 2) |
205 | - $info['NumericScale'] = intval($matches[2]); |
|
205 | + $info['NumericScale']=intval($matches[2]); |
|
206 | 206 | } |
207 | 207 | else |
208 | - $info['ColumnSize'] = intval($matches[1]); |
|
208 | + $info['ColumnSize']=intval($matches[1]); |
|
209 | 209 | } |
210 | 210 | else |
211 | - $info['DbType'] = $col['type']; |
|
212 | - $tableInfo->Columns[$columnId] = new TOracleTableColumn($info); |
|
211 | + $info['DbType']=$col['type']; |
|
212 | + $tableInfo->Columns[$columnId]=new TOracleTableColumn($info); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
216 | 216 | * @return string serial name if found, null otherwise. |
217 | 217 | */ |
218 | - protected function getSequenceName($tableInfo,$src) |
|
218 | + protected function getSequenceName($tableInfo, $src) |
|
219 | 219 | { |
220 | - $matches = array(); |
|
221 | - if(preg_match('/nextval\([^\']*\'([^\']+)\'[^\)]*\)/i',$src,$matches)) |
|
220 | + $matches=array(); |
|
221 | + if(preg_match('/nextval\([^\']*\'([^\']+)\'[^\)]*\)/i', $src, $matches)) |
|
222 | 222 | { |
223 | 223 | if(is_int(strpos($matches[1], '.'))) |
224 | 224 | return $matches[1]; |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | */ |
233 | 233 | protected function isPrecisionType($type) |
234 | 234 | { |
235 | - $type = strtolower(trim($type)); |
|
235 | + $type=strtolower(trim($type)); |
|
236 | 236 | return $type==='number'; // || $type==='interval' || strpos($type, 'time')===0; |
237 | 237 | } |
238 | 238 | |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | { |
247 | 247 | $this->getDbConnection()->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); |
248 | 248 | // select decode( a.CONSTRAINT_TYPE, 'P', 'PRIMARY KEY (', 'FOREIGN KEY (' )||b.COLUMN_NAME||')' as consrc, |
249 | - $sql = |
|
249 | + $sql= |
|
250 | 250 | <<<EOD |
251 | 251 | select b.COLUMN_NAME as consrc, |
252 | 252 | a.CONSTRAINT_TYPE as contype |
@@ -257,24 +257,24 @@ discard block |
||
257 | 257 | and a.CONSTRAINT_TYPE in ('P','R') |
258 | 258 | EOD; |
259 | 259 | $this->getDbConnection()->setActive(true); |
260 | - $command = $this->getDbConnection()->createCommand($sql); |
|
260 | + $command=$this->getDbConnection()->createCommand($sql); |
|
261 | 261 | //$command->bindValue(':table', $tableName); |
262 | 262 | //$command->bindValue(':schema', $schemaName); |
263 | - $primary = array(); |
|
264 | - $foreign = array(); |
|
263 | + $primary=array(); |
|
264 | + $foreign=array(); |
|
265 | 265 | foreach($command->query() as $row) |
266 | 266 | { |
267 | - switch( strtolower( $row['contype'] ) ) |
|
267 | + switch(strtolower($row['contype'])) |
|
268 | 268 | { |
269 | 269 | case 'p': |
270 | - $primary = array_merge( $primary, array(strtolower( $row['consrc'] )) ); |
|
270 | + $primary=array_merge($primary, array(strtolower($row['consrc']))); |
|
271 | 271 | /* |
272 | 272 | $arr = $this->getPrimaryKeys($row['consrc']); |
273 | 273 | $primary = array_merge( $primary, array(strtolower( $arr[0] )) ); |
274 | 274 | */ |
275 | 275 | break; |
276 | 276 | case 'r': |
277 | - $foreign = array_merge( $foreign, array(strtolower( $row['consrc'] )) ); |
|
277 | + $foreign=array_merge($foreign, array(strtolower($row['consrc']))); |
|
278 | 278 | /* |
279 | 279 | // if(($fkey = $this->getForeignKeys($row['consrc']))!==null) |
280 | 280 | $fkey = $this->getForeignKeys( $row['consrc'] ); |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | break; |
284 | 284 | } |
285 | 285 | } |
286 | - return array($primary,$foreign); |
|
286 | + return array($primary, $foreign); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | /** |
@@ -293,9 +293,9 @@ discard block |
||
293 | 293 | */ |
294 | 294 | protected function getPrimaryKeys($src) |
295 | 295 | { |
296 | - $matches = array(); |
|
296 | + $matches=array(); |
|
297 | 297 | if(preg_match('/PRIMARY\s+KEY\s+\(([^\)]+)\)/i', $src, $matches)) |
298 | - return preg_split('/,\s+/',$matches[1]); |
|
298 | + return preg_split('/,\s+/', $matches[1]); |
|
299 | 299 | return array(); |
300 | 300 | } |
301 | 301 | |
@@ -306,16 +306,16 @@ discard block |
||
306 | 306 | */ |
307 | 307 | protected function getForeignKeys($src) |
308 | 308 | { |
309 | - $matches = array(); |
|
310 | - $brackets = '\(([^\)]+)\)'; |
|
311 | - $find = "/FOREIGN\s+KEY\s+{$brackets}\s+REFERENCES\s+([^\(]+){$brackets}/i"; |
|
309 | + $matches=array(); |
|
310 | + $brackets='\(([^\)]+)\)'; |
|
311 | + $find="/FOREIGN\s+KEY\s+{$brackets}\s+REFERENCES\s+([^\(]+){$brackets}/i"; |
|
312 | 312 | if(preg_match($find, $src, $matches)) |
313 | 313 | { |
314 | - $keys = preg_split('/,\s+/', $matches[1]); |
|
315 | - $fkeys = array(); |
|
314 | + $keys=preg_split('/,\s+/', $matches[1]); |
|
315 | + $fkeys=array(); |
|
316 | 316 | foreach(preg_split('/,\s+/', $matches[3]) as $i => $fkey) |
317 | - $fkeys[$keys[$i]] = $fkey; |
|
318 | - return array('table' => str_replace('"','',$matches[2]), 'keys' => $fkeys); |
|
317 | + $fkeys[$keys[$i]]=$fkey; |
|
318 | + return array('table' => str_replace('"', '', $matches[2]), 'keys' => $fkeys); |
|
319 | 319 | } |
320 | 320 | } |
321 | 321 | |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | { |
329 | 329 | foreach($tableInfo->getForeignKeys() as $fk) |
330 | 330 | { |
331 | - if( $fk==$columnId ) |
|
331 | + if($fk==$columnId) |
|
332 | 332 | //if(in_array($columnId, array_keys($fk['keys']))) |
333 | 333 | return true; |
334 | 334 | } |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | WHERE object_type = 'TABLE' AND owner=:schema |
358 | 358 | EOD; |
359 | 359 | $command=$this->getDbConnection()->createCommand($sql); |
360 | - $command->bindParam(':schema',$schema); |
|
360 | + $command->bindParam(':schema', $schema); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | $rows=$command->queryAll(); |
@@ -203,11 +203,9 @@ discard block |
||
203 | 203 | $info['NumericPrecision'] = intval($matches[1]); |
204 | 204 | if(count($matches) > 2) |
205 | 205 | $info['NumericScale'] = intval($matches[2]); |
206 | - } |
|
207 | - else |
|
206 | + } else |
|
208 | 207 | $info['ColumnSize'] = intval($matches[1]); |
209 | - } |
|
210 | - else |
|
208 | + } else |
|
211 | 209 | $info['DbType'] = $col['type']; |
212 | 210 | $tableInfo->Columns[$columnId] = new TOracleTableColumn($info); |
213 | 211 | } |
@@ -349,8 +347,7 @@ discard block |
||
349 | 347 | SELECT table_name, '{$schema}' as table_schema FROM user_tables |
350 | 348 | EOD; |
351 | 349 | $command=$this->getDbConnection()->createCommand($sql); |
352 | - } |
|
353 | - else |
|
350 | + } else |
|
354 | 351 | { |
355 | 352 | $sql=<<<EOD |
356 | 353 | SELECT object_name as table_name, owner as table_schema FROM all_objects |
@@ -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==='') |
@@ -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) |
@@ -233,8 +233,7 @@ discard block |
||
233 | 233 | $newid=substr($id,$pos+1); |
234 | 234 | if ($control!==null) |
235 | 235 | $control=$control->$newid; |
236 | - } |
|
237 | - else |
|
236 | + } else |
|
238 | 237 | { |
239 | 238 | // TCheckBoxList overrides findControl() with a fake implementation |
240 | 239 | // but accepts a second parameter to use the standard one |
@@ -296,8 +295,7 @@ discard block |
||
296 | 295 | { |
297 | 296 | $group=$this->getValidationGroup(); |
298 | 297 | return $this->getPage()->getValidators($group)->getCount()>0; |
299 | - } |
|
300 | - else |
|
298 | + } else |
|
301 | 299 | return false; |
302 | 300 | } |
303 | 301 |
@@ -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) |
@@ -179,14 +179,14 @@ |
||
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 |
@@ -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 | /** |
@@ -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 | { |
@@ -48,10 +48,10 @@ discard block |
||
48 | 48 | public function __construct($condition=null, $parameters=array()) |
49 | 49 | { |
50 | 50 | if(!is_array($parameters) && func_num_args() > 1) |
51 | - $parameters = array_slice(func_get_args(),1); |
|
51 | + $parameters=array_slice(func_get_args(), 1); |
|
52 | 52 | $this->_parameters=new TAttributeCollection; |
53 | 53 | $this->_parameters->setCaseSensitive(true); |
54 | - $this->_parameters->copyFrom((array)$parameters); |
|
54 | + $this->_parameters->copyFrom((array) $parameters); |
|
55 | 55 | $this->_ordersBy=new TAttributeCollection; |
56 | 56 | $this->_ordersBy->setCaseSensitive(true); |
57 | 57 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | */ |
110 | 110 | public function setSelect($value) |
111 | 111 | { |
112 | - $this->_select = $value; |
|
112 | + $this->_select=$value; |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | { |
129 | 129 | if(empty($value)) { |
130 | 130 | // reset the condition |
131 | - $this->_condition = null; |
|
131 | + $this->_condition=null; |
|
132 | 132 | return; |
133 | 133 | } |
134 | 134 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | if(preg_match('/ORDER\s+BY\s+(.*?)(?=LIMIT)|ORDER\s+BY\s+(.*?)$/i', $value, $matches) > 0) { |
142 | 142 | // condition contains ORDER BY |
143 | - $value = str_replace($matches[0], '', $value); |
|
143 | + $value=str_replace($matches[0], '', $value); |
|
144 | 144 | if(strlen($matches[1]) > 0) { |
145 | 145 | $this->setOrdersBy($matches[1]); |
146 | 146 | } else if(strlen($matches[2]) > 0) { |
@@ -150,23 +150,23 @@ discard block |
||
150 | 150 | |
151 | 151 | if(preg_match('/LIMIT\s+([\d\s,]+)/i', $value, $matches) > 0) { |
152 | 152 | // condition contains limit |
153 | - $value = str_replace($matches[0], '', $value); // remove limit from query |
|
153 | + $value=str_replace($matches[0], '', $value); // remove limit from query |
|
154 | 154 | if(strpos($matches[1], ',')) { // both offset and limit given |
155 | - list($offset, $limit) = explode(',', $matches[1]); |
|
156 | - $this->_limit = (int)$limit; |
|
157 | - $this->_offset = (int)$offset; |
|
155 | + list($offset, $limit)=explode(',', $matches[1]); |
|
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 | 163 | if(preg_match('/OFFSET\s+(\d+)/i', $value, $matches) > 0) { |
164 | 164 | // condition contains offset |
165 | - $value = str_replace($matches[0], '', $value); // remove offset from query |
|
166 | - $this->_offset = (int)$matches[1]; // set offset in criteria |
|
165 | + $value=str_replace($matches[0], '', $value); // remove offset from query |
|
166 | + $this->_offset=(int) $matches[1]; // set offset in criteria |
|
167 | 167 | } |
168 | 168 | |
169 | - $this->_condition = trim($value); |
|
169 | + $this->_condition=trim($value); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -213,12 +213,12 @@ discard block |
||
213 | 213 | $this->_ordersBy->copyFrom($value); |
214 | 214 | else |
215 | 215 | { |
216 | - $value=trim(preg_replace('/\s+/',' ',(string)$value)); |
|
216 | + $value=trim(preg_replace('/\s+/', ' ', (string) $value)); |
|
217 | 217 | $orderBys=array(); |
218 | - foreach(explode(',',$value) as $orderBy) |
|
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 | } |
@@ -261,23 +261,23 @@ discard block |
||
261 | 261 | */ |
262 | 262 | public function __toString() |
263 | 263 | { |
264 | - $str = ''; |
|
265 | - if(strlen((string)$this->getCondition()) > 0) |
|
266 | - $str .= '"'.(string)$this->getCondition().'"'; |
|
267 | - $params = array(); |
|
264 | + $str=''; |
|
265 | + if(strlen((string) $this->getCondition()) > 0) |
|
266 | + $str.='"'.(string) $this->getCondition().'"'; |
|
267 | + $params=array(); |
|
268 | 268 | foreach($this->getParameters() as $k=>$v) |
269 | - $params[] = "{$k} => ${v}"; |
|
269 | + $params[]="{$k} => ${v}"; |
|
270 | 270 | if(count($params) > 0) |
271 | - $str .= ', "'.implode(', ',$params).'"'; |
|
272 | - $orders = array(); |
|
271 | + $str.=', "'.implode(', ', $params).'"'; |
|
272 | + $orders=array(); |
|
273 | 273 | foreach($this->getOrdersBy() as $k=>$v) |
274 | - $orders[] = "{$k} => ${v}"; |
|
274 | + $orders[]="{$k} => ${v}"; |
|
275 | 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; |
|
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 | } |