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());
}
}
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());
}
}
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));
}
}
}
}
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());
}
}
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;
}
Aggregations