com.caucho.quercus.lib.db
Class JdbcConnectionResource

java.lang.Object
  extended by com.caucho.quercus.lib.db.JdbcConnectionResource
All Implemented Interfaces:
EnvCleanup
Direct Known Subclasses:
Mysqli, Oracle, Postgres

public abstract class JdbcConnectionResource
extends java.lang.Object
implements EnvCleanup

Represents a JDBC Connection value.


Nested Class Summary
protected static class JdbcConnectionResource.SqlParseToken
           
 
Field Summary
protected  ConnectionEntry _conn
           
protected  java.lang.String _driver
           
protected  int _flags
           
protected  java.lang.String _host
           
protected  int _port
           
protected  java.lang.String _socket
           
protected  JdbcConnectionResource.SqlParseToken _sqlParseToken
           
protected  java.lang.String _url
           
protected static java.lang.String ENCODING
           
 
Constructor Summary
JdbcConnectionResource(Env env)
           
 
Method Summary
 void cleanup()
          Implements the EnvCleanup interface.
protected  void clearErrors()
           
 boolean close(Env env)
          Closes the connection.
 void closeStatement(java.sql.Statement stmt)
           
 boolean commit()
          commits the transaction of the current connection
protected abstract  ConnectionEntry connectImpl(Env env, java.lang.String host, java.lang.String userName, java.lang.String password, java.lang.String dbname, int port, java.lang.String socket, int flags, java.lang.String driver, java.lang.String url, boolean isNewLink)
          Connects to the underlying database.
protected  boolean connectInternal(Env env, java.lang.String host, java.lang.String userName, java.lang.String password, java.lang.String dbname, int port, java.lang.String socket, int flags, java.lang.String driver, java.lang.String url, boolean isNewLink)
          Set the current underlying connection and corresponding information: host, port and database name.
protected  JdbcResultResource createResult(Env env, java.sql.Statement stmt, java.sql.ResultSet rs)
          Creates a database-specific result.
 StringValue error(Env env)
          Returns the error string for the most recent function call.
 int getAffectedRows()
          Returns the affected rows from the last query.
protected  Value getCatalog()
           
protected  JdbcResultResource getCatalogs()
          Returns JdbcResultResource of available databases
 java.lang.String getCharacterSetName()
          Returns the client encoding.
 java.lang.String getClientEncoding()
          Alias for getCharacterSetName
 java.lang.String getClientInfo()
          Deprecated.  
 java.sql.Connection getConnection(Env env)
          Returns the connection
 java.lang.String getDbName()
           
 java.lang.String getDriver()
           
 Env getEnv()
           
 int getErrorCode()
          Returns the last error code.
 java.lang.String getErrorMessage()
          Returns the last error message.
 int getFieldCount()
           
 java.lang.String getHost()
           
 java.lang.String getHostInfo()
          returns the URL string for the given connection IE: jdbc:mysql://localhost:3306/test XXX: PHP returns Localhost via UNIX socket
protected  java.sql.Connection getJavaConnection()
          Returns the unwrapped SQL connection associated to this statement.
 java.lang.String getPassword()
           
 int getPort()
           
protected  JdbcResultResource getResultResource()
          Get the current result resource
 java.lang.String getServerInfo()
          returns the server version
 JdbcTableMetaData getTableMetaData(Env env, java.lang.String catalog, java.lang.String schema, java.lang.String table)
          Returns the table metadata.
 java.lang.String getUrl()
           
 java.lang.String getURL()
          Returns the data source.
 java.lang.String getUserName()
           
protected  java.sql.SQLWarning getWarnings()
          This function was added for PostgreSQL pg_last_notice
 boolean isConnected()
           
protected  boolean isSeekable()
          Returns true if this connection supports TYPE_SCROLL_INSENSITIVE.
protected  void keepResourceValues(java.sql.Statement stmt)
          This function is overriden in Postgres to keep result set references for php/430a (see also php/1f33)
protected  boolean keepStatementOpen()
          This function is overriden in Postgres to keep statement references for php/430a
