File tree Expand file tree Collapse file tree 2 files changed +19
-21
lines changed Expand file tree Collapse file tree 2 files changed +19
-21
lines changed Original file line number Diff line number Diff line change @@ -113,10 +113,7 @@ protected function _addExpressions($conditions, $trueValues) {
113
113
if ($ trueValue === 'literal ' ) {
114
114
$ trueValue = $ k ;
115
115
} elseif (is_string ($ trueValue ) || is_numeric ($ trueValue )) {
116
- $ trueValue = [
117
- 'value ' => $ trueValue ,
118
- 'type ' => null
119
- ];
116
+ $ trueValue = $ this ->_parseValue ($ trueValue );
120
117
}
121
118
122
119
$ this ->_conditions [] = $ c ;
@@ -150,7 +147,7 @@ protected function _parseValue($value) {
150
147
if (is_string ($ value ) || is_numeric ($ value )) {
151
148
$ value = [
152
149
'value ' => $ value ,
153
- 'type ' => null
150
+ 'type ' => is_string ( $ value ) ? null : $ this -> _getType ( $ value )
154
151
];
155
152
} elseif (is_array ($ value ) && !isset ($ value ['value ' ])) {
156
153
$ value = array_keys ($ value );
@@ -159,6 +156,23 @@ protected function _parseValue($value) {
159
156
return $ value ;
160
157
}
161
158
159
+ /**
160
+ * Gets the correct type for the value
161
+ *
162
+ * @param mixed $value The value to test
163
+ *
164
+ * @return null|string
165
+ */
166
+ protected function _getType ($ value ) {
167
+ if (is_integer ($ value )) {
168
+ return 'integer ' ;
169
+ } elseif (is_float ($ value )) {
170
+ return 'float ' ;
171
+ }
172
+
173
+ return null ;
174
+ }
175
+
162
176
/**
163
177
* Compiles the relevant parts into sql
164
178
*
Original file line number Diff line number Diff line change @@ -2722,8 +2722,6 @@ public function testDirectIsNull() {
2722
2722
* @return void
2723
2723
*/
2724
2724
public function testSqlCaseStatement () {
2725
- $ convert = $ this ->connection ->driver () instanceof \Cake \Database \Driver \Sqlserver;
2726
-
2727
2725
$ query = new Query ($ this ->connection );
2728
2726
$ publishedCase = $ query
2729
2727
->newExpr ()
@@ -2738,20 +2736,6 @@ public function testSqlCaseStatement() {
2738
2736
->add (['published ' => 'N ' ])
2739
2737
);
2740
2738
2741
- //SQLServer requires the case statements to be converted to int
2742
- if ($ convert ) {
2743
- $ publishedCase = $ query ->func ()
2744
- ->convert ([
2745
- 'INT ' => 'literal ' ,
2746
- $ publishedCase
2747
- ]);
2748
- $ notPublishedCase = $ query ->func ()
2749
- ->convert ([
2750
- 'INT ' => 'literal ' ,
2751
- $ notPublishedCase
2752
- ]);
2753
- }
2754
-
2755
2739
$ results = $ query
2756
2740
->select ([
2757
2741
'published ' => $ query ->func ()->sum ($ publishedCase ),
You can’t perform that action at this time.
0 commit comments