summaryrefslogtreecommitdiff
path: root/adodb.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'adodb.inc.php')
-rw-r--r--adodb.inc.php357
1 files changed, 218 insertions, 139 deletions
diff --git a/adodb.inc.php b/adodb.inc.php
index a7ff42d5..7afdbfcb 100644
--- a/adodb.inc.php
+++ b/adodb.inc.php
@@ -14,7 +14,7 @@
/**
\mainpage
- @version v5.21.1-dev Unreleased
+ @version v5.22.0-dev Unreleased
@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community
@@ -210,7 +210,7 @@ if (!defined('_ADODB_LAYER')) {
/**
* ADODB version as a string.
*/
- $ADODB_vers = 'v5.21.1-dev Unreleased';
+ $ADODB_vers = 'v5.22.0-dev Unreleased';
/**
* Determines whether recordset->RecordCount() is used.
@@ -452,12 +452,39 @@ if (!defined('_ADODB_LAYER')) {
var $isoDates = false; /// accepts dates in ISO format
var $cacheSecs = 3600; /// cache for 1 hour
- // memcache
- var $memCache = false; /// should we use memCache instead of caching in files
- var $memCacheHost; /// memCache host
- var $memCachePort = 11211; /// memCache port
- var $memCacheCompress = false; /// Use 'true' to store the item compressed (uses zlib, not supported w/memcached library)
+ /*****************************************
+ * memcached server options
+ ******************************************/
+ /*
+ * Should we use memCache instead of caching in files
+ */
+ public $memCache = false;
+ /*
+ * A string, array of hosts or array of memcache connection
+ * options (see adodb.org)
+ */
+ public $memCacheHost;
+
+ /*
+ * Default port, may be ignored if connection object array
+ * is set
+ */
+ public $memCachePort = 11211;
+
+ /*
+ * Use 'true' to store the item compressed
+ * uses zlib, Direct option for memcache, else
+ * For memcached, use the memcacheOptions feature
+ */
+ public $memCacheCompress = false;
+ /*
+ * If using mecached, an array of options
+ * @link https://www.php.net/manual/en/memcached.constants.php
+ */
+ public $memCacheOptions = array();
+
+
var $sysDate = false; /// name of function that returns the current date
var $sysTimeStamp = false; /// name of function that returns the current timestamp
var $sysUTimeStamp = false; // name of function that returns the current timestamp accurate to the microsecond or nearest fraction
@@ -509,7 +536,24 @@ if (!defined('_ADODB_LAYER')) {
var $_logsql = false;
var $_transmode = ''; // transaction mode
-
+ /*
+ * A simple associative array of user-defined custom actual/meta types
+ */
+ public $customActualTypes = array();
+
+ /*
+ * An array of user-defined custom meta/actual types
+ *
+ $this->customMetaTypes[$meta] = array(
+ 'actual'=>'',
+ 'dictionary'=>'',
+ 'handler'=>'',
+ 'callback'=>''
+ );
+ */
+ public $customMetaTypes = array();
+
+
/**
* Default Constructor.
* We define it even though it does not actually do anything. This avoids
@@ -571,6 +615,50 @@ if (!defined('_ADODB_LAYER')) {
}
return $matches[1];
}
+
+ /**
+ * Set a custom meta type with a corresponding actual
+ *
+ * @param string $metaType The Custom ADOdb metatype
+ * @param string $dictionaryType The database dictionary type
+ * @param string $actualType The database actual type
+ * @param bool $handleAsType handle like an existing Metatype
+ * @param mixed $callBack A pre-processing function
+ *
+ * @return bool success if the actual exists
+ */
+ final public function setCustomMetaType(
+ $metaType,
+ $dictionaryType,
+ $actualType,
+ $handleAsType=false,
+ $callback=false){
+
+ $this->customMetaTypes[strtoupper($metaType)] = array(
+ 'actual'=>$actualType,
+ 'dictionary'=>strtoupper($dictionaryType),
+ 'handler'=>$handleAsType,
+ 'callback'=>$callback
+ );
+
+ /*
+ * Create a reverse lookup for the actualType
+ */
+ $this->customActualTypes[$actualType] = $metaType;
+
+ return true;
+ }
+
+ /**
+ * Get a list of custom meta types.
+ *
+ * @return string[]
+ */
+ final public function getCustomMetaTypes()
+ {
+ return $this->customMetaTypes;
+ }
+
/**
* Get server version info.
@@ -1914,16 +2002,6 @@ if (!defined('_ADODB_LAYER')) {
return $rv;
}
- function Transpose(&$rs,$addfieldnames=true) {
- $rs2 = $this->_rs2rs($rs);
- if (!$rs2) {
- return false;
- }
-
- $rs2->_transpose($addfieldnames);
- return $rs2;
- }
-
/*
Calculate the offset of a date for a particular database and generate
appropriate SQL. Useful for calculating future/past dates and storing
@@ -3564,13 +3642,14 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
}
- /**
- * RecordSet class that represents the dataset returned by the database.
- * To keep memory overhead low, this class holds only the current row in memory.
- * No prefetching of data is done, so the RecordCount() can return -1 ( which
- * means recordcount not known).
- */
- class ADORecordSet implements IteratorAggregate {
+/**
+ * RecordSet class that represents the dataset returned by the database.
+ *
+ * To keep memory overhead low, this class holds only the current row in memory.
+ * No prefetching of data is done, so the RecordCount() can return -1 (which
+ * means recordcount not known).
+ */
+class ADORecordSet implements IteratorAggregate {
/**
* public variables
@@ -3591,8 +3670,8 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
var $bind = false; /// used by Fields() to hold array - should be private?
var $fetchMode; /// default fetch mode
- var $connection = false; /// the parent connection
-
+ /** @var ADOConnection The parent connection */
+ var $connection = false;
/**
* private variables
*/
@@ -3612,10 +3691,14 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
var $_maxRecordCount = 0;
var $datetime = false;
+ public $customActualTypes;
+ public $customMetaTypes;
+
+
/**
* Constructor
*
- * @param resource|int queryID this is the queryID returned by ADOConnection->_query()
+ * @param resource|int $queryID Query ID returned by ADOConnection->_query()
*
*/
function __construct($queryID) {
@@ -3642,7 +3725,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
}
$this->_inited = true;
if ($this->_queryID) {
- @$this->_initrs();
+ @$this->_initRS();
} else {
$this->_numOfRows = 0;
$this->_numOfFields = 0;
@@ -3657,6 +3740,16 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
}
}
+ /**
+ * Recordset initialization stub
+ */
+ protected function _initRS() {}
+
+ /**
+ * Row fetch stub
+ * @return bool
+ */
+ protected function _fetch() {}
/**
* Generate a SELECT tag from a recordset, and return the HTML markup.
@@ -3795,24 +3888,28 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
return $this->GetArray($nRows);
}
- /*
- * Some databases allow multiple recordsets to be returned. This function
- * will return true if there is a next recordset, or false if no more.
- */
+ /**
+ * Checks if there is another available recordset.
+ *
+ * Some databases allow multiple recordsets to be returned.
+ *
+ * @return boolean true if there is a next recordset, or false if no more
+ */
function NextRecordSet() {
return false;
}
/**
- * return recordset as a 2-dimensional array.
+ * Return recordset as a 2-dimensional array.
+ *
* Helper function for ADOConnection->SelectLimit()
*
- * @param offset is the row to start calculations from (1-based)
- * @param [nrows] is the number of rows to return
+ * @param int $nrows Number of rows to return
+ * @param int $offset Starting row (1-based)
*
* @return array an array indexed by the rows (0-based) from the recordset
*/
- function GetArrayLimit($nrows,$offset=-1) {
+ function getArrayLimit($nrows, $offset=-1) {
if ($offset <= 0) {
return $this->GetArray($nrows);
}
@@ -3833,11 +3930,11 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
/**
* Synonym for GetArray() for compatibility with ADO.
*
- * @param [nRows] is the number of rows to return. -1 means every row.
+ * @param int $nRows Number of rows to return. -1 means every row.
*
* @return array an array indexed by the rows (0-based) from the recordset
*/
- function GetRows($nRows = -1) {
+ function getRows($nRows = -1) {
return $this->GetArray($nRows);
}
@@ -4050,8 +4147,8 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
/**
- * PEAR DB Compat - do not use internally
- */
+ * PEAR DB Compat - do not use internally
+ */
function Free() {
return $this->Close();
}
@@ -4225,6 +4322,14 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
return false;
}
+ /**
+ * Adjusts the result pointer to an arbitrary row in the result.
+ *
+ * @param int $row The row to seek to.
+ *
+ * @return bool False if the recordset contains no rows, otherwise true.
+ */
+ function _seek($row) {}
/**
* Get the value of a field in the current row by column name.
@@ -4298,8 +4403,9 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
* Use associative array to get fields array for databases that do not support
* associative arrays. Submitted by Paolo S. Asioli paolo.asioli#libero.it
*
- * @param int [$upper] Case for the array keys, defaults to uppercase
+ * @param int $upper Case for the array keys, defaults to uppercase
* (see ADODB_ASSOC_CASE_xxx constants)
+ * @return array
*/
function GetRowAssoc($upper = ADODB_ASSOC_CASE) {
$record = array();
@@ -4335,15 +4441,14 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
}
/**
- * Synonyms RecordCount and RowCount
+ * Number of rows in recordset.
*
* @return int Number of rows or -1 if this is not supported
*/
- function RecordCount() {
+ function recordCount() {
return $this->_numOfRows;
}
-
/**
* If we are using PageExecute(), this will return the maximum possible rows
* that can be returned when paging a recordset.
@@ -4351,26 +4456,32 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
* @return int
*/
function MaxRecordCount() {
- return ($this->_maxRecordCount) ? $this->_maxRecordCount : $this->RecordCount();
+ return ($this->_maxRecordCount) ? $this->_maxRecordCount : $this->recordCount();
}
/**
- * synonyms RecordCount and RowCount
+ * Number of rows in recordset.
+ * Alias for {@see recordCount()}
*
- * @return the number of rows or -1 if this is not supported
+ * @return int Number of rows or -1 if this is not supported
*/
- function RowCount() {
- return $this->_numOfRows;
+ function rowCount() {
+ return $this->recordCount();
}
-
- /**
- * Portable RecordCount. Pablo Roca <pabloroca@mvps.org>
+ /**
+ * Portable RecordCount.
*
- * @return the number of records from a previous SELECT. All databases support this.
+ * Be aware of possible problems in multiuser environments.
+ * For better speed the table must be indexed by the condition.
+ * Heavy test this before deploying.
*
- * But aware possible problems in multiuser environments. For better speed the table
- * must be indexed by the condition. Heavy test this before deploying.
+ * @param string $table
+ * @param string $condition
+ *
+ * @return int Number of records from a previous SELECT. All databases support this.
+ *
+ * @author Pablo Roca <pabloroca@mvps.org>
*/
function PO_RecordCount($table="", $condition="") {
@@ -4416,23 +4527,24 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
}
/**
- * Get the ADOFieldObject of a specific column.
+ * Get Field metadata for of a specific column.
*
- * @param fieldoffset is the column position to access(0-based).
+ * @param fieldoffset is the column position to access(0-based).
*
- * @return the ADOFieldObject for that column, or false.
+ * @return ADOFieldObject|false for that column, or false.
*/
- function FetchField($fieldoffset = -1) {
+ function fetchField($fieldoffset = -1) {
// must be defined by child class
return false;
}
/**
- * Get the ADOFieldObjects of all columns in an array.
+ * Get Field metadata for all the recordset's columns in an array.
*
+ * @return ADOFieldObject[]
*/
- function FieldTypesArray() {
+ function fieldTypesArray() {
static $arr = array();
if (empty($arr)) {
for ($i=0, $max=$this->_numOfFields; $i < $max; $i++) {
@@ -4456,11 +4568,11 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
* Return the fields array of the current row as an object for convenience.
* The default case is uppercase.
*
- * @param $isupper to set the object property names to uppercase
+ * @param bool $isUpper to set the object property names to uppercase
*
- * @return the object with the properties set to the fields of the current row
+ * @return ADOFetchObj The object with properties set to the fields of the current row
*/
- function FetchObject($isupper=true) {
+ function FetchObject($isUpper=true) {
if (empty($this->_obj)) {
$this->_obj = new ADOFetchObj();
$this->_names = array();
@@ -4469,12 +4581,11 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
$this->_names[] = $f->name;
}
}
- $i = 0;
$o = clone($this->_obj);
for ($i=0; $i <$this->_numOfFields; $i++) {
$name = $this->_names[$i];
- if ($isupper) {
+ if ($isUpper) {
$n = strtoupper($name);
} else {
$n = $name;
@@ -4489,8 +4600,8 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
* Return the fields array of the current row as an object for convenience.
* The default is lower-case field names.
*
- * @return the object with the properties set to the fields of the current row,
- * or false if EOF
+ * @return ADOFetchObj|false The object with properties set to the fields of the current row
+ * or false if EOF.
*
* Fixed bug reported by tim@orotech.net
*/
@@ -4503,17 +4614,17 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
* Return the fields array of the current row as an object for convenience.
* The default is upper case field names.
*
- * @param $isupper to set the object property names to uppercase
+ * @param bool $isUpper to set the object property names to uppercase
*
- * @return the object with the properties set to the fields of the current row,
- * or false if EOF
+ * @return ADOFetchObj|false The object with properties set to the fields of the current row
+ * or false if EOF.
*
* Fixed bug reported by tim@orotech.net
*/
- function FetchNextObject($isupper=true) {
+ function FetchNextObject($isUpper=true) {
$o = false;
if ($this->_numOfRows != 0 && !$this->EOF) {
- $o = $this->FetchObject($isupper);
+ $o = $this->FetchObject($isUpper);
$this->_currentRow++;
if ($this->_fetch()) {
return $o;
@@ -4524,37 +4635,29 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
}
/**
- * Get the metatype of the column. This is used for formatting. This is because
- * many databases use different names for the same type, so we transform the original
- * type to our standardised version which uses 1 character codes:
- *
- * @param t is the type passed in. Normally is ADOFieldObject->type.
- * @param len is the maximum length of that field. This is because we treat character
- * fields bigger than a certain size as a 'B' (blob).
- * @param fieldobj is the field object returned by the database driver. Can hold
- * additional info (eg. primary_key for mysql).
+ * Get the ADOdb metatype.
*
- * @return the general type of the data:
- * C for character < 250 chars
- * X for teXt (>= 250 chars)
- * B for Binary
- * N for numeric or floating point
- * D for date
- * T for timestamp
- * L for logical/Boolean
- * I for integer
- * R for autoincrement counter/integer
+ * Many databases use different names for the same type, so we transform
+ * the native type to our standardised one, which uses 1 character codes.
+ * @see https://adodb.org/dokuwiki/doku.php?id=v5:dictionary:dictionary_index#portable_data_types
*
+ * @param string|ADOFieldObject $t Native type (usually ADOFieldObject->type)
+ * It is also possible to provide an
+ * ADOFieldObject here.
+ * @param int $len The field's maximum length. This is because we treat
+ * character fields bigger than a certain size as a 'B' (blob).
+ * @param ADOFieldObject $fieldObj Field object returned by the database driver;
+ * can hold additional info (eg. primary_key for mysql).
*
- */
- function MetaType($t,$len=-1,$fieldobj=false) {
- if (is_object($t)) {
- $fieldobj = $t;
- $t = $fieldobj->type;
- $len = $fieldobj->max_length;
+ * @return string The ADOdb Standard type
+ */
+ function metaType($t, $len = -1, $fieldObj = false) {
+ if ($t instanceof ADOFieldObject) {
+ $fieldObj = $t;
+ $t = $fieldObj->type;
+ $len = $fieldObj->max_length;
}
-
// changed in 2.32 to hashing instead of switch stmt for speed...
static $typeMap = array(
'VARCHAR' => 'C',
@@ -4661,8 +4764,6 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
"SQLBOOL" => 'L'
);
-
- $tmap = false;
$t = strtoupper($t);
$tmap = (isset($typeMap[$t])) ? $typeMap[$t] : ADODB_DEFAULT_METATYPE;
switch ($tmap) {
@@ -4678,7 +4779,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
return 'C';
case 'I':
- if (!empty($fieldobj->primary_key)) {
+ if (!empty($fieldObj->primary_key)) {
return 'R';
}
return 'I';
@@ -4687,8 +4788,8 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
return 'N';
case 'B':
- if (isset($fieldobj->binary)) {
- return ($fieldobj->binary) ? 'B' : 'X';
+ if (isset($fieldObj->binary)) {
+ return ($fieldObj->binary) ? 'B' : 'X';
}
return 'B';
@@ -4739,8 +4840,10 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
/**
* set/returns the current recordset page when paginating
+ * @param int $page
+ * @return int
*/
- function AbsolutePage($page=-1) {
+ function absolutePage($page=-1) {
if ($page != -1) {
$this->_currentPage = $page;
}
@@ -4749,6 +4852,8 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
/**
* set/returns the status of the atFirstPage flag when paginating
+ * @param bool $status
+ * @return bool
*/
function AtFirstPage($status=false) {
if ($status != false) {
@@ -4757,6 +4862,10 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
return $this->_atFirstPage;
}
+ /**
+ * @param bool $page
+ * @return bool
+ */
function LastPageNo($page = false) {
if ($page != false) {
$this->_lastPageNo = $page;
@@ -4766,6 +4875,8 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
/**
* set/returns the status of the atLastPage flag when paginating
+ * @param bool $status
+ * @return bool
*/
function AtLastPage($status=false) {
if ($status != false) {
@@ -4813,39 +4924,7 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1
$this->fetchMode = $ADODB_FETCH_MODE;
}
- function _transpose($addfieldnames=true) {
- global $ADODB_INCLUDED_LIB;
-
- if (empty($ADODB_INCLUDED_LIB)) {
- include_once(ADODB_DIR.'/adodb-lib.inc.php');
- }
- $hdr = true;
-
- $fobjs = $addfieldnames ? $this->_fieldobjects : false;
- adodb_transpose($this->_array, $newarr, $hdr, $fobjs);
- //adodb_pr($newarr);
-
- $this->_skiprow1 = false;
- $this->_array = $newarr;
- $this->_colnames = $hdr;
-
- adodb_probetypes($newarr,$this->_types);
-
- $this->_fieldobjects = array();
-
- foreach($hdr as $k => $name) {
- $f = new ADOFieldObject();
- $f->name = $name;
- $f->type = $this->_types[$k];
- $f->max_length = -1;
- $this->_fieldobjects[] = $f;
- }
- $this->fields = reset($this->_array);
-
- $this->_initrs();
-
- }
-
+
/**
* Setup the array.
*