gudusoft.gsqlparser
Class TCustomSqlStatement

java.lang.Object
  extended by gudusoft.gsqlparser.nodes.TParseTreeNode
      extended by gudusoft.gsqlparser.TCustomSqlStatement
All Implemented Interfaces:
Visitable
Direct Known Subclasses:
TAlterSessionStatement, TAlterTableStatement, TBlockSqlStatement, TCreateDatabaseSqlStatement, TCreateIndexSqlStatement, TCreateMaterializedSqlStatement, TCreateTableSqlStatement, TCreateViewSqlStatement, TCustomDb2Stmt, TCustomMySQLStmt, TCustomOracleSqlStmt, TDb2StmtStub, TDeleteSqlStatement, TDropIndexSqlStatement, TDropRoleSqlStatement, TDropTableSqlStatement, TDropTriggerSqlStatement, TDropViewSqlStatement, TExecuteSqlStatement, TFetchSqlStatement, TGrantSqlStatement, TInsertSqlStatement, TLockSqlStatement, TMdxAlterCube, TMdxCalculate, TMdxCall, TMdxCase, TMdxClearCalculations, TMdxCreateAction, TMdxCreateCellCalculation, TMdxCreateGlobalCube, TMdxCreateMember, TMdxCreateSessionCube, TMdxCreateSet, TMdxCreateSubCube, TMdxDrillthrough, TMdxDropAction, TMdxDropCellCalculation, TMdxDropMember, TMdxDropSet, TMdxDropSubcube, TMdxExpression, TMdxFreeze, TMdxIf, TMdxRefreshCube, TMdxScope, TMdxSelect, TMdxUpdate, TMergeSqlStatement, TMssqlBeginDialog, TMssqlBeginTran, TMssqlBreak, TMssqlBulkInsert, TMssqlClose, TMssqlCommit, TMssqlContinue, TMssqlDeallocate, TMssqlDeclare, TMssqlDropDbObject, TMssqlDropIndex, TMssqlDropTable, TMssqlDropView, TMssqlDummyStmt, TMssqlEndConversation, TMssqlErrorStmt, TMssqlExecute, TMssqlExecuteAs, TMssqlFetch, TMssqlGo, TMssqlGoTo, TMssqlGrant, TMssqlIfElse, TMssqlLabel, TMssqlOpen, TMssqlPrint, TMssqlRaiserror, TMssqlReturn, TMssqlRevert, TMssqlRollback, TMssqlSaveTran, TMssqlSendOnConversation, TMssqlSet, TMssqlStmtStub, TMssqlTruncateTable, TMssqlUpdateStatistics, TMssqlUpdateText, TMssqlUse, TMssqlWaitFor, TMssqlWithas, TMySQLStmtStub, TOracleExecuteProcedure, TPlsqlStmt, TSelectSqlStatement, TSqlplusCmdStatement, TTeradataAbort, TTeradataBeginLogging, TTeradataBeginTransaction, TTeradataCommit, TTeradataCreateTrigger, TTeradataDropDbObject, TTeradataEndLogging, TTeradataEndTransaction, TTeradataExecute, TTeradataGrant, TTeradataNotImplement, TTeradataRollback, TTeradataSetRole, TTeradataSetSession, TTeradataSetTimezone, TTruncateStatement, TUnknownSqlStatement, TUpdateSqlStatement, TUsingSqlStatement

public class TCustomSqlStatement
extends TParseTreeNode

TCustomSqlStatement is the root class for all SQL statements.


Field Summary
 EDbVendor dbvendor
          SQL dialect of this statement.
 int dummytag
          Tag used by parser internally.
 TJoinList joins
          joins represents table sources in following clauses of SQL statement: from clause of select statement. from clause of delete statement, Specifies an additional FROM clause, This Transact-SQL extension to DELETE allows specifying data from table_source and deleting the corresponding rows from the table in the first FROM clause. from clause of update statement, Specifies that a table, view, or derived table source is used to provide the criteria for the update operation.
 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 SQL statements.
 
Constructor Summary
TCustomSqlStatement(EDbVendor dbvendor)
           
 
Method Summary
 TWhereClause addWhereClause(java.lang.String condition)
          This method must be override in select/delete/update statement
 TTable analyzeFromTable(TFromTable pfromTable)
           
 TJoin analyzeJoin(TJoinExpr pJoinExpr, TJoin pJoin, java.lang.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 )
 int doParseStatement(TCustomSqlStatement psql)
           
 TCTEList getCteList()
          Multiple common table expressions TCTE can be specified following the single WITH keyword.
 int getErrorCount()
          Number of syntax errors for this statement.
 TObjectName getLabelName()
           
 TOutputClause getOutputClause()
          Used in delete, update statement.
 TCustomSqlStatement getParentStmt()
           
 TResultColumnList getResultColumnList()
          Items in select_list.
 TReturningClause getReturningClause()
          Used in delete, update statement.
 TStatementList getStatements()
          Saves all first level sub statements.
 java.util.Stack getSymbolTable()
           
 TTable getTargetTable()
          target table in the delete/insert/update/create table statement.
 TTopClause getTopClause()
          Used in select, delete, update statement.
 TCustomSqlStatement getTopStatement()
           
 TWhereClause getWhereClause()
          restrict the rows selected to those that satisfy one or more conditions.
 boolean isnzplsql()
           
 boolean isoracleplsql()
           
 boolean ispgplsql()
           
 void linkColumnReferenceToTable(TObjectName cr, ESqlClause plocation)
           
 int locateVariableOrParameter(TObjectName cr)
           
 boolean OracleStatementCanBeSeparatedByBeginEndPair()
           
 int parsestatement(TCustomSqlStatement pparentsql, boolean isparsetreeavailable)
          Parse this statement.
 void setCteList(TCTEList cteList)
           
 void setLabelName(TObjectName labelName)
           
 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 setWhereClause(TWhereClause whereClause)
           
 