protected  JdbcConnectionResource.SqlParseToken parseSqlToken(java.lang.String sql, JdbcConnectionResource.SqlParseToken prevToken)
          Parse a token from a string containing a SQL statement.
 boolean ping(Env env)
          Pings the database
protected  StringValue realEscapeString(StringValue str)
          Escape the given string for SQL statements.
protected  Value realQuery(Env env, java.lang.String sql)
          Execute a single query.
 boolean rollback()
          rolls the current transaction back NOTE: quercus doesn't seem to support the idea of savepoints
protected  void saveErrors(java.sql.SQLException e)
           
 void setAffectedRows(int i)
           
 boolean setAutoCommit(boolean mode)
          sets auto-commmit to true or false
 void setCatalog(java.lang.String name)
          Sets the catalog
 boolean setClientEncoding(java.lang.String encoding)
          Set encoding on the client side of the connection.
protected  void setResultResource(JdbcResultResource rs)
          Set the current result resource
protected  void setWarnings(java.sql.SQLWarning warnings)
          Set the current SQL warnings.
 java.lang.Object toObject()
          Converts to an object.
 java.lang.String toString()
          Converts to a string.
 JdbcConnectionResource validateConnection()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_conn

protected ConnectionEntry _conn

_host

protected java.lang.String _host

_port

protected int _port

_driver

protected java.lang.String _driver

_url

protected java.lang.String _url

_flags

protected int _flags

_socket

protected java.lang.String _socket

_sqlParseToken

protected JdbcConnectionResource.SqlParseToken _sqlParseToken

ENCODING

protected static final java.lang.String ENCODING
See Also:
Constant Field Values
Constructor Detail

JdbcConnectionResource

public JdbcConnectionResource(Env env)
Method Detail

error

public StringValue error(Env env)
Returns the error string for the most recent function call. This method is not invoked from PHP code.


isConnected

public boolean isConnected()

getEnv

public Env getEnv()

getHost

public java.lang.String getHost()

getUserName

public java.lang.String getUserName()

getPassword

public java.lang.String getPassword()

getDbName

public java.lang.String getDbName()

getPort

public int getPort()

getDriver

public java.lang.String getDriver()

getUrl

public java.lang.String getUrl()

connectInternal

protected final boolean connectInternal(Env env,
                                        java.lang.String host,
                                        java.lang.String userName,
                                        java.lang.String password,
                                        java.lang.String dbname,
                                        int port,
                                        java.lang.String socket,
                                        int flags,
                                        java.lang.String driver,
                                        java.lang.String url,
                                        boolean isNewLink)
Set the current underlying connection and corresponding information: host, port and database name.

Parameters:
host - server host
port - server port
dbname - database name

connectImpl

protected abstract ConnectionEntry connectImpl(Env env,
                                               java.lang.String host,
                                               java.lang.String userName,
                                               java.lang.String password,
                                               java.lang.String dbname,
                                               int port,
                                               java.lang.String socket,
                                               int flags,
                                               java.lang.String driver,
                                               java.lang.String url,
                                               boolean isNewLink)
Connects to the underlying database.


realEscapeString

protected StringValue realEscapeString(StringValue str)
Escape the given string for SQL statements.

Parameters:
str - a string
Returns:
the string escaped for SQL statements

getAffectedRows

public int getAffectedRows()
Returns the affected rows from the last query.


setAffectedRows

public void setAffectedRows(int i)

getFieldCount

public int getFieldCount()
Returns:
_fieldCount

getCatalogs

protected JdbcResultResource getCatalogs()
Returns JdbcResultResource of available databases


getCatalog

protected Value getCatalog()
Returns:
current catalog or false if error

getCharacterSetName

public java.lang.String getCharacterSetName()
Returns the client encoding. XXX: stubbed out. has to be revised once we figure out what to do with character encoding


getClientEncoding

public java.lang.String getClientEncoding()
Alias for getCharacterSetName


setClientEncoding

