<?php
/**
* Project: web.framework: the PHP5 MVC framework
* File: WebDBRecordSet.abstract.class.php
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* You may contact the authors of web.framework by e-mail at:
* hide@address.com
*
* The latest version of web.framework can be obtained from:
* http://sourceforge.net/projects/webframework
*
* @link http://sourceforge.net/projects/webframework
* @copyright 2005 Marcin Staniszczak
* @author Marcin Staniszczak <hide@address.com>
* @version 1.0.0
*/
/**
* This class must be implement by any RecordSets classes
*
* @abstract
* @name AWebDBRecordSet
* @version 1.0.0
* @package web.framework
* @subpackage web.db
*
* @author Marcin Staniszczak
* @copyright 2005 Marcin Staniszczak
*/
abstract class AWebDBRecordSet implements IteratorAggregate {
const
FETCHMODE_ASSOC = 0,
FETCHMODE_NUM = 1;
const
ASSOCCASE_LOWER = 0,
ASSOCCASE_UPPER = 1,
ASSOCCASE_ORGINAL = 2;
protected
$resResource = null,
$resResult = null,
$intFetchMode = null,
$intAssocCase = null;
protected
$arrFields = null,
$intCursorPos = 0;
/**
* The class constructor
*
* @access public
* @param resource DB connection resource
* @param resource SQL query result
* @param integer fetch mode method (FETCHMODE_ASSOC - associate array, FETCHMODE_NUM - normal array)
* @param integer return result mode (ASSOCCASE_LOWER, ASSOCCASE_UPPER, ASSOCCASE_ORGINAL)
*/
public function __construct($resResource, $resResult, $intFetchMode=null, $intAssocCase=null) {
$this->resResult = $resResult;
$this->resResource = $resResource;
if ($intFetchMode!==null) {
$this->intFetchMode = $intFetchMode;
} else {
$this->intFetchMode = AWebDBRecordSet::FETCHMODE_ASSOC;
}
$this->setAssocCase($intAssocCase);
}
/**
* The class destructor
*
* @access public
*/
public function __destruct() {
$this->close();
}
/**
* Return DB connection resource
*
* @access public
* @return resource DB connection resource
*/
public function getResource() {
//var_dump($this->resResource);
return $this->resResource;
}
/**
* Letter case size in returned records
*
* @access public
* @param integer ASSOCCASE_LOWER, ASSOCCASE_UPPER, ASSOCCASE_ORGINAL
*/
public function setAssocCase($intAssocCase) {
if ($intAssocCase>=0 && $intAssocCase<=3) {
$this->intAssocCase = $intAssocCase;
} else {
$this->intAssocCase = AWebDBRecordSet::ASSOCCASE_ORGINAL;
}
}
/**
* Return letter case size
*
* @access public
* @return ASSOCCASE_LOWER, ASSOCCASE_UPPER, ASSOCCASE_ORGINAL
*/
public function getAssocCase() {
return $this->intAssocCase;
}
/**
* Return RecordSet's iterator object
*
* @access public
* @return iterator
*/
public function getIterator() {
return new RecordSetIterator($this);
}
/**
* Return key
*
* @access public
* @return key
*/
public function getKey() {
return $this->intCursorPos;
}
/**
* Return Value
*
* @access public
* @return array with records
*/
public function getValue() {
return $this->arrFields;
}
/**
* Set pointer on the next record
*
* @abstract
* @access public
* @param integer position
*/
abstract function seek($intPosition);
/**
* Go to the next record
*
* @abstract
* @access public
* @return true - all it's ok, false - no new records
*/
abstract function next();
/**
* Return records number
*
* @abstract
* @access public
* @return integer records number
*/
abstract public function count();
/**
* Close query results resource
*
* @abstract
* @access public
*/
abstract function close();
}
/**
* Records's iterator
*
* @name RecordSetIterator
* @version 1.0.0
* @package web.framework
* @subpackage web.db
*
* @author Marcin Staniszczak
* @copyright 2005 Marcin Staniszczak
*/
class RecordSetIterator implements Iterator {
private
$objRS = null,
$resCurrent = null;
/**
* The class constructor
*
* @access public
* @param AWebDBRecordSet database records handling object
*/
public function __construct(AWebDBRecordSet $objRS) {
$this->objRS = $objRS;
}
/**
* Set iterator on first element
*
* @access public
*/
public function rewind() {
$this->objRS->seek(0);
}
/**
* Chck for next record exist ad if, move to it
*
* @access public
*/
public function valid() {
$blnCurrent = $this->objRS->next();
return $blnCurrent;
}
/**
* Return key
*
* @access public
*/
public function key() {
return $this->objRS->getKey();
}
/**
* Return value
*
* @access public
*/
public function current() {
return $this->objRS->getValue();
}
/**
* Move to the next record
*
* @access public
*/
public function next() {
}
}
/**
* RecordSet read exception
* @package web.framework
* @subpackage exceptions
*/
class WD_RecordSet_Exception extends WD_Exception {}
?>