use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.
the class PostgrePlanAnalyser method explain.
public void explain(DBCSession session) throws DBCException {
JDBCSession connection = (JDBCSession) session;
boolean oldAutoCommit = false;
try {
oldAutoCommit = connection.getAutoCommit();
if (oldAutoCommit) {
connection.setAutoCommit(false);
}
try (JDBCPreparedStatement dbStat = connection.prepareStatement("EXPLAIN (FORMAT XML, ANALYSE) " + query)) {
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
if (dbResult.next()) {
SQLXML planXML = dbResult.getSQLXML(1);
parsePlan(planXML);
}
} catch (XMLException e) {
throw new DBCException("Can't parse plan XML", e);
}
}
} catch (SQLException e) {
throw new DBCException(e, session.getDataSource());
} finally {
// Rollback changes because EXPLAIN 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 SQLiteMetaModel method loadTriggers.
@Override
public List<? extends GenericTrigger> loadTriggers(DBRProgressMonitor monitor, @NotNull GenericStructContainer container, @Nullable GenericTable table) throws DBException {
if (table == null) {
return Collections.emptyList();
}
try (JDBCSession session = DBUtils.openMetaSession(monitor, container.getDataSource(), "Read triggers")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT name FROM sqlite_master WHERE type='trigger' AND tbl_name=?")) {
dbStat.setString(1, table.getName());
List<GenericTrigger> result = new ArrayList<>();
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
while (dbResult.next()) {
String name = JDBCUtils.safeGetString(dbResult, 1);
result.add(new GenericTrigger(container, table, name, null));
}
}
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 TeradataMetaModel method getTableDDL.
@Override
public String getTableDDL(DBRProgressMonitor monitor, GenericTable sourceObject) throws DBException {
GenericDataSource dataSource = sourceObject.getDataSource();
boolean isView = sourceObject.isView();
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Read Teradata object DDL")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SHOW " + (isView ? "VIEW" : "TABLE") + " " + sourceObject.getFullyQualifiedName(DBPEvaluationContext.DDL))) {
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
StringBuilder sql = new StringBuilder();
while (dbResult.nextRow()) {
sql.append(dbResult.getString(1));
}
return sql.toString();
}
}
} catch (SQLException e) {
throw new DBException(e, dataSource);
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.
the class PostgreDataType method readEnumValues.
private void readEnumValues(JDBCSession session) throws DBException {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT e.enumlabel \n" + "FROM pg_catalog.pg_enum e\n" + "WHERE e.enumtypid=?")) {
dbStat.setLong(1, getObjectId());
try (JDBCResultSet rs = dbStat.executeQuery()) {
List<String> values = new ArrayList<>();
while (rs.nextRow()) {
values.add(JDBCUtils.safeGetString(rs, 1));
}
enumValues = values.toArray();
}
} catch (SQLException e) {
throw new DBException("Error reading enum values", e, getDataSource());
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.
the class PostgreDataTypeCache method prepareObjectsStatement.
@Override
protected JDBCStatement prepareObjectsStatement(@NotNull JDBCSession session, @NotNull PostgreSchema owner) throws SQLException {
final JDBCPreparedStatement dbStat = session.prepareStatement("SELECT t.oid,t.* \n" + "FROM pg_catalog.pg_type t WHERE typnamespace=?\n" + "ORDER by t.oid");
dbStat.setLong(1, owner.getObjectId());
return dbStat;
}
Aggregations