Ferreteria/v0.3/class/tMonokeyQueryableSource: Difference between revisions
< Ferreteria | v0.3 | class
Jump to navigation
Jump to search
(Created page with "{{page/code/class|ferreteria}} <source lang=php> // PURPOSE: additional things you can do with a single-keyed queryable source trait tMonokeyQueryableSource { // ++ UTILIT...") |
(updated code) |
||
Line 4: | Line 4: | ||
trait tMonokeyQueryableSource { | trait tMonokeyQueryableSource { | ||
// ++ UTILITY ++ // | // ++ UTILITY ++ // | ||
// 2017-03-18 created for EventPlex | /*---- | ||
REQUIRES: | |||
GetKeyName() : tDataDesign_singleKey | |||
GetDatabase() : tQueryableSource | |||
SelectRows() : tQueryableSource | |||
GetRowCount() : tSequentialAccess | |||
HasRows() : tSequentialAccess | |||
NextRow() : tSequentialAccess | |||
ClearFields() : cFieldRow - PROBABLY USED WRONG HERE | |||
*/ | |||
public function GetRow_forKey($id) { | |||
//$t = $this->GetSourceObject(); | |||
$t = $this; | |||
$sqlWhere = $t->GetKeyName().'='.$this->GetDatabase()->SanitizeValue($id); | |||
$this->SelectRows($sqlWhere); | |||
if ($this->GetRowCount() == 0) { // WORKING HERE | |||
// 2018-12-25 not sure this will ever happen now? | |||
echo '<b>SQL</b>: '.$this->sql; | |||
throw new \exception('SelectRows() returned no rows.'); | |||
} else { | |||
if ($this->HasRows()) { | |||
$this->NextRow(); // advance to first (only) row | |||
} else { | |||
// 2018-12-25 might need to be Rows->ClearValues() | |||
$this->ClearValues(); // so HasValues() (formerly HasRow()) will return FALSE | |||
} | |||
} | |||
return $rc; | |||
} | |||
// 2017-03-18 created for EventPlex | |||
public function GetRows_forKeyList($sqlIDs) { | public function GetRows_forKeyList($sqlIDs) { | ||
$sqlWhere = $this->GetKeyName().' IN ('.$sqlIDs.')'; | |||
return $this->SelectRows($sqlWhere); | |||
} | } | ||
Revision as of 15:26, 15 January 2019
// PURPOSE: additional things you can do with a single-keyed queryable source
trait tMonokeyQueryableSource {
// ++ UTILITY ++ //
/*----
REQUIRES:
GetKeyName() : tDataDesign_singleKey
GetDatabase() : tQueryableSource
SelectRows() : tQueryableSource
GetRowCount() : tSequentialAccess
HasRows() : tSequentialAccess
NextRow() : tSequentialAccess
ClearFields() : cFieldRow - PROBABLY USED WRONG HERE
*/
public function GetRow_forKey($id) {
//$t = $this->GetSourceObject();
$t = $this;
$sqlWhere = $t->GetKeyName().'='.$this->GetDatabase()->SanitizeValue($id);
$this->SelectRows($sqlWhere);
if ($this->GetRowCount() == 0) { // WORKING HERE
// 2018-12-25 not sure this will ever happen now?
echo '<b>SQL</b>: '.$this->sql;
throw new \exception('SelectRows() returned no rows.');
} else {
if ($this->HasRows()) {
$this->NextRow(); // advance to first (only) row
} else {
// 2018-12-25 might need to be Rows->ClearValues()
$this->ClearValues(); // so HasValues() (formerly HasRow()) will return FALSE
}
}
return $rc;
}
// 2017-03-18 created for EventPlex
public function GetRows_forKeyList($sqlIDs) {
$sqlWhere = $this->GetKeyName().' IN ('.$sqlIDs.')';
return $this->SelectRows($sqlWhere);
}
// -- UTILITY -- //
}