Search in sources :

Example 1 with GenericDataSource

use of org.jkiss.dbeaver.ext.generic.model.GenericDataSource in project dbeaver by serge-rider.

the class SQLiteTableManager method addObjectRenameActions.

@Override
protected void addObjectRenameActions(List<DBEPersistAction> actions, ObjectRenameCommand command) {
    final GenericDataSource dataSource = command.getObject().getDataSource();
    actions.add(new SQLDatabasePersistAction("Rename table", //$NON-NLS-1$
    "ALTER TABLE " + command.getObject().getFullyQualifiedName(DBPEvaluationContext.DDL) + " RENAME TO " + //$NON-NLS-1$
    DBUtils.getQuotedIdentifier(dataSource, command.getNewName())));
}
Also used : GenericDataSource(org.jkiss.dbeaver.ext.generic.model.GenericDataSource) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 2 with GenericDataSource

use of org.jkiss.dbeaver.ext.generic.model.GenericDataSource in project dbeaver by serge-rider.

the class NetezzaMetaModel method getProcedureDDL.

@Override
public String getProcedureDDL(DBRProgressMonitor monitor, GenericProcedure sourceObject) throws DBException {
    GenericDataSource dataSource = sourceObject.getDataSource();
    try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Read Netezza procedure source")) {
        try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT p.proceduresignature,p.returns,p.proceduresource " + "FROM _v_procedure p " + "WHERE p.owner=? AND p.procedure=?")) {
            dbStat.setString(1, sourceObject.getContainer().getName());
            dbStat.setString(2, sourceObject.getName());
            try (JDBCResultSet dbResult = dbStat.executeQuery()) {
                if (dbResult.nextRow()) {
                    return "CREATE OR REPLACE PROCEDURE " + dbResult.getString(1) + " RETURNS " + dbResult.getString(2) + "LANGUAGE NZPLSQL AS BEGIN_PROC\n" + dbResult.getString(3) + "\nEND_PROC;";
                }
                return "-- Netezza procedure source not found";
            }
        }
    } catch (SQLException e) {
        throw new DBException(e, dataSource);
    }
}
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) GenericDataSource(org.jkiss.dbeaver.ext.generic.model.GenericDataSource)

Example 3 with GenericDataSource

use of org.jkiss.dbeaver.ext.generic.model.GenericDataSource in project dbeaver by serge-rider.

the class NetezzaMetaModel method getViewDDL.

public String getViewDDL(DBRProgressMonitor monitor, GenericTable sourceObject) throws DBException {
    GenericDataSource dataSource = sourceObject.getDataSource();
    try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Read Netezza view source")) {
        try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT v.definition " + "FROM _v_view v, _v_objs_owned o " + "WHERE v.objid = o.objid AND o.DATABASE=? AND v.VIEWNAME=?")) {
            dbStat.setString(1, sourceObject.getContainer().getName());
            dbStat.setString(2, sourceObject.getName());
            try (JDBCResultSet dbResult = dbStat.executeQuery()) {
                if (dbResult.nextRow()) {
                    return "CREATE OR REPLACE VIEW " + sourceObject.getName() + " AS\n" + dbResult.getString(1);
                }
                return "-- Netezza view definition not found";
            }
        }
    } catch (SQLException e) {
        throw new DBException(e, dataSource);
    }
}
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) GenericDataSource(org.jkiss.dbeaver.ext.generic.model.GenericDataSource)

Example 4 with GenericDataSource

use of org.jkiss.dbeaver.ext.generic.model.GenericDataSource 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);
    }
}
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) GenericDataSource(org.jkiss.dbeaver.ext.generic.model.GenericDataSource)

Aggregations

GenericDataSource (org.jkiss.dbeaver.ext.generic.model.GenericDataSource)4 SQLException (java.sql.SQLException)3 DBException (org.jkiss.dbeaver.DBException)3 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)3 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)3 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)3 SQLDatabasePersistAction (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)1