Search in sources :

Example 31 with SQLDialect

use of org.jkiss.dbeaver.model.sql.SQLDialect in project dbeaver by serge-rider.

the class DBUtils method createStatement.

@NotNull
public static DBCStatement createStatement(@NotNull DBCSession session, @NotNull String query, boolean scrollable) throws DBCException {
    SQLDialect dialect = SQLUtils.getDialectFromObject(session.getDataSource());
    DBCStatementType statementType = DBCStatementType.SCRIPT;
    query = SQLUtils.makeUnifiedLineFeeds(session.getDataSource(), query);
    if (SQLUtils.isExecQuery(dialect, query)) {
        statementType = DBCStatementType.EXEC;
        query = dialect.formatStoredProcedureCall(session.getDataSource(), query);
    }
    return session.prepareStatement(statementType, query, scrollable && session.getDataSource().getInfo().supportsResultSetScroll(), false, false);
}
Also used : BasicSQLDialect(org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect) SQLDialect(org.jkiss.dbeaver.model.sql.SQLDialect) NotNull(org.jkiss.code.NotNull)

Example 32 with SQLDialect

use of org.jkiss.dbeaver.model.sql.SQLDialect in project dbeaver by serge-rider.

the class DBUtils method getFullQualifiedName.

@NotNull
public static String getFullQualifiedName(@Nullable DBPDataSource dataSource, @NotNull DBPNamedObject... path) {
    StringBuilder name = new StringBuilder(20 * path.length);
    if (dataSource == null) {
        // It is not SQL identifier, let's just make it simple then
        for (DBPNamedObject namePart : path) {
            if (isVirtualObject(namePart)) {
                continue;
            }
            if (name.length() > 0) {
                name.append('.');
            }
            name.append(namePart.getName());
        }
    } else {
        final SQLDialect sqlDialect = dataSource.getSQLDialect();
        DBPNamedObject parent = null;
        for (DBPNamedObject namePart : path) {
            if (namePart == null || isVirtualObject(namePart)) {
                continue;
            }
            if (namePart instanceof DBSCatalog && ((sqlDialect.getCatalogUsage() & SQLDialect.USAGE_DML) == 0)) {
                // Do not use catalog name in FQ name
                continue;
            }
            if (namePart instanceof DBSSchema && ((sqlDialect.getSchemaUsage() & SQLDialect.USAGE_DML) == 0)) {
                // Do not use schema name in FQ name
                continue;
            }
            // Check for valid object name
            if (!isValidObjectName(namePart.getName())) {
                continue;
            }
            if (name.length() > 0) {
                if (parent instanceof DBSCatalog) {
                    if (!sqlDialect.isCatalogAtStart()) {
                        log.warn("Catalog name should be at the start of full-qualified name!");
                    }
                    name.append(sqlDialect.getCatalogSeparator());
                } else {
                    name.append(sqlDialect.getStructSeparator());
                }
            }
            name.append(DBUtils.getQuotedIdentifier(dataSource, namePart.getName()));
            parent = namePart;
        }
    }
    return name.toString();
}
Also used : BasicSQLDialect(org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect) SQLDialect(org.jkiss.dbeaver.model.sql.SQLDialect) NotNull(org.jkiss.code.NotNull)

Example 33 with SQLDialect

use of org.jkiss.dbeaver.model.sql.SQLDialect in project dbeaver by serge-rider.

the class SQLScriptParserTest method setDialect.

private SQLDialect setDialect(String name) throws DBException {
    SQLDialectRegistry registry = SQLDialectRegistry.getInstance();
    SQLDialect dialect = registry.getDialect(name).createInstance();
    Mockito.when(dataSource.getSQLDialect()).thenReturn(dialect);
    return dialect;
}
Also used : SQLDialect(org.jkiss.dbeaver.model.sql.SQLDialect) SQLDialectRegistry(org.jkiss.dbeaver.model.sql.registry.SQLDialectRegistry)

Example 34 with SQLDialect

use of org.jkiss.dbeaver.model.sql.SQLDialect in project dbeaver by dbeaver.

the class DBUtils method getFullyQualifiedName.

@NotNull
public static String getFullyQualifiedName(@NotNull DBPDataSource dataSource, @NotNull String... names) {
    SQLDialect dialect = SQLUtils.getDialectFromDataSource(dataSource);
    StringBuilder name = new StringBuilder(names.length * 16);
    for (String namePart : names) {
        if (namePart == null) {
            continue;
        }
        if (name.length() > 0)
            name.append(dialect.getStructSeparator());
        name.append(DBUtils.getQuotedIdentifier(dataSource, namePart));
    }
    return name.toString();
}
Also used : BasicSQLDialect(org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect) SQLDialect(org.jkiss.dbeaver.model.sql.SQLDialect) NotNull(org.jkiss.code.NotNull)

Example 35 with SQLDialect

use of org.jkiss.dbeaver.model.sql.SQLDialect in project dbeaver by dbeaver.

the class DBUtils method createStatement.

@NotNull
public static DBCStatement createStatement(@NotNull DBCSession session, @NotNull String query, boolean scrollable) throws DBCException {
    SQLDialect dialect = SQLUtils.getDialectFromObject(session.getDataSource());
    DBCStatementType statementType = DBCStatementType.SCRIPT;
    query = SQLUtils.makeUnifiedLineFeeds(session.getDataSource(), query);
    if (SQLUtils.isExecQuery(dialect, query)) {
        statementType = DBCStatementType.EXEC;
        query = dialect.formatStoredProcedureCall(session.getDataSource(), query);
    }
    return session.prepareStatement(statementType, query, scrollable && session.getDataSource().getInfo().supportsResultSetScroll(), false, false);
}
Also used : BasicSQLDialect(org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect) SQLDialect(org.jkiss.dbeaver.model.sql.SQLDialect) NotNull(org.jkiss.code.NotNull)

Aggregations

SQLDialect (org.jkiss.dbeaver.model.sql.SQLDialect)40 NotNull (org.jkiss.code.NotNull)17 BasicSQLDialect (org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect)11 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)6 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)6 Map (java.util.Map)4 StyledText (org.eclipse.swt.custom.StyledText)4 FillLayout (org.eclipse.swt.layout.FillLayout)4 GridData (org.eclipse.swt.layout.GridData)4 Composite (org.eclipse.swt.widgets.Composite)4 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)4 JDBCStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement)4 ExecuteBatchImpl (org.jkiss.dbeaver.model.impl.data.ExecuteBatchImpl)4 JDBCSQLDialect (org.jkiss.dbeaver.model.impl.jdbc.JDBCSQLDialect)4 SQLEditorBase (org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase)4 BadLocationException (org.eclipse.jface.text.BadLocationException)3 IDocument (org.eclipse.jface.text.IDocument)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ITextViewer (org.eclipse.jface.text.ITextViewer)2