Skip to content

Commit 7097296

Browse files
authored
Merge pull request #97 from WebFiori/dev
Dev
2 parents 8f7de1b + bccb467 commit 7097296

17 files changed

+204
-72
lines changed

.github/workflows/php80.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
6363
sudo apt update
6464
sudo apt install mssql-tools18
65-
/opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P 1234567890@Eu -Q 'create database testing_db'
65+
/opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P 1234567890@Eu -Q 'create database testing_db' -C
6666
6767
- name: Install Dependencies
6868
run: composer install --prefer-source --no-interaction --no-dev

.github/workflows/php81.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ${{ matrix.os }}
1212
services:
1313
sql.data:
14-
image: mcr.microsoft.com/mssql/server:2019-CU25-ubuntu-20.04
14+
image: mcr.microsoft.com/mssql/server:2019-latest
1515
env:
1616
SA_PASSWORD: 1234567890@Eu
1717
ACCEPT_EULA: Y
@@ -56,7 +56,12 @@ jobs:
5656
done
5757
5858
- name: Setup MSSQL
59-
run: sqlcmd -S localhost -U SA -P 1234567890@Eu -Q 'create database testing_db'
59+
run: |
60+
curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
61+
curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
62+
sudo apt update
63+
sudo apt install mssql-tools18
64+
/opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P 1234567890@Eu -Q 'create database testing_db' -C
6065
6166
- name: Install Dependencies
6267
run: composer install --prefer-source --no-interaction --no-dev

.github/workflows/php82.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ${{ matrix.os }}
1212
services:
1313
sql.data:
14-
image: mcr.microsoft.com/mssql/server:2019-CU25-ubuntu-20.04
14+
image: mcr.microsoft.com/mssql/server:2019-latest
1515
env:
1616
SA_PASSWORD: 1234567890@Eu
1717
ACCEPT_EULA: Y
@@ -56,7 +56,12 @@ jobs:
5656
done
5757
5858
- name: Setup MSSQL
59-
run: sqlcmd -S localhost -U SA -P 1234567890@Eu -Q 'create database testing_db'
59+
run: |
60+
curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
61+
curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
62+
sudo apt update
63+
sudo apt install mssql-tools18
64+
/opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P 1234567890@Eu -Q 'create database testing_db' -C
6065
6166
- name: Install Dependencies
6267
run: composer install --prefer-source --no-interaction --no-dev

.github/workflows/php83.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ${{ matrix.os }}
1212
services:
1313
sql.data:
14-
image: mcr.microsoft.com/mssql/server:2019-CU25-ubuntu-20.04
14+
image: mcr.microsoft.com/mssql/server:2019-latest
1515
env:
1616
SA_PASSWORD: 1234567890@Eu
1717
ACCEPT_EULA: Y
@@ -56,7 +56,12 @@ jobs:
5656
done
5757
5858
- name: Setup MSSQL
59-
run: sqlcmd -S localhost -U SA -P 1234567890@Eu -Q 'create database testing_db'
59+
run: |
60+
curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
61+
curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
62+
sudo apt update
63+
sudo apt install mssql-tools18
64+
/opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P 1234567890@Eu -Q 'create database testing_db' -C
6065
6166
- name: Install Dependencies
6267
run: composer install --prefer-source --no-interaction --no-dev

.github/workflows/php84.yml

+7-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ${{ matrix.os }}
1212
services:
1313
sql.data:
14-
image: mcr.microsoft.com/mssql/server:2019-CU27-ubuntu-20.04
14+
image: mcr.microsoft.com/mssql/server:2019-latest
1515
env:
1616
SA_PASSWORD: 1234567890@Eu
1717
ACCEPT_EULA: Y
@@ -27,13 +27,6 @@ jobs:
2727
name: PHP${{matrix.php}} - ${{matrix.os}}
2828

