Skip to content

Commit 09db014

Browse files
authored
Merge pull request #173 from Planetbiru/feature/version-3.22.0
Update PicoDatabasePersistence.php
2 parents 6de4844 + 63d4ad3 commit 09db014

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/Database/PicoDatabasePersistence.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,12 +943,31 @@ private function getWhere($info, $queryBuilder)
943943
return implode(" and ", $wheres);
944944
}
945945

946+
/**
947+
* Builds a WHERE clause based on the table's primary key columns.
948+
*
949+
* This method constructs a WHERE clause for an SQL query using the primary keys
950+
* defined in the provided table information. It retrieves the values from the
951+
* current object, escapes them using the query builder, and generates conditions
952+
* for each primary key. If a value is null, the condition will use "IS NULL".
953+
*
954+
* @param PicoTableInfo $info Table information containing primary key definitions.
955+
* @param PicoDatabaseQueryBuilder $queryBuilder Query builder used to escape values safely.
956+
* @return stdClass An object containing:
957+
* - columns: associative array of column names and their values
958+
* - whereClause: the constructed WHERE clause string
959+
* @throws NoPrimaryKeyDefinedException If no primary keys are defined in the table.
960+
*/
946961
private function getWhereWithColumns($info, $queryBuilder)
947962
{
963+
$result = new stdClass;
948964
if($this->whereIsDefinedFirst && !empty($this->whereStr))
949965
{
950-
return $this->whereStr;
966+
$result->columns = array();
967+
$result->whereClause = $this->whereStr;
968+
return $result;
951969
}
970+
952971
$wheres = array();
953972
$columns = array();
954973
foreach($info->getPrimaryKeys() as $property=>$column)
@@ -971,7 +990,7 @@ private function getWhereWithColumns($info, $queryBuilder)
971990
{
972991
throw new NoPrimaryKeyDefinedException("No primary key defined");
973992
}
974-
$result = new stdClass;
993+
975994
$result->columns = $columns;
976995
$result->whereClause = implode(" and ", $wheres);
977996
return $result;

0 commit comments

Comments
 (0)