Search in sources :

Example 1 with ParameterValueSet

use of org.apache.derby.iapi.sql.ParameterValueSet in project derby by apache.

the class EmbedPreparedStatement method setScale.

/**
 * Set the scale of a parameter.
 *
 * @param parameterIndex The first parameter is 1, the second is 2, ...
 * @param scale	The scale
 * @exception SQLException thrown on failure.
 */
private void setScale(int parameterIndex, int scale) throws SQLException {
    checkStatus();
    if (scale < 0)
        throw newSQLException(SQLState.BAD_SCALE_VALUE, scale);
    try {
        ParameterValueSet pvs = getParms();
        /* JDBC is one-based, DBMS is zero-based */
        DataValueDescriptor value = pvs.getParameter(parameterIndex - 1);
        int origvaluelen = value.getLength();
        ((VariableSizeDataValue) value).setWidth(VariableSizeDataValue.IGNORE_PRECISION, scale, false);
        if (value.getLength() < origvaluelen) {
            activation.addWarning(StandardException.newWarning(SQLState.LANG_VALUE_TRUNCATED, value.getString()));
        }
    } catch (StandardException t) {
        throw EmbedResultSet.noStateChangeException(t);
    }
}
Also used : ParameterValueSet(org.apache.derby.iapi.sql.ParameterValueSet) StandardException(org.apache.derby.shared.common.error.StandardException) VariableSizeDataValue(org.apache.derby.iapi.types.VariableSizeDataValue) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 2 with ParameterValueSet

use of org.apache.derby.iapi.sql.ParameterValueSet in project derby by apache.

the class EmbedCallableStatement method executeStatement.

protected final boolean executeStatement(Activation a, boolean executeQuery, boolean executeUpdate) throws SQLException {
    // need this additional check (it's also in the super.executeStatement
    // to ensure we have an activation for the getParams
    checkExecStatus();
    synchronized (getConnectionSynchronization()) {
        wasNull = false;
        // right object to hold the return value from the CallableStatement.
        try {
            getParms().validate();
        } catch (StandardException e) {
            throw EmbedResultSet.noStateChangeException(e);
        }
        /* KLUDGE - ? = CALL ... returns a ResultSet().  We
			 * need executeUpdate to be false in that case.
			 */
        boolean execResult = super.executeStatement(a, executeQuery, (executeUpdate && (!hasReturnOutputParameter)));
        // Fetch the getParms into a local variable now because the
        // activation associated with a CallableStatement at this
        // point(after the executStatement) is the current activation.
        // We can now safely stuff the return value of the
        // CallableStatement into the following ParameterValueSet object.
        ParameterValueSet pvs = getParms();
        /*
			** If we have a return parameter, then we
			** consume it from the returned ResultSet
			** reset the ResultSet set to null.
			*/
        if (hasReturnOutputParameter) {
            if (SanityManager.DEBUG) {
                SanityManager.ASSERT(results != null, "null results even though we are supposed to have a return parameter");
            }
            boolean gotRow = results.next();
            if (SanityManager.DEBUG) {
                SanityManager.ASSERT(gotRow, "the return resultSet didn't have any rows");
            }
            try {
                DataValueDescriptor returnValue = pvs.getReturnValueForSet();
                returnValue.setValueFromResultSet(results, 1, true);
            } catch (StandardException e) {
                throw EmbedResultSet.noStateChangeException(e);
            } finally {
                results.close();
                results = null;
            }
            // This is a form of ? = CALL which current is not a procedure call.
            // Thus there cannot be any user result sets, so return false. execResult
            // is set to true since a result set was returned, for the return parameter.
            execResult = false;
        }
        return execResult;
    }
}
Also used : ParameterValueSet(org.apache.derby.iapi.sql.ParameterValueSet) StandardException(org.apache.derby.shared.common.error.StandardException) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 3 with ParameterValueSet

use of org.apache.derby.iapi.sql.ParameterValueSet in project derby by apache.

the class SetRoleConstantAction method executeConstantAction.

// INTERFACE METHODS
/**
 *  This is the guts of the Execution-time logic for SET ROLE.
 *
 *  @see ConstantAction#executeConstantAction
 *
 * @exception StandardException     Thrown on failure
 */
