Ferreteria/v2/class/ftSingleKeyedDBTable: Difference between revisions
< Ferreteria | v2 | class
Jump to navigation
Jump to search
(Created page with "{{page/code/class}} * '''file''': {{l/ferreteria/file|db/v2/tables/db-table-keyed.php}} * '''uses''': {{l/version|class|ftKeyedTable}} * '''used by''': ** {{l/version|class|fc...") |
m (Woozle moved page Ferreteria/v2/class/ftSingleKeyedTable to Ferreteria/v2/class/ftSingleKeyedDBTable: renaming the class) |
(No difference)
| |
Revision as of 00:24, 13 September 2019
- file: Template:L/ferreteria/file
- uses: Template:L/version
- 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
trait ftSingleKeyedTable {
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;
}
}