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);
}
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();
}
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;
}
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();
}
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);
}
Aggregations