Search in sources :

Example 96 with Set

use of org.h2.command.dml.Set in project h2database by h2database.

the class JdbcDatabaseMetaData method getIndexInfo.

/**
 * Gets the list of indexes for this database. The primary key index (if
 * there is one) is also listed, with the name PRIMARY_KEY. The result set
 * is sorted by NON_UNIQUE ('false' first), TYPE, TABLE_SCHEM, INDEX_NAME,
 * and ORDINAL_POSITION.
 *
 * <ol>
 * <li>TABLE_CAT (String) table catalog</li>
 * <li>TABLE_SCHEM (String) table schema</li>
 * <li>TABLE_NAME (String) table name</li>
 * <li>NON_UNIQUE (boolean) 'true' if non-unique</li>
 * <li>INDEX_QUALIFIER (String) index catalog</li>
 * <li>INDEX_NAME (String) index name</li>
 * <li>TYPE (short) the index type (always tableIndexOther)</li>
 * <li>ORDINAL_POSITION (short) column index (1, 2, ...)</li>
 * <li>COLUMN_NAME (String) column name</li>
 * <li>ASC_OR_DESC (String) ascending or descending (always 'A')</li>
 * <li>CARDINALITY (int) numbers of unique values</li>
 * <li>PAGES (int) number of pages use (always 0)</li>
 * <li>FILTER_CONDITION (String) filter condition (always empty)</li>
 * <li>SORT_TYPE (int) the sort type bit map: 1=DESCENDING,
 * 2=NULLS_FIRST, 4=NULLS_LAST</li>
 * </ol>
 *
 * @param catalogPattern null or the catalog name
 * @param schemaPattern null (to get all objects) or a schema name
 *            (uppercase for unquoted names)
 * @param tableName table name (must be specified)
 * @param unique only unique indexes
 * @param approximate is ignored
 * @return the list of indexes and columns
 * @throws SQLException if the connection is closed
 */
