com.caucho.quercus.lib.db
Class JdbcStatementResource

java.lang.Object
  extended by com.caucho.quercus.lib.db.JdbcStatementResource
Direct Known Subclasses:
MysqliStatement, OracleStatement, PostgresStatement

public class JdbcStatementResource
extends java.lang.Object

Represents a JDBC Statement value.


Constructor Summary
JdbcStatementResource(JdbcConnectionResource connV)
          Constructor for JdbcStatementResource
 
Method Summary
protected  boolean bindParams(Env env, java.lang.String types, Value[] params)
          Creates _types and _params array for this prepared statement.
 boolean bindResults(Env env, Value[] outParams)
          Associate (bind) columns in the result set to variables.
 void close()
          Closes the result set, if any, and closes this statement.
protected  boolean dataSeek(int offset)
          Advance the cursor the number of rows given by offset.
 int errorCode()
          Returns the error number for the last error.
 java.lang.String errorMessage()
          Returns the error message for the last error.
 boolean execute(Env env)
          Executes a prepared Query.
protected  boolean executeStatement()
          Executes underlying statement Known subclasses: see PostgresStatement.execute
 Value fetch(Env env)
          Fetch results from a prepared statement into bound variables.
 boolean freeResult()
          Frees the associated result.
 int getFieldCount()
          Returns the number of fields in the result set.
protected  java.sql.Connection getJavaConnection()
          Returns the underlying SQL connection associated to this statement.
protected  java.sql.ResultSetMetaData getMetaData()
          Returns the meta data for corresponding to the current result set.
 int getNumRows()
          Returns the number of rows in the result set.
protected  Value getParam(int i)
          Returns a parameter value Known subclasses: see PostgresStatement.execute
protected  int getParamLength()
          Returns the number of parameters available to binding Known subclasses: see PostgresStatement.execute
protected  java.sql.PreparedStatement getPreparedStatement()
          Returns the internal prepared statement.
 JdbcResultResource getResultMetadata()
          Resets _fieldOffset in _resultResource
protected  java.sql.ResultSet getResultSet()
          Returns the internal result set.
 java.lang.String getStatementType()
          Returns this statement type.
 int paramCount()
          Counts the number of parameter markers in the query string.
 boolean prepare(Env env, StringValue query)
          Prepares this statement with the given query.
 boolean prepareStatement(Env env, java.lang.String query)
          Prepares statement with the given query.
protected  void setObject(int i, java.lang.Object param)
          Sets the given parameter Known subclasses: see PostgresStatement.execute
protected  void setPreparedStatement(java.sql.PreparedStatement stmt)
          Changes the internal statement.
protected  void setResultSet(java.sql.ResultSet rs)
          Changes the internal result set.
 java.lang.String toString()
          Returns a string representation for this object.
 JdbcConnectionResource validateConnection()
          Validates the connection resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JdbcStatementResource

public JdbcStatementResource(JdbcConnectionResource connV)
Constructor for JdbcStatementResource

Parameters:
connV - a JdbcConnectionResource connection
Method Detail

bindParams

protected boolean bindParams(Env env,
                             java.lang.String types,
                             Value[] params)
Creates _types and _params array for this prepared statement.

Parameters:
types - = string of i,d,s,b (ie: "idds")
params - = array of values (probably Vars)
Returns:
true on success ir false on failure

bindResults

public boolean bindResults(Env env,
                           Value[] outParams)
Associate (bind) columns in the result set to variables.

NB: we assume that the statement has been executed and compare the # of outParams w/ the # of columns in the resultset because we cannot know in advance how many columns "SELECT * FROM TableName" can return.

PHP 5.0 seems to provide some rudimentary checking on # of outParams even before the statement has been executed and only issues a warning in the case of "SELECT * FROM TableName".

Our implementation REQUIRES the execute happen first.

Parameters:
env - the PHP executing environment
outParams - the output variables
Returns:
true on success or false on failure

