ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
MDB2_Result_Common Class Reference
+ Inheritance diagram for MDB2_Result_Common:
+ Collaboration diagram for MDB2_Result_Common:

Public Member Functions

 __construct (&$db, &$result, $limit=0, $offset=0)
 Constructor.
 MDB2_Result_Common (&$db, &$result, $limit=0, $offset=0)
 PHP 4 Constructor.
 setResultTypes ($types)
 Define the list of types to be associated with the columns of a given result set.
 seek ($rownum=0)
 Seek to a specific row in a result set.
fetchRow ($fetchmode=MDB2_FETCHMODE_DEFAULT, $rownum=null)
 Fetch and return a row of data.
 fetchOne ($colnum=0, $rownum=null)
 fetch single column from the next row from a result set
 fetchCol ($colnum=0)
 Fetch and return a column from the current row pointer position.
 fetchAll ($fetchmode=MDB2_FETCHMODE_DEFAULT, $rekey=false, $force_array=false, $group=false)
 Fetch and return all rows from the current row pointer position.
 rowCount ()
 Returns the actual row number that was last fetched (count from 0)
 numRows ()
 Returns the number of rows in a result object.
 nextResult ()
 Move the internal result pointer to the next available result.
 getColumnNames ($flip=false)
 Retrieve the names of columns returned by the DBMS in a query result or from the cache.
 _getColumnNames ()
 Retrieve the names of columns returned by the DBMS in a query result.
 numCols ()
 Count the number of columns returned by the DBMS in a query result.
 getResource ()
 return the resource associated with the result object
 bindColumn ($column, &$value, $type=null)
 Set bind variable to a column.
 _assignBindColumns ($row)
 Bind a variable to a value in the result row.
 free ()
 Free the internal resources associated with result.

Data Fields

 $db
 $result
 $rownum = -1
 $types = array()
 $values = array()
 $offset
 $offset_count = 0
 $limit
 $column_names

Detailed Description

Definition at line 3343 of file MDB2.php.

Constructor & Destructor Documentation

MDB2_Result_Common::__construct ( $db,
$result,
  $limit = 0,
  $offset = 0 
)

Constructor.

Definition at line 3363 of file MDB2.php.

References $db, $limit, $offset, and $result.

Referenced by MDB2_Result_Common().

{
$this->db =& $db;
$this->result =& $result;
$this->offset = $offset;
$this->limit = max(0, $limit - 1);
}

+ Here is the caller graph for this function:

Member Function Documentation

MDB2_Result_Common::_assignBindColumns (   $row)

Bind a variable to a value in the result row.

Parameters
arrayrow data
Returns
mixed MDB2_OK on success, a MDB2 error on failure

private

Definition at line 3786 of file MDB2.php.

References $row, and MDB2_OK.

Referenced by MDB2_Result_oci8\fetchRow(), MDB2_Result_mysql\fetchRow(), and MDB2_BufferedResult_oci8\fetchRow().

{
$row = array_values($row);
foreach ($row as $column => $value) {
if (array_key_exists($column, $this->values)) {
$this->values[$column] = $value;
}
}
return MDB2_OK;
}

+ Here is the caller graph for this function:

MDB2_Result_Common::_getColumnNames ( )

Retrieve the names of columns returned by the DBMS in a query result.

Returns
mixed Array variable that holds the names of columns as keys or an MDB2 error on failure. Some DBMS may not return any columns when the result set does not contain any rows.

private

Reimplemented in MDB2_Result_mysql, and MDB2_Result_oci8.

Definition at line 3702 of file MDB2.php.

References MDB2_ERROR_UNSUPPORTED.

{
return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
}
MDB2_Result_Common::bindColumn (   $column,
$value,
  $type = null 
)

Set bind variable to a column.

Parameters
intcolumn number or name
mixedvariable reference
stringspecifies the type of the field
Returns
mixed MDB2_OK on success, a MDB2 error on failure

public

Definition at line 3754 of file MDB2.php.

References $type, MDB2_OK, and MDB2_PORTABILITY_FIX_CASE.

{
if (!is_numeric($column)) {
if ($this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
if ($this->db->options['field_case'] == CASE_LOWER) {
$column = strtolower($column);
} else {
$column = strtoupper($column);
}
}
$column = $column_names[$column];
}
$this->values[$column] =& $value;
if (!is_null($type)) {
$this->types[$column] = $type;
}
return MDB2_OK;
}
MDB2_Result_Common::fetchAll (   $fetchmode = MDB2_FETCHMODE_DEFAULT,
  $rekey = false,
  $force_array = false,
  $group = false 
)

Fetch and return all rows from the current row pointer position.

Parameters
int$fetchmodethe fetch mode to use:
  • MDB2_FETCHMODE_ORDERED
  • MDB2_FETCHMODE_ASSOC
  • MDB2_FETCHMODE_ORDERED | MDB2_FETCHMODE_FLIPPED
  • MDB2_FETCHMODE_ASSOC | MDB2_FETCHMODE_FLIPPED
