Compare commits
2 Commits
da5d203768
...
6c6733b503
Author | SHA1 | Date | |
---|---|---|---|
6c6733b503 | |||
e641bc321d |
@ -84,7 +84,7 @@ class MsSQL implements AdapterInterface, MigrateInterface, SqlAdapterInterface {
|
||||
$pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);
|
||||
$pdo->setAttribute(\PDO::SQLSRV_ATTR_ENCODING, \PDO::SQLSRV_ENCODING_UTF8);
|
||||
}
|
||||
catch(PDOException $ex){
|
||||
catch(\PDOException $ex){
|
||||
throw $ex;
|
||||
}
|
||||
finally {
|
||||
|
@ -78,7 +78,7 @@ class MySQL implements AdapterInterface, MigrateInterface, SqlAdapterInterface {
|
||||
$pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);
|
||||
$pdo->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
|
||||
}
|
||||
catch(PDOException $ex){
|
||||
catch(\PDOException $ex){
|
||||
throw $ex;
|
||||
}
|
||||
finally {
|
||||
|
@ -19,22 +19,11 @@ class SQLite implements AdapterInterface, MigrateInterface, SqlAdapterInterface
|
||||
|
||||
const DSN_PREFIX = "sqlite";
|
||||
|
||||
public string $path;
|
||||
|
||||
public array $pragma;
|
||||
|
||||
public function __construct(
|
||||
? string $path = null,
|
||||
? array $pragma = null
|
||||
) {
|
||||
if ($path !== null) {
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
if ($pragma !== null) {
|
||||
$this->pragma = $pragma;
|
||||
}
|
||||
}
|
||||
public null|string $path = null,
|
||||
public null|array $pragmaBegin = null,
|
||||
public null|array $pragmaClose = null,
|
||||
) { }
|
||||
|
||||
public function connect() : PdoObject
|
||||
{
|
||||
@ -44,9 +33,14 @@ class SQLite implements AdapterInterface, MigrateInterface, SqlAdapterInterface
|
||||
$pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
|
||||
$pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);
|
||||
|
||||
$pdo->onClose = function(PdoObject $obj) {
|
||||
static::registerPragma($obj, $this->pragmaClose);
|
||||
};
|
||||
|
||||
$this->exportFunctions($pdo);
|
||||
$this->registerPragma($pdo, $this->pragmaBegin);
|
||||
}
|
||||
catch(PDOException $ex){
|
||||
catch(\PDOException $ex){
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
@ -63,7 +57,8 @@ class SQLite implements AdapterInterface, MigrateInterface, SqlAdapterInterface
|
||||
public function setup(array $configuration) : void
|
||||
{
|
||||
$this->path = $configuration['path'] ?? "";
|
||||
$this->pragma = $configuration['pragma'] ?? [];
|
||||
$this->pragmaBegin = $configuration['pragma_begin'] ?? [];
|
||||
$this->pragmaClose = $configuration['pragma_close'] ?? [];
|
||||
}
|
||||
|
||||
# https://sqlite.org/lang_keywords.html
|
||||
@ -187,6 +182,16 @@ class SQLite implements AdapterInterface, MigrateInterface, SqlAdapterInterface
|
||||
$pdo->sqliteCreateFunction('year', fn($date) => ( new \DateTime($date) )->format('Y'), 1);
|
||||
}
|
||||
|
||||
public static function registerPragma(PdoObject $pdo, array $pragmaList) : void
|
||||
{
|
||||
$builder = new QueryBuilder\SqliteQueryBuilder();
|
||||
|
||||
foreach($pragmaList as $pragma) {
|
||||
list($key, $value) = explode('=', $pragma);
|
||||
$pdo->query($builder->pragma($key, $value)->render());
|
||||
}
|
||||
}
|
||||
|
||||
public function generateAlterColumn(FieldDefinition $definition, array $field) : string|\Stringable
|
||||
{
|
||||
return implode(" ", [
|
||||
|
@ -15,6 +15,8 @@ class PdoObject extends PDO {
|
||||
|
||||
public mixed $lastInsertId = null;
|
||||
|
||||
public \Closure $onClose;
|
||||
|
||||
public function select(string $sql, array $parameters = []): PDOStatement
|
||||
{
|
||||
static::$dump && call_user_func_array(static::$dump, [ $sql, $parameters ]);
|
||||
@ -32,6 +34,13 @@ class PdoObject extends PDO {
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
if ($this->onClose ?? null) {
|
||||
call_user_func($this->onClose, $this);
|
||||
}
|
||||
}
|
||||
|
||||
public function runQuery(string $sql, array $parameters = []): ? static
|
||||
{
|
||||
static::$dump && call_user_func_array(static::$dump, [ $sql, $parameters ]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user