use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.
the class ExasolCurrentUserPrivileges method verifyPriv.
private static Boolean verifyPriv(String sql, JDBCSession session) {
JDBCPreparedStatement dbStat;
Boolean hasPriv;
try {
dbStat = session.prepareStatement(C_CONNECTIONS);
ResultSet rs = dbStat.executeQuery();
rs.close();
dbStat.close();
hasPriv = true;
} catch (SQLException e) {
hasPriv = false;
}
return hasPriv;
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.
the class ExasolPlanAnalyser method explain.
public void explain(DBCSession session) throws DBCException {
rootNodes = new ArrayList<>();
JDBCSession connection = (JDBCSession) session;
boolean oldAutoCommit = false;
try {
oldAutoCommit = connection.getAutoCommit();
if (oldAutoCommit)
connection.setAutoCommit(false);
//alter session
JDBCUtils.executeSQL(connection, "ALTER SESSION SET PROFILE = 'ON'");
//execute query
JDBCUtils.executeSQL(connection, query);
//alter session
JDBCUtils.executeSQL(connection, "ALTER SESSION SET PROFILE = 'OFF'");
//rollback in case of DML
connection.rollback();
//alter session
JDBCUtils.executeSQL(connection, "FLUSH STATISTICS");
connection.commit();
//retrieve execute info
try (JDBCPreparedStatement stmt = connection.prepareStatement("SELECT * FROM EXA_USER_PROFILE_LAST_DAY WHERE SESSION_ID = CURRENT_SESSION AND STMT_ID = (select max(stmt_id) from EXA_USER_PROFILE_LAST_DAY where sql_text = ?)")) {
stmt.setString(1, query);
try (JDBCResultSet dbResult = stmt.executeQuery()) {
while (dbResult.next()) {
ExasolPlanNode node = new ExasolPlanNode(null, dbResult);
rootNodes.add(node);
}
}
}
} catch (SQLException e) {
throw new DBCException(e, session.getDataSource());
} finally {
//rollback changes because profile actually executes query and it could be INSERT/UPDATE
try {
connection.rollback();
if (oldAutoCommit)
connection.setAutoCommit(true);
} catch (SQLException e) {
LOG.error("Error closing plan analyser", e);
}
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement 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.JDBCPreparedStatement 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.JDBCPreparedStatement in project dbeaver by serge-rider.
the class DB2GranteeAuthCache method prepareObjectsStatement.
@Override
protected JDBCStatement prepareObjectsStatement(@NotNull JDBCSession session, @NotNull DB2Grantee db2Grantee) throws SQLException {
String userType = db2Grantee.getType().name();
String userName = db2Grantee.getName();
String sql;
int nbMax;
if (db2Grantee.getDataSource().isAtLeastV9_7()) {
sql = SQL;
nbMax = 22;
} else {
sql = SQL_WITHOUT_MODULE;
nbMax = 20;
}
JDBCPreparedStatement dbStat = session.prepareStatement(sql);
for (int i = 1; i <= nbMax; ) {
dbStat.setString(i++, userType);
dbStat.setString(i++, userName);
}
return dbStat;
}
Aggregations