use of com.alibaba.druid.DbType in project druid by alibaba.
the class SQLObjectImpl method output.
public void output(Appendable buf) {
DbType dbType = null;
if (this instanceof OracleSQLObject) {
dbType = DbType.oracle;
} else if (this instanceof MySqlObject) {
dbType = DbType.mysql;
} else if (this instanceof PGSQLObject) {
dbType = DbType.postgresql;
} else if (this instanceof SQLDbTypedObject) {
dbType = ((SQLDbTypedObject) this).getDbType();
}
accept(SQLUtils.createOutputVisitor(buf, dbType));
}
use of com.alibaba.druid.DbType in project druid by alibaba.
the class FromSubqueryResolver method resolve.
public static List<SQLStatement> resolve(SQLCreateViewStatement stmt) {
List<SQLStatement> targetList = new ArrayList<SQLStatement>();
targetList.add(stmt);
String viewName = SQLUtils.normalize(stmt.getName().getSimpleName());
FromSubqueryResolver visitor = new FromSubqueryResolver(targetList, viewName);
SQLWithSubqueryClause withSubqueryClause = stmt.getSubQuery().getWithSubQuery();
if (withSubqueryClause != null) {
stmt.getSubQuery().setWithSubQuery(null);
for (SQLWithSubqueryClause.Entry entry : withSubqueryClause.getEntries()) {
String entryName = entry.getAlias();
SQLCreateViewStatement entryStmt = new SQLCreateViewStatement();
entryStmt.setOrReplace(true);
entryStmt.setDbType(stmt.getDbType());
String entryViewName = visitor.generateSubViewName();
entryStmt.setName(entryViewName);
entryStmt.setSubQuery(entry.getSubQuery());
visitor.targetList.add(0, entryStmt);
visitor.mappings.put(entryName, entryViewName);
entryStmt.accept(visitor);
}
}
stmt.accept(visitor);
DbType dbType = stmt.getDbType();
for (int i = 0; i < targetList.size() - 1; ++i) {
SQLCreateViewStatement targetStmt = (SQLCreateViewStatement) targetList.get(i);
targetStmt.setOrReplace(true);
targetStmt.setDbType(dbType);
targetStmt.setAfterSemi(true);
}
return targetList;
}
use of com.alibaba.druid.DbType in project druid by alibaba.
the class SQLDataTypeValidator method check.
public static void check(List<SQLStatement> stmtList) {
if (stmtList.size() == 0) {
return;
}
DbType dbType = stmtList.get(0).getDbType();
SQLDataTypeValidator v = of(dbType);
check(stmtList, dbType);
}
use of com.alibaba.druid.DbType in project druid by alibaba.
the class WallFilter method init.
@Override
public synchronized void init(DataSourceProxy dataSource) {
if (dataSource == null) {
LOG.error("dataSource should not be null");
return;
}
if (this.dbTypeName == null || this.dbTypeName.trim().length() == 0) {
if (dataSource.getDbType() != null) {
this.dbTypeName = dataSource.getDbType();
} else {
this.dbTypeName = JdbcUtils.getDbType(dataSource.getRawJdbcUrl(), "");
}
}
if (dbTypeName == null) {
dbTypeName = JdbcUtils.getDbType(dataSource.getUrl(), null);
}
DbType dbType = DbType.of(this.dbTypeName);
switch(dbType) {
case mysql:
case oceanbase:
case drds:
case mariadb:
case tidb:
case h2:
case presto:
case trino:
if (config == null) {
config = new WallConfig(MySqlWallProvider.DEFAULT_CONFIG_DIR);
}
provider = new MySqlWallProvider(config);
break;
case oracle:
case ali_oracle:
case oceanbase_oracle:
if (config == null) {
config = new WallConfig(OracleWallProvider.DEFAULT_CONFIG_DIR);
}
provider = new OracleWallProvider(config);
break;
case sqlserver:
case jtds:
if (config == null) {
config = new WallConfig(SQLServerWallProvider.DEFAULT_CONFIG_DIR);
}
provider = new SQLServerWallProvider(config);
break;
case postgresql:
case edb:
case polardb:
case greenplum:
case gaussdb:
if (config == null) {
config = new WallConfig(PGWallProvider.DEFAULT_CONFIG_DIR);
}
provider = new PGWallProvider(config);
break;
case db2:
if (config == null) {
config = new WallConfig(DB2WallProvider.DEFAULT_CONFIG_DIR);
}
provider = new DB2WallProvider(config);
break;
case sqlite:
if (config == null) {
config = new WallConfig(SQLiteWallProvider.DEFAULT_CONFIG_DIR);
}
provider = new SQLiteWallProvider(config);
break;
case clickhouse:
if (config == null) {
config = new WallConfig(ClickhouseWallProvider.DEFAULT_CONFIG_DIR);
}
provider = new ClickhouseWallProvider(config);
break;
default:
throw new IllegalStateException("dbType not support : " + dbType + ", url " + dataSource.getUrl());
}
provider.setName(dataSource.getName());
this.inited = true;
}
use of com.alibaba.druid.DbType in project druid by alibaba.
the class ExportConditions method evaluate.
public String evaluate(String sql, String dbTypeName, Boolean compactValues) {
DbType dbType = dbTypeName == null ? null : DbType.valueOf(dbTypeName);
try {
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, dbType);
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(dbType);
for (SQLStatement stmt : statementList) {
stmt.accept(visitor);
}
List<List<Object>> rows = new ArrayList<List<Object>>();
List<Condition> conditions = visitor.getConditions();
for (int i = 0; i < conditions.size(); ++i) {
TableStat.Condition condition = conditions.get(i);
Column column = condition.getColumn();
String operator = condition.getOperator();
List<Object> values = condition.getValues();
List<Object> row = new ArrayList<Object>();
row.add(column.getTable());
row.add(column.getName());
row.add(operator);
if (values.size() == 0) {
row.add(null);
} else if (values.size() == 1) {
if (compactValues != null && compactValues.booleanValue()) {
row.add(values);
} else {
row.add(values.get(0));
}
} else {
row.add(values);
}
rows.add(row);
}
return JSONUtils.toJSONString(rows);
} catch (Exception ex) {
System.err.println("error sql : " + sql);
ex.printStackTrace();
return null;
}
}
Aggregations