## org.eclipse.datatools.connectivity.oda
Interface IQuery

All Known Subinterfaces:
  IAdvancedQuery

All Known Implementing Classes:
  OdaAdvancedQuery, OdaQuery

public interface IQuery

The base query interface to prepare and execute a query text to retrieve data. This base interface covers most basic query capabilities, such as returning data rows in a single result set, and may support scalar input parameters.

Note: An IQuery object must ALWAYS be prepared before calling execute(). For example:

`query.prepare( "SELECT * FROM TABLE" );
// prepare succeeded, no exception was thrown
query.execute();`

An input parameter may be referenced by name or position.
The case-sensitivity of a name is implementation-dependent. All indices in this interface are 1-based.

Method Summary
`void` `clearInParameters()` An optional method to clear the current input parameter values immediately.
`void` `close()` Attempts to close this IQuery.
`IResultSet` `executeQuery()` Executes the query's prepared query text and returns a single IResultSet object.
`int` `findInParameter(java.lang.String parameterName)` Returns the 1-based index of the specified input parameter.
`int` `getMaxRows()` Returns the maximum number of rows that can be fetched from the query's result set(s).
`IResultSetMetaData` `getMetaData()` Returns the metadata of the current result set for this prepared IQuery.
`IParameterMetaData` `getParameterMetaData()` Returns the count, data types, and other metadata attributes of the parameters defined in this prepared IQuery object.
`SortSpec` `getSortSpec()` Returns the sort specification associated with this `IQuery`.
`void` `prepare(java.lang.String queryText)` Performs necessary checks to determine whether the query text is of a valid format supported by this IQuery implementation.
`void` `setAppContext(java.lang.Object context)` Sets the query context passed through from an application.
`void` `setBigDecimal(int parameterId, java.math.BigDecimal value)` Sets the designated parameter to the given decimal value.
`void` `setBigDecimal(java.lang.String parameterName, java.math.BigDecimal value)` Sets the designated parameter to the given decimal value.
`void` `setDate(int parameterId, java.sql.Date value)` Sets the designated parameter to the given Date value.
`void` `setDate(java.lang.String parameterName, java.sql.Date value)` Sets the designated parameter to the given Date value.
`void` `setDouble(int parameterId, double value)` Sets the designated parameter to the given double value.
`void` `setDouble(java.lang.String parameterName, double value)` Sets the designated parameter to the given double value.
`void` `setInt(int parameterId, int value)` Sets the designated parameter to the given integer value.
`void` `setInt(java.lang.String parameterName, int value)` Sets the designated parameter to the given integer value.
`void` `setMaxRows(int max)` Specifies the maximum number of rows that can be fetched from the query's result set(s).
`void` `setProperty(java.lang.String name, java.lang.String value)` Sets the named property with the specified value.
`void` `setSortSpec(SortSpec sortBy)` Specifies the sort specification for this `IQuery`.
`void` `setString(int parameterId, java.lang.String value)` Sets the designated parameter to the given string value.
`void` `setString(java.lang.String parameterName, java.lang.String value)` Sets the designated parameter to the given string value.
`void` `setTime(int parameterId, java.sql.Time value)` Sets the designated parameter to the given Time value.
`void` `setTime(java.lang.String parameterName, java.sql.Time value)` Sets the designated parameter to the given Time value.
`void` `setTimestamp(int parameterId, java.sql.Timestamp value)` Sets the designated parameter to the given Timestamp value.
`void` `setTimestamp(java.lang.String parameterName, java.sql.Timestamp value)` Sets the designated parameter to the given Timestamp value.

Method Detail

### prepare

    public void prepare(java.lang.String queryText)
                 throws OdaException

  Performs necessary checks to determine whether the query text is of a valid format supported by this IQuery implementation.

  Parameters:
    `queryText` - a query text to prepare or pre-compile; it cannot be null.
  Throws:
    `OdaException` - if data source error occurs

### setAppContext

    public void setAppContext(java.lang.Object context)
                       throws OdaException

  Sets the query context passed through from an application. Its handling is specific to individual driver implementation. The context argument could be null. The method may be called by an ODA consumer application with a null argument, i.e. passing a null context object to this instance, only if a non-null context was previously passed through to the same instance.
  Note: This method should be called before prepare().
  An optional method. If any part of the context is not recognized by the driver, it should simply ignore, and not throw an exception.

  Parameters:
    `context` - Application context object of this instance.
  Throws:
    `OdaException` - if data source error occurs
  Since:
    3.0

