📄 statement.java
字号:
SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ } this.maxFieldSize = max; } /** * 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 { return this.maxFieldSize; } /** * 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 { if ((max > MysqlDefs.MAX_ROWS) || (max < 0)) { throw new SQLException(Messages.getString("Statement.15") + max //$NON-NLS-1$ +" > " //$NON-NLS-1$ //$NON-NLS-2$ +MysqlDefs.MAX_ROWS + ".", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ //$NON-NLS-2$ } if (max == 0) { max = -1; } this.maxRows = max; this.maxRowsChanged = true; if (this.maxRows == -1) { this.connection.unsetMaxRows(this); this.maxRowsChanged = false; } else { // Most people don't use setMaxRows() // so don't penalize them // with the extra query it takes // to do it efficiently unless we need // to. this.connection.maxRowsChanged(this); } } /** * 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 { if (this.maxRows <= 0) { return 0; } return this.maxRows; } /** * 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 { return getMoreResults(CLOSE_CURRENT_RESULT); } /** * @see Statement#getMoreResults(int) */ public synchronized boolean getMoreResults(int current) throws SQLException { ResultSet nextResultSet = this.results.getNextResultSet(); switch (current) { case java.sql.Statement.CLOSE_CURRENT_RESULT: if (this.results != null) { this.results.close(); } break; case java.sql.Statement.CLOSE_ALL_RESULTS: if (this.results != null) { this.results.close(); } closeAllOpenResults(); break; case java.sql.Statement.KEEP_CURRENT_RESULT: if (!this.connection.getDontTrackOpenResources()) { this.openResults.add(this.results); } break; default: throw new SQLException(Messages.getString("Statement.19"), //$NON-NLS-1$ SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ } this.results = nextResultSet; if (this.results == null) { this.updateCount = -1; this.lastInsertId = -1; } else if (this.results.reallyResult()) { this.updateCount = -1; this.lastInsertId = -1; } else { this.updateCount = this.results.getUpdateCount(); this.lastInsertId = this.results.getUpdateID(); } return ((this.results != null) && this.results.reallyResult()) ? true : false; } /** * 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 { if (seconds < 0) { throw new SQLException(Messages.getString("Statement.21"), //$NON-NLS-1$ SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ } this.timeout = seconds; } /** * 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 this.timeout; } /** * 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 (why?) */ public synchronized java.sql.ResultSet getResultSet() throws SQLException { return ((this.results != null) && this.results.reallyResult()) ? (java.sql.ResultSet) this.results : null; } /** * JDBC 2.0 Determine the result set concurrency. * * @return CONCUR_UPDATABLE or CONCUR_READONLY * * @throws SQLException if an error occurs */ public synchronized int getResultSetConcurrency() throws SQLException { return this.resultSetConcurrency; } /** * @see Statement#getResultSetHoldability() */ public int getResultSetHoldability() throws SQLException { return java.sql.ResultSet.HOLD_CURSORS_OVER_COMMIT; } /** * JDBC 2.0 Determine the result set type. * * @return the ResultSet type (SCROLL_SENSITIVE or SCROLL_INSENSITIVE) * * @throws SQLException if an error occurs. */ public synchronized int getResultSetType() throws SQLException { return this.resultSetType; } /** * 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 { if (this.results == null) { return -1; } if (this.results.reallyResult()) { return -1; } int truncatedUpdateCount = 0; if (this.results.getUpdateCount() > Integer.MAX_VALUE) { truncatedUpdateCount = Integer.MAX_VALUE; } else { truncatedUpdateCount = (int) this.results.getUpdateCount(); } return truncatedUpdateCount; } /** * The first warning reported by calls on this Statement is returned. A * Statement's execute methods clear its java.sql.SQLWarning chain. * Subsequent Statement warnings will be chained to this * java.sql.SQLWarning. * * <p> * The Warning chain is automatically cleared each time a statement is * (re)executed. * </p> * * <p> * <B>Note:</B> If you are processing a ResultSet then any warnings * associated with ResultSet reads will be chained on the ResultSet * object. * </p> * * @return the first java.sql.SQLWarning or null * * @exception SQLException if a database access error occurs */ public synchronized java.sql.SQLWarning getWarnings() throws SQLException { if (this.connection.versionMeetsMinimum(4, 1, 0)) { SQLWarning pendingWarningsFromServer = SQLError.convertShowWarningsToSQLWarnings(this.connection); if (this.warningChain != null) { this.warningChain.setNextWarning(pendingWarningsFromServer); } else { this.warningChain = pendingWarningsFromServer; } return this.warningChain; } return this.warningChain; } /** * DOCUMENT ME! * * @param sql DOCUMENT ME! * * @throws SQLException DOCUMENT ME! */ public synchronized void addBatch(String sql) throws SQLException { if (this.batchedArgs == null) { this.batchedArgs = new ArrayList(); } if (sql != null) { this.batchedArgs.add(sql); } } /** * Cancel can be used by one thread to cancel a statement that is being * executed by another thread. However this driver is synchronous, so * this really has no meaning - we define it as a no-op (i.e. you can't * cancel, but there is no error if you try.) * * @exception SQLException only because thats the spec. */ public void cancel() throws SQLException { // No-op } /** * JDBC 2.0 Make the set of commands in the current batch empty. This * method is optional. * * @exception SQLException if a database-access error occurs, or the driver * does not support batch statements */ public synchronized void clearBatch() throws SQLException { if (this.batchedArgs != null) { this.batchedArgs.clear(); } } /** * 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 { this.warningChain = null; } /** * 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. * </p> * * @exception SQLException if a database access error occurs */ public void close() throws SQLException { realClose(true); } /** * Workaround for containers that 'check' for sane values * of Statement.setFetchSize(). * * @throws SQLException */ public void enableStreamingResults() throws SQLException { setFetchSize(Integer.MIN_VALUE); setResultSetType(ResultSet.TYPE_FORWARD_ONLY); } /** * Execute a SQL statement that may return multiple results. We don't have * to worry about this since we do not support multiple ResultSets. You * can use getResultSet or getUpdateCount to retrieve the result. * * @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 synchronized boolean execute(String sql) throws SQLException { checkNullOrEmptyQuery(sql); checkClosed(); char firstNonWsChar = StringUtils.firstNonWsCharUc(sql); boolean isSelect = true; if (firstNonWsChar != 'S') { isSelect = false; if (this.connection.isReadOnly()) { throw new SQLException(Messages.getString("Statement.27") //$NON-NLS-1$ +Messages.getString("Statement.28"), //$NON-NLS-1$ SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ } } if (this.doEscapeProcessing) { Object escapedSqlResult = EscapeProcessor.escapeSQL(sql, this.connection.serverSupportsConvertFn()); if (escapedSqlResult instanceof String) { sql = (String)escapedSqlResult; } else { sql = ((EscapeProcessorResult)escapedSqlResult).escapedSql; } } if (this.results != null) { if (!this.connection.getHoldResultsOpenOverStatementClose()) { this.results.realClose(false); } } CachedResultSetMetaData cachedMetaData = null; ResultSet rs = null; // If there isn't a limit clause in the SQL // then limit the number of rows to return in // an efficient manner. Only do this if // setMaxRows() hasn't been used on any Statements // generated from the current Connection (saves // a query, and network traffic). synchronized (this.connection.getMutex()) { String oldCatalog = null; if (!this.connection.getCatalog().equals(this.currentCatalog)) { oldCatalog = this.connection.getCatalog(); this.connection.setCatalog(this.currentCatalog); } // // Check if we have cached metadata for this query...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -