📄 statement.java
字号:
* 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 int getQueryTimeout() throws SQLException
{
return timeout;
}
/**
* Sets the queryTimeout limit
*
* @param seconds - the new query timeout limit in seconds
* @exception SQLException if a database access error occurs
*/
public void setQueryTimeout(int seconds) throws SQLException
{
timeout = seconds;
}
/**
*
* @exception SQLException
*/
public void cancel() throws SQLException
{
if (tds == null)
{
throw new SQLException("Statement is closed");
}
try
{
tds.cancel();
}
catch(com.internetcds.jdbc.tds.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 SQLWarning getWarnings() throws SQLException
{
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 void clearWarnings() throws SQLException
{
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
{
NotImplemented();
}
/**
* @param sql any SQL statement
* @return true if the next result is a ResulSet, false if it is
* an update count or there are no more results
* @exception SQLException if a database access error occurs
*/
public boolean execute(String sql) throws SQLException
{
SQLException exception = null;
if (tds == null)
{
throw new SQLException("Statement is closed");
}
closeResults();
clearWarnings();
updateCount = -1;
try
{
if (escapeProcessing)
{
sql = Tds.toNativeSql(sql, tds.getServerType());
}
tds.executeQuery(sql, this, timeout);
}
catch(java.io.IOException e)
{
throw new SQLException("Network error- " + e.getMessage());
}
catch(com.internetcds.jdbc.tds.TdsException e)
{
throw new SQLException("TDS error- " + e.getMessage());
}
return getMoreResults();
} // execute()
/**
* 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 java.sql.ResultSet getResultSet() throws SQLException
{
try
{
if (tds == null)
{
throw new SQLException("Statement is closed");
}
closeResults();
if (tds.peek()==TdsDefinitions.TDS_DONEINPROC)
{
PacketResult tmp = tds.processSubPacket();
}
if (tds.isResultSet()) // JJ 1999-01-09 used be: ;getMoreResults())
{
startResultSet();
}
else if (updateCount!=-1)
{
if (! tds.isEndOfResults())
{
// XXX
throw new SQLException("Internal error. "+
" expected EndOfResults, found 0x"
+ Integer.toHexString(tds.peek()&0xff));
}
PacketEndTokenResult end =
(PacketEndTokenResult) tds.processSubPacket();
updateCount = end.getRowCount();
results = null;
}
else
{
// We didn't have more data and we didn't have an update count,
// now what?
throw new SQLException("Internal error. Confused");
}
}
catch(java.io.IOException e)
{
throw new SQLException(e.getMessage());
}
catch(TdsException e)
{
throw new SQLException(e.getMessage());
}
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 int getUpdateCount() throws SQLException
{
// if (updateCount == -1)
// {
// throw new SQLException("Don't have a count yet.");
// }
// XXX This isn't correct. We need to check to see if
// the result was a result set or if there are no more results.
// If either of those are true we are supposed to return -1
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 boolean getMoreResults() throws SQLException
{
SQLException exception = null;
if (tds == null)
{
throw new SQLException("Statement is closed");
}
updateCount = -1; // Do we need this global variable?
if (!tds.moreResults())
{
return false;
}
closeResults(); // Reset all internal variables (why is this done here?)
try
{
tds.isResultSet();
// Keep eating garbage and warnings until we reach the next result
while (!tds.isResultSet() && !tds.isEndOfResults())
{
if (tds.isProcId())
{
tds.processSubPacket();
}
else if (tds.isDoneInProc())
{
PacketDoneInProcResult tmp =
(PacketDoneInProcResult)tds.processSubPacket();
}
else if (tds.isTextUpdate())
{
PacketResult tmp1 =
(PacketResult)tds.processSubPacket();
}
else if (tds.isMessagePacket() || tds.isErrorPacket())
{
PacketMsgResult tmp = (PacketMsgResult)tds.processSubPacket();
exception = warningChain.addOrReturn(tmp);
}
else if (tds.isReturnStatus())
{
tds.processSubPacket();
// skipToEnd();
}
else
{
throw new SQLException("Protocol confusion. "
+ "Got a 0x"
+ Integer.toHexString((tds.peek() & 0xff))
+ " packet");
}
} // end while
if (exception != null)
{
try
{
tds.discardResultSet(null);
}
catch(java.io.IOException e)
{
throw new SQLException("Error discarding result set while processing sql error- " +
exception.getMessage() +
"\nIOException was " +
e.getMessage());
}
catch(com.internetcds.jdbc.tds.TdsException e)
{
throw new SQLException("Error discarding result set while processing sql error- " +
exception.getMessage() +
"\nIOException was " +
e.getMessage());
}
throw exception;
}
if (tds.isEndOfResults())
{
PacketEndTokenResult end =
(PacketEndTokenResult)tds.processSubPacket();
updateCount = end.getRowCount();
return false;
}
else if (tds.isResultSet())
{
return true;
}
else
{
throw new SQLException("Protocol confusion. "
+ "Got a 0x"
+ Integer.toHexString((tds.peek() & 0xff))
+ " packet");
}
}
catch(java.io.IOException e)
{
throw new SQLException("Network error- " + e.getMessage());
}
catch(com.internetcds.jdbc.tds.TdsException e)
{
throw new SQLException("TDS error- " + e.getMessage());
}
}
protected void startResultSet()
throws SQLException
{
Columns names = null;
Columns info = null;
SQLException exception = null;
try
{
while (!tds.isResultRow() && !tds.isEndOfResults())
{
PacketResult tmp = tds.processSubPacket();
if (tmp.getPacketType() == TdsDefinitions.TDS_DONEINPROC)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -