Browse Source

Fix remaining test problems

dbtest
J. King 2 years ago
parent
commit
0f2da754c5
  1. 4
      lib/Db/AbstractDriver.php
  2. 4
      lib/Db/Driver.php
  3. 2
      lib/Db/MySQL/Driver.php
  4. 2
      lib/Db/MySQL/PDODriver.php
  5. 4
      lib/Db/PostgreSQL/Driver.php
  6. 4
      lib/Db/PostgreSQL/PDODriver.php
  7. 4
      lib/Db/SQLite3/PDODriver.php
  8. 2
      tests/lib/AbstractTest.php
  9. 4
      tests/lib/DatabaseDrivers/MySQLPDO.php

4
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;
}
}

4
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;
}

2
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 */

2
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();

4
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;
}
}

4
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;
}
}

4
lib/Db/SQLite3/PDODriver.php

@ -81,4 +81,8 @@ class PDODriver extends AbstractPDODriver {
}
}
}
public function stringOutput(): bool {
return true;
}
}

2
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;

4
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) {

Loading…
Cancel
Save