mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add demo
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package com.alibaba.druid.demo.sql;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class CreateTableSetSchemaDemo extends TestCase {
|
||||
|
||||
public void test_schemaStat() throws Exception {
|
||||
String sql = "create table t(fid varchar(20))";
|
||||
|
||||
String dbType = JdbcConstants.ORACLE;
|
||||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
|
||||
List<SQLStatement> stmtList = parser.parseStatementList();
|
||||
|
||||
SchemaStatVisitor statVisitor = SQLUtils.createSchemaStatVisitor(dbType);
|
||||
for (SQLStatement stmt : stmtList) {
|
||||
SQLCreateTableStatement createTable = ((SQLCreateTableStatement) stmt);
|
||||
createTable.setSchema("sc001");
|
||||
}
|
||||
|
||||
String sql2 = SQLUtils.toSQLString(stmtList, JdbcConstants.ORACLE);
|
||||
System.out.println(sql2);
|
||||
}
|
||||
}
|
||||
@@ -27,16 +27,16 @@ public class PGVisitorDemo extends TestCase {
|
||||
System.out.println(tableSource);
|
||||
}
|
||||
|
||||
public static class ExportTableAliasVisitor extends PGASTVisitorAdapter {
|
||||
private Map<String, SQLTableSource> aliasMap = new HashMap<String, SQLTableSource>();
|
||||
public boolean visit(SQLExprTableSource x) {
|
||||
String alias = x.getAlias();
|
||||
aliasMap.put(alias, x);
|
||||
return true;
|
||||
}
|
||||
public static class ExportTableAliasVisitor extends PGASTVisitorAdapter {
|
||||
private Map<String, SQLTableSource> aliasMap = new HashMap<String, SQLTableSource>();
|
||||
public boolean visit(SQLExprTableSource x) {
|
||||
String alias = x.getAlias();
|
||||
aliasMap.put(alias, x);
|
||||
return true;
|
||||
}
|
||||
|
||||
public Map<String, SQLTableSource> getAliasMap() {
|
||||
return aliasMap;
|
||||
public Map<String, SQLTableSource> getAliasMap() {
|
||||
return aliasMap;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user