boolif set to true, the $all will have the first column as its first dimension
boolused only when the query returns exactly two columns. If true, the values of the returned array will be one-element arrays instead of scalars.
boolif true, the values of the returned array is wrapped in another array. If the same key value (in the first column) repeats itself, the values will be appended to this array instead of overwriting the existing values.
Returns
mixed data array on success, a MDB2 error on failure

public

See Also
getAssoc()

Definition at line 3550 of file MDB2.php.

References $row, fetchRow(), PEAR\isError(), MDB2_ERROR_TRUNCATED, and MDB2_FETCHMODE_ASSOC.

{
$all = array();
$row = $this->fetchRow($fetchmode);
return $row;
} elseif (!$row) {
return $all;
}
$shift_array = $rekey ? false : null;
if (!is_null($shift_array)) {
if (is_object($row)) {
$colnum = count(get_object_vars($row));
} else {
$colnum = count($row);
}
if ($colnum < 2) {
return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,
'rekey feature requires atleast 2 column', __FUNCTION__);
}
$shift_array = (!$force_array && $colnum == 2);
}
if ($rekey) {
do {
if (is_object($row)) {
$arr = get_object_vars($row);
$key = reset($arr);
unset($row->{$key});
} else {
if ($fetchmode & MDB2_FETCHMODE_ASSOC) {
$key = reset($row);
unset($row[key($row)]);
} else {
$key = array_shift($row);
}
if ($shift_array) {
$row = array_shift($row);
}
}
if ($group) {
$all[$key][] = $row;
} else {
$all[$key] = $row;
}
} while (($row = $this->fetchRow($fetchmode)));
} elseif ($fetchmode & MDB2_FETCHMODE_FLIPPED) {
do {
foreach ($row as $key => $val) {
$all[$key][] = $val;
}
} while (($row = $this->fetchRow($fetchmode)));
} else {
do {
$all[] = $row;
} while (($row = $this->fetchRow($fetchmode)));
}
return $all;
}

+ Here is the call graph for this function:

MDB2_Result_Common::fetchCol (   $colnum = 0)

Fetch and return a column from the current row pointer position.

Parameters
intthe column number to fetch
Returns
mixed data array on success, a MDB2 error on failure

public

Definition at line 3504 of file MDB2.php.

References $row, fetchRow(), PEAR\isError(), MDB2_ERROR_TRUNCATED, MDB2_FETCHMODE_ASSOC, and MDB2_FETCHMODE_ORDERED.

{
$column = array();
$fetchmode = is_numeric($colnum) ? MDB2_FETCHMODE_ORDERED : MDB2_FETCHMODE_ASSOC;
$row = $this->fetchRow($fetchmode);
if (is_array($row)) {
if (!array_key_exists($colnum, $row)) {
return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,
'column is not defined in the result set: '.$colnum, __FUNCTION__);
}
do {
$column[] = $row[$colnum];
} while (is_array($row = $this->fetchRow($fetchmode)));
}
return $row;
}
return $column;
}

+ Here is the call graph for this function:

MDB2_Result_Common::fetchOne (   $colnum = 0,
  $rownum = null 
)

fetch single column from the next row from a result set

Parameters
intthe column number to fetch
intnumber of the row where the data can be found
Returns
string data on success, a MDB2 error on failure

public

Definition at line 3478 of file MDB2.php.

References $row, $rownum, fetchRow(), PEAR\isError(), MDB2_ERROR_TRUNCATED, MDB2_FETCHMODE_ASSOC, and MDB2_FETCHMODE_ORDERED.

{
$fetchmode = is_numeric($colnum) ? MDB2_FETCHMODE_ORDERED : MDB2_FETCHMODE_ASSOC;
$row = $this->fetchRow($fetchmode, $rownum);
if (!is_array($row) || PEAR::isError($row)) {
return $row;
}
if (!array_key_exists($colnum, $row)) {
return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,
'column is not defined in the result set: '.$colnum, __FUNCTION__);
}
return $row[$colnum];
}

+ Here is the call graph for this function:

& MDB2_Result_Common::fetchRow (   $fetchmode = MDB2_FETCHMODE_DEFAULT,
  $rownum = null 
)

Fetch and return a row of data.

Parameters
inthow the array data should be indexed
intnumber of the row where the data can be found
Returns
int data array on success, a MDB2 error on failure

public

Reimplemented in MDB2_BufferedResult_oci8, MDB2_Result_mysql, and MDB2_Result_oci8.

Definition at line 3458 of file MDB2.php.

References MDB2_ERROR_UNSUPPORTED.

Referenced by fetchAll(), fetchCol(), fetchOne(), and seek().

{
$err =& $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
return $err;
}

+ Here is the caller graph for this function:

MDB2_Result_Common::free ( )

Free the internal resources associated with result.

Returns
bool true on success, false if result is invalid

public

Reimplemented in MDB2_BufferedResult_oci8, MDB2_Result_mysql, and MDB2_Result_oci8.

Definition at line 3807 of file MDB2.php.

References MDB2_OK.

{
$this->result = false;
return MDB2_OK;
}
MDB2_Result_Common::getColumnNames (   $flip = false)

Retrieve the names of columns returned by the DBMS in a query result or from the cache.

