Skip to content

Commit

Permalink
Merge pull request #75 from WebFiori/dev
Browse files Browse the repository at this point in the history
Add Support for SQL Transactions
  • Loading branch information
usernane authored Jul 30, 2023
2 parents 15c77b7 + 8900b85 commit ca04c4c
Show file tree
Hide file tree
Showing 15 changed files with 536 additions and 82 deletions.
20 changes: 10 additions & 10 deletions tests/webfiori/database/tests/common/InsertBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ public function test03() {

$this->assertEquals('insert into [users] ([user_id], [created_on], [is_active]) values (?, ?, ?);', $helper->getQuery());
$this->assertEquals([
[1, 1, 2, 4],
[date('Y-m-d H:i:s'), 1, 5, 58734173],
[1, 1, 2, -7]
1,
date('Y-m-d H:i:s'),
1
], $helper->getQueryParams());
$helper->insert([
'user-id' => 1,
Expand All @@ -210,13 +210,13 @@ public function test03() {
$this->assertEquals('insert into [users] ([user_id], [email], [username], [password], [age], [created_on], [is_active]) values (?, ?, ?, ?, ?, ?, ?);', $helper->getQuery());
$encoded = $helper->getQueryParams()[1][2];
$this->assertEquals([
[1, 1, 2, 4],
['[email protected]', 1, $encoded, 12 ],
['warrior', 1, $encoded, 12],
['abcd', 1, $encoded, 12],
[33.3, 1, 3, 3],
[date('Y-m-d H:i:s'), 1, 5, 58734173],
[1, 1, 2, -7],
1,
'[email protected]',
'warrior',
'abcd',
33.3,
date('Y-m-d H:i:s'),
1
], $helper->getQueryParams());
}
}
28 changes: 21 additions & 7 deletions tests/webfiori/database/tests/mssql/MSSQLColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public function testSetDefault00() {
$col = new MSSQLColumn('date', 'datetime2');
$col->setDefault('2019-11-09');
$this->assertEquals('2019-11-09',$col->getDefault());
$this->assertEquals('[date] [datetime2] not null default \'2019-11-09\'',$col.'');
$this->assertEquals('[date] [datetime2](1) not null default \'2019-11-09\'',$col.'');
}
/**
* @test
Expand All @@ -294,7 +294,7 @@ public function testSetDefault01() {
$col = new MSSQLColumn('date', 'datetime2');
$col->setDefault('2019-07-07 09:09:09');
$this->assertEquals('2019-07-07 09:09:09',$col->getDefault());
$this->assertEquals('[date] [datetime2] not null default \'2019-07-07 09:09:09\'',$col.'');
$this->assertEquals('[date] [datetime2](1) not null default \'2019-07-07 09:09:09\'',$col.'');
}
/**
* @test
Expand All @@ -303,7 +303,7 @@ public function testSetDefault02() {
$col = new MSSQLColumn('date', 'datetime2');
$col->setDefault('');
$this->assertNull($col->getDefault());
$this->assertEquals('[date] [datetime2] not null',$col.'');
$this->assertEquals('[date] [datetime2](1) not null',$col.'');
}
/**
* @test
Expand All @@ -312,7 +312,8 @@ public function testSetDefault03() {
$col = new MSSQLColumn('date', 'datetime2');
$col->setDefault('2019-07-07 09:09:09');
$this->assertEquals('2019-07-07 09:09:09',$col->getDefault());
$this->assertEquals('[date] [datetime2] not null default \'2019-07-07 09:09:09\'',$col.'');
$col->setSize(4);
$this->assertEquals('[date] [datetime2](4) not null default \'2019-07-07 09:09:09\'',$col.'');
}
/**
* @test
Expand All @@ -321,10 +322,10 @@ public function testSetDefault04() {
$col = new MSSQLColumn('date', 'datetime2');
$col->setDefault('2019-15-07 09:09:09');
$this->assertNull($col->getDefault());
$this->assertEquals('[date] [datetime2] not null',$col.'');
$this->assertEquals('[date] [datetime2](1) not null',$col.'');
$col->setDefault('2019-12-33 09:09:09');
$this->assertNull($col->getDefault());
$this->assertEquals('[date] [datetime2] not null',$col.'');
$this->assertEquals('[date] [datetime2](1) not null',$col.'');
$col->setDefault('2019-12-31 24:09:09');
$this->assertNull($col->getDefault());
$col->setDefault('2019-12-31 23:60:09');
Expand Down Expand Up @@ -392,7 +393,7 @@ public function testSetDefault08() {
$col = new MSSQLColumn('date', 'datetime2');
$col->setDefault('now');
$this->assertEquals('now',$col->getDefault());
$this->assertEquals('[date] [datetime2] not null default getdate()',$col.'');
$this->assertEquals('[date] [datetime2](1) not null default getdate()',$col.'');
}
/**
* @test
Expand Down Expand Up @@ -516,6 +517,19 @@ public function testSetType06() {
$col->setDefault('current_timestamp');
$this->assertEquals('current_timestamp', $col->getDefault());
}
/**
* @test
*/
public function testSetType07() {
$col = new MSSQLColumn();
$col->setDatatype('datetime2');
$col->setSize(0);
$this->assertEquals(0, $col->getSize());
$col->setDatatype('datetime2');
$this->assertEquals(0, $col->getSize());
$col->setDatatype('int');
$this->assertEquals(1, $col->getSize());
}
/**
* @test
*/
Expand Down
Loading

0 comments on commit ca04c4c

Please sign in to comment.