close

public void close()
Closes the result set, if any, and closes this statement.


dataSeek

protected boolean dataSeek(int offset)
Advance the cursor the number of rows given by offset.

Parameters:
offset - the number of rows to move the cursor
Returns:
true on success or false on failure

errorCode

public int errorCode()
Returns the error number for the last error.

Returns:
the error number

errorMessage

public java.lang.String errorMessage()
Returns the error message for the last error.

Returns:
the error message

execute

public boolean execute(Env env)
Executes a prepared Query.

Parameters:
env - the PHP executing environment
Returns:
true on success or false on failure

executeStatement

protected boolean executeStatement()
                            throws java.sql.SQLException
Executes underlying statement Known subclasses: see PostgresStatement.execute

Throws:
java.sql.SQLException

fetch

public Value fetch(Env env)
Fetch results from a prepared statement into bound variables.

Returns:
true on success, false on error, null if no more rows

freeResult

public boolean freeResult()
Frees the associated result.

Returns:
true on success or false on failure

getMetaData

protected java.sql.ResultSetMetaData getMetaData()
                                          throws java.sql.SQLException
Returns the meta data for corresponding to the current result set.

Returns:
the result set meta data
Throws:
java.sql.SQLException

getNumRows

public int getNumRows()
               throws java.sql.SQLException
Returns the number of rows in the result set.

Returns:
the number of rows in the result set
Throws:
java.sql.SQLException

getPreparedStatement

protected java.sql.PreparedStatement getPreparedStatement()
Returns the internal prepared statement.

Returns:
the internal prepared statement

getResultMetadata

public JdbcResultResource getResultMetadata()
Resets _fieldOffset in _resultResource

Returns:
null if _resultResource == null, otherwise _resultResource

getResultSet

protected java.sql.ResultSet getResultSet()
Returns the internal result set.

Returns:
the internal result set

getJavaConnection

protected java.sql.Connection getJavaConnection()
                                         throws java.sql.SQLException
Returns the underlying SQL connection associated to this statement.

Throws:
java.sql.SQLException

getStatementType

public java.lang.String getStatementType()
Returns this statement type.

Returns:
this statement type: SELECT, UPDATE, DELETE, INSERT, CREATE, DROP, ALTER, BEGIN, DECLARE, or UNKNOWN.

paramCount

public int paramCount()
Counts the number of parameter markers in the query string.

Returns:
the number of parameter markers in the query string

prepare

public boolean prepare(Env env,
                       StringValue query)
Prepares this statement with the given query.

Parameters:
query - SQL query
Returns:
true on success or false on failure

prepareStatement

public boolean prepareStatement(Env env,
                                java.lang.String query)
Prepares statement with the given query.

Parameters:
query - SQL query
Returns:
true on success or false on failure

getParam

protected Value getParam(int i)
Returns a parameter value Known subclasses: see PostgresStatement.execute


getParamLength

protected int getParamLength()
Returns the number of parameters available to binding Known subclasses: see PostgresStatement.execute


setPreparedStatement

protected void setPreparedStatement(java.sql.PreparedStatement stmt)
Changes the internal statement.


setResultSet

protected void setResultSet(java.sql.ResultSet rs)
Changes the internal result set.


getFieldCount

public int getFieldCount()
Returns the number of fields in the result set.

Parameters:
env - the PHP executing environment
Returns:
the number of fields in the result set

setObject

protected void setObject(int i,
                         java.lang.Object param)
                  throws java.lang.Exception
Sets the given parameter Known subclasses: see PostgresStatement.execute

Throws:
java.lang.Exception

toString

public java.lang.String toString()
Returns a string representation for this object.

Overrides:
toString in class java.lang.Object
Returns:
the string representation for this object

validateConnection

public JdbcConnectionResource validateConnection()
Validates the connection resource.

Returns:
the validated connection resource