- Completed SQLite pragma's missing code

This commit is contained in:
Dave M. 2023-10-31 16:11:23 +00:00
parent 6c6733b503
commit 953fc35680
3 changed files with 17 additions and 7 deletions

View File

@ -57,8 +57,8 @@ class SQLite implements AdapterInterface, MigrateInterface, SqlAdapterInterface
public function setup(array $configuration) : void public function setup(array $configuration) : void
{ {
$this->path = $configuration['path'] ?? ""; $this->path = $configuration['path'] ?? "";
$this->pragmaBegin = $configuration['pragma_begin'] ?? []; $this->pragmaBegin = array_filter($configuration['pragma_begin'] ?? []);
$this->pragmaClose = $configuration['pragma_close'] ?? []; $this->pragmaClose = array_filter($configuration['pragma_close'] ?? []);
} }
# https://sqlite.org/lang_keywords.html # https://sqlite.org/lang_keywords.html
@ -187,8 +187,16 @@ class SQLite implements AdapterInterface, MigrateInterface, SqlAdapterInterface
$builder = new QueryBuilder\SqliteQueryBuilder(); $builder = new QueryBuilder\SqliteQueryBuilder();
foreach($pragmaList as $pragma) { foreach($pragmaList as $pragma) {
list($key, $value) = explode('=', $pragma); list($key, $value) = explode('=', $pragma) + [ null, null ];
$pdo->query($builder->pragma($key, $value)->render());
$sql = $builder->pragma($key, $value)->render();
$query = $pdo->query($sql);
if ( ! $query->execute() ) {
throw new \InvalidArgumentException(sprintf("Pragma query could not be executed : %s", $sql));
}
$builder->reset();
} }
} }

View File

@ -30,7 +30,7 @@ class Pragma extends \Ulmus\Query\Fragment {
public function render() : string public function render() : string
{ {
if ( isset($this->value) ) { if ( isset($this->value) ) {
$value = sprintf($this->callable ? " (%s)" : " = %s", $this->value); $value = sprintf($this->callable ? " (%s)" : "=%s", $this->value);
} }
return $this->renderSegments([ return $this->renderSegments([

View File

@ -144,13 +144,15 @@ class Repository
} }
} }
public function clone(object|array $entity) : bool public function clone(object|array $entity) : object|false
{ {
$entity = is_object($entity) ? clone $entity : $entity;
foreach(Ulmus::resolveEntity($this->entityClass)->getPrimaryKeyField() as $key => $field) { foreach(Ulmus::resolveEntity($this->entityClass)->getPrimaryKeyField() as $key => $field) {
unset($entity->$key); unset($entity->$key);
} }
return $this->save($entity); return $this->save($entity) ? $entity : false;
} }
public function save(object|array $entity, ? array $fieldsAndValue = null, bool $replace = false) : bool public function save(object|array $entity, ? array $fieldsAndValue = null, bool $replace = false) : bool