2929
steps:
30-
- name: List Containers
31-
run: docker ps -a
32-
- name: List
33-
run: |
34-
ls /opt/mssql/bin
35-
ls /opt/mssql-tools/bin
36-
ls /opt/mssql-tools18/bin
3730

3831
- name: Clone Repo
3932
uses: actions/checkout@v4
@@ -64,7 +57,12 @@ jobs:
6457
done
6558
6659
- name: Setup MSSQL
67-
run: sqlcmd -S localhost -U SA -P 1234567890@Eu -Q 'create database testing_db'
60+
run: |
61+
curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
62+
curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
63+
sudo apt update
64+
sudo apt install mssql-tools18
65+
/opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P 1234567890@Eu -Q 'create database testing_db' -C
6866
6967
- name: Install Dependencies
7068
run: composer install --prefer-source --no-interaction --no-dev

phpunit.xml

+2-17
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,8 @@
66
<whitelist addUncoveredFilesFromWhitelist="true">
77
<directory suffix=".php">./webfiori/database/mysql</directory>
88
<directory suffix=".php">./webfiori/database/mssql</directory>
9-
<directory suffix=".php">./webfiori/database/AbstractQuery.php</directory>
10-
<directory suffix=".php">./webfiori/database/Column.php</directory>
11-
<directory suffix=".php">./webfiori/database/Condition.php</directory>
12-
<directory suffix=".php">./webfiori/database/Connection.php</directory>
13-
<directory suffix=".php">./webfiori/database/Database.php</directory>
14-
<directory suffix=".php">./webfiori/database/EntityMapper.php</directory>
15-
<directory suffix=".php">./webfiori/database/Expression.php</directory>
16-
<directory suffix=".php">./webfiori/database/ForeignKey.php</directory>
17-
<directory suffix=".php">./webfiori/database/JoinTable.php</directory>
18-
<directory suffix=".php">./webfiori/database/ResultSet.php</directory>
19-
<directory suffix=".php">./webfiori/database/SelectExpression.php</directory>
20-
<directory suffix=".php">./webfiori/database/Table.php</directory>
21-
<directory suffix=".php">./webfiori/database/WhereExpression.php</directory>
22-
<directory suffix=".php">./webfiori/database/RecordMapper.php</directory>
23-
<directory suffix=".php">./webfiori/database/InsertBuilder.php</directory>
24-
<directory suffix=".php">./webfiori/database/migration/AbstractMigration.php</directory>
25-
<directory suffix=".php">./webfiori/database/migration/MigrationsRunner.php</directory>
9+
<directory suffix=".php">./webfiori/database</directory>
10+
<directory suffix=".php">./webfiori/database/migration</directory>
2611
</whitelist>
2712
</filter>
2813
<logging>

