Search in sources :

Example 16 with JDBCResultSet

use of org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet in project dbeaver by serge-rider.

the class SQLServerMetaModel method loadTriggers.

@Override
public List<? extends GenericTrigger> loadTriggers(DBRProgressMonitor monitor, @NotNull GenericStructContainer container, @Nullable GenericTable table) throws DBException {
    assert table != null;
    try (JDBCSession session = DBUtils.openMetaSession(monitor, container.getDataSource(), "Read triggers")) {
        String schema = getSystemSchema(getServerType(monitor, container.getDataSource()));
        String catalog = DBUtils.getQuotedIdentifier(table.getCatalog());
        String query = "SELECT triggers.name FROM " + catalog + "." + schema + ".sysobjects tables, " + catalog + "." + schema + ".sysobjects triggers\n" + "WHERE triggers.type = 'TR'\n" + "AND triggers.deltrig = tables.id\n" + "AND user_name(tables.uid) = ? AND tables.name = ?";
        try (JDBCPreparedStatement dbStat = session.prepareStatement(query)) {
            dbStat.setString(1, table.getSchema().getName());
            dbStat.setString(2, table.getName());
            List<GenericTrigger> result = new ArrayList<>();
            try (JDBCResultSet dbResult = dbStat.executeQuery()) {
                while (dbResult.next()) {
                    String name = JDBCUtils.safeGetString(dbResult, 1);
                    if (name == null) {
                        continue;
                    }
                    name = name.trim();
                    GenericTrigger trigger = new GenericTrigger(container, table, name, null);
                    result.add(trigger);
                }
            }
            return result;
        }
    } catch (SQLException e) {
        throw new DBException(e, container.getDataSource());
    }
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) DBException(org.jkiss.dbeaver.DBException) SQLException(java.sql.SQLException) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) ArrayList(java.util.ArrayList)

Example 17 with JDBCResultSet

use of org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet in project dbeaver by serge-rider.

the class DerbyMetaModel method loadSequences.

@Override
public List<GenericSequence> loadSequences(@NotNull DBRProgressMonitor monitor, @NotNull GenericStructContainer container) throws DBException {
    try (JDBCSession session = DBUtils.openMetaSession(monitor, container.getDataSource(), "Read procedure definition")) {
        try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT seq.SEQUENCENAME,seq.CURRENTVALUE,seq.MINIMUMVALUE,seq.MAXIMUMVALUE,seq.INCREMENT\n" + "FROM sys.SYSSEQUENCES seq,sys.SYSSCHEMAS s\n" + "WHERE seq.SCHEMAID=s.SCHEMAID AND s.SCHEMANAME=?")) {
            dbStat.setString(1, container.getName());
            try (JDBCResultSet dbResult = dbStat.executeQuery()) {
                List<GenericSequence> result = new ArrayList<GenericSequence>();
                while (dbResult.next()) {
                    GenericSequence sequence = new GenericSequence(container, JDBCUtils.safeGetString(dbResult, 1), "", JDBCUtils.safeGetLong(dbResult, 2), JDBCUtils.safeGetLong(dbResult, 3), JDBCUtils.safeGetLong(dbResult, 4), JDBCUtils.safeGetLong(dbResult, 5));
                    result.add(sequence);
                }
                return result;
            }
        }
    } catch (SQLException e) {
        throw new DBException(e, container.getDataSource());
    }
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) DBException(org.jkiss.dbeaver.DBException) SQLException(java.sql.SQLException) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) ArrayList(java.util.ArrayList)

Example 18 with JDBCResultSet

use of org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet in project dbeaver by serge-rider.

the class DB2PlanStatement method loadChildren.

// -------------
// Load children
// -------------
private void loadChildren(JDBCSession session) throws SQLException {
    mapDataObjects = new HashMap<>(32);
    try (JDBCPreparedStatement sqlStmt = session.prepareStatement(String.format(SEL_BASE_SELECT, planTableSchema, "EXPLAIN_OBJECT", "OBJECT_SCHEMA,OBJECT_NAME"))) {
        setQueryParameters(sqlStmt);
        try (JDBCResultSet res = sqlStmt.executeQuery()) {
            DB2PlanObject db2PlanObject;
            while (res.next()) {
                db2PlanObject = new DB2PlanObject(res);
                mapDataObjects.put(db2PlanObject.getNodeName(), db2PlanObject);
            }
        }
    }
    mapOperators = new HashMap<>(64);
    try (JDBCPreparedStatement sqlStmt = session.prepareStatement(String.format(SEL_BASE_SELECT, planTableSchema, "EXPLAIN_OPERATOR", "OPERATOR_ID"))) {
        setQueryParameters(sqlStmt);
        try (JDBCResultSet res = sqlStmt.executeQuery()) {
            DB2PlanOperator db2PlanOperator;
            while (res.next()) {
                db2PlanOperator = new DB2PlanOperator(session, res, this, planTableSchema);
                mapOperators.put(db2PlanOperator.getNodeName(), db2PlanOperator);
                if (db2PlanOperator.getOperatorType() == DB2PlanOperatorType.RETURN) {
                    rootNode = db2PlanOperator;
                }
            }
        }
    }
    listStreams = new ArrayList<>();
    try (JDBCPreparedStatement sqlStmt = session.prepareStatement(String.format(SEL_BASE_SELECT, planTableSchema, "EXPLAIN_STREAM", "STREAM_ID DESC"))) {
        setQueryParameters(sqlStmt);
        try (JDBCResultSet res = sqlStmt.executeQuery()) {
            while (res.next()) {
                listStreams.add(new DB2PlanStream(res, this));
            }
        }
    }
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)

