Skip to content

Commit 2e97b02

Browse files
committed
Add polyfill for PDO driver specific sub class constants
1 parent 41ace00 commit 2e97b02

File tree

7 files changed

+265
-0
lines changed

7 files changed

+265
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
namespace Pdo;
12+
13+
use PDO;
14+
15+
if (\PHP_VERSION_ID < 80400) {
16+
class Dblib
17+
{
18+
public const ATTR_CONNECTION_TIMEOUT = PDO::DBLIB_ATTR_CONNECTION_TIMEOUT;
19+
public const ATTR_QUERY_TIMEOUT = PDO::DBLIB_ATTR_QUERY_TIMEOUT;
20+
public const ATTR_STRINGIFY_UNIQUEIDENTIFIER = PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER;
21+
public const ATTR_VERSION = PDO::DBLIB_ATTR_VERSION;
22+
public const ATTR_TDS_VERSION = PDO::DBLIB_ATTR_TDS_VERSION;
23+
public const ATTR_SKIP_EMPTY_ROWSETS = PDO::DBLIB_ATTR_SKIP_EMPTY_ROWSETS;
24+
public const ATTR_DATETIME_CONVERT = PDO::DBLIB_ATTR_DATETIME_CONVERT;
25+
}
26+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
namespace Pdo;
12+
13+
use PDO;
14+
15+
if (\PHP_VERSION_ID < 80400) {
16+
class Firebird
17+
{
18+
public const ATTR_DATE_FORMAT = PDO::FB_ATTR_DATE_FORMAT;
19+
public const ATTR_TIME_FORMAT = PDO::FB_ATTR_TIME_FORMAT;
20+
public const ATTR_TIMESTAMP_FORMAT = PDO::FB_ATTR_TIMESTAMP_FORMAT;
21+
}
22+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
namespace Pdo;
12+
13+
use PDO;
14+
15+
if (\PHP_VERSION_ID < 80400) {
16+
class Mysql
17+
{
18+
public const ATTR_COMPRESS = PDO::MYSQL_ATTR_COMPRESS;
19+
public const ATTR_DIRECT_QUERY = PDO::MYSQL_ATTR_DIRECT_QUERY;
20+
public const ATTR_FOUND_ROWS = PDO::MYSQL_ATTR_FOUND_ROWS;
21+
public const ATTR_IGNORE_SPACE = PDO::MYSQL_ATTR_IGNORE_SPACE;
22+
public const ATTR_INIT_COMMAND = PDO::MYSQL_ATTR_INIT_COMMAND;
23+
public const ATTR_LOCAL_INFILE = PDO::MYSQL_ATTR_LOCAL_INFILE;
24+
public const ATTR_LOCAL_INFILE_DIRECTORY = PDO::MYSQL_ATTR_LOCAL_INFILE_DIRECTORY;
25+
public const ATTR_MAX_BUFFER_SIZE = PDO::MYSQL_ATTR_MAX_BUFFER_SIZE;
26+
public const ATTR_MULTI_STATEMENTS = PDO::MYSQL_ATTR_MULTI_STATEMENTS;
27+
public const ATTR_READ_DEFAULT_FILE = PDO::MYSQL_ATTR_READ_DEFAULT_FILE;
28+
public const ATTR_READ_DEFAULT_GROUP = PDO::MYSQL_ATTR_READ_DEFAULT_GROUP;
29+
public const ATTR_SERVER_PUBLIC_KEY = PDO::MYSQL_ATTR_SERVER_PUBLIC_KEY;
30+
public const ATTR_SSL_CA = PDO::MYSQL_ATTR_SSL_CA;
31+
public const ATTR_SSL_CAPATH = PDO::MYSQL_ATTR_SSL_CAPATH;
32+
public const ATTR_SSL_CERT = PDO::MYSQL_ATTR_SSL_CERT;
33+
public const ATTR_SSL_CIPHER = PDO::MYSQL_ATTR_SSL_CIPHER;
34+
public const ATTR_SSL_KEY = PDO::MYSQL_ATTR_SSL_KEY;
35+
public const ATTR_SSL_VERIFY_SERVER_CERT = PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT;
36+
public const ATTR_USE_BUFFERED_QUERY = PDO::MYSQL_ATTR_USE_BUFFERED_QUERY;
37+
}
38+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
namespace Pdo;
12+
13+
use PDO;
14+
15+
if (\PHP_VERSION_ID < 80400) {
16+
class Odbc
17+
{
18+
public const ATTR_USE_CURSOR_LIBRARY = PDO::ODBC_ATTR_USE_CURSOR_LIBRARY;
19+
public const ATTR_ASSUME_UTF8 = PDO::ODBC_ATTR_ASSUME_UTF8;
20+
public const SQL_USE_IF_NEEDED = PDO::ODBC_SQL_USE_IF_NEEDED;
21+
public const SQL_USE_DRIVER = PDO::ODBC_SQL_USE_DRIVER;
22+
public const SQL_USE_ODBC = PDO::ODBC_SQL_USE_ODBC;
23+
}
24+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
namespace Pdo;
12+
13+
use PDO;
14+
15+
if (\PHP_VERSION_ID < 80400) {
16+
class Pgsql
17+
{
18+
public const ATTR_DISABLE_PREPARES = PDO::PGSQL_ATTR_DISABLE_PREPARES;
19+
}
20+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
namespace Pdo;
12+
13+
use PDO;
14+
15+
if (\PHP_VERSION_ID < 80400) {
16+
class Sqlite
17+
{
18+
public const ATTR_EXTENDED_RESULT_CODES = PDO::SQLITE_ATTR_EXTENDED_RESULT_CODES;
19+
public const ATTR_OPEN_FLAGS = PDO::SQLITE_ATTR_OPEN_FLAGS;
20+
public const ATTR_READONLY_STATEMENT = PDO::SQLITE_ATTR_READONLY_STATEMENT;
21+
public const DETERMINISTIC = PDO::SQLITE_DETERMINISTIC;
22+
public const OPEN_READONLY = PDO::SQLITE_OPEN_READONLY;
23+
public const OPEN_READWRITE = PDO::SQLITE_OPEN_READWRITE;
24+
public const OPEN_CREATE = PDO::SQLITE_OPEN_CREATE;
25+
}
26+
}

tests/Php84/PdoTest.php

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Polyfill\Tests\Php84;
13+
14+
use PHPUnit\Framework\TestCase;
15+
16+
class PdoTest extends TestCase
17+
{
18+
/**
19+
* @requires extension pdo_dblib
20+
*/
21+
public function testDblibConstants()
22+
{
23+
$this->assertSame(1000, \Pdo\Dblib::ATTR_CONNECTION_TIMEOUT);
24+
$this->assertSame(1001, \Pdo\Dblib::ATTR_QUERY_TIMEOUT);
25+
$this->assertSame(1002, \Pdo\Dblib::ATTR_STRINGIFY_UNIQUEIDENTIFIER);
26+
$this->assertSame(1003, \Pdo\Dblib::ATTR_VERSION);
27+
$this->assertSame(1004, \Pdo\Dblib::ATTR_TDS_VERSION);
28+
$this->assertSame(1005, \Pdo\Dblib::ATTR_SKIP_EMPTY_ROWSETS);
29+
$this->assertSame(1006, \Pdo\Dblib::ATTR_DATETIME_CONVERT);
30+
}
31+
32+
/**
33+
* @requires extension pdo_firebird
34+
*/
35+
public function testFirebirdConstants()
36+
{
37+
$this->assertSame(1000, \Pdo\Firebird::ATTR_DATE_FORMAT);
38+
$this->assertSame(1001, \Pdo\Firebird::ATTR_TIME_FORMAT);
39+
$this->assertSame(1002, \Pdo\Firebird::ATTR_TIMESTAMP_FORMAT);
40+
}
41+
42+
/**
43+
* @requires extension pdo_mysql
44+
*/
45+
public function testMysqlConstants()
46+
{
47+
$this->assertSame(1000, \Pdo\Mysql::ATTR_USE_BUFFERED_QUERY);
48+
$this->assertSame(1001, \Pdo\Mysql::ATTR_LOCAL_INFILE);
49+
$this->assertSame(1002, \Pdo\Mysql::ATTR_INIT_COMMAND);
50+
$this->assertSame(1003, \Pdo\Mysql::ATTR_COMPRESS);
51+
$this->assertSame(1004, \Pdo\Mysql::ATTR_DIRECT_QUERY);
52+
$this->assertSame(1005, \Pdo\Mysql::ATTR_FOUND_ROWS);
53+
$this->assertSame(1006, \Pdo\Mysql::ATTR_IGNORE_SPACE);
54+
$this->assertSame(1007, \Pdo\Mysql::ATTR_SSL_KEY);
55+
$this->assertSame(1008, \Pdo\Mysql::ATTR_SSL_CERT);
56+
$this->assertSame(1009, \Pdo\Mysql::ATTR_SSL_CA);
57+
$this->assertSame(1010, \Pdo\Mysql::ATTR_SSL_CAPATH);
58+
$this->assertSame(1011, \Pdo\Mysql::ATTR_SSL_CIPHER);
59+
$this->assertSame(1012, \Pdo\Mysql::ATTR_SERVER_PUBLIC_KEY);
60+
$this->assertSame(1013, \Pdo\Mysql::ATTR_MULTI_STATEMENTS);
61+
$this->assertSame(1014, \Pdo\Mysql::ATTR_SSL_VERIFY_SERVER_CERT);
62+
$this->assertSame(1015, \Pdo\Mysql::ATTR_LOCAL_INFILE_DIRECTORY);
63+
}
64+
65+
/**
66+
* @requires extension pdo_mysql
67+
* @requires extension libmysqlclient
68+
*/
69+
public function testMysqlConstantsMysqlnd()
70+
{
71+
$this->assertSame(1003, \Pdo\Mysql::ATTR_READ_DEFAULT_FILE);
72+
$this->assertSame(1004, \Pdo\Mysql::ATTR_READ_DEFAULT_GROUP);
73+
$this->assertSame(1005, \Pdo\Mysql::ATTR_MAX_BUFFER_SIZE);
74+
}
75+
76+
/**
77+
* @requires extension pdo_odbc
78+
*/
79+
public function testOdbcConstants()
80+
{
81+
$this->assertSame(0, \Pdo\Odbc::SQL_USE_IF_NEEDED);
82+
$this->assertSame(1, \Pdo\Odbc::SQL_USE_ODBC);
83+
$this->assertSame(2, \Pdo\Odbc::SQL_USE_DRIVER);
84+
$this->assertSame(1000, \Pdo\Odbc::ATTR_USE_CURSOR_LIBRARY);
85+
$this->assertSame(1001, \Pdo\Odbc::ATTR_ASSUME_UTF8);
86+
}
87+
88+
/**
89+
* @requires extension pdo_pgsql
90+
*/
91+
public function testPgsqlConstants()
92+
{
93+
$this->assertSame(1000, \Pdo\Pgsql::ATTR_DISABLE_PREPARES);
94+
}
95+
96+
/**
97+
* @requires extension pdo_sqlite
98+
*/
99+
public function testSqliteConstants()
100+
{
101+
$this->assertSame(1, \Pdo\Sqlite::OPEN_READONLY);
102+
$this->assertSame(2, \Pdo\Sqlite::OPEN_READWRITE);
103+
$this->assertSame(4, \Pdo\Sqlite::OPEN_CREATE);
104+
$this->assertSame(1000, \Pdo\Sqlite::ATTR_OPEN_FLAGS);
105+
$this->assertSame(1001, \Pdo\Sqlite::ATTR_READONLY_STATEMENT);
106+
$this->assertSame(1002, \Pdo\Sqlite::ATTR_EXTENDED_RESULT_CODES);
107+
$this->assertSame(2048, \Pdo\Sqlite::DETERMINISTIC);
108+
}
109+
}

0 commit comments

Comments
 (0)