Search in sources :

Example 26 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 27 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)

Aggregations

SQLDialect (org.jkiss.dbeaver.model.sql.SQLDialect)27 NotNull (org.jkiss.code.NotNull)12 BasicSQLDialect (org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect)6 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)5 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 SQLDataSource (org.jkiss.dbeaver.model.sql.SQLDataSource)4 BadLocationException (org.eclipse.jface.text.BadLocationException)3 IDocument (org.eclipse.jface.text.IDocument)3 StyledText (org.eclipse.swt.custom.StyledText)3 FillLayout (org.eclipse.swt.layout.FillLayout)3 GridData (org.eclipse.swt.layout.GridData)3 Composite (org.eclipse.swt.widgets.Composite)3 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)3 SQLEditorBase (org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase)3 File (java.io.File)2 Map (java.util.Map)2 ITextViewer (org.eclipse.jface.text.ITextViewer)2 TextAttribute (org.eclipse.jface.text.TextAttribute)2