Search in sources :

Example 41 with JDBCPreparedStatement

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

the class DB2TableCheckConstraintCache method prepareObjectsStatement.

@NotNull
@Override
protected JDBCStatement prepareObjectsStatement(JDBCSession session, DB2Schema db2Schema, DB2Table forTable) throws SQLException {
    String sql;
    if (forTable != null) {
        sql = SQL_CK_TAB;
    } else {
        sql = SQL_CK_ALL;
    }
    JDBCPreparedStatement dbStat = session.prepareStatement(sql);
    dbStat.setString(1, db2Schema.getName());
    if (forTable != null) {
        dbStat.setString(2, forTable.getName());
    }
    return dbStat;
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) NotNull(org.jkiss.code.NotNull)

Example 42 with JDBCPreparedStatement

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

the class DB2TableIndexCache method prepareObjectsStatement.

@Override
protected JDBCStatement prepareObjectsStatement(@NotNull JDBCSession session, @NotNull DB2TableBase db2Table) throws SQLException {
    final JDBCPreparedStatement dbStat = session.prepareStatement(SQL_INDS_TAB);
    dbStat.setString(1, db2Table.getSchema().getName());
    dbStat.setString(2, db2Table.getName());
    return dbStat;
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)

Example 43 with JDBCPreparedStatement

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

the class DB2TableReferenceCache method prepareObjectsStatement.

@NotNull
@Override
protected JDBCStatement prepareObjectsStatement(JDBCSession session, DB2Schema db2Schema, DB2Table forTable) throws SQLException {
    String sql;
    if (forTable != null) {
        sql = SQL_REF_TAB;
    } else {
        sql = SQL_REF_ALL;
    }
    JDBCPreparedStatement dbStat = session.prepareStatement(sql);
    dbStat.setString(1, db2Schema.getName());
    if (forTable != null) {
        dbStat.setString(2, forTable.getName());
    }
    return dbStat;
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) NotNull(org.jkiss.code.NotNull)

Example 44 with JDBCPreparedStatement

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

the class DB2TableForeignKeyCache method prepareObjectsStatement.

@NotNull
@Override
protected JDBCStatement prepareObjectsStatement(JDBCSession session, DB2Schema db2Schema, DB2Table forTable) throws SQLException {
    String sql;
    if (forTable != null) {
        sql = SQL_FK_TAB;
    } else {
        sql = SQL_FK_ALL;
    }
    JDBCPreparedStatement dbStat = session.prepareStatement(sql);
    dbStat.setString(1, db2Schema.getName());
    if (forTable != null) {
        dbStat.setString(2, forTable.getName());
    }
    return dbStat;
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) NotNull(org.jkiss.code.NotNull)

Example 45 with JDBCPreparedStatement

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

the class PostgreMetaModel method loadTriggers.

@Override
public List<PostgreGenericTrigger> loadTriggers(DBRProgressMonitor monitor, @NotNull GenericStructContainer container, @Nullable GenericTable table) throws DBException {
    try (JDBCSession session = DBUtils.openMetaSession(monitor, container.getDataSource(), "Read triggers")) {
        StringBuilder sql = new StringBuilder();
        sql.append("SELECT trigger_name,event_manipulation,action_order,action_condition,action_statement,action_orientation,action_timing\n" + "FROM INFORMATION_SCHEMA.TRIGGERS\n" + "WHERE ");
        if (table == null) {
            sql.append("trigger_schema=? AND event_object_table IS NULL");
        } else {
            sql.append("event_object_schema=? AND event_object_table=?");
        }
        try (JDBCPreparedStatement dbStat = session.prepareStatement(sql.toString())) {
            if (table == null) {
                dbStat.setString(1, container.getSchema().getName());
            } else {
                dbStat.setString(1, table.getSchema().getName());
                dbStat.setString(2, table.getName());
            }
            Map<String, PostgreGenericTrigger> result = new LinkedHashMap<>();
            try (JDBCResultSet dbResult = dbStat.executeQuery()) {
                while (dbResult.next()) {
                    String name = JDBCUtils.safeGetString(dbResult, "trigger_name");
                    if (name == null) {
                        continue;
                    }
                    String manipulation = JDBCUtils.safeGetString(dbResult, "event_manipulation");
                    PostgreGenericTrigger trigger = result.get(name);
                    if (trigger != null) {
                        trigger.addManipulation(manipulation);
                        continue;
                    }
                    String description = "";
                    trigger = new PostgreGenericTrigger(container, table, name, description, manipulation, JDBCUtils.safeGetString(dbResult, "action_orientation"), JDBCUtils.safeGetString(dbResult, "action_timing"), JDBCUtils.safeGetString(dbResult, "action_statement"));
                    result.put(name, trigger);
                }
            }
            return new ArrayList<>(result.values());
        }
    } 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) PostgreGenericTrigger(org.jkiss.dbeaver.ext.postgresql.model.PostgreGenericTrigger) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)100 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)66 SQLException (java.sql.SQLException)49 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)46 DBException (org.jkiss.dbeaver.DBException)45 ArrayList (java.util.ArrayList)18 DBCException (org.jkiss.dbeaver.model.exec.DBCException)15 NotNull (org.jkiss.code.NotNull)12 AbstractObjectReference (org.jkiss.dbeaver.model.impl.struct.AbstractObjectReference)10 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)10 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)8 DB2DataSource (org.jkiss.dbeaver.ext.db2.model.DB2DataSource)4 DB2XMLString (org.jkiss.dbeaver.ext.db2.info.DB2XMLString)3 GenericDataSource (org.jkiss.dbeaver.ext.generic.model.GenericDataSource)3 ResultSet (java.sql.ResultSet)2 DB2Parameter (org.jkiss.dbeaver.ext.db2.info.DB2Parameter)2 DB2Schema (org.jkiss.dbeaver.ext.db2.model.DB2Schema)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Clob (java.sql.Clob)1 SQLXML (java.sql.SQLXML)1