Search in sources :

Example 56 with SQLWarning

use of java.sql.SQLWarning in project jOOQ by jOOQ.

the class FieldsImpl method field0.

private final <U> U field0(String fieldName, FieldOrIndex<U> result) {
    if (fieldName == null)
        return result.resultNull();
    Field<?> columnMatch = null;
    int indexMatch = -1;
    for (int i = 0; i < fields.length; i++) {
        Field<?> f = fields[i];
        if (f.getName().equals(fieldName)) {
            if (columnMatch == null) {
                columnMatch = f;
                indexMatch = i;
            } else // [#4476] [#4477] [#5046] This might be unintentional from a user
            // perspective, e.g. when ambiguous ID columns are present.
            {
                log.info("Ambiguous match found for " + fieldName + ". Both " + columnMatch + " and " + f + " match.", new SQLWarning());
            }
        }
    }
    return result.result(columnMatch, indexMatch);
}
Also used : SQLWarning(java.sql.SQLWarning)

Example 57 with SQLWarning

use of java.sql.SQLWarning in project jOOQ by jOOQ.

the class FieldsImpl method field0.

private final <U> U field0(Field<?> field, FieldOrIndex<U> result) {
    if (field == null)
        return result.resultNull();
    // [#4540] Try finding a match by identity
    for (int i = 0; i < fields.length; i++) {
        Field<?> f = fields[i];
        if (f == field)
            return result.result(f, i);
    }
    // [#1802] Try finding an exact match (e.g. exact matching qualified name)
    for (int i = 0; i < fields.length; i++) {
        Field<?> f = fields[i];
        if (f.equals(field))
            return result.result(f, i);
    }
    // [#4283] table / column matches are better than only column matches
    Field<?> columnMatch = null;
    Field<?> columnMatch2 = null;
    int indexMatch = -1;
    String tableName = tableName(field);
    String fieldName = field.getName();
    for (int i = 0; i < fields.length; i++) {
        Field<?> f = fields[i];
        String fName = f.getName();
        if (tableName != null) {
            String tName = tableName(f);
            if (tName != null && tableName.equals(tName) && fName.equals(fieldName))
                return result.result(f, i);
        }
        // In case no exact match was found, return the first field with matching name
        if (fName.equals(fieldName)) {
            if (columnMatch == null) {
                columnMatch = f;
                indexMatch = i;
            } else // [#4476] [#4477] This might be unintentional from a user
            // perspective, e.g. when ambiguous ID columns are present.
            // [#5578] Finish the loop, though, as we might have an exact match
            // despite some ambiguity
            {
                columnMatch2 = f;
            }
        }
    }
    if (columnMatch2 != null)
        if (log.isInfoEnabled())
            log.info("Ambiguous match found for " + fieldName + ". Both " + columnMatch + " and " + columnMatch2 + " match.", new SQLWarning());
    return result.result(columnMatch, indexMatch);
}
Also used : SQLWarning(java.sql.SQLWarning)

Example 58 with SQLWarning

use of java.sql.SQLWarning in project dbeaver by serge-rider.

the class PostgreToolWithStatus method getExecuteStatistics.

@Override
public List<ToolStatus> getExecuteStatistics(OBJECT_TYPE object, SETTINGS settings, DBEPersistAction action, DBCSession session, DBCStatement dbStat) throws DBCException {
    List<ToolStatus> statusList = new ArrayList<>();
    try {
        int warnNum = 0;
        SQLWarning warning = ((JDBCStatement) dbStat).getWarnings();
        while (warning != null) {
            statusList.add(new ToolStatus(object, warning.getMessage()));
            warnNum++;
            warning = warning.getNextWarning();
        }
        if (warnNum == 0) {
            statusList.add(new ToolStatus(object, "Done"));
        }
    } catch (SQLException e) {
    // ignore
    }
    return statusList;
}
Also used : SQLWarning(java.sql.SQLWarning) JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList)

Example 59 with SQLWarning

use of java.sql.SQLWarning in project dbeaver by serge-rider.

the class DB2ToolWithStatus method getExecuteStatistics.

@Override
public List<ToolStatus> getExecuteStatistics(OBJECT_TYPE object, SETTINGS settings, DBEPersistAction action, DBCSession session, DBCStatement dbStat) throws DBCException {
    List<ToolStatus> statusList = new ArrayList<>();
    try {
        int warnNum = 0;
        SQLWarning warning = ((JDBCStatement) dbStat).getWarnings();
        while (warning != null) {
            statusList.add(new ToolStatus(object, warning.getMessage()));
            warnNum++;
            warning = warning.getNextWarning();
        }
        if (warnNum == 0) {
            // $NON-NLS-1$
            statusList.add(new ToolStatus(object, "Done"));
        }
    } catch (SQLException e) {
    // ignore
    }
    return statusList;
}
Also used : SQLWarning(java.sql.SQLWarning) JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList)

Example 60 with SQLWarning

use of java.sql.SQLWarning in project dbeaver by serge-rider.

the class SQLServerToolWithStatus method getExecuteStatistics.

@Override
public List<ToolStatus> getExecuteStatistics(OBJECT_TYPE object, SETTINGS settings, DBEPersistAction action, DBCSession session, DBCStatement dbStat) throws DBCException {
    List<ToolStatus> statusList = new ArrayList<>();
    try {
        int warnNum = 0;
        SQLWarning warning = ((JDBCStatement) dbStat).getWarnings();
        while (warning != null) {
            statusList.add(new ToolStatus(object, warning.getMessage()));
            warnNum++;
            warning = warning.getNextWarning();
        }
        if (warnNum == 0) {
            statusList.add(new ToolStatus(object, "Done"));
        }
    } catch (SQLException e) {
    // ignore
    }
    return statusList;
}
Also used : SQLWarning(java.sql.SQLWarning) JDBCStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList)

Aggregations

SQLWarning (java.sql.SQLWarning)153 SQLException (java.sql.SQLException)49 Statement (java.sql.Statement)37 PreparedStatement (java.sql.PreparedStatement)30 Connection (java.sql.Connection)26 ResultSet (java.sql.ResultSet)23 Test (org.testng.annotations.Test)19 Test (org.junit.Test)17 BaseTest (util.BaseTest)15 CallableStatement (java.sql.CallableStatement)13 ArrayList (java.util.ArrayList)9 JDBCStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement)8 ResultSetMetaData (java.sql.ResultSetMetaData)6 Expectations (org.jmock.Expectations)6 IOException (java.io.IOException)4 FilterChainImpl (com.alibaba.druid.filter.FilterChainImpl)3 PrestoWarning (com.facebook.presto.spi.PrestoWarning)3 Properties (java.util.Properties)3 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)3 StatementContext (org.apache.derby.iapi.sql.conn.StatementContext)3