Skip to content

Commit

Permalink
SqlsrvDriver: enables SQLSRV_ATTR_FORMAT_DECIMALS (BC break)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Aug 18, 2024
1 parent 08521ce commit 71f30c9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/Database/Drivers/Engines/SQLServerEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ public function resolveColumnConverter(array $meta, TypeConverter $converter): ?
return match ($meta['nativeType']) {
'timestamp' => null, // timestamp does not mean time in sqlsrv
'bit' => $converter->convertBoolean ? $converter->toBool(...) : null,
'decimal', 'numeric',
'double', 'double precision', 'float', 'real', 'money', 'smallmoney' => fn($value): float => (float) (is_string($value) && str_starts_with($value, '.') ? '0' . $value : $value),
default => $converter->resolve($meta['nativeType']),
};
}
Expand Down
6 changes: 6 additions & 0 deletions src/Database/Drivers/PDO/SQLSrv/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public function getDatabaseEngine(): Drivers\Engines\SQLServerEngine
}


protected function initialize(array $options): void
{
$this->pdo->setAttribute(\PDO::SQLSRV_ATTR_FORMAT_DECIMALS, true);
}


public function getMetaTypeKey(): string
{
return 'sqlsrv:decl_type';
Expand Down

0 comments on commit 71f30c9

Please sign in to comment.