Java Code Examples for com.mysql.cj.jdbc.result.ResultSetInternalMethods#getUpdateID()
The following examples show how to use
com.mysql.cj.jdbc.result.ResultSetInternalMethods#getUpdateID() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatementImpl.java From lams with GNU General Public License v2.0 | 4 votes |
protected long executeUpdateInternal(String sql, boolean isBatch, boolean returnGeneratedKeys) throws SQLException { synchronized (checkClosed().getConnectionMutex()) { JdbcConnection locallyScopedConn = this.connection; checkNullOrEmptyQuery(sql); resetCancelledState(); char firstStatementChar = StringUtils.firstAlphaCharUc(sql, findStartOfStatement(sql)); this.retrieveGeneratedKeys = returnGeneratedKeys; this.lastQueryIsOnDupKeyUpdate = returnGeneratedKeys && firstStatementChar == 'I' && containsOnDuplicateKeyInString(sql); ResultSetInternalMethods rs = null; if (this.doEscapeProcessing) { Object escapedSqlResult = EscapeProcessor.escapeSQL(sql, this.session.getServerSession().getDefaultTimeZone(), this.session.getServerSession().getCapabilities().serverSupportsFracSecs(), getExceptionInterceptor()); sql = escapedSqlResult instanceof String ? (String) escapedSqlResult : ((EscapeProcessorResult) escapedSqlResult).escapedSql; } if (locallyScopedConn.isReadOnly(false)) { throw SQLError.createSQLException(Messages.getString("Statement.42") + Messages.getString("Statement.43"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor()); } if (StringUtils.startsWithIgnoreCaseAndWs(sql, "select")) { throw SQLError.createSQLException(Messages.getString("Statement.46"), "01S03", getExceptionInterceptor()); } implicitlyCloseAllOpenResults(); // The checking and changing of catalogs must happen in sequence, so synchronize on the same mutex that _conn is using CancelQueryTask timeoutTask = null; String oldCatalog = null; try { timeoutTask = startQueryTimer(this, getTimeoutInMillis()); if (!locallyScopedConn.getCatalog().equals(getCurrentCatalog())) { oldCatalog = locallyScopedConn.getCatalog(); locallyScopedConn.setCatalog(getCurrentCatalog()); } // // Only apply max_rows to selects // locallyScopedConn.setSessionMaxRows(-1); statementBegins(); // null catalog: force read of field info on DML rs = ((NativeSession) locallyScopedConn.getSession()).execSQL(this, sql, -1, null, false, getResultSetFactory(), getCurrentCatalog(), null, isBatch); if (timeoutTask != null) { stopQueryTimer(timeoutTask, true, true); timeoutTask = null; } } catch (CJTimeoutException | OperationCancelledException e) { throw SQLExceptionsMapping.translateException(e, this.exceptionInterceptor); } finally { stopQueryTimer(timeoutTask, false, false); if (oldCatalog != null) { locallyScopedConn.setCatalog(oldCatalog); } if (!isBatch) { this.query.getStatementExecuting().set(false); } } this.results = rs; rs.setFirstCharOfQuery(firstStatementChar); this.updateCount = rs.getUpdateCount(); this.lastInsertId = rs.getUpdateID(); return this.updateCount; } }
Example 2
Source File: ClientPreparedStatement.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Some prepared statements return multiple results; the execute method * handles these complex statements as well as the simpler form of * statements handled by executeQuery and executeUpdate * * @return true if the next result is a ResultSet; false if it is an update * count or there are no more results * * @exception SQLException * if a database access error occurs */ public boolean execute() throws SQLException { synchronized (checkClosed().getConnectionMutex()) { JdbcConnection locallyScopedConn = this.connection; if (!this.doPingInstead && !checkReadOnlySafeStatement()) { throw SQLError.createSQLException(Messages.getString("PreparedStatement.20") + Messages.getString("PreparedStatement.21"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, this.exceptionInterceptor); } ResultSetInternalMethods rs = null; this.lastQueryIsOnDupKeyUpdate = false; if (this.retrieveGeneratedKeys) { this.lastQueryIsOnDupKeyUpdate = containsOnDuplicateKeyUpdateInSQL(); } this.batchedGeneratedKeys = null; resetCancelledState(); implicitlyCloseAllOpenResults(); clearWarnings(); if (this.doPingInstead) { doPingInstead(); return true; } setupStreamingTimeout(locallyScopedConn); Message sendPacket = ((PreparedQuery<?>) this.query).fillSendPacket(); String oldCatalog = null; if (!locallyScopedConn.getCatalog().equals(this.getCurrentCatalog())) { oldCatalog = locallyScopedConn.getCatalog(); locallyScopedConn.setCatalog(this.getCurrentCatalog()); } // // Check if we have cached metadata for this query... // CachedResultSetMetaData cachedMetadata = null; boolean cacheResultSetMetadata = locallyScopedConn.getPropertySet().getBooleanReadableProperty(PropertyDefinitions.PNAME_cacheResultSetMetadata) .getValue(); if (cacheResultSetMetadata) { cachedMetadata = locallyScopedConn.getCachedMetaData(((PreparedQuery<?>) this.query).getOriginalSql()); } // // Only apply max_rows to selects // locallyScopedConn.setSessionMaxRows(((PreparedQuery<?>) this.query).getParseInfo().getFirstStmtChar() == 'S' ? this.maxRows : -1); rs = executeInternal(this.maxRows, sendPacket, createStreamingResultSet(), (((PreparedQuery<?>) this.query).getParseInfo().getFirstStmtChar() == 'S'), cachedMetadata, false); if (cachedMetadata != null) { locallyScopedConn.initializeResultsMetadataFromCache(((PreparedQuery<?>) this.query).getOriginalSql(), cachedMetadata, rs); } else { if (rs.hasRows() && cacheResultSetMetadata) { locallyScopedConn.initializeResultsMetadataFromCache(((PreparedQuery<?>) this.query).getOriginalSql(), null /* will be created */, rs); } } if (this.retrieveGeneratedKeys) { rs.setFirstCharOfQuery(((PreparedQuery<?>) this.query).getParseInfo().getFirstStmtChar()); } if (oldCatalog != null) { locallyScopedConn.setCatalog(oldCatalog); } if (rs != null) { this.lastInsertId = rs.getUpdateID(); this.results = rs; } return ((rs != null) && rs.hasRows()); } }
Example 3
Source File: ClientPreparedStatement.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Added to allow batch-updates * * @param bindings * @param isReallyBatch * * @return the update count * * @throws SQLException * if a database error occurs */ protected long executeUpdateInternal(QueryBindings<?> bindings, boolean isReallyBatch) throws SQLException { synchronized (checkClosed().getConnectionMutex()) { JdbcConnection locallyScopedConn = this.connection; if (locallyScopedConn.isReadOnly(false)) { throw SQLError.createSQLException(Messages.getString("PreparedStatement.34") + Messages.getString("PreparedStatement.35"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, this.exceptionInterceptor); } if ((((PreparedQuery<?>) this.query).getParseInfo().getFirstStmtChar() == 'S') && isSelectQuery()) { throw SQLError.createSQLException(Messages.getString("PreparedStatement.37"), "01S03", this.exceptionInterceptor); } resetCancelledState(); implicitlyCloseAllOpenResults(); ResultSetInternalMethods rs = null; Message sendPacket = ((PreparedQuery<?>) this.query).fillSendPacket(bindings); String oldCatalog = null; if (!locallyScopedConn.getCatalog().equals(this.getCurrentCatalog())) { oldCatalog = locallyScopedConn.getCatalog(); locallyScopedConn.setCatalog(this.getCurrentCatalog()); } // // Only apply max_rows to selects // locallyScopedConn.setSessionMaxRows(-1); rs = executeInternal(-1, sendPacket, false, false, null, isReallyBatch); if (this.retrieveGeneratedKeys) { rs.setFirstCharOfQuery(((PreparedQuery<?>) this.query).getParseInfo().getFirstStmtChar()); } if (oldCatalog != null) { locallyScopedConn.setCatalog(oldCatalog); } this.results = rs; this.updateCount = rs.getUpdateCount(); if (containsOnDuplicateKeyUpdateInSQL() && this.compensateForOnDuplicateKeyUpdate) { if (this.updateCount == 2 || this.updateCount == 0) { this.updateCount = 1; } } this.lastInsertId = rs.getUpdateID(); return this.updateCount; } }
Example 4
Source File: StatementImpl.java From FoxTelem with GNU General Public License v3.0 | 4 votes |
protected long executeUpdateInternal(String sql, boolean isBatch, boolean returnGeneratedKeys) throws SQLException { synchronized (checkClosed().getConnectionMutex()) { JdbcConnection locallyScopedConn = this.connection; checkNullOrEmptyQuery(sql); resetCancelledState(); char firstStatementChar = StringUtils.firstAlphaCharUc(sql, findStartOfStatement(sql)); this.retrieveGeneratedKeys = returnGeneratedKeys; this.lastQueryIsOnDupKeyUpdate = returnGeneratedKeys && firstStatementChar == 'I' && containsOnDuplicateKeyInString(sql); ResultSetInternalMethods rs = null; if (this.doEscapeProcessing) { Object escapedSqlResult = EscapeProcessor.escapeSQL(sql, this.session.getServerSession().getDefaultTimeZone(), this.session.getServerSession().getCapabilities().serverSupportsFracSecs(), this.session.getServerSession().isServerTruncatesFracSecs(), getExceptionInterceptor()); sql = escapedSqlResult instanceof String ? (String) escapedSqlResult : ((EscapeProcessorResult) escapedSqlResult).escapedSql; } if (locallyScopedConn.isReadOnly(false)) { throw SQLError.createSQLException(Messages.getString("Statement.42") + Messages.getString("Statement.43"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor()); } if (StringUtils.startsWithIgnoreCaseAndWs(sql, "select")) { throw SQLError.createSQLException(Messages.getString("Statement.46"), "01S03", getExceptionInterceptor()); } implicitlyCloseAllOpenResults(); // The checking and changing of catalogs must happen in sequence, so synchronize on the same mutex that _conn is using CancelQueryTask timeoutTask = null; String oldCatalog = null; try { timeoutTask = startQueryTimer(this, getTimeoutInMillis()); if (!locallyScopedConn.getCatalog().equals(getCurrentCatalog())) { oldCatalog = locallyScopedConn.getCatalog(); locallyScopedConn.setCatalog(getCurrentCatalog()); } // // Only apply max_rows to selects // locallyScopedConn.setSessionMaxRows(-1); statementBegins(); // null catalog: force read of field info on DML rs = ((NativeSession) locallyScopedConn.getSession()).execSQL(this, sql, -1, null, false, getResultSetFactory(), getCurrentCatalog(), null, isBatch); if (timeoutTask != null) { stopQueryTimer(timeoutTask, true, true); timeoutTask = null; } } catch (CJTimeoutException | OperationCancelledException e) { throw SQLExceptionsMapping.translateException(e, this.exceptionInterceptor); } finally { stopQueryTimer(timeoutTask, false, false); if (oldCatalog != null) { locallyScopedConn.setCatalog(oldCatalog); } if (!isBatch) { this.query.getStatementExecuting().set(false); } } this.results = rs; rs.setFirstCharOfQuery(firstStatementChar); this.updateCount = rs.getUpdateCount(); this.lastInsertId = rs.getUpdateID(); return this.updateCount; } }
Example 5
Source File: ClientPreparedStatement.java From FoxTelem with GNU General Public License v3.0 | 4 votes |
@Override public boolean execute() throws SQLException { synchronized (checkClosed().getConnectionMutex()) { JdbcConnection locallyScopedConn = this.connection; if (!this.doPingInstead && !checkReadOnlySafeStatement()) { throw SQLError.createSQLException(Messages.getString("PreparedStatement.20") + Messages.getString("PreparedStatement.21"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, this.exceptionInterceptor); } ResultSetInternalMethods rs = null; this.lastQueryIsOnDupKeyUpdate = false; if (this.retrieveGeneratedKeys) { this.lastQueryIsOnDupKeyUpdate = containsOnDuplicateKeyUpdateInSQL(); } this.batchedGeneratedKeys = null; resetCancelledState(); implicitlyCloseAllOpenResults(); clearWarnings(); if (this.doPingInstead) { doPingInstead(); return true; } setupStreamingTimeout(locallyScopedConn); Message sendPacket = ((PreparedQuery<?>) this.query).fillSendPacket(); String oldCatalog = null; if (!locallyScopedConn.getCatalog().equals(this.getCurrentCatalog())) { oldCatalog = locallyScopedConn.getCatalog(); locallyScopedConn.setCatalog(this.getCurrentCatalog()); } // // Check if we have cached metadata for this query... // CachedResultSetMetaData cachedMetadata = null; boolean cacheResultSetMetadata = locallyScopedConn.getPropertySet().getBooleanProperty(PropertyKey.cacheResultSetMetadata).getValue(); if (cacheResultSetMetadata) { cachedMetadata = locallyScopedConn.getCachedMetaData(((PreparedQuery<?>) this.query).getOriginalSql()); } // // Only apply max_rows to selects // locallyScopedConn.setSessionMaxRows(((PreparedQuery<?>) this.query).getParseInfo().getFirstStmtChar() == 'S' ? this.maxRows : -1); rs = executeInternal(this.maxRows, sendPacket, createStreamingResultSet(), (((PreparedQuery<?>) this.query).getParseInfo().getFirstStmtChar() == 'S'), cachedMetadata, false); if (cachedMetadata != null) { locallyScopedConn.initializeResultsMetadataFromCache(((PreparedQuery<?>) this.query).getOriginalSql(), cachedMetadata, rs); } else { if (rs.hasRows() && cacheResultSetMetadata) { locallyScopedConn.initializeResultsMetadataFromCache(((PreparedQuery<?>) this.query).getOriginalSql(), null /* will be created */, rs); } } if (this.retrieveGeneratedKeys) { rs.setFirstCharOfQuery(((PreparedQuery<?>) this.query).getParseInfo().getFirstStmtChar()); } if (oldCatalog != null) { locallyScopedConn.setCatalog(oldCatalog); } if (rs != null) { this.lastInsertId = rs.getUpdateID(); this.results = rs; } return ((rs != null) && rs.hasRows()); } }
Example 6
Source File: ClientPreparedStatement.java From FoxTelem with GNU General Public License v3.0 | 4 votes |
/** * Added to allow batch-updates * * @param bindings * bindings object * @param isReallyBatch * is it a batched statement? * * @return the update count * * @throws SQLException * if a database error occurs */ protected long executeUpdateInternal(QueryBindings<?> bindings, boolean isReallyBatch) throws SQLException { synchronized (checkClosed().getConnectionMutex()) { JdbcConnection locallyScopedConn = this.connection; if (locallyScopedConn.isReadOnly(false)) { throw SQLError.createSQLException(Messages.getString("PreparedStatement.34") + Messages.getString("PreparedStatement.35"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, this.exceptionInterceptor); } if ((((PreparedQuery<?>) this.query).getParseInfo().getFirstStmtChar() == 'S') && isSelectQuery()) { throw SQLError.createSQLException(Messages.getString("PreparedStatement.37"), "01S03", this.exceptionInterceptor); } resetCancelledState(); implicitlyCloseAllOpenResults(); ResultSetInternalMethods rs = null; Message sendPacket = ((PreparedQuery<?>) this.query).fillSendPacket(bindings); String oldCatalog = null; if (!locallyScopedConn.getCatalog().equals(this.getCurrentCatalog())) { oldCatalog = locallyScopedConn.getCatalog(); locallyScopedConn.setCatalog(this.getCurrentCatalog()); } // // Only apply max_rows to selects // locallyScopedConn.setSessionMaxRows(-1); rs = executeInternal(-1, sendPacket, false, false, null, isReallyBatch); if (this.retrieveGeneratedKeys) { rs.setFirstCharOfQuery(((PreparedQuery<?>) this.query).getParseInfo().getFirstStmtChar()); } if (oldCatalog != null) { locallyScopedConn.setCatalog(oldCatalog); } this.results = rs; this.updateCount = rs.getUpdateCount(); if (containsOnDuplicateKeyUpdateInSQL() && this.compensateForOnDuplicateKeyUpdate) { if (this.updateCount == 2 || this.updateCount == 0) { this.updateCount = 1; } } this.lastInsertId = rs.getUpdateID(); return this.updateCount; } }