📄 tdsstatement.java
字号:
// }
// SAfe And now, keep consuming data and hope the server cancels
// this as soon as possible (I'm not so sure, however, that
// this will happen; I think that even if the data amount is
// huge, the server sends it as soon as possible so the cancel
// could come too late; or not?)
while( getMoreResults(actTds, warningChain, false) || updateCount!=-1 );
}
}
/**
* In many cases, it is desirable to immediately release a
* Statement's database and JDBC resources instead of waiting
* for this to happen when it is automatically closed. The
* close method provides this immediate release.
*
* <p><B>Note:</B> A Statement is automatically closed when it is
* garbage collected. When a Statement is closed, its current
* ResultSet, if one exists, is also closed.
*
* @exception SQLException if a database access error occurs (why?)
*/
public synchronized void close() throws SQLException
{
if( isClosed )
return;
// SAfe Mark Statement as closed internally, too
isClosed = true;
// MJH MarkAsClosed is always called to prevent memory leak.
connection.markAsClosed(this);
if( actTds != null )
// Tds not yet released.
try
{
// SAfe: Must do this to ensure no garbage is left behind
skipToEnd();
// MJH Do not Rollback any pending transactions!
connection.freeTds(actTds);
actTds = null;
}
catch( net.sourceforge.jtds.jdbc.TdsException e )
{
throw new SQLException(e.toString());
}
}
/**
* The maxFieldSize limit (in bytes) is the maximum amount of
* data returned for any column value; it only applies to
* BINARY, VARBINARY, LONGVARBINARY, CHAR, VARCHAR and LONGVARCHAR
* columns. If the limit is exceeded, the excess data is silently
* discarded.
*
* @return the current max column size limit; zero means unlimited
* @exception SQLException if a database access error occurs
*/
public synchronized int getMaxFieldSize() throws SQLException
{
checkClosed();
return maxFieldSize;
}
/**
* Sets the maxFieldSize
*
* @param max the new max column size limit; zero means unlimited
* @exception SQLException if size exceeds buffer size
*/
public synchronized void setMaxFieldSize(int max) throws SQLException
{
checkClosed();
maxFieldSize = max;
}
/**
* The maxRows limit is set to limit the number of rows that
* any ResultSet can contain. If the limit is exceeded, the
* excess rows are silently dropped.
*
* @return the current maximum row limit; zero means unlimited
* @exception SQLException if a database access error occurs
*/
public synchronized int getMaxRows() throws SQLException
{
checkClosed();
return maxRows;
}
/**
* Set the maximum number of rows
*
* @param max the new max rows limit; zero means unlimited
* @exception SQLException if a database access error occurs
* @see #getMaxRows
*/
public synchronized void setMaxRows(int max) throws SQLException
{
checkClosed();
if( maxRows < 0 )
throw new SQLException("Negative row count");
maxRows = max;
}
/**
* If escape scanning is on (the default), the driver will do escape
* substitution before sending the SQL to the database.
*
* @param enable true to enable; false to disable
* @exception SQLException if a database access error occurs
*/
public synchronized void setEscapeProcessing(boolean enable) throws SQLException
{
checkClosed();
escapeProcessing = enable;
}
/**
* The queryTimeout limit is the number of seconds the driver
* will wait for a Statement to execute. If the limit is
* exceeded, a SQLException is thrown.
*
* @return the current query timeout limit in seconds; 0 = unlimited
* @exception SQLException if a database access error occurs
*/
public synchronized int getQueryTimeout() throws SQLException
{
checkClosed();
return timeout;
}
/**
* Sets the queryTimeout limit
*
* @param seconds - the new query timeout limit in seconds
* @exception SQLException if a database access error occurs
*/
public synchronized void setQueryTimeout(int seconds) throws SQLException
{
checkClosed();
timeout = seconds;
}
/**
*
* @exception SQLException
*/
public void cancel() throws SQLException
{
checkClosed();
try
{
if( actTds != null )
actTds.cancel();
}
catch(net.sourceforge.jtds.jdbc.TdsException e)
{
throw new SQLException(e.getMessage());
}
catch(java.io.IOException e)
{
throw new SQLException(e.getMessage());
}
}
/**
* The first warning reported by calls on this Statement is
* returned. A Statement's execute methods clear its SQLWarning
* chain. Subsequent Statement warnings will be chained to this
* SQLWarning.
*
* <p>The Warning chain is automatically cleared each time a statement
* is (re)executed.
*
* <p><B>Note:</B> If you are processing a ResultSet then any warnings
* associated with ResultSet reads will be chained on the ResultSet
* object.
*
* @return the first SQLWarning on null
* @exception SQLException if a database access error occurs
*/
public synchronized SQLWarning getWarnings() throws SQLException
{
checkClosed();
return warningChain.getWarnings();
}
/**
* After this call, getWarnings returns null until a new warning
* is reported for this Statement.
*
* @exception SQLException if a database access error occurs (why?)
*/
public synchronized void clearWarnings() throws SQLException
{
checkClosed();
warningChain.clearWarnings();
}
/**
* setCursorName defines the SQL cursor name that will be used by
* subsequent execute methods. This name can then be used in SQL
* positioned update/delete statements to identify the current row
* in the ResultSet generated by this statement. If a database
* doesn't support positioned update/delete, this method is a
* no-op.
*
* @param name the new cursor name
* @exception SQLException if a database access error occurs
*/
public void setCursorName(String name) throws SQLException
{
// SAfe As the javadoc above says, this should be a no-op.
}
public synchronized boolean execute(String sql) throws SQLException
{
checkClosed();
return internalExecute(sql);
}
synchronized Tds getTds(boolean mainTds) throws SQLException
{
// SAfe If the main Tds is requested, then simply return it
if( mainTds )
return connection.allocateTds(mainTds);
// SAfe Else, find one and assign it to this Statement
if( actTds == null )
{
actTds=connection.allocateTds(mainTds);
actTds.setStatement(this);
return actTds;
}
else
return actTds;
}
/**
* getResultSet returns the current result as a ResultSet. It
* should only be called once per result.
*
* @return the current result set; null if there are no more
* @exception SQLException if a database access error occurs
*/
public synchronized java.sql.ResultSet getResultSet() throws SQLException
{
checkClosed();
return results;
}
/**
* getUpdateCount returns the current result as an update count,
* if the result is a ResultSet or there are no more results, -1
* is returned. It should only be called once per result.
*
* @return the current result as an update count.
* @exception SQLException if a database access error occurs
*/
public synchronized int getUpdateCount() throws SQLException
{
checkClosed();
return updateCount;
}
/**
* getMoreResults moves to a Statement's next result. If it returns
* true, this result is a ResulSet.
*
* @return true if the next ResultSet is valid
* @exception SQLException if a database access error occurs
*/
public synchronized boolean getMoreResults() throws SQLException
{
checkClosed();
return getMoreResults(actTds, warningChain, true);
}
public boolean getMoreResults(int current) throws SQLException
{
throw new SQLException("Not Implemented");
}
void handleRetStat(PacketRetStatResult packet)
{
}
void handleParamResult(PacketOutputParamResult packet)
throws SQLException
{
}
synchronized boolean getMoreResults(Tds tds, SQLWarningChain wChain, boolean allowTdsRelease)
throws SQLException
{
updateCount = -1;
if( tds == null )
return false;
// Reset all internal variables (do it before checking for more results)
closeResults(false);
if( !tds.moreResults() )
{
if( allowTdsRelease )
releaseTds();
return false;
}
try
{
// Keep eating garbage and warnings until we reach the next result
while( true )
{
if( tds.isResultSet() )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -