diff --git a/src/Common/PdoObject.php b/src/Common/PdoObject.php index a626e6a..3a2cf66 100644 --- a/src/Common/PdoObject.php +++ b/src/Common/PdoObject.php @@ -82,27 +82,7 @@ class PdoObject extends PDO { $this->beginTransaction(); } - foreach($parameters as $key => $value) { - switch(strtolower(gettype($value))) { - case "boolean": - $type = Pdo::PARAM_BOOL; - break; - - case "integer": - $type = Pdo::PARAM_INT; - break; - - case "null": - $type = Pdo::PARAM_NULL; - break; - - case "string": - default: - $type = Pdo::PARAM_STR; - } - - $statement->bindValue($key, (string) $value, $type); - } + $this->bindVariables($statement, $parameters); $this->executionStatus = $statement->execute(); @@ -131,4 +111,36 @@ class PdoObject extends PDO { return null; } + + protected function bindVariables(PDOStatement $statement, array &$parameters) : void + { + if ($parameters) { + if (array_is_list($parameters)) { + $parameters = array_combine(range(1, count($parameters)), array_values($parameters)); + } + else { + foreach ($parameters as $key => $value) { + switch (strtolower(gettype($value))) { + #$type = Pdo::PARAM_BOOL; + #break; + + case "boolean": + case "integer": + $type = Pdo::PARAM_INT; + break; + + case "null": + $type = Pdo::PARAM_NULL; + break; + + case "string": + default: + $type = Pdo::PARAM_STR; + } + + $statement->bindValue($key, $value, $type); + } + } + } + } } diff --git a/src/Query/Values.php b/src/Query/Values.php index 2ffc826..be33dea 100644 --- a/src/Query/Values.php +++ b/src/Query/Values.php @@ -27,7 +27,7 @@ class Values extends Fragment { # index starts at '1' for Pdo params $this->rows[] = array_combine(range(1, count($row)), array_values($row)); - + return $this; } diff --git a/src/Query/Where.php b/src/Query/Where.php index fd37cc6..007df5b 100644 --- a/src/Query/Where.php +++ b/src/Query/Where.php @@ -128,7 +128,7 @@ class Where extends Fragment { } } else { - $stack[] = $this->filterValue(false); + $stack[] = $this->filterValue(Sql::raw("(SELECT NULL WHERE FALSE)")); } return "(" . implode(", ", $stack) . ")"; diff --git a/src/Repository.php b/src/Repository.php index 56d11a7..24f859e 100644 --- a/src/Repository.php +++ b/src/Repository.php @@ -242,7 +242,7 @@ class Repository $primaryKeyDefinition = Ulmus::resolveEntity($this->entityClass)->getPrimaryKeyField(); - if ( $replace || ! $entity->isLoaded() ) { + if ( ! $entity->isLoaded() ) { # $dataset = array_filter($dataset, fn($item, $field) => ! ($this->entityResolver->searchFieldAnnotation($field, new Field, false)->readonly ?? false), \ARRAY_FILTER_USE_BOTH); $statement = $this->insertSqlQuery($fieldsAndValue ?? $dataset, $replace)->runInsertQuery(); @@ -277,6 +277,8 @@ class Repository return $update ? (bool) $update->rowCount : false; } } + + return 0; } public function replace(object|array $entity, ? array $fieldsAndValue = null) : bool