use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.
the class FireBirdMetaModel method loadTriggers.
@Override
public List<GenericTrigger> loadTriggers(DBRProgressMonitor monitor, @NotNull GenericStructContainer container, @Nullable GenericTable table) throws DBException {
try (JDBCSession session = DBUtils.openMetaSession(monitor, container.getDataSource(), "Read triggers")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT RDB$TRIGGER_NAME,RDB$TRIGGER_SEQUENCE,RDB$TRIGGER_TYPE,RDB$DESCRIPTION FROM RDB$TRIGGERS\n" + "WHERE RDB$RELATION_NAME" + (table == null ? " IS NULL" : "=?"))) {
if (table != null) {
dbStat.setString(1, 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();
int sequence = JDBCUtils.safeGetInt(dbResult, 2);
int type = JDBCUtils.safeGetInt(dbResult, 3);
String description = JDBCUtils.safeGetString(dbResult, 4);
FireBirdTrigger trigger = new FireBirdTrigger(container, table, name, description, FireBirdTriggerType.getByType(type), sequence);
result.add(trigger);
}
}
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 FireBirdMetaModel method loadSequences.
@Override
public List<GenericSequence> loadSequences(@NotNull DBRProgressMonitor monitor, @NotNull GenericStructContainer container) throws DBException {
try (JDBCSession session = DBUtils.openMetaSession(monitor, container.getDataSource(), "Read sequences")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT RDB$GENERATOR_NAME,RDB$DESCRIPTION FROM RDB$GENERATORS")) {
List<GenericSequence> result = new ArrayList<>();
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
while (dbResult.next()) {
String name = JDBCUtils.safeGetString(dbResult, 1);
if (name == null) {
continue;
}
name = name.trim();
String description = JDBCUtils.safeGetString(dbResult, 2);
GenericSequence sequence = new GenericSequence(container, name, description, -1, 0, -1, 1);
result.add(sequence);
}
}
// Obtain sequence values
for (GenericSequence sequence : result) {
try (JDBCPreparedStatement dbSeqStat = session.prepareStatement("SELECT GEN_ID(" + sequence.getName() + ", 0) from RDB$DATABASE")) {
try (JDBCResultSet seqResults = dbSeqStat.executeQuery()) {
seqResults.next();
sequence.setLastValue(JDBCUtils.safeGetLong(seqResults, 1));
}
}
}
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 InformixMetaModel 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 query = "SELECT T1.trigname \n" + "FROM informix.systriggers AS T1, informix.systables AS T2 \n" + "WHERE T2.tabid = T1.tabid AND T2.tabname = ?";
try (JDBCPreparedStatement dbStat = session.prepareStatement(query)) {
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.JDBCPreparedStatement in project dbeaver by serge-rider.
the class SQLServerMetaModel method extractSource.
private String extractSource(DBRProgressMonitor monitor, GenericDataSource dataSource, String catalog, String schema, String name) throws DBException {
ServerType serverType = getServerType(monitor, dataSource);
String systemSchema = getSystemSchema(serverType);
catalog = DBUtils.getQuotedIdentifier(dataSource, catalog);
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Read source code")) {
String mdQuery = serverType == ServerType.SQL_SERVER ? catalog + "." + systemSchema + ".sp_helptext '" + schema + "." + name + "'" : "SELECT sc.text\n" + "FROM " + catalog + "." + systemSchema + ".sysobjects so\n" + "INNER JOIN " + catalog + "." + systemSchema + ".syscomments sc on sc.id = so.id\n" + "WHERE user_name(so.uid)=? AND so.name=?";
try (JDBCPreparedStatement dbStat = session.prepareStatement(mdQuery)) {
if (serverType == ServerType.SYBASE) {
dbStat.setString(1, schema);
dbStat.setString(2, name);
}
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 HSQLMetaModel method loadSequences.
@Override
public List<GenericSequence> loadSequences(@NotNull DBRProgressMonitor monitor, @NotNull GenericStructContainer container) throws DBException {
try (JDBCSession session = DBUtils.openMetaSession(monitor, container.getDataSource(), "Read sequences")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT * FROM INFORMATION_SCHEMA.SEQUENCES WHERE SEQUENCE_SCHEMA=?")) {
dbStat.setString(1, container.getName());
List<GenericSequence> result = new ArrayList<>();
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
while (dbResult.next()) {
String name = JDBCUtils.safeGetString(dbResult, "SEQUENCE_NAME");
if (name == null) {
continue;
}
GenericSequence sequence = new GenericSequence(container, name, null, JDBCUtils.safeGetLong(dbResult, "NEXT_VALUE"), JDBCUtils.safeGetLong(dbResult, "MINIMUM_VALUE"), JDBCUtils.safeGetLong(dbResult, "MAXIMUM_VALUE"), JDBCUtils.safeGetLong(dbResult, "INCREMENT"));
result.add(sequence);
}
}
return result;
}
} catch (SQLException e) {
throw new DBException(e, container.getDataSource());
}
}
Aggregations