Package org.apache.derby.iapi.sql

Examples of org.apache.derby.iapi.sql.PreparedStatement


    SQLText = sql;   

    try {
      Activation activation;
      try {
        PreparedStatement preparedStatement = lcc.prepareInternalStatement
            (lcc.getDefaultSchema(), sql, resultSetConcurrency==JDBC20Translation.CONCUR_READ_ONLY, false);
        activation =
          preparedStatement.getActivation(lcc, resultSetType == JDBC20Translation.TYPE_SCROLL_INSENSITIVE);
        checkRequiresCallableStatement(activation);
       } catch (Throwable t) {
        throw handleException(t);
       }
View Full Code Here


          }
        }

        // if this was a prepared statement, this just
        // gets it for us, it won't recompile unless it is invalid.
        PreparedStatement ps = a.getPreparedStatement();
        ps.rePrepare(lcc);
        addWarning(ps.getCompileTimeWarnings());


        /*
        ** WARNING WARNING
        **
        ** Any state set in the activation before execution *must* be copied
        ** to the new activation in GenericActivationHolder.execute() when
        ** the statement has been recompiled. State such as
        ** singleExecution, cursorName, holdability, maxRows.
        */

        if (cursorName != null)
        {
          a.setCursorName(cursorName);
        }
               
                boolean executeHoldable = getExecuteHoldable();
        a.setResultSetHoldability(executeHoldable);

        //reset the activation to clear warnings
        //and clear existing result sets in case this has been cached
        a.reset();
        a.setMaxRows(maxRows);
                ResultSet resultsToWrap = ps.execute(a,
                                                     false,
                                                     timeoutMillis);
        addWarning(a.getWarnings());


        if (resultsToWrap.returnsRows()) {

                    // The statement returns rows, so calling it with
                    // executeUpdate() is not allowed.
                    if (executeUpdate) {
                        throw StandardException.newException(
                                SQLState.LANG_INVALID_CALL_TO_EXECUTE_UPDATE);
                    }

          EmbedResultSet lresults = factory.newEmbedResultSet(getEmbedConnection(), resultsToWrap, forMetaData, this, ps.isAtomic());
          results = lresults;


          // Set up the finalization of the ResultSet to
          // mark the activation as unused. It will be
          // closed sometime later by the connection
          // outside of finalization.
          if (a.isSingleExecution())
            lresults.singleUseActivation = a;

          updateCount = -1;
          retval = true;
        }
        else {

          // Only applipable for an insert statement, which does not return rows.
          //the auto-generated keys resultset will be null if used for non-insert statement
          if (a.getAutoGeneratedKeysResultsetMode() && (resultsToWrap.getAutoGeneratedKeysResultset() != null))
          {
            resultsToWrap.getAutoGeneratedKeysResultset().open();
            autoGeneratedKeysResultSet = factory.newEmbedResultSet(getEmbedConnection(),
              resultsToWrap.getAutoGeneratedKeysResultset(), false, this, ps.isAtomic());
          }

          updateCount = resultsToWrap.modifiedRowCount();

          results = null; // note that we have none.
View Full Code Here

    AlterTableConstantAction.executeUpdate(lcc, updateStmt);
  }

  private static void executeUpdate(LanguageConnectionContext lcc, String updateStmt) throws StandardException
  {
    PreparedStatement ps = lcc.prepareInternalStatement(updateStmt);

        // This is a substatement; for now, we do not set any timeout
        // for it. We might change this behaviour later, by linking
        // timeout to its parent statement's timeout settings.
    ResultSet rs = ps.executeSubStatement(lcc, true, 0L);
    rs.close();
  }
View Full Code Here

    String maxStr = (increment > 0) ? "MAX" : "MIN";
        String maxStmt = "SELECT  " + maxStr + "(" +
                IdUtil.normalToDelimited(columnName) + ") FROM " +
                IdUtil.mkQualifiedName(td.getSchemaName(), td.getName());

    PreparedStatement ps = lcc.prepareInternalStatement(maxStmt);

        // This is a substatement, for now we do not set any timeout for it
        // We might change this later by linking timeout to parent statement
    ResultSet rs = ps.executeSubStatement(lcc, false, 0L);
    DataValueDescriptor[] rowArray = rs.getNextRow().getRowArray();
    rs.close();
    rs.finish();

    return rowArray[0].getLong();
View Full Code Here

  }

  public void rePrepare(LanguageConnectionContext lcc)
    throws StandardException {
    if (!upToDate()) {
      PreparedStatement ps = statement.prepare(lcc);

      if (SanityManager.DEBUG)
        SanityManager.ASSERT(ps == this, "ps != this");
    }
  }
