New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repository: fixed persistHasManyChanges() for PostgreSQL (fixes #59) #114

Merged
merged 1 commit into from Aug 31, 2017

Conversation

Projects
None yet
2 participants
@janpecha
Collaborator

janpecha commented Aug 30, 2017

Oprava pro issue #59. Nevím jestli je ta oprava skutečně funkční, aktuálně nemám k dispozici PostgreSQL, dořeším to o víkendu.

EDIT: podle http://sqlfiddle.com/#!17/a2920/4 by to fungovat mělo

$this->connection->query(
'DELETE FROM %n WHERE [ctid] IN (SELECT [ctid] FROM %n WHERE %n = ? AND %n = ? LIMIT %i)',
$relationshipTable,
$relationshipTable,

This comment has been minimized.

@castamir

castamir Aug 31, 2017

Collaborator

neni tu ten radek omylem 2x?
Pokud se meni jen sql prikaz (query), tak prosim o upraveni podminky tak, aby volani $this->connection->query($query... bylo jen jedno

@castamir

castamir Aug 31, 2017

Collaborator

neni tu ten radek omylem 2x?
Pokud se meni jen sql prikaz (query), tak prosim o upraveni podminky tak, aby volani $this->connection->query($query... bylo jen jedno

This comment has been minimized.

@janpecha

janpecha Aug 31, 2017

Collaborator

Bohužel není - jméno tabulky je nutné předat 2x - jednou pro DELETE FROM a podruhé pro subselect SELECT ... FROM, jinak by stačilo jen přepsat samotné query, ale tady se mění i parametry. Alternativně by to šlo přepsat ještě do tohoto tvaru:

$query = array();

if ($driver instanceof \Dibi\Drivers\PostgreDriver) {
	$query[] = 'DELETE FROM %n WHERE [ctid] IN (SELECT [ctid] FROM %n WHERE %n = ? AND %n = ? LIMIT %i)';
	$query[] = $relationshipTable;

} else {
	$query[] = 'DELETE FROM %n WHERE %n = ? AND %n = ? %lmt';
}

$query[] = $relationshipTable;
$query[] = $columnReferencingSourceTable;
$query[] = $entity->$idField;
$query[] = $columnReferencingTargetTable;
$query[] = $value;
$query[] = -$count;

$this->connection->query($query);

Případně parametry přesunout do pole a pro PostgreSQL udělat array_unshift($params, $relationshipTable) a vypodmínkovat query.

@janpecha

janpecha Aug 31, 2017

Collaborator

Bohužel není - jméno tabulky je nutné předat 2x - jednou pro DELETE FROM a podruhé pro subselect SELECT ... FROM, jinak by stačilo jen přepsat samotné query, ale tady se mění i parametry. Alternativně by to šlo přepsat ještě do tohoto tvaru:

$query = array();

if ($driver instanceof \Dibi\Drivers\PostgreDriver) {
	$query[] = 'DELETE FROM %n WHERE [ctid] IN (SELECT [ctid] FROM %n WHERE %n = ? AND %n = ? LIMIT %i)';
	$query[] = $relationshipTable;

} else {
	$query[] = 'DELETE FROM %n WHERE %n = ? AND %n = ? %lmt';
}

$query[] = $relationshipTable;
$query[] = $columnReferencingSourceTable;
$query[] = $entity->$idField;
$query[] = $columnReferencingTargetTable;
$query[] = $value;
$query[] = -$count;

$this->connection->query($query);

Případně parametry přesunout do pole a pro PostgreSQL udělat array_unshift($params, $relationshipTable) a vypodmínkovat query.

This comment has been minimized.

@castamir

castamir Aug 31, 2017

Collaborator

Aha, uz mi to docvaklo, promin. Pak vse v poradku.

@castamir

castamir Aug 31, 2017

Collaborator

Aha, uz mi to docvaklo, promin. Pak vse v poradku.

@castamir

This comment has been minimized.

Show comment
Hide comment
@castamir

castamir Aug 31, 2017

Collaborator

ale jinak GJ

Collaborator

castamir commented Aug 31, 2017

ale jinak GJ

@castamir castamir merged commit 33d320c into Tharos:develop Aug 31, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@janpecha janpecha deleted the inlm:pr/postgres-fix-removefromx branch Sep 1, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment