Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/ColumnBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@

use PHPUnit\Framework\Attributes\DataProviderExternal;
use Yiisoft\Db\Mssql\Tests\Provider\ColumnBuilderProvider;
use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait;
use Yiisoft\Db\Tests\Common\CommonColumnBuilderTest;

/**
* @group mssql
*/
class ColumnBuilderTest extends CommonColumnBuilderTest
{
use IntegrationTestTrait;

#[DataProviderExternal(ColumnBuilderProvider::class, 'buildingMethods')]
public function testBuildingMethods(
string $buildingMethod,
Expand Down
6 changes: 3 additions & 3 deletions tests/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testSelectWithPhpTypecasting(): void
$expected = [
'null' => null,
1 => 1,
'2.5' => 2.5,
'2.5' => '2.5',
'string' => 'string',
];

Expand All @@ -67,13 +67,13 @@ public function testSelectWithPhpTypecasting(): void
->withPhpTypecasting()
->queryScalar();

$this->assertSame(2.5, $result);
$this->assertSame('2.5', $result);

$result = $db->createCommand('SELECT 2.5 UNION SELECT 3.3')
->withPhpTypecasting()
->queryColumn();

$this->assertSame([2.5, 3.3], $result);
$this->assertSame(['2.5', '3.3'], $result);

$db->close();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Provider/ColumnFactoryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public static function dbTypes(): array
['smallint', ColumnType::SMALLINT, IntegerColumn::class],
['int', ColumnType::INTEGER, IntegerColumn::class],
['bigint', ColumnType::BIGINT, IntegerColumn::class],
['numeric', ColumnType::DECIMAL, DoubleColumn::class],
['decimal', ColumnType::DECIMAL, DoubleColumn::class],
['numeric', ColumnType::DECIMAL, StringColumn::class],
['decimal', ColumnType::DECIMAL, StringColumn::class],
['float', ColumnType::FLOAT, DoubleColumn::class],
['real', ColumnType::FLOAT, DoubleColumn::class],
['double', ColumnType::DOUBLE, DoubleColumn::class],
Expand Down
10 changes: 5 additions & 5 deletions tests/Provider/QueryBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,9 @@ public static function insertReturningPks(): array
['order_id' => 1, 'item_id' => 1, 'quantity' => 1, 'subtotal' => 1.0],
[],
<<<SQL
SET NOCOUNT ON;DECLARE @temporary_inserted TABLE ([order_id] int, [item_id] int);INSERT INTO {{%order_item}} ([order_id], [item_id], [quantity], [subtotal]) OUTPUT INSERTED.[order_id],INSERTED.[item_id] INTO @temporary_inserted VALUES (1, 1, 1, 1);SELECT * FROM @temporary_inserted;
SET NOCOUNT ON;DECLARE @temporary_inserted TABLE ([order_id] int, [item_id] int);INSERT INTO {{%order_item}} ([order_id], [item_id], [quantity], [subtotal]) OUTPUT INSERTED.[order_id],INSERTED.[item_id] INTO @temporary_inserted VALUES (1, 1, 1, :qp0);SELECT * FROM @temporary_inserted;
SQL,
[],
[':qp0' => new Param('1', DataType::STRING)],
],
];
}
Expand Down Expand Up @@ -642,14 +642,14 @@ public static function upsertReturning(): array
['id_1' => 1, 'id_2' => 2.5, 'type' => 'Test'],
true,
['id_1', 'id_2'],
'SET NOCOUNT ON;DECLARE @temporary_inserted TABLE ([id_1] int, [id_2] decimal(5,2));'
. 'MERGE [notauto_pk] WITH (HOLDLOCK) USING (VALUES (1, 2.5, :qp0)) AS EXCLUDED'
'SET NOCOUNT ON;DECLARE @temporary_inserted TABLE ([id_1] int, [id_2] decimal(5,1));'
. 'MERGE [notauto_pk] WITH (HOLDLOCK) USING (VALUES (1, :qp0, :qp1)) AS EXCLUDED'
. ' ([id_1], [id_2], [type]) ON (([notauto_pk].[id_1]=EXCLUDED.[id_1])'
. ' AND ([notauto_pk].[id_2]=EXCLUDED.[id_2])) WHEN MATCHED THEN UPDATE SET [type]=EXCLUDED.[type]'
. ' WHEN NOT MATCHED THEN INSERT ([id_1], [id_2], [type])'
. ' VALUES (EXCLUDED.[id_1], EXCLUDED.[id_2], EXCLUDED.[type])'
. ' OUTPUT INSERTED.[id_1],INSERTED.[id_2] INTO @temporary_inserted;SELECT * FROM @temporary_inserted;',
[':qp0' => new Param('Test', DataType::STRING)],
[':qp0' => new Param('2.5', DataType::STRING), ':qp1' => new Param('Test', DataType::STRING)],
],
'no return columns' => [
'type',
Expand Down
17 changes: 8 additions & 9 deletions tests/Provider/SchemaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ public static function columns(): array
collation: 'SQL_Latin1_General_CP1_CI_AS',
),
'float_col' => new DoubleColumn(
ColumnType::DECIMAL,
dbType: 'decimal',
ColumnType::FLOAT,
dbType: 'float',
notNull: true,
size: 4,
scale: 3,
size: 53,
),
'float_col2' => new DoubleColumn(
ColumnType::FLOAT,
Expand All @@ -85,12 +84,12 @@ public static function columns(): array
'blob_col' => new BinaryColumn(
dbType: 'varbinary',
),
'numeric_col' => new DoubleColumn(
'numeric_col' => new StringColumn(
ColumnType::DECIMAL,
dbType: 'decimal',
size: 5,
scale: 2,
defaultValue: 33.22,
size: 5,
defaultValue: '33.22',
),
'datetime_col' => new DateTimeColumn(
dbType: 'datetime',
Expand Down Expand Up @@ -221,7 +220,7 @@ public static function resultColumns(): array
'len' => 2147483647,
'precision' => 0,
]],
[new DoubleColumn(ColumnType::DECIMAL, dbType: 'decimal', name: 'float_col', size: 4, scale: 3), [
[new StringColumn(ColumnType::DECIMAL, dbType: 'decimal', name: 'float_col', scale: 3, size: 4), [
'flags' => 0,
'sqlsrv:decl_type' => 'decimal',
'native_type' => 'string',
Expand Down Expand Up @@ -291,7 +290,7 @@ public static function resultColumns(): array
'len' => 0,
'precision' => 0,
]],
[new DoubleColumn(ColumnType::DECIMAL, dbType: 'numeric', name: '2.5', size: 2, scale: 1), [
[new StringColumn(ColumnType::DECIMAL, dbType: 'numeric', name: '2.5', scale: 1, size: 2), [
'flags' => 0,
'sqlsrv:decl_type' => 'numeric',
'native_type' => 'string',
Expand Down
4 changes: 2 additions & 2 deletions tests/Support/Fixture/mssql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ CREATE TABLE [dbo].[type] (
[char_col] [char](100) NOT NULL,
[char_col2] [varchar](100) COLLATE Latin1_General_CI_AS DEFAULT 'something',
[char_col3] [text],
[float_col] [decimal](4,3) NOT NULL,
[float_col] [float] NOT NULL,
[float_col2] [float] DEFAULT '1.23',
[blob_col] [varbinary](MAX),
[numeric_col] [decimal](5,2) DEFAULT '33.22',
Expand Down Expand Up @@ -178,7 +178,7 @@ CREATE TABLE [dbo].[default_pk] (

CREATE TABLE [dbo].[notauto_pk] (
[id_1] [INT],
[id_2] [DECIMAL](5,2),
[id_2] [DECIMAL](5,1),
[type] [VARCHAR](255) NOT NULL,
CONSTRAINT [PK_notauto_pk] PRIMARY KEY CLUSTERED (
[id_1] ASC,
Expand Down
7 changes: 5 additions & 2 deletions tests/Type/DecimalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public function testCreateTableWithDefaultValue(): void

$this->assertSame('decimal', $tableSchema?->getColumn('Mydecimal')->getDbType());
$this->assertSame(38, $tableSchema?->getColumn('Mydecimal')->getSize());
$this->assertSame(9.9999999999999998e+037, $tableSchema?->getColumn('Mydecimal')->getDefaultValue());
$this->assertSame(
'99999999999999997748809823456034029568',
$tableSchema?->getColumn('Mydecimal')->getDefaultValue(),
);

$db->createCommand()->insert('decimal_default', [])->execute();
}
Expand Down Expand Up @@ -61,7 +64,7 @@ public function testDefaultValue(): void

$this->assertSame('decimal', $tableSchema?->getColumn('Mydecimal')->getDbType());
$this->assertSame(38, $tableSchema?->getColumn('Mydecimal')->getSize());
$this->assertSame(9.9999999999999998e+037, $tableSchema?->getColumn('Mydecimal')->getDefaultValue());
$this->assertSame('9.9999999999999998e+037', $tableSchema?->getColumn('Mydecimal')->getDefaultValue());

$db->createCommand()->dropTable('decimal_default')->execute();
}
Expand Down
7 changes: 5 additions & 2 deletions tests/Type/NumericTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public function testCreateTableWithDefaultValue(): void

$this->assertSame('numeric', $tableSchema?->getColumn('Mynumeric')->getDbType());
$this->assertSame(38, $tableSchema?->getColumn('Mynumeric')->getSize());
$this->assertSame(9.9999999999999998e+037, $tableSchema?->getColumn('Mynumeric')->getDefaultValue());
$this->assertSame(
'99999999999999997748809823456034029568',
$tableSchema?->getColumn('Mynumeric')->getDefaultValue(),
);

$db->createCommand()->dropTable('numeric_default')->execute();
}
Expand Down Expand Up @@ -61,7 +64,7 @@ public function testDefaultValue(): void

$this->assertSame('numeric', $tableSchema?->getColumn('Mynumeric')->getDbType());
$this->assertSame(38, $tableSchema?->getColumn('Mynumeric')->getSize());
$this->assertSame(9.9999999999999998e+037, $tableSchema?->getColumn('Mynumeric')->getDefaultValue());
$this->assertSame('9.9999999999999998e+037', $tableSchema?->getColumn('Mynumeric')->getDefaultValue());

$db->createCommand()->dropTable('numeric_default')->execute();
}
Expand Down
Loading