View Full Code Here

      Activation activation,
      ResultSet rs,
      NoPutResultSet[] subqueryTrackingArray)
    throws StandardException
  {
    PreparedStatement preStmt = activation.getPreparedStatement();

    // If the prepared statement is null then the result set is being
    // finished as a result of a activation being closed during a recompile.
    // In this case statistics should not be generated.
    if (preStmt == null)
      return null;




    ResultSetStatistics topResultSetStatistics;

    if (rs instanceof NoPutResultSet)
    {
      topResultSetStatistics =
                  getResultSetStatistics((NoPutResultSet) rs);
    }
    else
    {
      topResultSetStatistics = getResultSetStatistics(rs);
    }

    /* Build up the info on the materialized subqueries */
    int subqueryTrackingArrayLength =
        (subqueryTrackingArray == null) ? 0 :
          subqueryTrackingArray.length;
    ResultSetStatistics[] subqueryRSS =
        new ResultSetStatistics[subqueryTrackingArrayLength];
    boolean anyAttached = false;
    for (int index = 0; index < subqueryTrackingArrayLength; index++)
    {
      if (subqueryTrackingArray[index] != null &&
        subqueryTrackingArray[index].getPointOfAttachment() == -1)
      {
        subqueryRSS[index] =
            getResultSetStatistics(subqueryTrackingArray[index]);
        anyAttached = true;
      }
    }
    if (anyAttached == false)
    {
      subqueryRSS = null;
    }

    // Get the info on all of the materialized subqueries (attachment point = -1)
    return new RunTimeStatisticsImpl(
                preStmt.getSPSName(),
                activation.getCursorName(),
                preStmt.getSource(),
                preStmt.getCompileTimeInMillis(),
                preStmt.getParseTimeInMillis(),
                preStmt.getBindTimeInMillis(),
                preStmt.getOptimizeTimeInMillis(),
                preStmt.getGenerateTimeInMillis(),
                rs.getExecuteTime(),
                preStmt.getBeginCompileTimestamp(),
                preStmt.getEndCompileTimestamp(),
                rs.getBeginExecutionTimestamp(),
                rs.getEndExecutionTimestamp(),
                subqueryRSS,
                topResultSetStatistics);
  }
View Full Code Here

    AlterTableConstantAction.executeUpdate(lcc, updateStmt);
  }

  private static void executeUpdate(LanguageConnectionContext lcc, String updateStmt) throws StandardException
  {
    PreparedStatement ps = lcc.prepareInternalStatement(updateStmt);

        // This is a substatement; for now, we do not set any timeout
        // for it. We might change this behaviour later, by linking
        // timeout to its parent statement's timeout settings.
    ResultSet rs = ps.execute(lcc, true, 0L);
    rs.close();
  }
View Full Code Here

    String maxStmt = "SELECT " + maxStr + "(\"" + columnName + "\")"  +
        "FROM \"" + td.getSchemaName() + "\".\"" + td.getName() + "\"";


    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    PreparedStatement ps = lcc.prepareInternalStatement(maxStmt);

        // This is a substatement, for now we do not set any timeout for it
        // We might change this later by linking timeout to parent statement
    ResultSet rs = ps.execute(lcc, false, 0L);
    DataValueDescriptor[] rowArray = rs.getNextRow().getRowArray();
    rs.close();
    rs.finish();

    return rowArray[0].getLong();
View Full Code Here

    AlterTableConstantAction.executeUpdate(lcc, updateStmt);
  }

  private static void executeUpdate(LanguageConnectionContext lcc, String updateStmt) throws StandardException
  {
    PreparedStatement ps = lcc.prepareInternalStatement(updateStmt);

        // This is a substatement; for now, we do not set any timeout
        // for it. We might change this behaviour later, by linking
        // timeout to its parent statement's timeout settings.
    ResultSet rs = ps.executeSubStatement(lcc, true, 0L);
    rs.close();
  }
View Full Code Here

    String maxStmt = "SELECT " + maxStr + "(\"" + columnName + "\")"  +
        "FROM \"" + td.getSchemaName() + "\".\"" + td.getName() + "\"";


    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    PreparedStatement ps = lcc.prepareInternalStatement(maxStmt);

        // This is a substatement, for now we do not set any timeout for it
        // We might change this later by linking timeout to parent statement
    ResultSet rs = ps.executeSubStatement(lcc, false, 0L);
    DataValueDescriptor[] rowArray = rs.getNextRow().getRowArray();
    rs.close();
    rs.finish();

    return rowArray[0].getLong();
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.sql.PreparedStatement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.