### setProperty

    public void setProperty(java.lang.String name,
                            java.lang.String value)
                     throws OdaException

  Sets the named property with the specified value. Multiple calls using the same property name may be allowed to assign multiple values to the same property. Its handling is specific to individual driver implementation.
  Each ODA extension property defined for a data set triggers an ODA consumer to call this method with corresponding property value, which could be null. An ODA consumer does not distinguish whether a property value is not set or explicitly set to null. Its handling is specific to individual driver implementation.
  Note: This method should be called before executeQuery() or other extended execution method(s).
  An optional method.

  Parameters:
    `name` - name of the property.
    `value` - value to assign to the named property; could be null.
  Throws:
    `OdaException` - if data source error occurs

### close

    public void close()
               throws OdaException

  Attempts to close this IQuery.

  Throws:
    `OdaException` - if data source error occurs

### setMaxRows

    public void setMaxRows(int max)
                    throws OdaException

  Specifies the maximum number of rows that can be fetched from the query's result set(s).
  An optional method.

  Parameters:
    `max` - the maximum number of rows that can be fetched from each result set of this IQuery; zero means there is no limit.
  Throws:
    `OdaException` - if data source error occurs

### getMaxRows

    public int getMaxRows()
                   throws OdaException

  Returns the maximum number of rows that can be fetched from the query's result set(s).
  An optional method.

  Returns:
    the maximum number of rows that can be fetched from each result set of this IQuery; zero means there is no limit.
  Throws:
    `OdaException` - if data source error occurs

### getMetaData

    public IResultSetMetaData getMetaData()
                                   throws OdaException

  Returns the metadata of the current result set for this prepared IQuery. This should only be called after prepare(). If the method is called before the IQuery is executed, the returned metadata refers to its first result set.

  Returns:
    an IResultSetMetaData object.
  Throws:
    `OdaException` - if data source error occurs

### executeQuery

    public IResultSet executeQuery()
                            throws OdaException

  Executes the query's prepared query text and returns a single IResultSet object. Note: This should only be called after prepare().

  Returns:
    an IResultSet object.
  Throws:
    `OdaException` - if data source error occurs

### clearInParameters

    public void clearInParameters()
                           throws OdaException

  An optional method to clear the current input parameter values immediately.

  In general, input parameter values remain in force for repeated use of a query. Setting a parameter value automatically clears its previous value. However, to reset all the parameters to their default values without explicitly setting new values, use this method.

  Throws:
    `OdaException` - if data source error occurs
    `java.lang.UnsupportedOperationException` - if this operation is not supported

### setInt

    public void setInt(java.lang.String parameterName,
                       int value)
                throws OdaException

  Sets the designated parameter to the given integer value.

  Parameters:
    `parameterName` - name of the parameter.
    `value` - integer value.
  Throws:
    `OdaException` - if data source error occurs

### setInt

    public void setInt(int parameterId,
                       int value)
                throws OdaException

  Sets the designated parameter to the given integer value.

  Parameters:
    `parameterId` - id of the parameter (1-based).
    `value` - integer value.
  Throws:
    `OdaException` - if data source error occurs

### setDouble

    public void setDouble(java.lang.String parameterName,
                          double value)
                   throws OdaException

  Sets the designated parameter to the given double value.

  Parameters:
    `parameterName` - name of the parameter.
    `value` - double value.
  Throws:
    `OdaException` - if data source error occurs

### setDouble

    public void setDouble(int parameterId,
                          double value)
                   throws OdaException

  Sets the designated parameter to the given double value.

  Parameters:
    `parameterId` - id of the parameter (1-based).
    `value` - double value.
  Throws:
    `OdaException` - if data source error occurs

### setBigDecimal

    public void setBigDecimal(java.lang.String parameterName,
                              java.math.BigDecimal value)
                       throws OdaException

  Sets the designated parameter to the given decimal value.

  Parameters:
    `parameterName` - name of the parameter.
    `value` - decimal value.
  Throws:
    `OdaException` - if data source error occurs

### setBigDecimal

    public void setBigDecimal(int parameterId,
                              java.math.BigDecimal value)
                       throws OdaException

  Sets the designated parameter to the given decimal value.

  Parameters:
    `parameterId` - id of the parameter (1-based).
    `value` - decimal value.
  Throws:
    `OdaException` - if data source error occurs

