diff --git a/lib/Db/AbstractDriver.php b/lib/Db/AbstractDriver.php index 2a6a973e..66e65f27 100644 --- a/lib/Db/AbstractDriver.php +++ b/lib/Db/AbstractDriver.php @@ -204,4 +204,8 @@ abstract class AbstractDriver implements Driver { public function prepare(string $query, ...$paramType): Statement { return $this->prepareArray($query, $paramType); } + + public function stringOutput(): bool { + return false; + } } diff --git a/lib/Db/Driver.php b/lib/Db/Driver.php index 09f16e78..6f1e311f 100644 --- a/lib/Db/Driver.php +++ b/lib/Db/Driver.php @@ -72,6 +72,7 @@ interface Driver { * The tokens the implementation must understand are: * * - "greatest": the GREATEST function implemented by PostgreSQL and MySQL + * - "least": the LEAST function implemented by PostgreSQL and MySQL * - "nocase": the name of a general-purpose case-insensitive collation sequence * - "like": the case-insensitive LIKE operator * - "integer": the integer type to use for explicit casts @@ -91,4 +92,7 @@ interface Driver { * This should be restricted to quick maintenance; in SQLite terms it might include ANALYZE, but not VACUUM */ public function maintenance(): bool; + + /** Reports whether the implementation will coerce integer and float values to text (string) */ + public function stringOutput(): bool; } diff --git a/lib/Db/MySQL/Driver.php b/lib/Db/MySQL/Driver.php index 10bc766d..fa7a9752 100644 --- a/lib/Db/MySQL/Driver.php +++ b/lib/Db/MySQL/Driver.php @@ -12,7 +12,7 @@ use JKingWeb\Arsse\Db\Exception; class Driver extends \JKingWeb\Arsse\Db\AbstractDriver { use ExceptionBuilder; - protected const SQL_MODE = "ANSI_QUOTES,HIGH_NOT_PRECEDENCE,NO_BACKSLASH_ESCAPES,NO_ENGINE_SUBSTITUTION,PIPES_AS_CONCAT,STRICT_ALL_TABLES"; + protected const SQL_MODE = "ANSI_QUOTES,HIGH_NOT_PRECEDENCE,NO_BACKSLASH_ESCAPES,NO_ENGINE_SUBSTITUTION,PIPES_AS_CONCAT,STRICT_ALL_TABLES,NO_UNSIGNED_SUBTRACTION"; protected const TRANSACTIONAL_LOCKS = false; /** @var \mysqli */ diff --git a/lib/Db/MySQL/PDODriver.php b/lib/Db/MySQL/PDODriver.php index 18cda0be..590b73c4 100644 --- a/lib/Db/MySQL/PDODriver.php +++ b/lib/Db/MySQL/PDODriver.php @@ -29,7 +29,7 @@ class PDODriver extends Driver { try { $this->db = new \PDO($dsn, $user, $password, [ \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, - \PDO::ATTR_STRINGIFY_FETCHES => true, + \PDO::ATTR_STRINGIFY_FETCHES => false, ]); } catch (\PDOException $e) { $msg = $e->getMessage(); diff --git a/lib/Db/PostgreSQL/Driver.php b/lib/Db/PostgreSQL/Driver.php index f78855cf..e290967a 100644 --- a/lib/Db/PostgreSQL/Driver.php +++ b/lib/Db/PostgreSQL/Driver.php @@ -232,4 +232,8 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver { $this->exec("ANALYZE"); return true; } + + public function stringOutput(): bool { + return true; + } } diff --git a/lib/Db/PostgreSQL/PDODriver.php b/lib/Db/PostgreSQL/PDODriver.php index 93daf667..71d18eb9 100644 --- a/lib/Db/PostgreSQL/PDODriver.php +++ b/lib/Db/PostgreSQL/PDODriver.php @@ -60,4 +60,8 @@ class PDODriver extends Driver { public function prepareArray(string $query, array $paramTypes): \JKingWeb\Arsse\Db\Statement { return new PDOStatement($this->db, $query, $paramTypes); } + + public function stringOutput(): bool { + return false; + } } diff --git a/lib/Db/SQLite3/PDODriver.php b/lib/Db/SQLite3/PDODriver.php index 86ab1cdc..87ecfc30 100644 --- a/lib/Db/SQLite3/PDODriver.php +++ b/lib/Db/SQLite3/PDODriver.php @@ -81,4 +81,8 @@ class PDODriver extends AbstractPDODriver { } } } + + public function stringOutput(): bool { + return true; + } } diff --git a/tests/lib/AbstractTest.php b/tests/lib/AbstractTest.php index a22913df..f498a543 100644 --- a/tests/lib/AbstractTest.php +++ b/tests/lib/AbstractTest.php @@ -422,7 +422,7 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase { // serialize to CSV, null being represented by no value if ($v === null) { $row[] = ""; - } elseif (static::$stringOutput || is_string($v)) { + } elseif ($drv->stringOutput() || is_string($v)) { $row[] = '"'.str_replace('"', '""', (string) $v).'"'; } else { $row[] = (string) $v; diff --git a/tests/lib/DatabaseDrivers/MySQLPDO.php b/tests/lib/DatabaseDrivers/MySQLPDO.php index 46248684..ba01dd4e 100644 --- a/tests/lib/DatabaseDrivers/MySQLPDO.php +++ b/tests/lib/DatabaseDrivers/MySQLPDO.php @@ -16,7 +16,7 @@ trait MySQLPDO { protected static $dbResultClass = \JKingWeb\Arsse\Db\PDOResult::class; protected static $dbStatementClass = \JKingWeb\Arsse\Db\MySQL\PDOStatement::class; protected static $dbDriverClass = \JKingWeb\Arsse\Db\MySQL\PDODriver::class; - protected static $stringOutput = true; + protected static $stringOutput = false; public static function dbInterface() { try { @@ -33,7 +33,7 @@ trait MySQLPDO { $dsn = "mysql:".implode(";", $dsn); $d = new \PDO($dsn, Arsse::$conf->dbMySQLUser, Arsse::$conf->dbMySQLPass, [ \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, - \PDO::ATTR_STRINGIFY_FETCHES => true, + \PDO::ATTR_STRINGIFY_FETCHES => false, \PDO::MYSQL_ATTR_MULTI_STATEMENTS => false, ]); foreach (\JKingWeb\Arsse\Db\MySQL\PDODriver::makeSetupQueries() as $q) {