From 3b718f9fec21e47015e0e50c74f9f5d5c646c582 Mon Sep 17 00:00:00 2001 From: John Saunders Date: Sat, 20 Nov 2021 09:30:23 +0000 Subject: [PATCH] stop mysql errors on updates to table where a column is updated that is not part of the unique columns restrictions --- src/DB/ShardDB.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/DB/ShardDB.php b/src/DB/ShardDB.php index c0af042..70625f0 100644 --- a/src/DB/ShardDB.php +++ b/src/DB/ShardDB.php @@ -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 ); + } } } }