Difference between revisions of "Ferreteria/v2/class/ftSingleKeyedDBTable"

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
< Ferreteria‎ | v2‎ | class
Jump to: navigation, 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...")
(No difference)

Revision as of 20:23, 12 September 2019

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;
    }
}