public class TCustomSqlStatement extends TParseTreeNode
Modifier and Type | Field and Description |
---|---|
EDbVendor |
dbvendor
SQL dialect of this statement.
|
int |
dummytag
Tag used by parser internally.
|
protected boolean |
isparsed |
TJoinList |
joins
joins represents table sources in the from clause.
|
TCustomParser |
parser
Parser used to parse this statement.
|
TCustomParser |
plsqlparser
PLSQL parser used to parse this statement.
|
TParseTreeNode |
rootNode
Original Parse tree node from parser
|
TSourceTokenList |
sourcetokenlist
Source tokens included in this statement.
|
ESqlStatementType |
sqlstatementtype
Type of this statement.
|
TTableList |
tables
Provides a quick way to access all tables involved in this SQL statement.
|
Constructor and Description |
---|
TCustomSqlStatement(EDbVendor dbvendor) |
Modifier and Type | Method and Description |
---|---|
void |
addToTables(TTable pTable) |
TWhereClause |
addWhereClause(String condition) |
TTable |
analyzeFromTable(TFromTable pfromTable,
Boolean addToTableList) |
TJoin |
analyzeJoin(TJoinExpr pJoinExpr,
TJoin pJoin,
Boolean isSub) |
TTable |
analyzeTablename(TObjectName tableName) |
boolean |
checkNonQualifiedColumnReferenceInSubQueryOfUplevelStmt(TObjectName crf,
boolean sameLevelOnly)
Found out is a non qualified column is a column in uplevel subquery table like this:
take ma_parkey for example: ma_parkey is not a physical column
SELECT c_mandant
, CASE WHEN EXISTS (SELECT 1
FROM CDS_H_GRUPPE GRP1
WHERE GRP1.c_mandant = c_mandant
AND GRP1.parkey1 = ma_parkey)
THEN 1
ELSE NULL
END MA_ME
FROM (SELECT c_mandant
, CASE WHEN funktionscode = 'U'
THEN parkey1
ELSE parkey2
END MA_PARKEY
FROM
CDS_H_GRUPPE
)
|
void |
clearError() |
protected int |
dochecksyntax(TCustomSqlStatement psql) |
int |
doParseStatement(TCustomSqlStatement psql) |
TTable |
findTable(ETableEffectType pTableEffectType) |
protected boolean |
fireOnMetaDatabaseTableColumn(String pServer,
String pDatabase,
String pSchema,
String pTable,
String pColumn) |
TCustomSqlStatement |
getAncestorStmt() |
TCTEList |
getCteList()
Multiple common table expressions
TCTE can be specified following the single WITH keyword. |
Stack<TDaxFunction> |
getDaxFunctionStack() |
TObjectName |
getEndlabelName() |
int |
getErrorCount()
Number of syntax errors for this statement.
|
TTable |
getFirstPhysicalTable() |
TPTNodeList<TColumnWithSortOrder> |
getIndexColumns() |
TJoinList |
getJoins() |
TObjectName |
getLabelName() |
TObjectNameList |
getOrphanColumns() |
TOutputClause |
getOutputClause() |
TCustomSqlStatement |
getParentStmt() |
TResultColumnList |
getResultColumnList()
In select statement, this method returns Items in select_list.
|
TReturningClause |
getReturningClause() |
TStatementList |
getStatements()
Saves all first level sub statements.
|
Stack |
getSymbolTable() |
TTableList |
getTables() |
TTable |
getTargetTable()
target table in the delete/insert/update/create table statement.
|
TTopClause |
getTopClause() |
TCustomSqlStatement |
getTopStatement() |
Stack<TObjectName> |
getVariableStack() |
TWhereClause |
getWhereClause()
restrict the rows selected to those that satisfy one or more conditions.
|
boolean |
isnzplsql() |
boolean |
isoracleplsql() |
boolean |
ispgplsql() |
protected boolean |
isTableACTE(TTable pTable) |
boolean |
isverticaplsql() |
void |
linkColumnReferenceToTable(TObjectName cr,
ESqlClause plocation)
Deprecated.
As of v1.6.0.1, use
linkColumnToTable(gudusoft.gsqlparser.nodes.TObjectName, gudusoft.gsqlparser.ESqlClause) instead |
boolean |
linkColumnToTable(TObjectName pColumn,
ESqlClause pLocation) |
protected boolean |
linkToFirstTable(TObjectName pColumn,
int pCandidateTableCnt) |
boolean |
locateVariableOrParameter(TObjectName cr) |
boolean |
OracleStatementCanBeSeparatedByBeginEndPair() |
EActionOnParseError |
parseerrormessagehandle(TSyntaxError se)
Log error messages if syntax errors found while parsing this statement.
|
int |
parsestatement(TCustomSqlStatement pparentsql,
boolean isparsetreeavailable)
Parse this statement.
|
protected TCTEList |
searchCTEList() |
boolean |
searchDaxVariableInStack(TObjectName pName) |
void |
setCteList(TCTEList cteList) |
void |
setEndlabelName(TObjectName endlabelName) |
void |
setLabelName(TObjectName lName) |
void |
setOutputClause(TOutputClause outputClause) |
void |
setParentStmt(TCustomSqlStatement parentStmt) |
void |
setResultColumnList(TResultColumnList resultColumnList) |
void |
setReturningClause(TReturningClause returningClause) |
void |
setTargetTable(TTable targetTable) |
void |
setTopClause(TTopClause topClause) |
void |
setVariableStack(Stack<TObjectName> variableStack) |
void |
setWhereClause(TWhereClause whereClause) |
boolean |
VerticaStatementCanBeSeparatedByBeginEndPair() |
accept, acceptChildren, addAllMyTokensToTokenList, appendString, doParse, fastSetString, getColumnNo, getDummyTag, getEndToken, getGsqlparser, getLineNo, getNodeType, getStartToken, init, init, init, init, init, init, removeAllMyTokensFromTokenList, setDummyTag, setEndToken, setEndToken, setEndToken, setEndToken, setGsqlparser, setIncludingComment, setNodeType, setStartToken, setStartToken, setStartToken, setStartToken, setString, toScript, toString
public ESqlStatementType sqlstatementtype
public TSourceTokenList sourcetokenlist
TParseTreeNode.getStartToken()
, and TParseTreeNode.getEndToken()
of this statement.public EDbVendor dbvendor
public TCustomParser parser
public TCustomParser plsqlparser
public int dummytag
public TJoinList joins
SQL 1:
select f from t1
size of joins will be 1, t1 can be fetch via joins.getJoin(0).getTable()
SQL 2:
select f from t1,t2
size of joins will be 2,
t1 can be fetch via joins.getJoin(0).getTable()
t2 can be fetch via joins.getJoin(1).getTable()
SQL 3:
select f from t1 join t2 on t1.f1 = t2.f1
size of joins will be 1,
t1 information can be fetch via joins.getJoin(0).getTable()
In order to access t2, we need to introduce a new class TJoinItem
which includes all information about t2 and join condition.
There is a property named joinItems of TJoin
which is type of TJoinItemList
that includes a list of TJoinItem
.
this property can be access via TJoin.getJoinItems()
.
Now, t2 can be fetch via joins.getJoin(0).getJoinItems().getJoinItem(0).getTable()
SQL 4:
select f from t1 join t2 on t1.f1 = t2.f1 join t3 on t1.f1 = t3.f1
size of joins will be 1,
t1 can be fetch via joins.getJoin(0).getTable()
t2 can be fetch via joins.getJoin(0).getJoinItems().getJoinItem(0).getTable()
t3 can be fetch via joins.getJoin(0).getJoinItems().getJoinItem(1).getTable()
tables
public TTableList tables
It stores all tables in a flat way while joins
stores all tables in a hierarchical structure.
joins only represents tables in from clause of select/delete statement, and tables in update/insert statement.
tables
includes all tables in all types of SQL statements such as tables involved in a create table or create trigger statements.
public TParseTreeNode rootNode
protected boolean isparsed
public TCustomSqlStatement(EDbVendor dbvendor)
public TPTNodeList<TColumnWithSortOrder> getIndexColumns()
public void setVariableStack(Stack<TObjectName> variableStack)
public Stack<TObjectName> getVariableStack()
public Stack<TDaxFunction> getDaxFunctionStack()
public void setLabelName(TObjectName lName)
public TObjectName getLabelName()
public void setEndlabelName(TObjectName endlabelName)
public TObjectName getEndlabelName()
public TTable getTargetTable()
public void setTargetTable(TTable targetTable)
public TJoinList getJoins()
public TTableList getTables()
public TStatementList getStatements()
By iterating statements recursively, you can fetch all included statements in an easy way.
select f1+(select f2 from t2) from t1 where f2 > all (select f3 from t3 where f4 = (select f5 from t4))
Statements included in above SQL was save in a hierarchical way like this:
If this statement is a create procedure/function statement, then all declaration statements and statements in procedure body can also be fetched quickly by iterating this property recursively.
public void setCteList(TCTEList cteList)
public TCTEList getCteList()
TCTE
can be specified following the single WITH keyword.
Each common table expression specified can also be referenced by name in the FROM clause of subsequent common table expressions.
Used in select, delete, update statement.
public void setResultColumnList(TResultColumnList resultColumnList)
public TResultColumnList getResultColumnList()
public void setReturningClause(TReturningClause returningClause)
public TReturningClause getReturningClause()
returning clause.
public void setOutputClause(TOutputClause outputClause)
public TOutputClause getOutputClause()
public void setTopClause(TTopClause topClause)
public TTopClause getTopClause()
top clause.
public void setWhereClause(TWhereClause whereClause)
public TWhereClause addWhereClause(String condition)
public TWhereClause getWhereClause()
where clause.
protected TCTEList searchCTEList()
public TCustomSqlStatement getParentStmt()
public void setParentStmt(TCustomSqlStatement parentStmt)
public TCustomSqlStatement getAncestorStmt()
public Stack getSymbolTable()
public int getErrorCount()
public EActionOnParseError parseerrormessagehandle(TSyntaxError se)
se
- syntax error structure.public int parsestatement(TCustomSqlStatement pparentsql, boolean isparsetreeavailable)
pparentsql
- isparsetreeavailable
- public boolean OracleStatementCanBeSeparatedByBeginEndPair()
public boolean VerticaStatementCanBeSeparatedByBeginEndPair()
public boolean isnzplsql()
public boolean ispgplsql()
public boolean isverticaplsql()
public boolean isoracleplsql()
protected int dochecksyntax(TCustomSqlStatement psql)
public void clearError()
public int doParseStatement(TCustomSqlStatement psql)
public TTable analyzeTablename(TObjectName tableName)
protected boolean isTableACTE(TTable pTable)
public TTable findTable(ETableEffectType pTableEffectType)
public void addToTables(TTable pTable)
public TTable analyzeFromTable(TFromTable pfromTable, Boolean addToTableList)
public boolean locateVariableOrParameter(TObjectName cr)
protected boolean fireOnMetaDatabaseTableColumn(String pServer, String pDatabase, String pSchema, String pTable, String pColumn)
public TTable getFirstPhysicalTable()
public TObjectNameList getOrphanColumns()
protected boolean linkToFirstTable(TObjectName pColumn, int pCandidateTableCnt)
public boolean searchDaxVariableInStack(TObjectName pName)
public boolean linkColumnToTable(TObjectName pColumn, ESqlClause pLocation)
public void linkColumnReferenceToTable(TObjectName cr, ESqlClause plocation)
linkColumnToTable(gudusoft.gsqlparser.nodes.TObjectName, gudusoft.gsqlparser.ESqlClause)
insteadpublic boolean checkNonQualifiedColumnReferenceInSubQueryOfUplevelStmt(TObjectName crf, boolean sameLevelOnly)
public TCustomSqlStatement getTopStatement()
Copyright © 2019. All rights reserved.