Parameters
boolIf set to true the values are the column names, otherwise the names of the columns are the keys.
Returns
mixed Array variable that holds the names of columns or an MDB2 error on failure. Some DBMS may not return any columns when the result set does not contain any rows.

public

Definition at line 3674 of file MDB2.php.

References PEAR\isError().

Referenced by MDB2_BufferedResult_oci8\fetchRow().

{
if (!isset($this->column_names)) {
return $result;
}
$this->column_names = $result;
}
if ($flip) {
return array_flip($this->column_names);
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Result_Common::getResource ( )

return the resource associated with the result object

Returns
resource

public

Definition at line 3735 of file MDB2.php.

{
return $this->result;
}
MDB2_Result_Common::MDB2_Result_Common ( $db,
$result,
  $limit = 0,
  $offset = 0 
)

PHP 4 Constructor.

Definition at line 3377 of file MDB2.php.

References $db, $limit, $offset, $result, and __construct().

+ Here is the call graph for this function:

MDB2_Result_Common::nextResult ( )

Move the internal result pointer to the next available result.

Returns
true on success, false if there is no more result set or an error object on failure

public

Definition at line 3652 of file MDB2.php.

References MDB2_ERROR_UNSUPPORTED.

{
return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
}
MDB2_Result_Common::numCols ( )

Count the number of columns returned by the DBMS in a query result.

Returns
mixed integer value with the number of columns, a MDB2 error on failure

public

Reimplemented in MDB2_Result_mysql, and MDB2_Result_oci8.

Definition at line 3719 of file MDB2.php.

References MDB2_ERROR_UNSUPPORTED.

{
return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
}
MDB2_Result_Common::numRows ( )

Returns the number of rows in a result object.

Returns
mixed MDB2 Error Object or the number of rows

public

Reimplemented in MDB2_BufferedResult_mysql, and MDB2_BufferedResult_oci8.

Definition at line 3636 of file MDB2.php.

References MDB2_ERROR_UNSUPPORTED.

{
return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
}
MDB2_Result_Common::rowCount ( )

Returns the actual row number that was last fetched (count from 0)

Returns
int

public

Definition at line 3621 of file MDB2.php.

{
return $this->rownum + 1;
}
MDB2_Result_Common::seek (   $rownum = 0)

Seek to a specific row in a result set.

Parameters
intnumber of the row where the data can be found
Returns
mixed MDB2_OK on success, a MDB2 error on failure

public

Reimplemented in MDB2_BufferedResult_mysql, and MDB2_BufferedResult_oci8.

Definition at line 3432 of file MDB2.php.

References $rownum, fetchRow(), MDB2_ERROR_UNSUPPORTED, and MDB2_OK.

Referenced by MDB2_Result_oci8\fetchRow(), and MDB2_Result_mysql\fetchRow().

{
$target_rownum = $rownum - 1;
if ($this->rownum > $target_rownum) {
return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'seeking to previous rows not implemented', __FUNCTION__);
}
while ($this->rownum < $target_rownum) {
$this->fetchRow();
}
return MDB2_OK;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MDB2_Result_Common::setResultTypes (   $types)

Define the list of types to be associated with the columns of a given result set.

This function may be called before invoking fetchRow(), fetchOne(), fetchCol() and fetchAll() so that the necessary data type conversions are performed on the data to be retrieved by them. If this function is not called, the type of all result set columns is assumed to be text, thus leading to not perform any conversions.

Parameters
arrayvariable that lists the data types to be expected in the result set columns. If this array contains less types than the number of columns that are returned in the result set, the remaining columns are assumed to be of the type text. Currently, the types clob and blob are not fully supported.
Returns
mixed MDB2_OK on success, a MDB2 error on failure

public

Definition at line 3406 of file MDB2.php.

References $types, PEAR\isError(), and MDB2_OK.

{
$load = $this->db->loadModule('Datatype', null, true);
if (PEAR::isError($load)) {
return $load;
}
$types = $this->db->datatype->checkResultTypes($types);
return $types;
}
$this->types = $types;
return MDB2_OK;
}

+ Here is the call graph for this function:

Field Documentation

MDB2_Result_Common::$column_names

Definition at line 3355 of file MDB2.php.

Referenced by MDB2_BufferedResult_oci8\fetchRow().

MDB2_Result_Common::$db

Definition at line 3347 of file MDB2.php.

Referenced by __construct(), and MDB2_Result_Common().

MDB2_Result_Common::$limit

Definition at line 3354 of file MDB2.php.

Referenced by __construct(), and MDB2_Result_Common().

MDB2_Result_Common::$offset

Definition at line 3352 of file MDB2.php.

Referenced by __construct(), and MDB2_Result_Common().

MDB2_Result_Common::$offset_count = 0

Definition at line 3353 of file MDB2.php.

MDB2_Result_Common::$result

Definition at line 3348 of file MDB2.php.

Referenced by __construct(), and MDB2_Result_Common().

MDB2_Result_Common::$types = array()

Definition at line 3350 of file MDB2.php.

Referenced by setResultTypes().

MDB2_Result_Common::$values = array()

Definition at line 3351 of file MDB2.php.


The documentation for this class was generated from the following file: