Ferreteria/v2/class/ftSingleKeyedDBTable
< Ferreteria | v2 | class
Jump to navigation
Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
- file:
db/v2/tables/db-table-keyed.php
- uses: ftKeyedTable
- used by:
Functions
- public function GetRecord_forKey($id) {
- public function GetRecords_forKeyList($sqlIDs)
- 2017-03-18 created for EventPlex
- public function FigureSQL_forIDList($sqlWhere=NULL,$sqlSort=NULL,$sqlOther=NULL,$sSep=',')
Code
/*::::
HISTORY:
2019-09-12 changed name from ftSingleKeyedTable to ftSingleKeyedDBTable because it's clearly written
for tables that are in a database, rather than being usable in other contexts.
*/
trait ftSingleKeyedDBTable {
use ftKeyedTable;
// ++ SETUP ++ //
// PUBLIC because Recordset wrapper class needs to use it
abstract public function GetKeyName();
// -- SETUP -- //
// ++ RECORDS ++ //
public function GetRecord_forKey($id) {
$sqlFilt = $this->GetKeyName().'='.$this->GetConnection()->SanitizeValue($id);
$rc = $this->SelectRecords($sqlFilt);
if ($rc->RowCount() == 0) {
$rc->ClearFields(); // so HasRow() will return FALSE
} else {
$rc->NextRow(); // advance to first (only) row
}
return $rc;
}
// 2017-03-18 created for EventPlex
public function GetRecords_forKeyList($sqlIDs) {
$sqlWhere = $this->GetKeyName().' IN ('.$sqlIDs.')';
return $this->SelectRecords($sqlWhere);
}
public function FigureSQL_forIDList($sqlWhere=NULL,$sqlSort=NULL,$sqlOther=NULL,$sSep=',') {
$sql = $this->FigureSelectSQL($sqlWhere,$sqlSort,$sqlOther,'');
$sqlSource = $this->SourceString_forSelect();
$sqlOrderBy = is_null($sqlSort) ? '' : (' ORDER BY '.$sqlSort);
$sql = "SELECT GROUP_CONCAT(ID$sqlOrderBy SEPARATOR '$sSep') FROM $sqlSource";
if (!is_null($sqlWhere)) {
$sql .= ' WHERE '.$sqlWhere;
}
if (!is_null($sqlOther)) {
$sql .= ' '.$sqlOther;
}
$sql .= ' GROUP BY TRUE';
echo 'GOT TO '.__FILE__.' line '.__LINE__.' - SQL: '.$sql; die();
return $sql;
}
}