Example 19 with JDBCResultSet

use of org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet in project dbeaver by serge-rider.

the class DB2PlanAnalyser method explain.

// ----------------
// Business Methods
// ----------------
public void explain(JDBCSession session) throws DBCException {
    Integer stmtNo = STMT_NO_GEN.incrementAndGet();
    String explainStmt = String.format(PT_EXPLAIN, stmtNo, query);
    LOG.debug("Schema=" + planTableSchema + " : " + explainStmt);
    try {
        // Start by cleaning old rows for safety
        cleanExplainTables(session, stmtNo, planTableSchema);
        // Explain
        try (JDBCPreparedStatement dbStat = session.prepareStatement(String.format(PT_EXPLAIN, stmtNo, query))) {
            dbStat.execute();
        }
        // Build Node Structure
        try (JDBCPreparedStatement dbStat = session.prepareStatement(String.format(SEL_STMT, planTableSchema))) {
            dbStat.setInt(1, stmtNo);
            try (JDBCResultSet dbResult = dbStat.executeQuery()) {
                dbResult.next();
                db2PlanStatement = new DB2PlanStatement(session, dbResult, planTableSchema);
            }
        }
        listNodes = db2PlanStatement.buildNodes();
        // Clean afterward
        cleanExplainTables(session, stmtNo, planTableSchema);
    } catch (SQLException e) {
        throw new DBCException(e, session.getDataSource());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) SQLException(java.sql.SQLException) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) DBCException(org.jkiss.dbeaver.model.exec.DBCException)

Example 20 with JDBCResultSet

use of org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet in project dbeaver by serge-rider.

the class JDBCCallableStatementImpl method getResultSet.

@Nullable
@Override
public JDBCResultSet getResultSet() throws SQLException {
    JDBCResultSet resultSet = makeResultSet(getOriginal().getResultSet());
    if (resultSet == null && procedure != null) {
        JDBCResultSetCallable procResults = new JDBCResultSetCallable(getConnection(), this);
        try {
            Collection<? extends DBSProcedureParameter> params = procedure.getParameters(getConnection().getProgressMonitor());
            if (!CommonUtils.isEmpty(params)) {
                for (DBSProcedureParameter param : params) {
                    if (param.getParameterKind() == DBSProcedureParameterKind.OUT || param.getParameterKind() == DBSProcedureParameterKind.INOUT) {
                        procResults.addColumn(param.getName(), param.getParameterType());
                    }
                }
            }
        } catch (DBException e) {
            log.warn("Error extracting callable results", e);
        }
        procResults.addRow();
        return procResults;
    }
    return resultSet;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBSProcedureParameter(org.jkiss.dbeaver.model.struct.rdb.DBSProcedureParameter) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) Nullable(org.jkiss.code.Nullable)

Aggregations

JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)82 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)66 SQLException (java.sql.SQLException)57 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)54 DBException (org.jkiss.dbeaver.DBException)53 ArrayList (java.util.ArrayList)20 DBCException (org.jkiss.dbeaver.model.exec.DBCException)15 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)12 JDBCStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement)10 AbstractObjectReference (org.jkiss.dbeaver.model.impl.struct.AbstractObjectReference)10 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)8 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)5 GenericMetaObject (org.jkiss.dbeaver.ext.generic.model.meta.GenericMetaObject)4 NotNull (org.jkiss.code.NotNull)3 DB2XMLString (org.jkiss.dbeaver.ext.db2.info.DB2XMLString)3 DB2DataSource (org.jkiss.dbeaver.ext.db2.model.DB2DataSource)3 GenericDataSource (org.jkiss.dbeaver.ext.generic.model.GenericDataSource)3 Matcher (java.util.regex.Matcher)2 DB2Parameter (org.jkiss.dbeaver.ext.db2.info.DB2Parameter)2 DB2Schema (org.jkiss.dbeaver.ext.db2.model.DB2Schema)2