From 28b0090288602c651fcdc3e7bcb9a1dd852ddbdd Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 12 Jun 2024 12:03:06 -0700 Subject: [PATCH 1/2] fix types for taxa id-related prepared statements to match sqls expectation of integer types as well as make some cosmetic fixes to spacing for code readbility --- classes/RpcTaxonomy.php | 44 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/classes/RpcTaxonomy.php b/classes/RpcTaxonomy.php index 41e9c03931..5b9366afa9 100644 --- a/classes/RpcTaxonomy.php +++ b/classes/RpcTaxonomy.php @@ -110,7 +110,7 @@ public function getDynamicChildren($objId, $targetId, $displayAuthor, $limitToOc $sql = 'SELECT MIN(t.RankId) AS RankId FROM taxa t INNER JOIN taxstatus ts ON t.tid = ts.tid WHERE (t.rankid != 0) AND (ts.taxauthid = ?) LIMIT 1 '; //echo $sql.'
'; if ($statement = $this->conn->prepare($sql)) { - $statement->bind_param("s", $this->taxAuthID); + $statement->bind_param("i", $this->taxAuthID); $statement->execute(); $result = $statement->get_result(); while($row = $result->fetch_object()){ @@ -124,15 +124,15 @@ public function getDynamicChildren($objId, $targetId, $displayAuthor, $limitToOc if ($statement1 = $this->conn->prepare($sql1)) { $i = 0; - $statement1->bind_param("ss", $this->taxAuthID, $lowestRank); + $statement1->bind_param("ii", $this->taxAuthID, $lowestRank); $statement1->execute(); $result1 = $statement1->get_result(); while($row1 = $result1->fetch_object()){ - $rankName = (isset($taxonUnitArr[$row1->rankid])?$taxonUnitArr[$row1->rankid]:'Unknown'); - $label = '2-'.$row1->rankid.'-'.$rankName.'-'.$row1->sciname; + $rankName = (isset($taxonUnitArr[$row1->rankid]) ? $taxonUnitArr[$row1->rankid] : 'Unknown'); + $label = '2-' . $row1->rankid . '-' . $rankName.'-' . $row1->sciname; $sciName = $row1->sciname; - if($row1->tid == $targetId) $sciName = ''.$sciName.''; - $sciName = "".$rankName.": ".$sciName.($displayAuthor?" ".$row1->author:""); + if($row1->tid == $targetId) $sciName = '' . $sciName . ''; + $sciName = "" . $rankName . ": " . $sciName . ($displayAuthor ? " " . $row1->author : ""); $childArr[$i]['id'] = $row1->tid; $childArr[$i]['label'] = $label; $childArr[$i]['name'] = $sciName; @@ -140,7 +140,7 @@ public function getDynamicChildren($objId, $targetId, $displayAuthor, $limitToOc $sql3 = 'SELECT tid FROM taxaenumtree WHERE taxauthid = ? AND parenttid = ? LIMIT 1 '; //echo "
".$sql3."
"; if ($statement3 = $this->conn->prepare($sql3)) { - $statement3->bind_param("ss", $this->taxAuthID, $row1->tid); + $statement3->bind_param("ii", $this->taxAuthID, $row1->tid); $statement3->execute(); $result3 = $statement3->get_result(); if($row3 = $result3->fetch_object()){ @@ -150,7 +150,7 @@ public function getDynamicChildren($objId, $targetId, $displayAuthor, $limitToOc $sql4 = 'SELECT DISTINCT tid, tidaccepted FROM taxstatus WHERE (taxauthid = ?) AND (tidaccepted = ?) '; //echo "
".$sql4."
"; if ($statement4 = $this->conn->prepare($sql4)) { - $statement4->bind_param("ss", $this->taxAuthID, $row1->tid); + $statement4->bind_param("ii", $this->taxAuthID, $row1->tid); $statement4->execute(); $result4 = $statement4->get_result(); while($row4 = $result4->fetch_object()){ @@ -179,17 +179,17 @@ public function getDynamicChildren($objId, $targetId, $displayAuthor, $limitToOc $sql .= 'WHERE (ts.taxauthid = ?) AND (ts.tid = ts.tidaccepted) AND ((ts.parenttid = ?) OR (t.tid = ?)) '; //echo $sql.'
'; if ($statement = $this->conn->prepare($sql)) { - $statement->bind_param("sss", $this->taxAuthID, $objId, $objId); + $statement->bind_param("iii", $this->taxAuthID, $objId, $objId); $statement->execute(); $result = $statement->get_result(); $i = 0; while($r = $result->fetch_object()){ - $rankName = (isset($taxonUnitArr[$r->rankid])?$taxonUnitArr[$r->rankid]:'Unknown'); + $rankName = (isset($taxonUnitArr[$r->rankid]) ? $taxonUnitArr[$r->rankid] : 'Unknown'); $label = '2-'.$r->rankid.'-'.$rankName.'-'.$r->sciname; $sciName = $r->sciname; - if($r->rankid >= 180) $sciName = ''.$sciName.''; - if($r->tid == $targetId) $sciName = ''.$sciName.''; - $sciName = "".$rankName.": ".$sciName.($displayAuthor?" ".$r->author:""); + if($r->rankid >= 180) $sciName = '' . $sciName . ''; + if($r->tid == $targetId) $sciName = '' . $sciName . ''; + $sciName = "" . $rankName . ": " . $sciName . ($displayAuthor ? " " . $r->author : ""); if($r->tid == $objId){ $retArr['id'] = $r->tid; $retArr['label'] = $label; @@ -205,7 +205,7 @@ public function getDynamicChildren($objId, $targetId, $displayAuthor, $limitToOc $sql3 = 'SELECT tid FROM taxaenumtree WHERE taxauthid = ? AND parenttid = ? LIMIT 1 '; //echo 'sql3: '.$sql3.'
'; if ($statement3 = $this->conn->prepare($sql3)) { - $statement3->bind_param("ss", $this->taxAuthID, $r->tid); + $statement3->bind_param("ii", $this->taxAuthID, $r->tid); $statement3->execute(); $result3 = $statement3->get_result(); if($row3 = $result3->fetch_object()){ @@ -215,7 +215,7 @@ public function getDynamicChildren($objId, $targetId, $displayAuthor, $limitToOc $sql4 = 'SELECT DISTINCT tid, tidaccepted FROM taxstatus WHERE taxauthid = ? AND tidaccepted = ? '; //echo 'sql4: '.$sql4.'
'; if ($statement4 = $this->conn->prepare($sql4)) { - $statement4->bind_param("ss", $this->taxAuthID, $r->tid); + $statement4->bind_param("ii", $this->taxAuthID, $r->tid); $statement4->execute(); $result4 = $statement4->get_result(); while($row4 = $result4->fetch_object()){ @@ -243,16 +243,16 @@ public function getDynamicChildren($objId, $targetId, $displayAuthor, $limitToOc 'WHERE (ts.tid <> ts.tidaccepted) AND (ts.taxauthid = ?) AND (ts.tidaccepted = ?)'; //echo 'syn: '.$sqlSyns.'
'; if ($statementSyns = $this->conn->prepare($sqlSyns)) { - $statementSyns->bind_param("ss", $this->taxAuthID, $objId); + $statementSyns->bind_param("ii", $this->taxAuthID, $objId); $statementSyns->execute(); $resultSyns = $statementSyns->get_result(); while($row = $resultSyns->fetch_object()){ - $rankName = (isset($taxonUnitArr[$row->rankid])?$taxonUnitArr[$row->rankid]:'Unknown'); - $label = '1-'.$row->rankid.'-'.$rankName.'-'.$row->sciname; + $rankName = (isset($taxonUnitArr[$row->rankid]) ? $taxonUnitArr[$row->rankid] : 'Unknown'); + $label = '1-' . $row->rankid . '-' . $rankName . '-' . $row->sciname; $sciName = $row->sciname; - if($row->rankid >= 180) $sciName = ''.$sciName.''; - if($row->tid == $targetId) $sciName = ''.$sciName.''; - $sciName = '['.$sciName.']'.($displayAuthor?' '.$row->author:''); + if($row->rankid >= 180) $sciName = '' . $sciName . ''; + if($row->tid == $targetId) $sciName = '' . $sciName . ''; + $sciName = '[' . $sciName . ']' . ($displayAuthor ? ' ' . $row->author : ''); $childArr[$i]['id'] = $row->tid; $childArr[$i]['label'] = $label; $childArr[$i]['name'] = $sciName; @@ -281,4 +281,4 @@ public function isValidApiCall(){ return true; } } -?> \ No newline at end of file +?> From a4ffb2345a5ed1df3a9737868d66926b4726a0d5 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 12 Jun 2024 12:51:32 -0700 Subject: [PATCH 2/2] change result to statement for close --- classes/RpcTaxonomy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/RpcTaxonomy.php b/classes/RpcTaxonomy.php index 5b9366afa9..9dd420b677 100644 --- a/classes/RpcTaxonomy.php +++ b/classes/RpcTaxonomy.php @@ -117,7 +117,7 @@ public function getDynamicChildren($objId, $targetId, $displayAuthor, $limitToOc $lowestRank = $row->RankId; } $result->free(); - $result->close(); + $statement->close(); } $sql1 = 'SELECT DISTINCT t.tid, t.sciname, t.author, t.rankid FROM taxa t LEFT JOIN taxstatus ts ON t.tid = ts.tid WHERE ts.taxauthid = ? AND t.RankId = ? '; //echo "
".$sql1."
";