Methods inherited from class gudusoft.gsqlparser.nodes.TParseTreeNode
accept, addAllMyTokensToTokenList, doParse, getColumnNo, getDummyTag, getEndToken, getGsqlparser, getLineNo, getNodeType, getStartToken, init, init, init, init, init, init, setDummyTag, setEndToken, setEndToken, setGsqlparser, setNodeType, setStartToken, setStartToken, setString, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

sqlstatementtype

public ESqlStatementType sqlstatementtype
Type of this statement.


sourcetokenlist

public TSourceTokenList sourcetokenlist
Source tokens included in this statement. only source tokens available when this is a top level statement, otherwise, there is no source token in this statement. Please check TParseTreeNode.getStartToken(), and TParseTreeNode.getEndToken() of this statement.


dbvendor

public EDbVendor dbvendor
SQL dialect of this statement.


parser

public TCustomParser parser
Parser used to parse this statement.


plsqlparser

public TCustomParser plsqlparser
PLSQL parser used to parse this statement.


dummytag

public int dummytag
Tag used by parser internally.


joins

public TJoinList joins
joins represents table sources in following clauses of SQL statement:

Each table source in from clause was treated as a join which is type of TJoin.

The reason for this design is that we can treat all table sources in from clause in a uniform way.

Please check TJoin for more informations.

See Also:
getTargetTable()

tables

public TTableList tables
Provides a quick way to access all tables SQL statements.

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 invovled in a create table or create trigger statements.

items in tables in type of TTable while items in joins is type of TJoin.


rootNode

public TParseTreeNode rootNode
Original Parse tree node from parser

Constructor Detail

TCustomSqlStatement

public TCustomSqlStatement(EDbVendor dbvendor)
Method Detail

setLabelName

public void setLabelName(TObjectName labelName)

getLabelName

public TObjectName getLabelName()
Returns:
label name used in plsql statement.

getTargetTable

public TTable getTargetTable()
target table in the delete/insert/update/create table statement.

See Also:
joins, TSelectSqlStatement, TDeleteSqlStatement, TUpdateSqlStatement, TCreateTableSqlStatement, TMergeSqlStatement

setTargetTable

public void setTargetTable(TTable targetTable)

getStatements

public TStatementList getStatements()
Saves all first level sub statements.

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 recusively.


setCteList

public void setCteList(TCTEList cteList)

getCteList

public TCTEList getCteList()
Multiple common table expressions 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.

Returns:
List of common table expression.

setResultColumnList

public void setResultColumnList(TResultColumnList resultColumnList)

getResultColumnList

public TResultColumnList getResultColumnList()
Items in select_list. Can be *, expr, and name.* The select_list lets you specify the columns you want to retrieve from the database.

set clause in update statement.

Returns:

setReturningClause

public void setReturningClause(TReturningClause returningClause)

getReturningClause

public TReturningClause getReturningClause()
Used in delete, update statement.

Returns:

setOutputClause

public void setOutputClause(TOutputClause outputClause)

getOutputClause

public TOutputClause getOutputClause()
Used in delete, update statement.

Returns:

setTopClause

public void setTopClause(TTopClause topClause)

getTopClause

public TTopClause getTopClause()
Used in select, delete, update statement.

Returns:

setWhereClause

public void setWhereClause(TWhereClause whereClause)

addWhereClause

public TWhereClause addWhereClause(java.lang.String condition)
This method must be override in select/delete/update statement

Parameters:
condition -
Returns:

getWhereClause

public TWhereClause getWhereClause()
restrict the rows selected to those that satisfy one or more conditions. used in select, delete, update statement.

Returns:

getParentStmt

public TCustomSqlStatement getParentStmt()

setParentStmt

public void setParentStmt(TCustomSqlStatement parentStmt)

getSymbolTable

public java.util.Stack getSymbolTable()

getErrorCount

public int getErrorCount()
Number of syntax errors for this statement.

Returns:
0 means no syntax error.

parsestatement

public int parsestatement(TCustomSqlStatement pparentsql,
                          boolean isparsetreeavailable)
Parse this statement.

Parameters:
pparentsql -
isparsetreeavailable -
Returns:

OracleStatementCanBeSeparatedByBeginEndPair

public boolean OracleStatementCanBeSeparatedByBeginEndPair()

isnzplsql

public boolean isnzplsql()

ispgplsql

public boolean ispgplsql()

isoracleplsql

public boolean isoracleplsql()

doParseStatement

public int doParseStatement(TCustomSqlStatement psql)

analyzeTablename

public TTable analyzeTablename(TObjectName tableName)

analyzeFromTable

public TTable analyzeFromTable(TFromTable pfromTable)

analyzeJoin

public TJoin analyzeJoin(TJoinExpr pJoinExpr,
                         TJoin pJoin,
                         java.lang.Boolean isSub)

locateVariableOrParameter

public int locateVariableOrParameter(TObjectName cr)

linkColumnReferenceToTable

public void linkColumnReferenceToTable(TObjectName cr,
                                       ESqlClause plocation)

checkNonQualifiedColumnReferenceInSubQueryOfUplevelStmt

public 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 )

Parameters:
crf -
Returns:

getTopStatement

public TCustomSqlStatement getTopStatement()