public boolean setClientEncoding(java.lang.String encoding)
Set encoding on the client side of the connection. Return true if the encoding was set, otherwise false.


getClientInfo

public java.lang.String getClientInfo()
Deprecated. 

Returns the client version


getConnection

public final java.sql.Connection getConnection(Env env)
Returns the connection


getJavaConnection

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

Throws:
java.sql.SQLException

getURL

public java.lang.String getURL()
Returns the data source.


getErrorCode

public int getErrorCode()
Returns the last error code.


getErrorMessage

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


getHostInfo

public java.lang.String getHostInfo()
                             throws java.sql.SQLException
returns the URL string for the given connection IE: jdbc:mysql://localhost:3306/test XXX: PHP returns Localhost via UNIX socket

Throws:
java.sql.SQLException

getServerInfo

public java.lang.String getServerInfo()
                               throws java.sql.SQLException
returns the server version

Throws:
java.sql.SQLException

getTableMetaData

public JdbcTableMetaData getTableMetaData(Env env,
                                          java.lang.String catalog,
                                          java.lang.String schema,
                                          java.lang.String table)
                                   throws java.sql.SQLException
Returns the table metadata.

Throws:
java.sql.SQLException

closeStatement

public void closeStatement(java.sql.Statement stmt)

close

public boolean close(Env env)
Closes the connection.


cleanup

public void cleanup()
Implements the EnvCleanup interface. This method will deallocate resources associated with this connection. This method can be invoked via a call to close(), or it can be invoked when the environment is being cleaned up after a quercus request has been processed.

Specified by:
cleanup in interface EnvCleanup

validateConnection

public JdbcConnectionResource validateConnection()

realQuery

protected Value realQuery(Env env,
                          java.lang.String sql)
Execute a single query.


parseSqlToken

protected JdbcConnectionResource.SqlParseToken parseSqlToken(java.lang.String sql,
                                                             JdbcConnectionResource.SqlParseToken prevToken)
Parse a token from a string containing a SQL statement. If the prevToken is null, then the first token in parsed. If a SQL token can't be found in the string, then null is returned. If a SQL token is found, data is captured in the returned SqlParseToken result.


createResult

protected JdbcResultResource createResult(Env env,
                                          java.sql.Statement stmt,
                                          java.sql.ResultSet rs)
Creates a database-specific result.


setAutoCommit

public boolean setAutoCommit(boolean mode)
sets auto-commmit to true or false


commit

public boolean commit()
commits the transaction of the current connection


rollback

public boolean rollback()
rolls the current transaction back NOTE: quercus doesn't seem to support the idea of savepoints


setCatalog

public void setCatalog(java.lang.String name)
                throws java.sql.SQLException
Sets the catalog

Throws:
java.sql.SQLException

toObject

public java.lang.Object toObject()
Converts to an object.


toString

public java.lang.String toString()
Converts to a string.

Overrides:
toString in class java.lang.Object

keepResourceValues

protected void keepResourceValues(java.sql.Statement stmt)
This function is overriden in Postgres to keep result set references for php/430a (see also php/1f33)


keepStatementOpen

protected boolean keepStatementOpen()
This function is overriden in Postgres to keep statement references for php/430a


getResultResource

protected JdbcResultResource getResultResource()
Get the current result resource


setResultResource

protected void setResultResource(JdbcResultResource rs)
Set the current result resource


getWarnings

protected java.sql.SQLWarning getWarnings()
This function was added for PostgreSQL pg_last_notice

Returns:
warning messages

ping

public boolean ping(Env env)
Pings the database


setWarnings

protected void setWarnings(java.sql.SQLWarning warnings)
Set the current SQL warnings.

Parameters:
warnings - the new SQL warnings

clearErrors

protected void clearErrors()

saveErrors

protected void saveErrors(java.sql.SQLException e)

isSeekable

protected boolean isSeekable()
Returns true if this connection supports TYPE_SCROLL_INSENSITIVE. http://bugs.caucho.com/view.php?id=3746