public class TGetTableColumn extends Object
默认情况下,此工具仅输出具有表名(getTableName() != null)且不在排除列表中的表。
以下 ETableSource 类型的表在默认情况下不会出现在输出的表列表中:
ETableSource.subquery - 子查询(始终排除)ETableSource.openquery - OPENQUERY 表(始终排除)ETableSource.function - 表值函数(始终排除)ETableSource.unnest - UNNEST 表(因为 getTableName() 为 null,使用别名)ETableSource.tableExpr - 表表达式(因为 getTableName() 为 null,使用别名)showCTE 控制以下 ETableSource 类型的表会出现在默认输出中(如果 getTableName() 不为 null):
ETableSource.objectname - 普通基础表(始终输出)ETableSource.pivoted_table - PIVOT 表ETableSource.lateralView - LATERAL VIEW 表控制是否输出 CTE(公用表表达式)相关的表:
showCTE = false(默认):CTE 表不会出现在输出中showCTE = true:CTE 表会出现在输出中控制是否仅输出物理表(与 TSQLResolver2ResultFormatter 的 onlyPhysicalTables 选项兼容):
onlyPhysicalTables = false(默认):输出所有符合条件的表onlyPhysicalTables = true:仅输出 ETableSource.objectname 类型的物理表,
排除以下内容:
ETableSource.unnest - UNNEST 表ETableSource.pivoted_table - PIVOT 表ETableSource.lateralView - LATERAL VIEW 表要在输出中包含CTE表,请设置 showCTE = true:
TGetTableColumn getTableColumn = new TGetTableColumn(EDbVendor.dbvoracle);
getTableColumn.showCTE = true; // 启用CTE表的输出
getTableColumn.runText(sql);
注意:即使设置了 showCTE = true,以下类型的表仍然不会出现在表列表中:
ETableSource.subquery - 子查询(不是真正的物理表)ETableSource.openquery - OPENQUERY 表ETableSource.function - 表值函数ETableSource.unnest - UNNEST 表(getTableName() 为 null)ETableSource.tableExpr - 表表达式(getTableName() 为 null)注意:此表显示的是默认配置下的行为。showUnnest、showPivotTable、showLateralView 默认都为 true, 所以即使 onlyPhysicalTables=true,这三种表类型默认也会被输出。
| ETableSource 类型 | 默认输出 | showCTE=true | onlyPhysicalTables=true (默认 show*=true) | 原因 |
|---|---|---|---|---|
| objectname | ✓ 输出 | ✓ 输出 | ✓ 输出 | 普通基础表 |
| subquery | ✗ 不输出 | ✗ 不输出 | ✗ 不输出 | 显式排除 |
| openquery | ✗ 不输出 | ✗ 不输出 | ✗ 不输出 | 显式排除 |
| function | ✗ 不输出 | ✗ 不输出 | ✗ 不输出 | 显式排除 |
| CTE 表 | ✗ 不输出 | ✓ 输出 | ✗ 不输出 | 由 showCTE 控制,onlyPhysicalTables 排除 |
| unnest | ✗ 不输出 | ✗ 不输出 | ✓ 输出 | 由 showUnnest 控制(默认 true) |
| tableExpr | ✗ 不输出 | ✗ 不输出 | ✗ 不输出 | getTableName() 为 null |
| pivoted_table | ✓ 输出 | ✓ 输出 | ✓ 输出 | 由 showPivotTable 控制(默认 true) |
| lateralView | ✓ 输出 | ✓ 输出 | ✓ 输出 | 由 showLateralView 控制(默认 true) |
showCTE - 设置为 true 时,CTE表会包含在输出中onlyPhysicalTables - 设置为 true 时,仅输出 objectname 类型的物理表showUnnest - 设置为 true 时(默认),即使 onlyPhysicalTables=true,UNNEST 表也会被输出showPivotTable - 设置为 true 时(默认),即使 onlyPhysicalTables=true,PIVOT 表也会被输出showLateralView - 设置为 true 时(默认),即使 onlyPhysicalTables=true,LATERAL VIEW 表也会被输出showColumnsOfCTE - 设置为 true 时,显示CTE中的列showTableEffect - 设置为 true 时,显示表的操作类型(SELECT、INSERT、UPDATE、DELETE等)showDetail - 设置为 true 时,显示详细信息showSummary - 设置为 true 时(默认),显示汇总信息
// 示例1:仅获取物理表(默认行为)
TGetTableColumn gtc = new TGetTableColumn(EDbVendor.dbvoracle);
gtc.runText("SELECT * FROM employees e, (SELECT * FROM departments) d");
// 输出仅包含: employees(子查询 departments 不会出现)
// 示例2:包含CTE表
TGetTableColumn gtc2 = new TGetTableColumn(EDbVendor.dbvoracle);
gtc2.showCTE = true;
gtc2.runText("WITH cte AS (SELECT * FROM t1) SELECT * FROM cte, t2");
// 输出包含: t1, t2, cte(因为 showCTE = true)
// 示例3:仅输出物理表,但保留 PIVOT 表(默认行为)
TGetTableColumn gtc3 = new TGetTableColumn(EDbVendor.dbvoracle);
gtc3.onlyPhysicalTables = true;
gtc3.runText("SELECT * FROM t1 PIVOT (SUM(amount) FOR month IN ('Jan', 'Feb'))");
// 输出包含: t1 和 PIVOT 表(因为 showPivotTable 默认为 true)
// 示例4:仅输出物理表,排除 PIVOT 表
TGetTableColumn gtc4 = new TGetTableColumn(EDbVendor.dbvoracle);
gtc4.onlyPhysicalTables = true;
gtc4.showPivotTable = false; // 排除 PIVOT 表
gtc4.runText("SELECT * FROM t1 PIVOT (SUM(amount) FOR month IN ('Jan', 'Feb'))");
// 输出仅包含: t1(PIVOT 表被排除)
ETableSource,
ETableSource.objectname| Modifier and Type | Field and Description |
|---|---|
StringBuffer |
infos |
boolean |
isConsole |
boolean |
linkOrphanColumnToFirstTable |
boolean |
listStarColumn |
boolean |
onlyPhysicalTables
控制是否仅输出物理表(与
TSQLResolver2ResultFormatter 的 onlyPhysicalTables 选项兼容)。 |
StringBuffer |
outList |
boolean |
showBySQLClause |
boolean |
showColumnLocation |
boolean |
showColumnsOfCTE |
boolean |
showCTE |
boolean |
showDatatype |
boolean |
showDetail |
boolean |
showIndex |
boolean |
showJoin |
boolean |
showLateralView
当设置为
true(默认)时,即使 onlyPhysicalTables=true,LATERAL VIEW 表也会被输出。
当设置为 false 时,如果 onlyPhysicalTables=true,LATERAL VIEW 表会被排除。 |
boolean |
showPivotTable
当设置为
true(默认)时,即使 onlyPhysicalTables=true,PIVOT 表也会被输出。
当设置为 false 时,如果 onlyPhysicalTables=true,PIVOT 表会被排除。 |
boolean |
showStarColumnOfCTE |
boolean |
showSummary |
boolean |
showTableEffect |
boolean |
showTreeStructure |
boolean |
showUnnest
当设置为
true(默认)时,即使 onlyPhysicalTables=true,UNNEST 表也会被输出。
当设置为 false 时,如果 onlyPhysicalTables=true,UNNEST 表会被排除。 |
| Constructor and Description |
|---|
TGetTableColumn(EDbVendor pDBVendor) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
analyzeStmt(TCustomSqlStatement stmt,
int pNest) |
DisplayNameMode |
getDisplayNameMode()
Get the current display name mode.
|
StringBuffer |
getInfos() |
protected void |
run(String pQuery,
boolean isFile) |
void |
runFile(String pFileName) |
void |
runText(String pQuery) |
TGetTableColumn |
setDisplayNameMode(DisplayNameMode mode)
Set the display name mode for identifier formatting.
|
void |
setMetaDatabase(IMetaDatabase metaDatabase) |
void |
setResolverType(EResolverType resolverType) |
void |
setSqlEnv(TSQLEnv sqlEnv) |
public StringBuffer infos
public StringBuffer outList
public boolean isConsole
public boolean listStarColumn
public boolean showTableEffect
public boolean showColumnLocation
public boolean showDatatype
public boolean showIndex
public boolean showColumnsOfCTE
public boolean showStarColumnOfCTE
public boolean linkOrphanColumnToFirstTable
public boolean showDetail
public boolean showSummary
public boolean showTreeStructure
public boolean showBySQLClause
public boolean showJoin
public boolean showCTE
public boolean onlyPhysicalTables
TSQLResolver2ResultFormatter 的 onlyPhysicalTables 选项兼容)。
当设置为 true 时,仅输出 ETableSource.objectname 类型的物理表,
排除以下类型:
ETableSource.unnest - UNNEST 表ETableSource.pivoted_table - PIVOT 表ETableSource.lateralView - LATERAL VIEW 表默认值:false(输出所有符合条件的表,包括 unnest、pivoted_table、lateralView 等)
public boolean showUnnest
true(默认)时,即使 onlyPhysicalTables=true,UNNEST 表也会被输出。
当设置为 false 时,如果 onlyPhysicalTables=true,UNNEST 表会被排除。public boolean showPivotTable
true(默认)时,即使 onlyPhysicalTables=true,PIVOT 表也会被输出。
当设置为 false 时,如果 onlyPhysicalTables=true,PIVOT 表会被排除。public boolean showLateralView
true(默认)时,即使 onlyPhysicalTables=true,LATERAL VIEW 表也会被输出。
当设置为 false 时,如果 onlyPhysicalTables=true,LATERAL VIEW 表会被排除。public TGetTableColumn(EDbVendor pDBVendor)
public void setResolverType(EResolverType resolverType)
public void setMetaDatabase(IMetaDatabase metaDatabase)
public DisplayNameMode getDisplayNameMode()
public TGetTableColumn setDisplayNameMode(DisplayNameMode mode)
This controls how identifiers (table names, column names) are formatted in output:
DisplayNameMode.DISPLAY - Strip delimiters, preserve original case
(e.g., [OrderID] → OrderID)DisplayNameMode.SQL_RENDER - Preserve delimiters for valid SQL regeneration
(e.g., [Order ID] → [Order ID])DisplayNameMode.CANONICAL - Apply vendor-specific case folding
(e.g., Oracle: MyTable → MYTABLE)This method can be called after instantiation to change the mode for each SQL text being processed.
mode - the DisplayNameMode to usepublic StringBuffer getInfos()
protected void analyzeStmt(TCustomSqlStatement stmt, int pNest)