Ferreteria/v0.3/class/tDatabaseStorage

From Woozle Writes Code
< Ferreteria‎ | v0.3‎ | class
Revision as of 14:24, 19 January 2019 by htyp>Woozle (Woozle moved page Ferreteria/class/tDatabaseStorage to Ferreteria/v3/class/tDatabaseStorage without leaving a redirect: this is all v3 documentation, and we still need v2)
Jump to navigation Jump to search

Template:Page/code/class

/*tttt
  CEMENTS tSequentialAccess
  USE WITH: tQueryableSource type
*/
trait tDatabaseStorage {
    use tSequentialAccess;
    
    // ++ DATA CONTROL ++ //

    // CEMENTS: tSequentialAccess
    public function RewindRows() {
	$this->GetDatabase()->Result_Rewind($this);
    }
    
    // -- DATA CONTROL -- //
    // ++ DATA STATUS ++ //

    /*----
      RETURNS: number of rows in the resultset
      CEMENTS: tSequentialAccess
    */
    public function GetRowCount() {
	return $this->GetDatabase()->Result_RowCount($this);
    }
    // CEMENTS: tSequentialAccess
    public function HasRows() {
        return $this->GetRowCount() > 0;
    }

    // -- DATA STATUS -- //
    // ++ DATA READ: BASIC ++ //

    /*----
      ACTION: Retrieves the current row data and advances to the next
      RETURNS: row data as an array, or NULL if no more rows
      CEMENTS: tSequentialAccess
    */
    public function NextRow() {
	$db = $this->GetDatabase();
	$arVals = $db->Result_NextRow($this);
	$ok = FALSE;
	if (!is_null($arVals)) {
	    if (is_array($arVals)) {
                //echo 'THIS:<pre>'.print_r($this,TRUE).'</pre>';
                $op = $this->LoadRow_fromArray($arVals);
		//$this->LoadValues_fromNative($arVals);
		$ok = TRUE;
	    } else {
		throw new exception(
		  'Ferreteria error: Anomalous result from reading a row. Row data: [BEGIN] '
		  .print_r($arVals,TRUE)
		  .'[END] SQL: '
		  .$db->sql
		);
	    }
	}
	if (!$ok) {
            $this->LoadRow_fromArray(array());
        }
	return $arVals;
    }

    // -- DATA READ: BASIC -- //
    // ++ NOT IMPLEMENTED ++ //
    
    // public function FetchRows($sql) : see tQueryableSource
    // public function SelectRows(...) : see tQueryableSource
    // public function GetRow_forKey($id) : see tMonokeyQueryableSource
}