### setString

    public void setString(java.lang.String parameterName,
                          java.lang.String value)
                   throws OdaException

  Sets the designated parameter to the given string value. An ODA runtime driver may or may not support setString() on a non-String type parameter. The format of the string parameter is implementation-dependent.

  Parameters:
    `parameterName` - name of the parameter.
    `value` - string value.
  Throws:
    `OdaException` - if data source error occurs

### setString

    public void setString(int parameterId,
                          java.lang.String value)
                   throws OdaException

  Sets the designated parameter to the given string value. An ODA runtime driver may or may not support setString() on a non-String type parameter. The format of the string parameter is implementation-dependent.

  Parameters:
    `parameterId` - id of the parameter (1-based).
    `value` - string value.
  Throws:
    `OdaException` - if data source error occurs

### setDate

    public void setDate(java.lang.String parameterName,
                        java.sql.Date value)
                 throws OdaException

  Sets the designated parameter to the given Date value.

  Parameters:
    `parameterName` - name of the parameter.
    `value` - the java.sql.Date value.
  Throws:
    `OdaException` - if data source error occurs

### setDate

    public void setDate(int parameterId,
                        java.sql.Date value)
                 throws OdaException

  Sets the designated parameter to the given Date value.

  Parameters:
    `parameterId` - id of the parameter (1-based).
    `value` - the java.sql.Date value.
  Throws:
    `OdaException` - if data source error occurs

### setTime

    public void setTime(java.lang.String parameterName,
                        java.sql.Time value)
                 throws OdaException

  Sets the designated parameter to the given Time value.

  Parameters:
    `parameterName` - name of the parameter.
    `value` - the java.sql.Time value.
  Throws:
    `OdaException` - if data source error occurs

### setTime

    public void setTime(int parameterId,
                        java.sql.Time value)
                 throws OdaException

  Sets the designated parameter to the given Time value.

  Parameters:
    `parameterId` - id of the parameter (1-based).
    `value` - the java.sql.Time value.
  Throws:
    `OdaException` - if data source error occurs

### setTimestamp

    public void setTimestamp(java.lang.String parameterName,
                             java.sql.Timestamp value)
                      throws OdaException

  Sets the designated parameter to the given Timestamp value.

  Parameters:
    `parameterName` - name of the parameter.
    `value` - the java.sql.Timestamp value.
  Throws:
    `OdaException` - if data source error occurs

### setTimestamp

    public void setTimestamp(int parameterId,
                             java.sql.Timestamp value)
                      throws OdaException

  Sets the designated parameter to the given Timestamp value.

  Parameters:
    `parameterId` - id of the parameter (1-based).
    `value` - the java.sql.Timestamp value.
  Throws:
    `OdaException` - if data source error occurs

### findInParameter

    public int findInParameter(java.lang.String parameterName)
                        throws OdaException

  Returns the 1-based index of the specified input parameter.

  Parameters:
    `parameterName` - name of the parameter.
  Returns:
    index of the parameter.
  Throws:
    `OdaException` - if data source error occurs

### getParameterMetaData

    public IParameterMetaData getParameterMetaData()
                                            throws OdaException

  Returns the count, data types, and other metadata attributes of the parameters defined in this prepared IQuery object. Its implementation is required for ODA runtime drivers.

  Note: This should only be called after prepare() is called.

  Returns:
    an IParameterMetaData object that contains information about this prepared IQuery object's parameters.
  Throws:
    `OdaException` - if data source error occurs

### setSortSpec

    public void setSortSpec(SortSpec sortBy)
                     throws OdaException

  Specifies the sort specification for this `IQuery`. The setter must be called before this `IQuery` is executed or before `getMoreResults` is called. More sort keys can be added to the SortSpec after it is associated with the query. The final sort specification is then applied to subsequent result set(s) at execution.

  It is up to individual ODA runtme drivers to validate the type of sort specification that are acceptable to its data provider, based on its level of dynamic sorting support. An `OdaException` should be thrown if the specified sort specification is not valid or not supported by the driver.

  Parameters:
    `sortBy` - the sort specification assigned to this `IQuery`.
  Throws:
    `OdaException` - if data source error occurs

### getSortSpec

    public SortSpec getSortSpec()
                         throws OdaException

  Returns the sort specification associated with this `IQuery`.

  Returns:
    the `SortSpec` assigned to this `IQuery`; `null` if no `SortSpec` was explicitly set.
  Throws:
    `OdaException` - if data source error occurs

Copyright © 2006 Actuate, IBM Corporation, Sybase, Inc. and others. All rights reserved.