[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/creole/ -> ResultSet.php (sommaire)

(pas de description)

Poids: 380 lignes (17 kb)
Inclus ou requis:0 fois
Référencé: 0 fois
Nécessite: 0 fichiers

Définit 1 class

ResultSet:: (30 méthodes):
  getResource()
  setFetchmode()
  getFetchmode()
  isLowerAssocCase()
  next()
  previous()
  relative()
  absolute()
  seek()
  first()
  last()
  beforeFirst()
  afterLast()
  isAfterLast()
  isBeforeFirst()
  getCursorPos()
  getRow()
  getRecordCount()
  close()
  get()
  getArray()
  getBoolean()
  getBlob()
  getClob()
  getDate()
  getFloat()
  getInt()
  getString()
  getTime()
  getTimestamp()


Interface: ResultSet  - X-Ref

This is the interface for classes the wrap db results.

The get*() methods in this interface will format values before returning them. Note
that if they will return null if the database returned NULL.  If the requested column does
not exist than an exception (SQLException) will be thrown.

<code>
$rs = $conn->executeQuery("SELECT MAX(stamp) FROM event", ResultSet::FETCHMODE_NUM);
$rs->next();

$max_stamp = $rs->getTimestamp(1, "d/m/Y H:i:s");
// $max_stamp will be date string or null if no MAX(stamp) was found

$max_stamp = $rs->getTimestamp("max(stamp)", "d/m/Y H:i:s");
// will THROW EXCEPTION, because the resultset was fetched using numeric indexing
// SQLException: Invalid resultset column: max(stamp)
</code>

This class implements SPL IteratorAggregate, so you may iterate over the database results
using foreach():
<code>
foreach($rs as $row) {
print_r($row); // row is assoc array returned by getRow()
}
</code>

getResource()   X-Ref
Get the PHP native resource for the result.
Arguably this should not be part of the interface: i.e. every driver should implement
it if they have a result resource, but conceivably drivers could be created that do
not.  For now every single driver does have a "dblink" resource property, and other
classes (e.g. ResultSet) need this info in order to get correct native errors.  We'll
leave it in for now, as it helps with driver development, with the caveat that it
could be removed from the interface at a later point.

return: resource Query result or NULL if not not applicable.

setFetchmode($mode)   X-Ref
Sets the fetchmode used to retrieve results.
Changing fetchmodes mid-result retrieval is supported (haven't encountered any drivers
that don't support that yet).

param: int $mode ResultSet::FETCHMODE_NUM or  ResultSet::FETCHMODE_ASSOC (default).
return: void

getFetchmode()   X-Ref
Gets the fetchmode used to retrieve results.

return: int ResultSet::FETCHMODE_NUM or ResultSet::FETCHMODE_ASSOC (default).

isLowerAssocCase()   X-Ref
Whether assoc result keys get converted to lowercase for compatibility.

This defaults to FALSE unless Creole::COMPAT_ASSOC_LOWER flag has been passed to connection.
This property is read-only since it must be set when connection is created.  The
reason for this behavior is some drivers (e.g. SQLite) do the case conversions internally
based on a PHP ini value; it would not be possible to change the behavior from the ResultSet
(since query has already been executed).

return: boolean

next()   X-Ref
Moves the internal cursor to the next position and fetches the row at that position.

return: boolean <tt>true</tt> if success, <tt>false</tt> if no next record.

previous()   X-Ref
Moves the internal cursor to the previous position and fetches the
row at that position.

return: boolean <tt>true</tt> if success, <tt>false</tt> if no previous record.

relative($offset)   X-Ref
Moves the cursor a relative number of rows, either positive or negative and fetches
the row at that position.

Attempting to move beyond the first/last row in the result set positions the cursor before/after
the first/last row and issues a Warning. Calling relative(0) is valid, but does not change the cursor
position.

param: integer $offset
return: boolean <tt>true</tt> if cursor is on a row, <tt>false</tt> otherwise.

absolute($pos)   X-Ref
Moves the cursor to an absolute cursor position and fetches the row at that position.

Attempting to move beyond the first/last row in the result set positions the cursor before/after
the first/last row and issues a Warning.

param: integer $pos cursor position, first position is 1.
return: boolean <tt>true</tt> if cursor is on a row, <tt>false</tt> otherwise.

seek($rownum)   X-Ref
Moves cursor position WITHOUT FETCHING ROW AT THAT POSITION.

Generally this method is for internal driver stuff (e.g. other methods like
absolute() or relative() might call this and then call next() to get the row).
This method is public to facilitate more advanced ResultSet scrolling tools
-- e.g. cleaner implimentation of ResultSetIterator.

Some drivers will emulate seek() and not allow reverse seek (Oracle).

Seek is 0-based, but seek() is only for moving to the space _before_ the record
that you want to read.  I.e. if you seek(0) and then call next() you will have the
first row (i.e. same as calling first() or absolute(1)).

<strong>IMPORTANT:  You cannot rely on the return value of this method to know whether a given
record exists for reading.  In some cases seek() will correctly return <code>false</code> if
the position doesn't exist, but in other drivers the seek is not performed until the
record is fetched. You can check the return value of absolute() if you need to know
whether a specific rec position is valid.</strong>

param: int $rownum The cursor pos to seek to.
return: boolean true on success, false if unable to seek to specified record.

first()   X-Ref
Move cursor to beginning of recordset.

return: boolean <tt>true</tt> on success or <tt>false</tt> if not found.

last()   X-Ref
Move cursor to end of recordset.

return: boolean <tt>true</tt> on success or <tt>false</tt> if not found.

beforeFirst()   X-Ref
Sets cursort to before first record. This does not actually seek(), but
simply sets cursor pos to 0.
This is useful for inserting a record before the first in the set, etc.

return: void

afterLast()   X-Ref
Sets cursort to after the last record. This does not actually seek(), but
simply sets the cursor pos  to last + 1.
This [will be] useful for inserting a record after the last in the set,
when/if Creole supports updateable ResultSets.

return: void

isAfterLast()   X-Ref
Checks whether cursor is after the last record.

return: boolean

isBeforeFirst()   X-Ref
Checks whether cursor is before the first record.

return: boolean

getCursorPos()   X-Ref
Returns the current cursor position.
Cursor positions start at 0, but as soon as first row is fetched
cursor position is 1. (so first row is 1)

return: int

getRow()   X-Ref
Gets current fields (assoc array).

return: array

getRecordCount()   X-Ref
Get the number of rows in a result set.

return: int the number of rows

close()   X-Ref
Frees the resources allocated for this result set.
Also empties any internal field array so that any calls to
get() method on closed ResultSet will result in "Invalid column" SQLException.

return: void

get($column)   X-Ref
A generic get method returns unformatted (=string) value.
This returns the raw results from the database.  Usually this will be a string, but some drivers
also can return objects (lob descriptors, etc) in certain cases.

param: mixed $column Column name (string) or index (int) starting with 1 (if ResultSet::FETCHMODE_NUM was used) (if ResultSet::FETCHMODE_NUM was used).
return: mixed Usually expect a string.

getArray($column)   X-Ref
Reads a column as an array.
The value of the column is unserialized & returned as an array.  The generic case of this function is
very PHP-specific.  Other drivers (e.g. Postgres) will format values into their native array format.

param: mixed $column Column name (string) or index (int) starting with 1 (if ResultSet::FETCHMODE_NUM was used).
return: array value or null if database returned null.

getBoolean($column)   X-Ref
Returns value translated to boolean.
Default is to map 0 => false, 1 => true, but some database drivers may override this behavior.

param: mixed $column Column name (string) or index (int) starting with 1 (if ResultSet::FETCHMODE_NUM was used).
return: boolean value or null if database returned null.

getBlob($column)   X-Ref
Returns Blob with contents of column value.

param: mixed $column Column name (string) or index (int) starting with 1 (if ResultSet::FETCHMODE_NUM was used).
return: Blob New Blob with data from column or null if database returned null.

getClob($column)   X-Ref
Returns Clob with contents of column value.

param: mixed $column Column name (string) or index (int) starting with 1 (if ResultSet::FETCHMODE_NUM was used).
return: Clob New Clob object with data from column or null if database returned null.

getDate($column, $format = '%x')   X-Ref
Return a formatted date.

The default format for dates returned is preferred (in your locale, as specified using setlocale())
format w/o time (i.e. strftime("%x", $val)).  Override this by specifying a format second parameter.  You
can also specify a date()-style formatter; if you do, make sure there are no "%" symbols in your format string.

param: mixed $column Column name (string) or index (int) starting with 1 (if ResultSet::FETCHMODE_NUM was used).
param: string $format Date formatter for use w/ strftime() or date() (it will choose based on examination of format string)
return: mixed  Formatted date, or integer unix timestamp (using 00:00:00 for time) if $format was null.

getFloat($column)   X-Ref
Returns value cast as a float (in PHP this is same as double).

param: mixed $column Column name (string) or index (int) starting with 1 (if ResultSet::FETCHMODE_NUM was used).
return: float value or null if database returned null

getInt($column)   X-Ref
Returns value cast as integer.

param: mixed $column Column name (string) or index (int) starting with 1 (if ResultSet::FETCHMODE_NUM was used).
return: int value or null if database returned null

getString($column)   X-Ref
Returns value cast as string.

param: mixed $column Column name (string) or index (int) starting with 1 (if ResultSet::FETCHMODE_NUM was used).
return: string value or null if database returned null

getTime($column, $format = '%X')   X-Ref
Return a formatted time.

The default format for times returned is preferred (in your locale, as specified using setlocale())
format w/o date (i.e. strftime("%X", $val)).  Override this by specifying a format second parameter.  You
can also specify a date()-style formatter; if you do, make sure there are no "%" symbols in your format string.

param: mixed $column Column name (string) or index (int) starting with 1 (if ResultSet::FETCHMODE_NUM was used).
param: string $format Date formatter for use w/ strftime() or date() (it will choose based on examination of format string)
return: mixed  Formatted time, or integer unix timestamp (using today's date) if $format was null.

getTimestamp($column, $format = 'Y-m-d H:i:s')   X-Ref
Return a formatted timestamp.

The default format for timestamp is ISO standard YYYY-MM-DD HH:MM:SS (i.e. date('Y-m-d H:i:s', $val).
Override this by specifying a format second parameter.  You can also specify a strftime()-style formatter.

Hint: if you want to get the unix timestamp use the "U" formatter string.

param: mixed $column Column name (string) or index (int) starting with 1 (if ResultSet::FETCHMODE_NUM was used).
param: string $format Date formatter for use w/ strftime() or date() (it will choose based on examination of format string)
return: mixed Formatted timestamp, or integer unix timestamp (if $format was null)



Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7