Skip to content

Commit 22b282a

Browse files
committed
Fix for #568
1 parent 8b3b0a4 commit 22b282a

File tree

4 files changed

+73
-2
lines changed

4 files changed

+73
-2
lines changed

api.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -4702,6 +4702,16 @@ public function __construct(string $driver)
47024702

47034703
public function convertColumnValue(ReflectedColumn $column): string
47044704
{
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+
}
47054715
if ($column->isBinary()) {
47064716
switch ($this->driver) {
47074717
case 'mysql':
@@ -4734,7 +4744,6 @@ public function convertColumnName(ReflectedColumn $column, $value): string
47344744
return "encode($value::bytea, 'base64') as $value";
47354745
case 'sqlsrv':
47364746
return "CASE WHEN $value IS NULL THEN NULL ELSE (SELECT CAST($value as varbinary(max)) FOR XML PATH(''), BINARY BASE64) END as $value";
4737-
47384747
}
47394748
}
47404749
if ($column->isGeometry()) {
@@ -5122,6 +5131,8 @@ public function convertRecords(ReflectedTable $table, array $columnNames, array
51225131
private function convertInputValue($conversion, $value)
51235132
{
51245133
switch ($conversion) {
5134+
case 'boolean':
5135+
return $value ? 1 : 0;
51255136
case 'base64url_to_base64':
51265137
return str_pad(strtr($value, '-_', '+/'), ceil(strlen($value) / 4) * 4, '=', STR_PAD_RIGHT);
51275138
}
@@ -5130,6 +5141,9 @@ private function convertInputValue($conversion, $value)
51305141

51315142
private function getInputValueConversion(ReflectedColumn $column): string
51325143
{
5144+
if ($column->isBoolean()) {
5145+
return 'boolean';
5146+
}
51335147
if ($column->isBinary()) {
51345148
return 'base64url_to_base64';
51355149
}

src/Tqdev/PhpCrudApi/Database/ColumnConverter.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ public function __construct(string $driver)
1515

1616
public function convertColumnValue(ReflectedColumn $column): string
1717
{
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+
}
1828
if ($column->isBinary()) {
1929
switch ($this->driver) {
2030
case 'mysql':
@@ -47,7 +57,6 @@ public function convertColumnName(ReflectedColumn $column, $value): string
4757
return "encode($value::bytea, 'base64') as $value";
4858
case 'sqlsrv':
4959
return "CASE WHEN $value IS NULL THEN NULL ELSE (SELECT CAST($value as varbinary(max)) FOR XML PATH(''), BINARY BASE64) END as $value";
50-
5160
}
5261
}
5362
if ($column->isGeometry()) {

src/Tqdev/PhpCrudApi/Database/DataConverter.php

+5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public function convertRecords(ReflectedTable $table, array $columnNames, array
5656
private function convertInputValue($conversion, $value)
5757
{
5858
switch ($conversion) {
59+
case 'boolean':
60+
return $value ? 1 : 0;
5961
case 'base64url_to_base64':
6062
return str_pad(strtr($value, '-_', '+/'), ceil(strlen($value) / 4) * 4, '=', STR_PAD_RIGHT);
6163
}
@@ -64,6 +66,9 @@ private function convertInputValue($conversion, $value)
6466

6567
private function getInputValueConversion(ReflectedColumn $column): string
6668
{
69+
if ($column->isBoolean()) {
70+
return 'boolean';
71+
}
6772
if ($column->isBinary()) {
6873
return 'base64url_to_base64';
6974
}
Original file line numberDiff line numberDiff line change
@@ -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}

0 commit comments

Comments
 (0)