Skip to content

Commit

Permalink
stop mysql errors on updates to table where a column is updated that …
Browse files Browse the repository at this point in the history
…is not part of the unique columns restrictions
  • Loading branch information
JRSaunders committed Nov 20, 2021
1 parent 1d02f65 commit 3b718f9
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/DB/ShardDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,23 +508,25 @@ protected function handleDuplicateColumns( ShardDataRowInterface $dataRow, \Clos
$sqlArray[] = " {$column} = ? ";
}
}
$sql = "select " . join( ', ', $selectColumns ) .
" from {$dataRow->getUuid()->getTable()->getName()} where";
$sql = $sql . " ( " . join( 'or', $sqlArray ) . " ) and uuid != ? limit 1;";
$binds[] = $uuid->toString();
$nodesResults = $this->allNodesQuery( $uuid->getTable()->getName(), $sql, $binds );
if ( $nodesResults && $nodesResults->isSuccessful() ) {
$columnsIssue = [];
foreach ( $nodesResults->fetchDataRows() as $row ) {
foreach ( $selectColumns as $column ) {
if ( $dataRow->$column == $row->$column ) {
$columnsIssue[ $column ] = $dataRow->$column;
if ( $selectColumns ) {
$sql = "select " . join( ', ', $selectColumns ) .
" from {$dataRow->getUuid()->getTable()->getName()} where";
$sql = $sql . " ( " . join( 'or', $sqlArray ) . " ) and uuid != ? limit 1;";
$binds[] = $uuid->toString();
$nodesResults = $this->allNodesQuery( $uuid->getTable()->getName(), $sql, $binds );
if ( $nodesResults && $nodesResults->isSuccessful() ) {
$columnsIssue = [];
foreach ( $nodesResults->fetchDataRows() as $row ) {
foreach ( $selectColumns as $column ) {
if ( $dataRow->$column == $row->$column ) {
$columnsIssue[ $column ] = $dataRow->$column;
}
}
}
}

$handleDuplicateColumns( $dataRow, $columnsIssue );
$handleDuplicateColumns( $dataRow, $columnsIssue );

}
}
}
}
Expand Down

0 comments on commit 3b718f9

Please sign in to comment.