Change PDO to singleton instance

- Add SQLite throwaway DB implementation
- Add integration tests for Custom class
This commit is contained in:
2024-06-07 22:14:17 -04:00
parent d9ffc36fe6
commit 1ab961e35a
10 changed files with 244 additions and 11 deletions

View File

@@ -4,6 +4,7 @@ namespace BitBadger\PDODocument;
use BitBadger\PDODocument\Mapper\Mapper;
use PDO;
use PDOException;
use PDOStatement;
/**
@@ -22,7 +23,13 @@ class Custom
public static function &runQuery(string $query, array $parameters): PDOStatement
{
$debug = defined('PDO_DOC_DEBUG_SQL');
$stmt = Configuration::dbConn()->prepare($query);
try {
$stmt = Configuration::dbConn()->prepare($query);
} catch (PDOException $ex) {
$keyword = explode(' ', $query, 2)[0];
throw new DocumentException("Error executing $keyword statement: " . Configuration::dbConn()->errorCode(),
previous: $ex);
}
foreach ($parameters as $key => $value) {
if ($debug) echo "<pre>Binding $value to $key\n</pre>";
$dataType = match (true) {
@@ -115,7 +122,7 @@ class Custom
* @return mixed|false|T The scalar value if found, false if not
* @throws DocumentException If any is encountered
*/
public static function scalar(string $query, array $parameters, Mapper $mapper, ?PDO $pdo = null): mixed
public static function scalar(string $query, array $parameters, Mapper $mapper): mixed
{
try {
$stmt = &self::runQuery($query, $parameters);