You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This public function checks to see if all the stems of a tree have the same species code
Local
All stems of a tree should have the same species code.
$tempTableName = 'TempOldTrees';
$tempTableName = 'TempNewPlants';
publicfunctionscreenDuplSpec ($fileName)
{
//This public function checks to see if all the stems of a tree have the same species code//$q1 = "SELECT Tag,count(Tag) AS cnt FROM (SELECT DISTINCT Tag, Mnemonic, Errors FROM ".$fileName." GROUP BY Tag,Mnemonic,Errors UNION SELECT DISTINCT Tag, Mnemonic, Errors FROM ".$fileName."Error GROUP BY Tag,Mnemonic,Errors) AS t2 WHERE Errors<>'NONE' GROUP BY Tag HAVING cnt>1";$q1 = "SELECT Tag,count(Tag) AS cnt FROM (SELECT DISTINCT Tag, Mnemonic FROM ".$fileName." WHERE Errors<>'NONE' UNION SELECT DISTINCT Tag, Mnemonic FROM ".$fileName."Error WHERE Errors<>'NONE') AS t2 GROUP BY Tag HAVING cnt>1";
$runQ1 = $this->screeningdb->query($q1);
if ($runQ1->num_rows() > 0)
{
foreach($runQ1->result() as$row)
{
$q2 = 'UPDATE '.$fileName.' SET Errors = CONCAT(TRIM(Errors),";>1 Species") WHERE Tag = "'.$row->Tag.'" AND Errors <> "" AND Errors IS NOT NULL';
$q3 = 'UPDATE '.$fileName.' SET Errors = ">1 Species" WHERE Tag ="'.$row->Tag.'" AND (Errors = "" OR ISNULL(Errors))';
$runQ2 = $this->screeningdb->query($q2);
$runQ3 = $this->screeningdb->query($q3);
}
}
}
Here is an updated procedure to run this and mark its errors in the CMVErrors table! Function's been reviewed with GPT so it should work as intended, but full testing is still pending:
create
definer = azureroot@`%`procedure ValidateFindStemsInTreeWithDifferentSpecies()
BEGININSERTINTOforestgeo_bci.cmverrors (CoreMeasurementID, ValidationErrorID)
SELECTcm.CoreMeasurementID,
7AS ValidationErrorID
FROMforestgeo_bci.stems s
JOINforestgeo_bci.trees t ONs.TreeID=t.TreeIDJOINforestgeo_bci.species sp ONt.SpeciesID=sp.SpeciesIDJOINforestgeo_bci.coremeasurements cm ONs.StemID=cm.StemIDGROUP BYt.TreeID, cm.CoreMeasurementIDHAVINGCOUNT(DISTINCTsp.SpeciesCode) >1;
END;
See "instructions for writing a validation function". Below are notes from the spec, the original validation function (in the PHP language), and the SQL table structure.
The text was updated successfully, but these errors were encountered: