Search in sources :

Example 6 with JDBCStatement

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

the class ExasolTableCache method prepareChildrenStatement.

@SuppressWarnings("rawtypes")
@Override
protected JDBCStatement prepareChildrenStatement(@NotNull JDBCSession session, @NotNull ExasolSchema exasolSchema, @Nullable ExasolTable exasolTable) throws SQLException {
    String sql;
    if (exasolTable != null)
        sql = String.format(SQL_COLS_TAB, ExasolUtils.quoteString(exasolSchema.getName()), ExasolUtils.quoteString(exasolTable.getName()));
    else
        sql = String.format(SQL_COLS_ALL, ExasolUtils.quoteString(exasolSchema.getName()));
    JDBCStatement dbstat = session.createStatement();
    ((JDBCStatementImpl) dbstat).setQueryString(sql);
    return dbstat;
}
Also used : JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement) JDBCStatementImpl(org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl)

Example 7 with JDBCStatement

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

the class ExasolTableUniqueKeyCache method prepareObjectsStatement.

@SuppressWarnings("rawtypes")
@NotNull
@Override
protected JDBCStatement prepareObjectsStatement(JDBCSession session, ExasolSchema exasolSchema, ExasolTable forTable) throws SQLException {
    String sql;
    if (forTable != null) {
        sql = String.format(SQL_UK_TAB, ExasolUtils.quoteString(exasolSchema.getName()), ExasolUtils.quoteString(forTable.getName()));
    } else {
        sql = String.format(SQL_UK_ALL, ExasolUtils.quoteString(exasolSchema.getName()));
    }
    JDBCStatement dbStat = session.createStatement();
    ((JDBCStatementImpl) dbStat).setQueryString(sql);
    return dbStat;
}
Also used : JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement) JDBCStatementImpl(org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl) NotNull(org.jkiss.code.NotNull)

Example 8 with JDBCStatement

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

the class ExasolJDBCObjectSimpleCacheLiterals method prepareObjectsStatement.

@SuppressWarnings("rawtypes")
@Override
protected JDBCStatement prepareObjectsStatement(@NotNull JDBCSession session, @NotNull OWNER owner) throws SQLException {
    JDBCStatement dbStat = session.createStatement();
    //escape parameters
    for (int i = 0; i < queryParameters.length; i++) {
        queryParameters[i] = (Object) ExasolUtils.quoteString(queryParameters[i].toString());
    }
    executeQuery = String.format(query, queryParameters);
    ((JDBCStatementImpl) dbStat).setQueryString(executeQuery);
    return dbStat;
}
Also used : JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement) JDBCStatementImpl(org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl)

Example 9 with JDBCStatement

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

the class TableToolDialog method getScriptListener.

@Override
protected SQLScriptProgressListener<PostgreObject> getScriptListener() {
    return new SQLScriptStatusDialog<PostgreObject>(getShell(), getTitle() + " progress", null) {

        @Override
        protected void createStatusColumns(Tree objectTree) {
            TreeColumn msgColumn = new TreeColumn(objectTree, SWT.NONE);
            msgColumn.setText("Message");
        }

        @Override
        public void processObjectResults(@NotNull PostgreObject object, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
            if (statement == null) {
                return;
            }
            TreeItem treeItem = getTreeItem(object);
            if (treeItem != null) {
                try {
                    int warnNum = 0;
                    SQLWarning warning = ((JDBCStatement) statement).getWarnings();
                    while (warning != null) {
                        if (warnNum == 0) {
                            treeItem.setText(1, warning.getMessage());
                        } else {
                            TreeItem warnItem = new TreeItem(treeItem, SWT.NONE);
                            warnItem.setText(0, "");
                            warnItem.setText(1, warning.getMessage());
                        }
                        warnNum++;
                        warning = warning.getNextWarning();
                    }
                    if (warnNum == 0) {
                        treeItem.setText(1, "Done");
                    }
                } catch (SQLException e) {
                // ignore
                }
                treeItem.setExpanded(true);
            }
        }

        @Override
        public void endObjectProcessing(@NotNull PostgreObject object, Exception error) {
            super.endObjectProcessing(object, error);
            if (error != null) {
                TreeItem treeItem = getTreeItem(object);
                if (treeItem != null) {
                    treeItem.setText(1, error.getMessage());
                }
            }
        }
    };
}
Also used : SQLWarning(java.sql.SQLWarning) TreeItem(org.eclipse.swt.widgets.TreeItem) SQLException(java.sql.SQLException) NotNull(org.jkiss.code.NotNull) DBCStatement(org.jkiss.dbeaver.model.exec.DBCStatement) JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement) SQLScriptStatusDialog(org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog) DBCException(org.jkiss.dbeaver.model.exec.DBCException) SQLException(java.sql.SQLException) JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) PostgreObject(org.jkiss.dbeaver.ext.postgresql.model.PostgreObject) DBCResultSet(org.jkiss.dbeaver.model.exec.DBCResultSet) Nullable(org.jkiss.code.Nullable)

Example 10 with JDBCStatement

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

the class ExasolUtils method readSessions.

public static Collection<ExasolServerSession> readSessions(DBRProgressMonitor progressMonitor, JDBCSession session) throws SQLException {
    LOG.debug("read sessions");
    List<ExasolServerSession> listSessions = new ArrayList<>();
    //check dba view
    try {
        try (JDBCStatement dbStat = session.createStatement()) {
            try (JDBCResultSet dbResult = dbStat.executeQuery(SESS_DBA_QUERY)) {
                while (dbResult.next()) {
                    listSessions.add(new ExasolServerSession(dbResult));
                }
            }
        }
    //now try all view
    } catch (SQLException e) {
        try (JDBCStatement dbStat = session.createStatement()) {
            try (JDBCResultSet dbResult = dbStat.executeQuery(SESS_ALL_QUERY)) {
                while (dbResult.next()) {
                    listSessions.add(new ExasolServerSession(dbResult));
                }
            }
        }
    }
    return listSessions;
}
Also used : JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement) SQLException(java.sql.SQLException) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) ArrayList(java.util.ArrayList) ExasolServerSession(org.jkiss.dbeaver.ext.exasol.model.app.ExasolServerSession)

Aggregations

JDBCStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement)18 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)10 SQLException (java.sql.SQLException)9 DBException (org.jkiss.dbeaver.DBException)7 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)7 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)6 JDBCStatementImpl (org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl)6 NotNull (org.jkiss.code.NotNull)4 ArrayList (java.util.ArrayList)2 DBCException (org.jkiss.dbeaver.model.exec.DBCException)2 SQLWarning (java.sql.SQLWarning)1 Tree (org.eclipse.swt.widgets.Tree)1 TreeColumn (org.eclipse.swt.widgets.TreeColumn)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1 Nullable (org.jkiss.code.Nullable)1 ExasolObjectType (org.jkiss.dbeaver.ext.exasol.editors.ExasolObjectType)1 ExasolServerSession (org.jkiss.dbeaver.ext.exasol.model.app.ExasolServerSession)1 PostgreObject (org.jkiss.dbeaver.ext.postgresql.model.PostgreObject)1 DBCResultSet (org.jkiss.dbeaver.model.exec.DBCResultSet)1 DBCStatement (org.jkiss.dbeaver.model.exec.DBCStatement)1