tests/boot.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@
108108
} else {
109109
echo "Dropping test tables from MSSQL Server...\n";
110110
try{
111-
$mssqlConnInfo = new ConnectionInfo('mssql','sa', '1234567890@Eu', 'testing_db', SQL_SERVER_HOST);
111+
$mssqlConnInfo = new ConnectionInfo('mssql','sa', '1234567890@Eu', 'testing_db', SQL_SERVER_HOST, 1433, [
112+
'TrustServerCertificate' => 'true'
113+
]);
112114
$mssqlConn = new MSSQLConnection($mssqlConnInfo);
113115
$mssqlSchema = new MSSQLTestSchema();
114116
$mssqlSchema->setConnection($mssqlConn);

tests/webfiori/database/tests/MigrationsTest.php

+21-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPUnit\Framework\TestCase;
66
use webfiori\database\ConnectionInfo;
7+
use webfiori\database\DatabaseException;
78
use webfiori\database\migration\AbstractMigration;
89
use webfiori\database\migration\MigrationsRunner;
910

@@ -12,10 +13,27 @@ class MigrationsTest extends TestCase {
1213
* @test
1314
*/
1415
public function test00() {
15-
$connInfo = new ConnectionInfo('mysql','root', '123456', 'testing_db', '127.0.0.1');
16-
$m = new MigrationsRunner(__DIR__. DIRECTORY_SEPARATOR.'migrations', '\\webfiori\\database\\tests\\migrations', $connInfo);
16+
$this->expectException(DatabaseException::class);
17+
$this->expectExceptionMessage("Connection information not set.");
18+
$m = new MigrationsRunner(__DIR__. DIRECTORY_SEPARATOR.'migrations', '\\webfiori\\database\\tests\\migrations', null);
1719
$this->assertEquals(2, count($m->getMigrations()));
1820
$m->createMigrationsTable();
21+
}
22+
/**
23+
* @test
24+
*/
25+
public function test01() {
26+
$connInfo = new ConnectionInfo('mssql','sa', '1234567890@Eu', 'testing_db', SQL_SERVER_HOST, 1433, [
27+
'TrustServerCertificate' => 'true'
28+
]);
29+
$m = new MigrationsRunner(__DIR__. DIRECTORY_SEPARATOR.'migrations', '\\webfiori\\database\\tests\\migrations', null);
30+
$this->assertEquals(2, count($m->getMigrations()));
31+
try {
32+
$m->createMigrationsTable();
33+
} catch (DatabaseException $ex) {
34+
$m->setConnectionInfo($connInfo);
35+
}
36+
$m->createMigrationsTable();
1937
$this->assertNull($m->rollback());
2038
$applied = $m->apply();
2139
$this->assertEquals(2, count($applied));
@@ -28,5 +46,6 @@ public function test00() {
2846
$this->assertTrue($mig00 instanceof AbstractMigration);
2947
$this->assertEquals('Mig00', $mig00->getName());
3048
$this->assertEquals(0, $mig00->getOrder());
49+
$m->dropMigrationsTable();
3150
}
3251
}

tests/webfiori/database/tests/mssql/MSSQLQueryBuilderTest.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public function testTransaction02(int $userId) {
285285
});
286286
}, [$userId]);
287287
} catch (DatabaseException $ex) {
288-
$this->assertEquals("515 - The statement has been terminated due to following: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Cannot insert the value NULL into column 'age', table 'testing_db.dbo.users'; column does not allow nulls. INSERT fails.", $ex->getMessage());
288+
$this->assertEquals("515 - The statement has been terminated due to following: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Cannot insert the value NULL into column 'age', table 'testing_db.dbo.users'; column does not allow nulls. INSERT fails.", $ex->getMessage());
289289
$this->assertEquals(515, $ex->getCode());
290290
$user = $schema->table('users')->select()->where('id', $userId)->execute()->getRows()[0];
291291
$this->assertEquals([
@@ -717,7 +717,7 @@ public function testInsert05() {
717717
*/
718718
public function testInsert06() {
719719
$this->expectException(DatabaseException::class);
720-
$this->expectExceptionMessage("207 - Statement(s) could not be prepared due to the following: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid column name 'not_exist'.");
720+
$this->expectExceptionMessage("207 - Statement(s) could not be prepared due to the following: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Invalid column name 'not_exist'.");
721721
$schema = new MSSQLTestSchema();
722722
$q = $schema->table('users_tasks');
723723
$q->insert([
@@ -1164,7 +1164,9 @@ public function testSetConnection00() {
11641164
if (PHP_MAJOR_VERSION == 5) {
11651165
$this->markTestSkipped('PHP 5 has no MSSQL driver in selected setup.');
11661166
} else {
1167-
$connInfo = new ConnectionInfo('mssql','sa', '1234567890@Eu', 'testing_db', SQL_SERVER_HOST);
1167+
$connInfo = new ConnectionInfo('mssql','sa', '1234567890@Eu', 'testing_db', SQL_SERVER_HOST, 1433, [
1168+
'TrustServerCertificate' => 'true'
1169+
]);
11681170
$conn = new MSSQLConnection($connInfo);
11691171
$schema = new MSSQLTestSchema();
11701172
$schema->setConnection($conn);

tests/webfiori/database/tests/mssql/MSSQLTestSchema.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
*/
1414
class MSSQLTestSchema extends Database {
1515
public function __construct() {
16-
parent::__construct(new ConnectionInfo('mssql','sa', '1234567890@Eu', 'testing_db', SQL_SERVER_HOST));
16+
parent::__construct(new ConnectionInfo('mssql','sa', '1234567890@Eu', 'testing_db', SQL_SERVER_HOST, 1433, [
17+
'TrustServerCertificate' => 'true'
18+
]));
1719

1820
$table00 = new MSSQLTable('users');
1921
$table00->setComment('This table is used to hold users info.');

tests/webfiori/database/tests/mysql/MySQLTableTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public function testMap00() {
205205
$this->assertEquals('[t]', $mappedInstance->getName());
206206
$this->assertEquals("if not exists (select * from sysobjects where name='t' and xtype='U')\n"
207207
. "create table [t] (\n"
208-
. " [user_id_super] [int] not null,\n"
208+
. " [user_id_super] [int] identity(1,1) not null,\n"
209209
. " [email_x] [varchar](256) not null,\n"
210210
. " constraint t_pk primary key clustered([user_id_super]) on [PRIMARY],\n"
211211
. " constraint fk_ok foreign key ([user_id_super], [email_x]) references [users] ([user_id], [email]) on update cascade on delete cascade,\n"

webfiori/database/ColumnFactory.php

+17-13
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,27 @@ public static function map(string $to, Column $column) : Column {
9393
$from = 'mssql';
9494
}
9595
$optionsArr = [
96-
'type' => TypesMap::getType($from, $to, $column->getDatatype()),
97-
'default' => $column->getDefault(),
98-
'comment' => $column->getComment(),
99-
'primary' => $column->isPrimary(),
100-
'name' => $column->getName(),
101-
'size' => $column->getSize(),
102-
'scale' => $column->getScale(),
103-
'is-null' => $column->isNull(),
104-
'unique' => $column->isUnique(),
105-
'validator' => $column->getCustomCleaner(),
106-
'auto-update' => $column->isAutoUpdate()
96+
ColOption::TYPE => TypesMap::getType($from, $to, $column->getDatatype()),
97+
ColOption::DEFAULT => $column->getDefault(),
98+
ColOption::COMMENT => $column->getComment(),
99+
ColOption::PRIMARY => $column->isPrimary(),
100+
ColOption::NAME => $column->getName(),
101+
ColOption::SIZE => $column->getSize(),
102+
ColOption::SCALE => $column->getScale(),
103+
ColOption::NULL => $column->isNull(),
104+
ColOption::UNIQUE => $column->isUnique(),
105+
ColOption::VALIDATOR => $column->getCustomCleaner(),
106+
ColOption::AUTO_UPDATE => $column->isAutoUpdate()
107107
];
108108

109109
if ($column instanceof MSSQLColumn) {
110-
$optionsArr['identity'] = $column->isIdentity();
110+
$optionsArr[ColOption::IDENTITY] = $column->isIdentity();
111+
//If its an identity in mssql, then it must be auto inc in MySQL.
112+
$optionsArr[ColOption::AUTO_INCREMENT] = $column->isIdentity();
111113
} else if ($column instanceof MySQLColumn) {
112-
$optionsArr['auto-inc'] = $column->isAutoInc();
114+
$optionsArr[ColOption::AUTO_INCREMENT] = $column->isAutoInc();
115+
//If its auto inc in MySQL, it must be an identity in mssql.
116+
$optionsArr[ColOption::IDENTITY] = $column->isAutoInc();
113117
}
114118

115119
return self::create($to, $column->getName(), $optionsArr);

0 commit comments

Comments
 (0)