@Override
public ResultSet getIndexInfo(String catalogPattern, String schemaPattern, String tableName, boolean unique, boolean approximate) throws SQLException {
    try {
        if (isDebugEnabled()) {
            debugCode("getIndexInfo(" + quote(catalogPattern) + ", " + quote(schemaPattern) + ", " + quote(tableName) + ", " + unique + ", " + approximate + ");");
        }
        String uniqueCondition;
        if (unique) {
            uniqueCondition = "NON_UNIQUE=FALSE";
        } else {
            uniqueCondition = "TRUE";
        }
        checkClosed();
        PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT " + "TABLE_CATALOG TABLE_CAT, " + "TABLE_SCHEMA TABLE_SCHEM, " + "TABLE_NAME, " + "NON_UNIQUE, " + "TABLE_CATALOG INDEX_QUALIFIER, " + "INDEX_NAME, " + "INDEX_TYPE TYPE, " + "ORDINAL_POSITION, " + "COLUMN_NAME, " + "ASC_OR_DESC, " + // TODO meta data for number of unique values in an index
        "CARDINALITY, " + "PAGES, " + "FILTER_CONDITION, " + "SORT_TYPE " + "FROM INFORMATION_SCHEMA.INDEXES " + "WHERE TABLE_CATALOG LIKE ? ESCAPE ? " + "AND TABLE_SCHEMA LIKE ? ESCAPE ? " + "AND (" + uniqueCondition + ") " + "AND TABLE_NAME = ? " + "ORDER BY NON_UNIQUE, TYPE, TABLE_SCHEM, INDEX_NAME, ORDINAL_POSITION");
        prep.setString(1, getCatalogPattern(catalogPattern));
        prep.setString(2, "\\");
        prep.setString(3, getSchemaPattern(schemaPattern));
        prep.setString(4, "\\");
        prep.setString(5, tableName);
        return prep.executeQuery();
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Example 97 with Set

use of org.h2.command.dml.Set in project h2database by h2database.

the class JdbcDatabaseMetaData method getImportedKeys.

/**
 * Gets the list of primary key columns that are referenced by a table. The
 * result set is sorted by PKTABLE_CAT, PKTABLE_SCHEM, PKTABLE_NAME,
 * FK_NAME, KEY_SEQ.
 *
 * <ol>
 * <li>PKTABLE_CAT (String) primary catalog</li>
 * <li>PKTABLE_SCHEM (String) primary schema</li>
 * <li>PKTABLE_NAME (String) primary table</li>
 * <li>PKCOLUMN_NAME (String) primary column</li>
 * <li>FKTABLE_CAT (String) foreign catalog</li>
 * <li>FKTABLE_SCHEM (String) foreign schema</li>
 * <li>FKTABLE_NAME (String) foreign table</li>
 * <li>FKCOLUMN_NAME (String) foreign column</li>
 * <li>KEY_SEQ (short) sequence number (1, 2, ...)</li>
 * <li>UPDATE_RULE (short) action on update (see
 * DatabaseMetaData.importedKey...)</li>
 * <li>DELETE_RULE (short) action on delete (see
 * DatabaseMetaData.importedKey...)</li>
 * <li>FK_NAME (String) foreign key name</li>
 * <li>PK_NAME (String) primary key name</li>
 * <li>DEFERRABILITY (short) deferrable or not (always
 * importedKeyNotDeferrable)</li>
 * </ol>
 *
 * @param catalogPattern null (to get all objects) or the catalog name
 * @param schemaPattern the schema name of the foreign table
 * @param tableName the name of the foreign table
 * @return the result set
 * @throws SQLException if the connection is closed
 */
@Override
public ResultSet getImportedKeys(String catalogPattern, String schemaPattern, String tableName) throws SQLException {
    try {
        if (isDebugEnabled()) {
            debugCode("getImportedKeys(" + quote(catalogPattern) + ", " + quote(schemaPattern) + ", " + quote(tableName) + ");");
        }
        checkClosed();
        PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT " + "PKTABLE_CATALOG PKTABLE_CAT, " + "PKTABLE_SCHEMA PKTABLE_SCHEM, " + "PKTABLE_NAME PKTABLE_NAME, " + "PKCOLUMN_NAME, " + "FKTABLE_CATALOG FKTABLE_CAT, " + "FKTABLE_SCHEMA FKTABLE_SCHEM, " + "FKTABLE_NAME, " + "FKCOLUMN_NAME, " + "ORDINAL_POSITION KEY_SEQ, " + "UPDATE_RULE, " + "DELETE_RULE, " + "FK_NAME, " + "PK_NAME, " + "DEFERRABILITY " + "FROM INFORMATION_SCHEMA.CROSS_REFERENCES " + "WHERE FKTABLE_CATALOG LIKE ? ESCAPE ? " + "AND FKTABLE_SCHEMA LIKE ? ESCAPE ? " + "AND FKTABLE_NAME = ? " + "ORDER BY PKTABLE_CAT, PKTABLE_SCHEM, PKTABLE_NAME, FK_NAME, KEY_SEQ");
        prep.setString(1, getCatalogPattern(catalogPattern));
        prep.setString(2, "\\");
        prep.setString(3, getSchemaPattern(schemaPattern));
        prep.setString(4, "\\");
        prep.setString(5, tableName);
        return prep.executeQuery();
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Example 98 with Set

use of org.h2.command.dml.Set in project h2database by h2database.

the class JdbcDatabaseMetaData method getVersionColumns.

/**
 * Get the list of columns that are update when any value is updated.
 * The result set is always empty.
 *
 * <ol>
 * <li>1 SCOPE (int) not used</li>
 * <li>2 COLUMN_NAME (String) column name</li>
 * <li>3 DATA_TYPE (int) SQL data type - see also java.sql.Types</li>
 * <li>4 TYPE_NAME (String) data type name</li>
 * <li>5 COLUMN_SIZE (int) precision
 *         (values larger than 2 GB are returned as 2 GB)</li>
 * <li>6 BUFFER_LENGTH (int) length (bytes)</li>
 * <li>7 DECIMAL_DIGITS (int) scale</li>
 * <li>8 PSEUDO_COLUMN (int) is this column a pseudo column</li>
 * </ol>
 *
 * @param catalog null (to get all objects) or the catalog name
 * @param schema null (to get all objects) or a schema name
 * @param tableName table name (must be specified)
 * @return an empty result set
 * @throws SQLException if the connection is closed
 */
@Override
public ResultSet getVersionColumns(String catalog, String schema, String tableName) throws SQLException {
    try {
        if (isDebugEnabled()) {
            debugCode("getVersionColumns(" + quote(catalog) + ", " + quote(schema) + ", " + quote(tableName) + ");");
        }
        checkClosed();
        PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT " + "ZERO() SCOPE, " + "COLUMN_NAME, " + "CAST(DATA_TYPE AS INT) DATA_TYPE, " + "TYPE_NAME, " + "NUMERIC_PRECISION COLUMN_SIZE, " + "NUMERIC_PRECISION BUFFER_LENGTH, " + "NUMERIC_PRECISION DECIMAL_DIGITS, " + "ZERO() PSEUDO_COLUMN " + "FROM INFORMATION_SCHEMA.COLUMNS " + "WHERE FALSE");
        return prep.executeQuery();
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Example 99 with Set

use of org.h2.command.dml.Set in project h2database by h2database.

the class JdbcDatabaseMetaData method getUDTs.

/**
 * Gets the list of user-defined data types.
 * This call returns an empty result set.
 *
 * <ol>
 * <li>TYPE_CAT (String) catalog</li>
 * <li>TYPE_SCHEM (String) schema</li>
 * <li>TYPE_NAME (String) type name</li>
 * <li>CLASS_NAME (String) Java class</li>
 * <li>DATA_TYPE (short) SQL Type - see also java.sql.Types</li>
 * <li>REMARKS (String) description</li>
 * <li>BASE_TYPE (short) base type - see also java.sql.Types</li>
 * </ol>
 *
 * @param catalog ignored
 * @param schemaPattern ignored
 * @param typeNamePattern ignored
 * @param types ignored
 * @return an empty result set
 * @throws SQLException if the connection is closed
 */
@Override
public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) throws SQLException {
    try {
        if (isDebugEnabled()) {
            debugCode("getUDTs(" + quote(catalog) + ", " + quote(schemaPattern) + ", " + quote(typeNamePattern) + ", " + quoteIntArray(types) + ");");
        }
        checkClosed();
        PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT " + "CAST(NULL AS VARCHAR) TYPE_CAT, " + "CAST(NULL AS VARCHAR) TYPE_SCHEM, " + "CAST(NULL AS VARCHAR) TYPE_NAME, " + "CAST(NULL AS VARCHAR) CLASS_NAME, " + "CAST(NULL AS SMALLINT) DATA_TYPE, " + "CAST(NULL AS VARCHAR) REMARKS, " + "CAST(NULL AS SMALLINT) BASE_TYPE " + "FROM DUAL WHERE FALSE");
        return prep.executeQuery();
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Example 100 with Set

use of org.h2.command.dml.Set in project h2database by h2database.

the class JdbcDatabaseMetaData method getTablePrivileges.

/**
 * Gets the list of table privileges. The result set is sorted by
 * TABLE_SCHEM, TABLE_NAME, and PRIVILEGE.
 *
 * <ol>
 * <li>TABLE_CAT (String) table catalog</li>
 * <li>TABLE_SCHEM (String) table schema</li>
 * <li>TABLE_NAME (String) table name</li>
 * <li>GRANTOR (String) grantor of access</li>
 * <li>GRANTEE (String) grantee of access</li>
 * <li>PRIVILEGE (String) SELECT, INSERT, UPDATE, DELETE or REFERENCES
 * (only one per row)</li>
 * <li>IS_GRANTABLE (String) YES means the grantee can grant access to
 * others</li>
 * </ol>
 *
 * @param catalogPattern null (to get all objects) or the catalog name
 * @param schemaPattern null (to get all objects) or a schema name
 *            (uppercase for unquoted names)
 * @param tableNamePattern null (to get all objects) or a table name
 *            (uppercase for unquoted names)
 * @return the list of privileges
 * @throws SQLException if the connection is closed
 */
@Override
public ResultSet getTablePrivileges(String catalogPattern, String schemaPattern, String tableNamePattern) throws SQLException {
    try {
        if (isDebugEnabled()) {
            debugCode("getTablePrivileges(" + quote(catalogPattern) + ", " + quote(schemaPattern) + ", " + quote(tableNamePattern) + ");");
        }
        checkClosed();
        PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT " + "TABLE_CATALOG TABLE_CAT, " + "TABLE_SCHEMA TABLE_SCHEM, " + "TABLE_NAME, " + "GRANTOR, " + "GRANTEE, " + "PRIVILEGE_TYPE PRIVILEGE, " + "IS_GRANTABLE " + "FROM INFORMATION_SCHEMA.TABLE_PRIVILEGES " + "WHERE TABLE_CATALOG LIKE ? ESCAPE ? " + "AND TABLE_SCHEMA LIKE ? ESCAPE ? " + "AND TABLE_NAME LIKE ? ESCAPE ? " + "ORDER BY TABLE_SCHEM, TABLE_NAME, PRIVILEGE");
        prep.setString(1, getCatalogPattern(catalogPattern));
        prep.setString(2, "\\");
        prep.setString(3, getSchemaPattern(schemaPattern));
        prep.setString(4, "\\");
        prep.setString(5, getPattern(tableNamePattern));
        prep.setString(6, "\\");
        return prep.executeQuery();
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Aggregations

SQLException (java.sql.SQLException)107 DbException (org.h2.message.DbException)80 PreparedStatement (java.sql.PreparedStatement)78 Connection (java.sql.Connection)70 Statement (java.sql.Statement)63 ResultSet (java.sql.ResultSet)62 Value (org.h2.value.Value)51 JdbcConnection (org.h2.jdbc.JdbcConnection)48 SimpleResultSet (org.h2.tools.SimpleResultSet)36 HashSet (java.util.HashSet)28 Column (org.h2.table.Column)24 Savepoint (java.sql.Savepoint)23 ValueString (org.h2.value.ValueString)21 IOException (java.io.IOException)20 Random (java.util.Random)17 Expression (org.h2.expression.Expression)16 Task (org.h2.util.Task)16 ExpressionColumn (org.h2.expression.ExpressionColumn)14 ValueExpression (org.h2.expression.ValueExpression)13 IndexColumn (org.h2.table.IndexColumn)13