public void executeConstantAction(Activation activation) throws StandardException {
    LanguageConnectionContext lcc;
    DataDictionary dd;
    // find the language context.
    lcc = activation.getLanguageConnectionContext();
    dd = lcc.getDataDictionary();
    String thisRoleName = roleName;
    final String currentAuthId = lcc.getCurrentUserId(activation);
    final String dbo = lcc.getDataDictionary().getAuthorizationDatabaseOwner();
    TransactionController tc = lcc.getTransactionExecute();
    // SQL 2003, section 18.3, General rule 1:
    if (!tc.isIdle()) {
        throw StandardException.newException(SQLState.INVALID_TRANSACTION_STATE_ACTIVE_CONNECTION);
    }
    if (type == StatementType.SET_ROLE_DYNAMIC) {
        ParameterValueSet pvs = activation.getParameterValueSet();
        DataValueDescriptor dvs = pvs.getParameter(0);
        // SQL 2003, section 18.3, GR2: trim whitespace first, and
        // interpret as identifier, then we convert it to case normal form
        // here.
        String roleId = dvs.getString();
        if (roleId == null) {
            throw StandardException.newException(SQLState.ID_PARSE_ERROR);
        }
        thisRoleName = IdUtil.parseRoleId(roleId);
    }
    RoleGrantDescriptor rdDef = null;
    try {
        String oldRole = lcc.getCurrentRoleId(activation);
        if (oldRole != null && !oldRole.equals(thisRoleName)) {
            rdDef = dd.getRoleDefinitionDescriptor(oldRole);
            if (rdDef != null) {
                dd.getDependencyManager().invalidateFor(rdDef, DependencyManager.RECHECK_PRIVILEGES, lcc);
            }
        // else: old role else no longer exists, so ignore.
        }
        if (thisRoleName != null) {
            rdDef = dd.getRoleDefinitionDescriptor(thisRoleName);
            // SQL 2003, section 18.3, General rule 4:
            if (rdDef == null) {
                throw StandardException.newException(SQLState.ROLE_INVALID_SPECIFICATION, thisRoleName);
            }
            if (!lcc.roleIsSettable(activation, thisRoleName)) {
                throw StandardException.newException(SQLState.ROLE_INVALID_SPECIFICATION_NOT_GRANTED, thisRoleName);
            }
        }
    } finally {
        // reading above changes idle state, so reestablish it
        lcc.userCommit();
    }
    lcc.setCurrentRole(activation, rdDef != null ? thisRoleName : null);
}
Also used : ParameterValueSet(org.apache.derby.iapi.sql.ParameterValueSet) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) TransactionController(org.apache.derby.iapi.store.access.TransactionController) RoleGrantDescriptor(org.apache.derby.iapi.sql.dictionary.RoleGrantDescriptor)

Example 4 with ParameterValueSet

use of org.apache.derby.iapi.sql.ParameterValueSet in project derby by apache.

the class EmbedCallableStatement method addBatch.

public void addBatch() throws SQLException {
    checkStatus();
    ParameterValueSet pvs = getParms();
    int numberOfParameters = pvs.getParameterCount();
    for (int j = 1; j <= numberOfParameters; j++) {
        switch(pvs.getParameterMode(j)) {
            case (ParameterMetaData.parameterModeIn):
            case (ParameterMetaData.parameterModeUnknown):
                break;
            case (ParameterMetaData.parameterModeOut):
            case (ParameterMetaData.parameterModeInOut):
                throw newSQLException(SQLState.OUTPUT_PARAMS_NOT_ALLOWED);
        }
    }
    super.addBatch();
}
Also used : ParameterValueSet(org.apache.derby.iapi.sql.ParameterValueSet)

Example 5 with ParameterValueSet

use of org.apache.derby.iapi.sql.ParameterValueSet in project derby by apache.

the class SetSchemaConstantAction method executeConstantAction.

// INTERFACE METHODS
/**
 *	This is the guts of the Execution-time logic for SET SCHEMA.
 *
 *	@see ConstantAction#executeConstantAction
 *
 * @exception StandardException		Thrown on failure
 */
public void executeConstantAction(Activation activation) throws StandardException {
    LanguageConnectionContext lcc;
    DataDictionary dd;
    // find the language context.
    lcc = activation.getLanguageConnectionContext();
    dd = lcc.getDataDictionary();
    String thisSchemaName = schemaName;
    if (type == StatementType.SET_SCHEMA_DYNAMIC) {
        ParameterValueSet pvs = activation.getParameterValueSet();
        DataValueDescriptor dvs = pvs.getParameter(0);
        thisSchemaName = dvs.getString();
        // null parameter is not allowed
        if (thisSchemaName == null || thisSchemaName.length() > Limits.MAX_IDENTIFIER_LENGTH)
            throw StandardException.newException(SQLState.LANG_DB2_REPLACEMENT_ERROR, "CURRENT SCHEMA");
    } else if (type == StatementType.SET_SCHEMA_USER) {
        thisSchemaName = lcc.getCurrentUserId(activation);
    }
    SchemaDescriptor sd = dd.getSchemaDescriptor(thisSchemaName, lcc.getTransactionExecute(), true);
    lcc.setDefaultSchema(activation, sd);
}
Also used : ParameterValueSet(org.apache.derby.iapi.sql.ParameterValueSet) SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary)

Aggregations

ParameterValueSet (org.apache.derby.iapi.sql.ParameterValueSet)7 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)4 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)2 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)2 StandardException (org.apache.derby.shared.common.error.StandardException)2 RoleGrantDescriptor (org.apache.derby.iapi.sql.dictionary.RoleGrantDescriptor)1 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)1 TransactionController (org.apache.derby.iapi.store.access.TransactionController)1 VariableSizeDataValue (org.apache.derby.iapi.types.VariableSizeDataValue)1