File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace CodeIgniter \Settings \Database \Migrations ;
6+
7+ use CodeIgniter \Database \Forge ;
8+ use CodeIgniter \Database \Migration ;
9+ use CodeIgniter \Settings \Config \Settings ;
10+
11+ class ConvertSqlsrvValueColumn extends Migration
12+ {
13+ private readonly Settings $ config ;
14+
15+ public function __construct (?Forge $ forge = null )
16+ {
17+ $ this ->config = config ('Settings ' );
18+ $ this ->DBGroup = $ this ->config ->database ['group ' ] ?? null ;
19+
20+ parent ::__construct ($ forge );
21+ }
22+
23+ public function up (): void
24+ {
25+ if ($ this ->db ->getPlatform () !== 'SQLSRV ' ) {
26+ return ;
27+ }
28+
29+ $ this ->forge ->modifyColumn ($ this ->config ->database ['table ' ], [
30+ 'value ' => [
31+ 'type ' => 'VARCHAR ' ,
32+ 'constraint ' => 'MAX ' ,
33+ 'null ' => true ,
34+ ],
35+ ]);
36+ }
37+
38+ public function down (): void
39+ {
40+ if ($ this ->db ->getPlatform () !== 'SQLSRV ' ) {
41+ return ;
42+ }
43+
44+ $ this ->forge ->modifyColumn ($ this ->config ->database ['table ' ], [
45+ 'value ' => [
46+ 'type ' => 'TEXT ' ,
47+ 'null ' => true ,
48+ ],
49+ ]);
50+ }
51+ }
Original file line number Diff line number Diff line change @@ -109,7 +109,7 @@ public function persistPendingProperties(): void
109109 protected function prepareValue ($ value )
110110 {
111111 if (is_bool ($ value )) {
112- return ( int ) $ value ;
112+ return $ value ? ' 1 ' : ' 0 ' ;
113113 }
114114
115115 if (is_array ($ value ) || is_object ($ value )) {
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Tests ;
6+
7+ use CodeIgniter \Settings \Handlers \ArrayHandler ;
8+ use Tests \Support \TestCase ;
9+
10+ /**
11+ * @internal
12+ */
13+ final class BaseHandlerTest extends TestCase
14+ {
15+ public function testPrepareValueSerializesBooleansAsStrings (): void
16+ {
17+ $ prepareValue = self ::getPrivateMethodInvoker (new ArrayHandler (), 'prepareValue ' );
18+
19+ $ this ->assertSame ('1 ' , $ prepareValue (true ));
20+ $ this ->assertSame ('0 ' , $ prepareValue (false ));
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments