com.mysql.jdbc
Class MysqlIO

java.lang.Object
  extended bycom.mysql.jdbc.MysqlIO

public class MysqlIO
extends java.lang.Object

This class is used by Connection for communicating with the MySQL server.

See Also:
Connection

Field Summary
(package private) static int COMP_HEADER_LENGTH
           
(package private) static int HEADER_LENGTH
           
(package private) static int MIN_COMPRESS_LEN
           
(package private) static int NULL_LENGTH
           
protected  int serverCharsetIndex
           
 
Constructor Summary
protected MysqlIO(java.lang.String host, int port, java.lang.String socketFactoryClassName, java.util.Properties props, Connection conn, int socketTimeout)
          Constructor: Connect to the MySQL server and setup a stream connection.
 
Method Summary
protected  void changeUser(java.lang.String userName, java.lang.String password, java.lang.String database)
          Re-authenticates as the given user and password
protected  void checkForCharsetMismatch()
          Determines if the database charset is the same as the platform charset
(package private)  void closeStreamer(RowData streamer)
           
(package private)  void doHandshake(java.lang.String user, java.lang.String password, java.lang.String database)
          Initialize communications with the MySQL server.
protected  void forceClose()
          Forcibly closes the underlying socket to MySQL.
(package private)  java.lang.String getHost()
          Returns the host this IO is connected to
(package private) static int getMaxBuf()
           
protected  ResultSet getResultSet(long columnCount, int maxRows, int resultSetType, boolean streamResults, java.lang.String catalog)
          Build a result set.
(package private)  int getServerMajorVersion()
          Get the major version of the MySQL server we are talking to.
(package private)  int getServerMinorVersion()
          Get the minor version of the MySQL server we are talking to.
(package private)  int getServerSubMinorVersion()
          Get the sub-minor version of the MySQL server we are talking to.
(package private)  java.lang.String getServerVersion()
          Get the version string of the server we are talking to
(package private)  Buffer getSharedSendPacket()
          Returns the packet used for sending data (used by PreparedStatement) Guarded by external synchronization on a mutex.
protected  boolean hasLongColumnInfo()
          Does the server send back extra column info?
(package private)  byte[][] nextRow(int columnCount)
          Retrieve one row from the MySQL server.
(package private)  void quit()
          Log-off of the MySQL server and close the socket.
(package private)  void resetMaxBuf()
          Sets the buffer size to max-buf
(package private)  Buffer sendCommand(int command, java.lang.String extraData, Buffer queryPacket)
          Send a command to the MySQL server If data is to be sent with command, it should be put in ExtraData Raw packets can be sent by setting QueryPacket to something other than null.
protected  void setProfileSql(boolean flag)
          Should the driver generate SQL statement profiles?
(package private)  ResultSet sqlQuery(java.lang.String query, int maxRows, java.lang.String characterEncoding, Connection conn, int resultSetType, boolean streamResults, java.lang.String catalog)
          Send a query specified in the String "Query" to the MySQL server.
(package private)  ResultSet sqlQueryDirect(Buffer queryPacket, int maxRows, Connection conn, int resultSetType, boolean streamResults, java.lang.String catalog)
          Send a query stored in a packet directly to the server.
protected  Field unpackField(Buffer packet, boolean extractDefaultValues)
          Unpacks the Field information from the given packet.
(package private)  boolean versionMeetsMinimum(int major, int minor, int subminor)
          Does the version of the MySQL server we are connected to meet the given minimums?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_LENGTH

static final int NULL_LENGTH
See Also:
Constant Field Values

COMP_HEADER_LENGTH

static final int COMP_HEADER_LENGTH
See Also:
Constant Field Values

MIN_COMPRESS_LEN

static final int MIN_COMPRESS_LEN
See Also:
Constant Field Values

HEADER_LENGTH

static final int HEADER_LENGTH
See Also:
Constant Field Values

serverCharsetIndex

protected int serverCharsetIndex
Constructor Detail

MysqlIO

protected MysqlIO(java.lang.String host,
                  int port,
                  java.lang.String socketFactoryClassName,
                  java.util.Properties props,
                  Connection conn,
                  int socketTimeout)
           throws java.io.IOException,
                  java.sql.SQLException
Constructor: Connect to the MySQL server and setup a stream connection.

Parameters:
host - the hostname to connect to
port - the port number that the server is listening on
socketFactoryClassName - the socket factory to use
props - the Properties from DriverManager.getConnection()
conn - the Connection that is creating us
socketTimeout - the timeout to set for the socket (0 means no timeout)
Throws:
java.io.IOException - if an IOException occurs during connect.
java.sql.SQLException - if a database access error occurs.
Method Detail

setProfileSql

protected void setProfileSql(boolean flag)
Should the driver generate SQL statement profiles?

Parameters:
flag - should the driver enable profiling?

getResultSet

protected ResultSet getResultSet(long columnCount,
                                 int maxRows,
                                 int resultSetType,
                                 boolean streamResults,
                                 java.lang.String catalog)
                          throws java.lang.Exception
Build a result set. Delegates to buildResultSetWithRows() to build a JDBC-version-specific ResultSet, given rows as byte data, and field information.

Parameters:
columnCount - the number of columns in the result set
maxRows - the maximum number of rows to read (-1 means all rows)
resultSetType - the type of result set (CONCUR_UPDATABLE or READ_ONLY)
streamResults - should the result set be read all at once, or streamed?
catalog - the database name in use when the result set was created
Returns:
a result set
Throws:
java.lang.Exception - if a database access error occurs

forceClose

protected final void forceClose()
Forcibly closes the underlying socket to MySQL.


changeUser

protected void changeUser(java.lang.String userName,
                          java.lang.String password,
                          java.lang.String database)
                   throws java.sql.SQLException
Re-authenticates as the given user and password

Parameters:
userName - DOCUMENT ME!
password - DOCUMENT ME!
Throws:
java.sql.SQLException - DOCUMENT ME!

hasLongColumnInfo

protected boolean hasLongColumnInfo()
Does the server send back extra column info?

Returns:
true if so

unpackField

protected final Field unpackField(Buffer packet,
                                  boolean extractDefaultValues)
                           throws java.sql.SQLException
Unpacks the Field information from the given packet. Understands pre 4.1 and post 4.1 server version field packet structures.

Parameters:
packet - the packet containing the field information
extractDefaultValues - should default values be extracted?
Returns:
the unpacked field
Throws:
java.sql.SQLException

checkForCharsetMismatch

protected void checkForCharsetMismatch()
Determines if the database charset is the same as the platform charset


getMaxBuf

static int getMaxBuf()

getServerMajorVersion

final int getServerMajorVersion()
Get the major version of the MySQL server we are talking to.

Returns:
DOCUMENT ME!

getServerMinorVersion

final int getServerMinorVersion()
Get the minor version of the MySQL server we are talking to.

Returns:
DOCUMENT ME!

getServerSubMinorVersion

final int getServerSubMinorVersion()
Get the sub-minor version of the MySQL server we are talking to.

Returns:
DOCUMENT ME!

getServerVersion

java.lang.String getServerVersion()
Get the version string of the server we are talking to

Returns:
DOCUMENT ME!

doHandshake

void doHandshake(java.lang.String user,
                 java.lang.String password,
                 java.lang.String database)
           throws java.sql.SQLException
Initialize communications with the MySQL server. Handles logging on, and handling initial connection errors.

Parameters:
user - DOCUMENT ME!
password - DOCUMENT ME!
database - DOCUMENT ME!
Throws:
java.sql.SQLException - DOCUMENT ME!
java.sql.SQLException - DOCUMENT ME!

nextRow

final byte[][] nextRow(int columnCount)
                throws java.lang.Exception
Retrieve one row from the MySQL server. Note: this method is not thread-safe, but it is only called from methods that are guarded by synchronizing on this object.

Parameters:
columnCount - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.Exception - DOCUMENT ME!

quit

final void quit()
         throws java.sql.SQLException
Log-off of the MySQL server and close the socket.

Throws:
java.sql.SQLException - DOCUMENT ME!

getSharedSendPacket

Buffer getSharedSendPacket()
Returns the packet used for sending data (used by PreparedStatement) Guarded by external synchronization on a mutex.

Returns:
A packet to send data with

closeStreamer

void closeStreamer(RowData streamer)
             throws java.sql.SQLException
Throws:
java.sql.SQLException

resetMaxBuf

void resetMaxBuf()
Sets the buffer size to max-buf


sendCommand

final Buffer sendCommand(int command,
                         java.lang.String extraData,
                         Buffer queryPacket)
                  throws java.lang.Exception
Send a command to the MySQL server If data is to be sent with command, it should be put in ExtraData Raw packets can be sent by setting QueryPacket to something other than null.

Parameters:
command - DOCUMENT ME!
extraData - DOCUMENT ME!
queryPacket - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.Exception - DOCUMENT ME!
java.sql.SQLException - DOCUMENT ME!

sqlQuery

final ResultSet sqlQuery(java.lang.String query,
                         int maxRows,
                         java.lang.String characterEncoding,
                         Connection conn,
                         int resultSetType,
                         boolean streamResults,
                         java.lang.String catalog)
                  throws java.lang.Exception
Send a query specified in the String "Query" to the MySQL server. This method uses the specified character encoding to get the bytes from the query string.

Parameters:
query - DOCUMENT ME!
maxRows - DOCUMENT ME!
characterEncoding - DOCUMENT ME!
conn - DOCUMENT ME!
resultSetType - DOCUMENT ME!
streamResults - DOCUMENT ME!
catalog - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.Exception - DOCUMENT ME!

sqlQueryDirect

final ResultSet sqlQueryDirect(Buffer queryPacket,
                               int maxRows,
                               Connection conn,
                               int resultSetType,
                               boolean streamResults,
                               java.lang.String catalog)
                        throws java.lang.Exception
Send a query stored in a packet directly to the server.

Parameters:
queryPacket - DOCUMENT ME!
maxRows - DOCUMENT ME!
conn - DOCUMENT ME!
resultSetType - DOCUMENT ME!
streamResults - DOCUMENT ME!
catalog - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.Exception - DOCUMENT ME!

getHost

java.lang.String getHost()
Returns the host this IO is connected to

Returns:
DOCUMENT ME!

versionMeetsMinimum

boolean versionMeetsMinimum(int major,
                            int minor,
                            int subminor)
Does the version of the MySQL server we are connected to meet the given minimums?

Parameters:
major - DOCUMENT ME!
minor - DOCUMENT ME!
subminor - DOCUMENT ME!
Returns:
DOCUMENT ME!