@@ -440,6 +440,11 @@ public function isGeometry(): bool
440
440
return $ this ->type == 'geometry ' ;
441
441
}
442
442
443
+ public function isInteger (): bool
444
+ {
445
+ return in_array ($ this ->type , ['integer ' , 'bigint ' , 'smallint ' , 'tinyint ' ]);
446
+ }
447
+
443
448
public function setPk ($ value ) /*: void*/
444
449
{
445
450
$ this ->pk = $ value ;
@@ -484,18 +489,15 @@ public function jsonSerialize()
484
489
485
490
class ReflectedDatabase implements \JsonSerializable
486
491
{
487
- private $ name ;
488
492
private $ tableTypes ;
489
493
490
- public function __construct (String $ name , array $ tableTypes )
494
+ public function __construct (array $ tableTypes )
491
495
{
492
- $ this ->name = $ name ;
493
496
$ this ->tableTypes = $ tableTypes ;
494
497
}
495
498
496
499
public static function fromReflection (GenericReflection $ reflection ): ReflectedDatabase
497
500
{
498
- $ name = $ reflection ->getDatabaseName ();
499
501
$ tableTypes = [];
500
502
foreach ($ reflection ->getTables () as $ table ) {
501
503
$ tableName = $ table ['TABLE_NAME ' ];
@@ -505,19 +507,13 @@ public static function fromReflection(GenericReflection $reflection): ReflectedD
505
507
}
506
508
$ tableTypes [$ tableName ] = $ tableType ;
507
509
}
508
- return new ReflectedDatabase ($ name , $ tableTypes );
510
+ return new ReflectedDatabase ($ tableTypes );
509
511
}
510
512
511
513
public static function fromJson ( /* object */ $ json ): ReflectedDatabase
512
514
{
513
- $ name = $ json ->name ;
514
515
$ tableTypes = (array ) $ json ->tables ;
515
- return new ReflectedDatabase ($ name , $ tableTypes );
516
- }
517
-
518
- public function getName (): String
519
- {
520
- return $ this ->name ;
516
+ return new ReflectedDatabase ($ tableTypes );
521
517
}
522
518
523
519
public function hasTable (String $ tableName ): bool
@@ -547,7 +543,6 @@ public function removeTable(String $tableName): bool
547
543
public function serialize ()
548
544
{
549
545
return [
550
- 'name ' => $ this ->name ,
551
546
'tables ' => $ this ->tableTypes ,
552
547
];
553
548
}
@@ -987,12 +982,11 @@ public function __construct(Router $router, Responder $responder, ReflectionServ
987
982
988
983
public function getDatabase (Request $ request ): Response
989
984
{
990
- $ name = $ this ->reflection ->getDatabaseName ();
991
985
$ tables = [];
992
986
foreach ($ this ->reflection ->getTableNames () as $ table ) {
993
987
$ tables [] = $ this ->reflection ->getTable ($ table );
994
988
}
995
- $ database = ['name ' => $ name , ' tables ' => $ tables ];
989
+ $ database = ['tables ' => $ tables ];
996
990
return $ this ->responder ->success ($ database );
997
991
}
998
992
@@ -1701,6 +1695,8 @@ private function convertRecordValue($conversion, $value)
1701
1695
switch ($ conversion ) {
1702
1696
case 'boolean ' :
1703
1697
return $ value ? true : false ;
1698
+ case 'integer ' :
1699
+ return (int ) $ value ;
1704
1700
}
1705
1701
return $ value ;
1706
1702
}
@@ -1710,6 +1706,9 @@ private function getRecordValueConversion(ReflectedColumn $column): String
1710
1706
if (in_array ($ this ->driver , ['mysql ' , 'sqlsrv ' ]) && $ column ->isBoolean ()) {
1711
1707
return 'boolean ' ;
1712
1708
}
1709
+ if ($ this ->driver == 'sqlsrv ' && $ column ->getType () == 'bigint ' ) {
1710
+ return 'integer ' ;
1711
+ }
1713
1712
return 'none ' ;
1714
1713
}
1715
1714
@@ -1818,6 +1817,7 @@ private function getOptions(): array
1818
1817
\PDO ::ATTR_PERSISTENT => true ,
1819
1818
];
1820
1819
case 'sqlsrv ' :return $ options + [
1820
+ \PDO ::SQLSRV_ATTR_DIRECT_QUERY => false ,
1821
1821
\PDO ::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE => true ,
1822
1822
];
1823
1823
}
@@ -1886,7 +1886,11 @@ public function createSingle(ReflectedTable $table, array $columnValues) /*: ?St
1886
1886
$ stmt = $ this ->query ('SELECT LAST_INSERT_ID() ' , []);
1887
1887
break ;
1888
1888
}
1889
- return $ stmt ->fetchColumn (0 );
1889
+ $ pkValue = $ stmt ->fetchColumn (0 );
1890
+ if ($ this ->driver == 'sqlsrv ' && $ table ->getPk ()->getType () == 'bigint ' ) {
1891
+ return (int ) $ pkValue ;
1892
+ }
1893
+ return $ pkValue ;
1890
1894
}
1891
1895
1892
1896
public function selectSingle (ReflectedTable $ table , array $ columnNames , String $ id ) /*: ?array*/
@@ -3701,7 +3705,7 @@ private function isOperationOnColumnAllowed(String $operation, String $tableName
3701
3705
private function setPath (String $ tableName ) /*: void*/
3702
3706
{
3703
3707
$ table = $ this ->reflection ->getTable ($ tableName );
3704
- $ type = $ table ->getType ($ tableName );
3708
+ $ type = $ table ->getType ();
3705
3709
$ pk = $ table ->getPk ();
3706
3710
$ pkName = $ pk ? $ pk ->getName () : '' ;
3707
3711
foreach ($ this ->operations as $ operation => $ method ) {
@@ -3751,7 +3755,7 @@ private function setPath(String $tableName) /*: void*/
3751
3755
private function setComponentSchema (String $ tableName ) /*: void*/
3752
3756
{
3753
3757
$ table = $ this ->reflection ->getTable ($ tableName );
3754
- $ type = $ table ->getType ($ tableName );
3758
+ $ type = $ table ->getType ();
3755
3759
$ pk = $ table ->getPk ();
3756
3760
$ pkName = $ pk ? $ pk ->getName () : '' ;
3757
3761
foreach ($ this ->operations as $ operation => $ method ) {
@@ -3793,7 +3797,7 @@ private function setComponentSchema(String $tableName) /*: void*/
3793
3797
private function setComponentResponse (String $ tableName ) /*: void*/
3794
3798
{
3795
3799
$ table = $ this ->reflection ->getTable ($ tableName );
3796
- $ type = $ table ->getType ($ tableName );
3800
+ $ type = $ table ->getType ();
3797
3801
$ pk = $ table ->getPk ();
3798
3802
$ pkName = $ pk ? $ pk ->getName () : '' ;
3799
3803
foreach (['list ' , 'read ' ] as $ operation ) {
@@ -3818,7 +3822,7 @@ private function setComponentResponse(String $tableName) /*: void*/
3818
3822
private function setComponentRequestBody (String $ tableName ) /*: void*/
3819
3823
{
3820
3824
$ table = $ this ->reflection ->getTable ($ tableName );
3821
- $ type = $ table ->getType ($ tableName );
3825
+ $ type = $ table ->getType ();
3822
3826
$ pk = $ table ->getPk ();
3823
3827
$ pkName = $ pk ? $ pk ->getName () : '' ;
3824
3828
if ($ pkName && $ type == 'table ' ) {
0 commit comments