creole.common
[ class tree: creole.common ] [ index: creole.common ] [ all elements ]

Class: StatementCommon

Source Location: /creole/common/StatementCommon.php

Class Overview


Class that contains common/shared functionality for Statements.


Author(s):

Version:

  • $Revision: 1.4 $

Variables

Methods


Child classes:

MSSQLStatement
Class that contains MSSQL functionality for Statements.
MySQLStatement
MySQL Statement
ODBCStatement
ODBC Statement
OCI8Statement
Oracle (OCI8) Statement implementation.
PgSQLStatement
PostgreSQL Statement implementation.
SQLiteStatement
SQLite Statement

Class Details

[line 29]
Class that contains common/shared functionality for Statements.



Tags:

abstract:  
version:  $Revision: 1.4 $
author:  Hans Lellelid <hans@xmpl.org>


[ Top ]


Class Variables

$conn =

[line 35]

The database connection.



Tags:

access:  protected

Type:   Connection


[ Top ]

$limit =  0

[line 71]

Max rows to retrieve from DB.



Tags:

access:  protected

Type:   int


[ Top ]

$offset =  0

[line 78]

Offset at which to start processing DB rows.

"Skip X rows"




Tags:

access:  protected

Type:   int


[ Top ]

$resultClass =

[line 59]

The ResultSet class name.



Tags:

access:  protected

Type:   string


[ Top ]

$resultSet =

[line 41]

Temporarily hold a ResultSet object after an execute() query.



Tags:

access:  protected

Type:   ResultSet


[ Top ]

$stmt =

[line 65]

The prepared statement resource id.



Tags:

access:  protected

Type:   resource


[ Top ]

$updateCount =

[line 47]

Temporary hold the affected row cound after an execute() query.



Tags:

access:  protected

Type:   int


[ Top ]

$warnings = array()

[line 53]

Array of warning objects generated by methods performed on result set.



Tags:

var:  SQLWarning[]
access:  protected

Type:   array


[ Top ]



Class Methods


constructor __construct [line 85]

StatementCommon __construct( Connection $conn)

Create new statement instance.



Parameters:

Connection   $conn   Connection object

[ Top ]

method close [line 141]

void close( )

Free resources associated with this statement.

Some drivers will need to implement this method to free database result resources.




Tags:

access:  public


[ Top ]

method execute [line 157]

boolean execute( mixed $sql, [int $fetchmode = null])

Generic execute() function has to check to see whether SQL is an update or select query.

If you already know whether it's a SELECT or an update (manipulating) SQL, then use the appropriate method, as this one will incurr overhead to check the SQL.




Tags:

return:  True if it is a result set, false if not or if no more results (this is identical to JDBC return val).
access:  public
todo:  -cStatementCommon Update execute() to not use isSelect() method, but rather to determine type based on returned results.
throws:  SQLException


Parameters:

int   $fetchmode   Fetchmode (only applies to queries).

[ Top ]

method executeQuery [line 236]

object Creole::ResultSet executeQuery( string $sql, [int $fetchmode = null])

Executes the SQL query in this PreparedStatement object and returns the resultset generated by the query.



Tags:

access:  public
todo:  -cStatementCommon Put native query execution logic in statement subclasses.
throws:  SQLException If there is an error executing the specified query.


Overridden in child classes as:

MSSQLStatement::executeQuery()
Executes the SQL query in this PreparedStatement object and returns the resultset generated by the query.
ODBCStatement::executeQuery()

Parameters:

string   $sql   This method may optionally be called with the SQL statement.
int   $fetchmode   The mode to use when fetching the results (e.g. ResultSet::FETCHMODE_NUM, ResultSet::FETCHMODE_ASSOC).

[ Top ]

method executeUpdate [line 253]

int executeUpdate( string $sql)

Executes the SQL INSERT, UPDATE, or DELETE statement in this PreparedStatement object.



Tags:

return:  Number of affected rows (or 0 for drivers that return nothing).
access:  public
throws:  SQLException if a database access error occurs.


Parameters:

string   $sql   This method may optionally be called with the SQL statement.

[ Top ]

method getConnection [line 285]

Connection getConnection( )

Gets the db Connection that created this statement.



Tags:

access:  public


[ Top ]

method getLimit [line 106]

int getLimit( )

Returns the maximum number of rows to return or 0 for all.



Tags:

access:  public


[ Top ]

method getMoreResults [line 274]

boolean getMoreResults( )

Gets next result set (if this behavior is supported by driver).

Some drivers (e.g. MSSQL) support returning multiple result sets -- e.g. from stored procedures.

This function also closes any current restult set.

Default behavior is for this function to return false. Driver-specific implementations of this class can override this method if they actually support multiple result sets.




Tags:

return:  True if there is another result set, otherwise false.
access:  public


Overridden in child classes as:

MSSQLStatement::getMoreResults()
Gets next result set (if this behavior is supported by driver).

[ Top ]

method getOffset [line 129]

int getOffset( )

Returns the start row.

Offset only applies when Limit is set!




Tags:

access:  public


[ Top ]

method getResultSet [line 179]

RestultSet getResultSet( )

Get result set.

This assumes that the last thing done was an executeQuery() or an execute() with SELECT-type query.




Tags:

return:  (or null if none)
access:  public


[ Top ]

method getUpdateCount [line 189]

int getUpdateCount( )

Get update count.



Tags:

return:  Number of records affected, or
  1. null
if not applicable.
access:  public


[ Top ]

method isSelect [line 219]

boolean isSelect( string $sql)

Returns whether the passed SQL is a SELECT statement.

Returns true if SQL starts with 'SELECT' but not 'SELECT INTO'. This exists to support the execute() function -- which could either execute an update or a query.

Currently this function does not take into consideration comments, primarily because there are a number of different comment options for different drivers:

     -- SQL-defined comment, but not truly comment in Oracle
  # comment in mysql
  /* comment in mssql, others * /
  // comment sometimes?
  REM also comment ...

If you're wondering why we can't just execute the query and look at the return results to see whether it was an update or a select, the reason is that for update queries we need to do stuff before we execute them -- like start transactions if auto-commit is off.




Tags:

return:  Whether statement is a SELECT SQL statement.
access:  protected
see:  StatementCommon::execute()


Parameters:

string   $sql  

[ Top ]

method setLimit [line 97]

void setLimit( int $v)

Sets the maximum number of rows to return from db.

This will affect the SQL if the RDBMS supports native LIMIT; if not, it will be emulated. Limit only applies to queries (not update sql).




Tags:

access:  public


Parameters:

int   $v   Maximum number of rows or 0 for all rows.

[ Top ]

method setOffset [line 119]

void setOffset( int $v)

Sets the start row.

This will affect the SQL if the RDBMS supports native OFFSET; if not, it will be emulated. Offset only applies to queries (not update) and only is evaluated when LIMIT is set!




Tags:

access:  public


Parameters:

int   $v  

[ Top ]


Documentation generated on Mon, 23 Aug 2004 21:53:22 -0400 by phpDocumentor 1.3.0RC3