Skip to content

Commit

Permalink
Check that linktable exists in dbSearchList.
Browse files Browse the repository at this point in the history
  • Loading branch information
arnemorken committed Mar 27, 2024
1 parent 96d7832 commit 4b2cc4d
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions data/mysql/anyTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -880,38 +880,40 @@ protected function dbSearchList($linkType=null,$linkId=null)
if (isset($group_data) && $linkId == "") {
//$success = $this->dbExecListStmt(-1,$this->mType,$linkType,$linkId,$grouping,$simple,$limit) || $success; // -1 signifies this special query
$linktable = $this->findLinkTableName("group");
$linktable_id = $this->findLinkTableId("group");
$stmt = "SELECT DISTINCT ".$this->mTableName.".* ".
"FROM ".$this->mTableName." ".
"LEFT JOIN ".$linktable." ON CAST(".$linktable.".".$this->mIdKey." AS INT)=CAST(".$this->mTableName.".".$this->mIdKeyTable." AS INT) ".
"WHERE (";
$part_stmt = "";
foreach ($group_data as $gid => $group) {
if ($gid != "nogroup") {
$db_gid = is_numeric($gid) ? "CAST(".$gid." AS INT)" : "'".$gid."'";
$part_stmt .= $linktable.".".$linktable_id." != ".$db_gid." AND ";
if ($this->tableExists($linktable)) {
$linktable_id = $this->findLinkTableId("group");
$stmt = "SELECT DISTINCT ".$this->mTableName.".* ".
"FROM ".$this->mTableName." ".
"LEFT JOIN ".$linktable." ON CAST(".$linktable.".".$this->mIdKey." AS INT)=CAST(".$this->mTableName.".".$this->mIdKeyTable." AS INT) ".
"WHERE (";
$part_stmt = "";
foreach ($group_data as $gid => $group) {
if ($gid != "nogroup") {
$db_gid = is_numeric($gid) ? "CAST(".$gid." AS INT)" : "'".$gid."'";
$part_stmt .= $linktable.".".$linktable_id." != ".$db_gid." AND ";
}
}
}
$part_stmt = rtrim($part_stmt,"AND ");
if ($part_stmt != "") {
$part_stmt .= ") ";
$stmt .= $part_stmt."ORDER BY ". $this->mTableName.".".$this->mIdKeyTable." ";
//elog("dbSearchList:".$stmt);
if (!(!$stmt || $stmt == "" || !$this->query($stmt) || $this->isError())) {
// Get the data
$xdata = null;
$ok = $this->getRowData($xdata,"list",$grouping,$simple);
if ($ok) {
if (isset($xdata) && isset($xdata["nogroup"])) {
$this->mData["unknown"] = null;
$i = 0;
foreach ($xdata["nogroup"] as $key => $val) {
$this->mData["unknown"][$key] = $val;
++$i;
$part_stmt = rtrim($part_stmt,"AND ");
if ($part_stmt != "") {
$part_stmt .= ") ";
$stmt .= $part_stmt."ORDER BY ". $this->mTableName.".".$this->mIdKeyTable." ";
//elog("dbSearchList:".$stmt);
if (!(!$stmt || $stmt == "" || !$this->query($stmt) || $this->isError())) {
// Get the data
$xdata = null;
$ok = $this->getRowData($xdata,"list",$grouping,$simple);
if ($ok) {
if (isset($xdata) && isset($xdata["nogroup"])) {
$this->mData["unknown"] = null;
$i = 0;
foreach ($xdata["nogroup"] as $key => $val) {
$this->mData["unknown"][$key] = $val;
++$i;
}
$this->mData["unknown"]["grouping_num_results"] = $i;
}
$this->mData["unknown"]["grouping_num_results"] = $i;
$x=0;
}
$x=0;
}
}
}
Expand Down

0 comments on commit 4b2cc4d

Please sign in to comment.