001package gudusoft.gsqlparser.sqlenv; 002 003 004import gudusoft.gsqlparser.nodes.TTypeName; 005 006/** 007 * table column 008 */ 009public class TSQLColumn extends TSQLObject { 010 011 private TSQLTable sqlTable; 012 013 /** 014 * table include this column 015 * @return table 016 */ 017 public TSQLTable getSqlTable() { 018 return sqlTable; 019 } 020 021 /** 022 * create a new column and add to the table 023 * 024 * @param sqlTable table this column belongs to 025 * @param columnName column name 026 */ 027 public TSQLColumn(TSQLTable sqlTable,String columnName){ 028 super(sqlTable.getSqlEnv(),columnName,ESQLDataObjectType.dotColumn); 029 this.sqlTable = sqlTable; 030 } 031 032 public TSQLColumn(TSQLTable sqlTable, String columnName, TTypeName dataType){ 033 super(sqlTable.getSqlEnv(),columnName,ESQLDataObjectType.dotColumn); 034 this.sqlTable = sqlTable; 035 if (dataType != null){ 036 this.columnDataType = dataType.clone(); 037 } 038 } 039 040 private TTypeName columnDataType; 041 042 public TTypeName getColumnDataType() { 043 return columnDataType; 044 } 045 046 /** Only {@link TSQLTable#fillColumnDataType}, under the table's lock and seal check, sets the type afterwards. */ 047 void setColumnDataType(TTypeName dataType) { 048 this.columnDataType = (dataType == null) ? null : dataType.clone(); 049 } 050 051 052 public void setColumnName(String columnName){ 053 this.name = columnName; 054 } 055 056 private boolean unresolvedStar; 057 058 /** 059 * Whether this entry is a star lineage wrote back into the catalog for a table whose width it could not 060 * resolve (a {@code SELECT *} of an unknown table): stored as {@code *}, it is not a column of the table. A 061 * catalog column that is NAMED {@code *} is an ordinary column and reads {@code false}. 062 */ 063 public boolean isUnresolvedStar() { 064 return unresolvedStar; 065 } 066 067 public void setUnresolvedStar(boolean unresolvedStar) { 068 this.unresolvedStar = unresolvedStar; 069 } 070 071 @Override 072 public String toString(){ 073 074 String ret = "Column name: "+ name; 075 if (columnDataType != null){ 076 ret = ret +", data type: " + columnDataType.getDataType().toString(); 077 }else{ 078 ret = ret +", data type: N/A"; 079 } 080 return ret; 081 } 082 083}