Maurits van der Schee 5 years ago
parent
commit
22b282ab5b

+ 15
- 1
api.php View File

@@ -4702,6 +4702,16 @@ namespace Tqdev\PhpCrudApi\Database {
4702 4702
 
4703 4703
         public function convertColumnValue(ReflectedColumn $column): string
4704 4704
         {
4705
+            if ($column->isBoolean()) {
4706
+                switch ($this->driver) {
4707
+                    case 'mysql':
4708
+                        return "IFNULL(IF(?,TRUE,FALSE),NULL)";
4709
+                    case 'pgsql':
4710
+                        return "?";
4711
+                    case 'sqlsrv':
4712
+                        return "?";
4713
+                }
4714
+            }
4705 4715
             if ($column->isBinary()) {
4706 4716
                 switch ($this->driver) {
4707 4717
                     case 'mysql':
@@ -4734,7 +4744,6 @@ namespace Tqdev\PhpCrudApi\Database {
4734 4744
                         return "encode($value::bytea, 'base64') as $value";
4735 4745
                     case 'sqlsrv':
4736 4746
                         return "CASE WHEN $value IS NULL THEN NULL ELSE (SELECT CAST($value as varbinary(max)) FOR XML PATH(''), BINARY BASE64) END as $value";
4737
-
4738 4747
                 }
4739 4748
             }
4740 4749
             if ($column->isGeometry()) {
@@ -5122,6 +5131,8 @@ namespace Tqdev\PhpCrudApi\Database {
5122 5131
         private function convertInputValue($conversion, $value)
5123 5132
         {
5124 5133
             switch ($conversion) {
5134
+                case 'boolean':
5135
+                    return $value ? 1 : 0;
5125 5136
                 case 'base64url_to_base64':
5126 5137
                     return str_pad(strtr($value, '-_', '+/'), ceil(strlen($value) / 4) * 4, '=', STR_PAD_RIGHT);
5127 5138
             }
@@ -5130,6 +5141,9 @@ namespace Tqdev\PhpCrudApi\Database {
5130 5141
 
5131 5142
         private function getInputValueConversion(ReflectedColumn $column): string
5132 5143
         {
5144
+            if ($column->isBoolean()) {
5145
+                return 'boolean';
5146
+            }
5133 5147
             if ($column->isBinary()) {
5134 5148
                 return 'base64url_to_base64';
5135 5149
             }

+ 10
- 1
src/Tqdev/PhpCrudApi/Database/ColumnConverter.php View File

@@ -15,6 +15,16 @@ class ColumnConverter
15 15
 
16 16
     public function convertColumnValue(ReflectedColumn $column): string
17 17
     {
18
+        if ($column->isBoolean()) {
19
+            switch ($this->driver) {
20
+                case 'mysql':
21
+                    return "IFNULL(IF(?,TRUE,FALSE),NULL)";
22
+                case 'pgsql':
23
+                    return "?";
24
+                case 'sqlsrv':
25
+                    return "?";
26
+            }
27
+        }
18 28
         if ($column->isBinary()) {
19 29
             switch ($this->driver) {
20 30
                 case 'mysql':
@@ -47,7 +57,6 @@ class ColumnConverter
47 57
                     return "encode($value::bytea, 'base64') as $value";
48 58
                 case 'sqlsrv':
49 59
                     return "CASE WHEN $value IS NULL THEN NULL ELSE (SELECT CAST($value as varbinary(max)) FOR XML PATH(''), BINARY BASE64) END as $value";
50
-
51 60
             }
52 61
         }
53 62
         if ($column->isGeometry()) {

+ 5
- 0
src/Tqdev/PhpCrudApi/Database/DataConverter.php View File

@@ -56,6 +56,8 @@ class DataConverter
56 56
     private function convertInputValue($conversion, $value)
57 57
     {
58 58
         switch ($conversion) {
59
+            case 'boolean':
60
+                return $value ? 1 : 0;
59 61
             case 'base64url_to_base64':
60 62
                 return str_pad(strtr($value, '-_', '+/'), ceil(strlen($value) / 4) * 4, '=', STR_PAD_RIGHT);
61 63
         }
@@ -64,6 +66,9 @@ class DataConverter
64 66
 
65 67
     private function getInputValueConversion(ReflectedColumn $column): string
66 68
     {
69
+        if ($column->isBoolean()) {
70
+            return 'boolean';
71
+        }
67 72
         if ($column->isBinary()) {
68 73
             return 'base64url_to_base64';
69 74
         }

+ 43
- 0
tests/functional/001_records/084_update_tags_with_boolean.log View File

@@ -0,0 +1,43 @@
1
+GET /records/tags/1
2
+===
3
+200
4
+Content-Type: application/json
5
+Content-Length: 44
6
+
7
+{"id":1,"name":"funny","is_important":false}
8
+===
9
+PUT /records/tags/1
10
+
11
+{"id":1,"name":"funny","is_important":true}
12
+===
13
+200
14
+Content-Type: application/json
15
+Content-Length: 1
16
+
17
+1
18
+===
19
+GET /records/tags/1
20
+===
21
+200
22
+Content-Type: application/json
23
+Content-Length: 43
24
+
25
+{"id":1,"name":"funny","is_important":true}
26
+===
27
+PUT /records/tags/1
28
+
29
+{"id":1,"name":"funny","is_important":false}
30
+===
31
+200
32
+Content-Type: application/json
33
+Content-Length: 1
34
+
35
+1
36
+===
37
+GET /records/tags/1
38
+===
39
+200
40
+Content-Type: application/json
41
+Content-Length: 44
42
+
43
+{"id":1,"name":"funny","is_important":false}

Loading…
Cancel
Save