- Merge with Mssql repository bugfix
This commit is contained in:
1 parent
724ab250ab
commit
e1990e7cc0
11 files changed
+95
-87
No files matched your search
+22
-16
@@ -68,7 +68,7 @@ class Repository
|
||||
|
||||
public function count() : int
|
||||
{
|
||||
$this->removeQueryFragment(Query\Select::class);
|
||||
$this->removeQueryFragment([ Query\Select::class, Query\OrderBy::class, ]);
|
||||
|
||||
if ( $this->queryBuilder->getFragment(Query\GroupBy::class) ) {
|
||||
$this->select( "DISTINCT COUNT(*) OVER ()" );
|
||||
@@ -149,16 +149,20 @@ class Repository
|
||||
|
||||
$statement = $this->insertSqlQuery($fieldsAndValue ?? $dataset, $replace)->runInsertQuery();
|
||||
|
||||
if ( ( 0 !== $statement->lastInsertId ) &&
|
||||
( null !== $primaryKeyDefinition )) {
|
||||
|
||||
if ( null !== $primaryKeyDefinition ) {
|
||||
$pkField = key($primaryKeyDefinition);
|
||||
$dataset[$pkField] = $statement->lastInsertId;
|
||||
|
||||
if ($statement->lastInsertId ) {
|
||||
$dataset[$pkField] = $statement->lastInsertId;
|
||||
}
|
||||
elseif ($replace) {
|
||||
$pkValue = $dataset[$pkField];
|
||||
}
|
||||
}
|
||||
|
||||
$entity->entityFillFromDataset($dataset, true);
|
||||
|
||||
return (bool) $statement->lastInsertId;
|
||||
return (bool) ($pkValue ?? $statement->lastInsertId);
|
||||
}
|
||||
else {
|
||||
if ( $primaryKeyDefinition === null ) {
|
||||
@@ -270,7 +274,7 @@ class Repository
|
||||
{
|
||||
$schema = $schema ?: $this->entityResolver->schemaName();
|
||||
|
||||
$this->queryBuilder->truncate($this->escapeTable($table ?: $this->entityResolver->tableName()), $alias ?: $this->alias, $this->escapedDatabase(), $schema ? $this->escapeSchema($schema) : null);
|
||||
$this->queryBuilder->truncate($this->escapeTable($table ?: $this->entityResolver->tableName()), $this->escapeIdentifier($alias ?: $this->alias), $this->escapedDatabase(), $schema ? $this->escapeSchema($schema) : null);
|
||||
|
||||
$this->finalizeQuery();
|
||||
|
||||
@@ -336,7 +340,7 @@ class Repository
|
||||
|
||||
foreach ($entity::resolveEntity()->fieldList(Common\EntityResolver::KEY_COLUMN_NAME, true) as $key => $field) {
|
||||
if (null === $entity::resolveEntity()->searchFieldAnnotation($field['name'], new RelationIgnore)) {
|
||||
$this->select("$alias.$key as {$prependField}{$field['name']}");
|
||||
$this->select(sprintf("%s.$key as {$prependField}{$field['name']}", $this->escapeIdentifier($alias)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,7 +354,7 @@ class Repository
|
||||
foreach ($entity::resolveEntity()->fieldList(Common\EntityResolver::KEY_COLUMN_NAME, true) as $key => $field) {
|
||||
if (null === $entity::resolveEntity()->searchFieldAnnotation($field['name'], new RelationIgnore)) {
|
||||
$fieldlist[] = $key;
|
||||
$fieldlist[] = $entity::field($field['name'], $alias);
|
||||
$fieldlist[] = $entity::field($field['name'], $this->escapeIdentifier($alias));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,7 +384,7 @@ class Repository
|
||||
|
||||
public function insert(array $fieldlist, string $table, string $alias, ? string $schema, bool $replace = false) : self
|
||||
{
|
||||
$this->queryBuilder->insert($fieldlist, $this->escapeTable($table), $alias, $this->escapedDatabase(), $schema, $replace);
|
||||
$this->queryBuilder->insert($fieldlist, $this->escapeTable($table), $this->escapeIdentifier($alias), $this->escapedDatabase(), $schema, $replace);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -394,7 +398,7 @@ class Repository
|
||||
|
||||
public function update(string $table, string $alias, ? string $schema) : self
|
||||
{
|
||||
$this->queryBuilder->update($this->escapeTable($table), $alias, $this->escapedDatabase(), $schema);
|
||||
$this->queryBuilder->update($this->escapeTable($table), $this->escapeIdentifier($alias), $this->escapedDatabase(), $schema);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -418,13 +422,13 @@ class Repository
|
||||
|
||||
public function from(string $table, ? string $alias, ? string $schema) : self
|
||||
{
|
||||
$this->queryBuilder->from($this->escapeTable($table), $alias, $this->escapedDatabase(), $schema ? $this->escapeSchema($schema) : null);
|
||||
$this->queryBuilder->from($this->escapeTable($table), $this->escapeIdentifier($alias), $this->escapedDatabase(), $schema ? $this->escapeSchema($schema) : null);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function join(string $type, $table, $field, $value, ? string $alias = null, ? callable $callback = null) : self
|
||||
{
|
||||
$join = $this->queryBuilder->withJoin($type, $this->escapeTable($table), $field, $value, false, $alias);
|
||||
$join = $this->queryBuilder->withJoin($type, $this->escapeTable($table), $field, $value, false, $this->escapeIdentifier($alias));
|
||||
|
||||
if ( $callback ) {
|
||||
$callback($join);
|
||||
@@ -435,7 +439,7 @@ class Repository
|
||||
|
||||
public function outerJoin(string $type, $table, $field, $value, ? string $alias = null, ? callable $callback = null) : self
|
||||
{
|
||||
$join = $this->queryBuilder->withJoin($type, $this->escapeTable($table), $field, $value, true, $alias);
|
||||
$join = $this->queryBuilder->withJoin($type, $this->escapeTable($table), $field, $value, true, $this->escapeIdentifier($alias));
|
||||
|
||||
if ( $callback ) {
|
||||
$callback($join);
|
||||
@@ -563,7 +567,9 @@ class Repository
|
||||
|
||||
foreach($entity::resolveEntity()->fieldList(Common\EntityResolver::KEY_COLUMN_NAME, true) as $key => $field) {
|
||||
if ( null === $entity::resolveEntity()->searchFieldAnnotation($field['name'], new RelationIgnore) ) {
|
||||
$this->select("$alias.$key as {$alias}\${$field['name']}");
|
||||
$escAlias = $this->escapeIdentifier($alias);
|
||||
|
||||
$this->select("$escAlias.$key as $alias\${$field['name']}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -626,7 +632,7 @@ class Repository
|
||||
}
|
||||
|
||||
if ( null === $this->queryBuilder->getFragment(Query\Select::class) ) {
|
||||
$this->select("{$this->alias}.*");
|
||||
$this->select($this->escapeIdentifier($this->alias) . ".*");
|
||||
}
|
||||
|
||||
# Apply FILTER annotation to this too !
|
||||
|
||||
Reference in new issue
Block a user