Class TCustomSqlStatement
- Namespace
- gudusoft.gsqlparser
- Assembly
- gudusoft.gsqlparser.dll
TCustomSqlStatement is the root class for all SQL statements.
public class TCustomSqlStatement : TParseTreeNode, Visitable
- Inheritance
-
TCustomSqlStatement
- Implements
- Derived
- Inherited Members
Constructors
TCustomSqlStatement(EDbVendor)
constructor
public TCustomSqlStatement(EDbVendor dbvendor)
Parameters
dbvendorEDbVendor
Fields
isparsed
protected bool isparsed
Field Value
joins
joins represents table sources in the from clause. All structure information was reserved.
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 JoinItems.
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()
public TJoinList joins
Field Value
parser
Parser used to parse this statement.
public TCustomParser parser
Field Value
plsqlparser
PLSQL parser used to parse this statement.
public TCustomParser plsqlparser
Field Value
rootNode
Original Parse tree node from parser
public TParseTreeNode rootNode
Field Value
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.
public TSourceTokenList sourcetokenlist
Field Value
sqlstatementtype
Type of this statement.
public ESqlStatementType sqlstatementtype
Field Value
stmtDummyTag
Tag used by parser internally.
public int stmtDummyTag
Field Value
tables
Provides a quick way to access all tables involved in this SQL statement.
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 TTableList tables
Field Value
Properties
AncestorStmt
the topmost level statement which includes this statement
public virtual TCustomSqlStatement AncestorStmt { get; }
Property Value
CteList
common table list
public virtual TCTEList CteList { get; set; }
Property Value
DatabaseObjects
public List<TObjectName> DatabaseObjects { get; }
Property Value
EndLabelName
end label of SQL
public virtual TObjectName EndLabelName { get; set; }
Property Value
ErrorCount
Number of syntax errors for this statement.
public virtual int ErrorCount { get; }
Property Value
- int
0 means no syntax error.
FirstPhysicalTable
public virtual TTable FirstPhysicalTable { get; }
Property Value
Hint
public virtual string Hint { get; set; }
Property Value
LabelName
label of this SQL
public virtual TObjectName LabelName { get; set; }
Property Value
OracleHint
public virtual string OracleHint { get; set; }
Property Value
OrphanColumns
public virtual TObjectNameList OrphanColumns { get; }
Property Value
OutputClause
output clause
public virtual TOutputClause OutputClause { get; set; }
Property Value
ParentStmt
top level statement which includes this statement
public virtual TCustomSqlStatement ParentStmt { get; set; }
Property Value
ResultColumnList
refer to select list if statement is select.
public virtual TResultColumnList ResultColumnList { get; set; }
Property Value
ReturningClause
returning clause
public virtual TReturningClause ReturningClause { get; set; }
Property Value
Statements
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:
- (select f2 from t2)
- (select f3 from t3 where f4 = (select f5 from t4))
- (select f5 from t4)
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 virtual TStatementList Statements { get; }
Property Value
SymbolTable
symbol table used to store variable insdie stored procedure.
public virtual Stack SymbolTable { get; }
Property Value
TargetTable
target table in the delete/insert/update/create table statement.
public virtual TTable TargetTable { get; set; }
Property Value
TopClause
top clause of sql server
public virtual TTopClause TopClause { get; set; }
Property Value
TopStatement
return level topmost statement which include this statement.
public virtual TCustomSqlStatement TopStatement { get; }
Property Value
WhereClause
where predicate
public virtual TWhereClause WhereClause { get; set; }
Property Value
Methods
OracleStatementCanBeSeparatedByBeginEndPair()
public virtual bool OracleStatementCanBeSeparatedByBeginEndPair()
Returns
RewriteInit()
Changes of the sub-node of this statement will be saved only after calling this method.
public void RewriteInit()
addToTables(TTable)
public virtual void addToTables(TTable pTable)
Parameters
pTableTTable
addWhereClause(string)
this method was temporary disabled.
public virtual TWhereClause addWhereClause(string condition)
Parameters
conditionstring
Returns
analyzeFromTable(TFromTable, bool?)
public virtual TTable analyzeFromTable(TFromTable pfromTable, bool? addToTableList)
Parameters
pfromTableTFromTableaddToTableListbool?
Returns
analyzeJoin(TJoinExpr, TJoin, bool?)
public virtual TJoin analyzeJoin(TJoinExpr pJoinExpr, TJoin pJoin, bool? isSub)
Parameters
Returns
analyzeTablename(TObjectName)
return a TTable instance based on tableName
public virtual TTable analyzeTablename(TObjectName tableName)
Parameters
tableNameTObjectName
Returns
checkNonQualifiedColumnReferenceInSubQueryOfUplevelStmt(TObjectName, bool)
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
)
public virtual bool checkNonQualifiedColumnReferenceInSubQueryOfUplevelStmt(TObjectName crf, bool sameLevelOnly)
Parameters
crfTObjectNamesameLevelOnlybool
Returns
clearError()
public virtual void clearError()
doParseStatement(TCustomSqlStatement)
analyze SQL
public virtual int doParseStatement(TCustomSqlStatement psql)
Parameters
psqlTCustomSqlStatement
Returns
dochecksyntax(TCustomSqlStatement)
check syntax of this statement.
protected virtual int dochecksyntax(TCustomSqlStatement psql)
Parameters
psqlTCustomSqlStatement
Returns
findTable(ETableEffectType)
public virtual TTable findTable(ETableEffectType pTableEffectType)
Parameters
pTableEffectTypeETableEffectType
Returns
fireOnMetaDatabaseTableColumn(string, string, string, string, string)
protected virtual bool fireOnMetaDatabaseTableColumn(string pServer, string pDatabase, string pSchema, string pTable, string pColumn)
Parameters
Returns
isTableACTE(TTable)
check whether a table is an CTE
protected virtual bool isTableACTE(TTable pTable)
Parameters
pTableTTable
Returns
isnzplsql()
public virtual bool isnzplsql()
Returns
isoracleplsql()
public virtual bool isoracleplsql()
Returns
ispgplsql()
public virtual bool ispgplsql()
Returns
linkColumnReferenceToTable(TObjectName, ESqlClause)
[Obsolete("use linkColumnToTable instead")]
public virtual void linkColumnReferenceToTable(TObjectName cr, ESqlClause plocation)
Parameters
crTObjectNameplocationESqlClause
linkColumnToTable(TObjectName, ESqlClause)
public virtual bool linkColumnToTable(TObjectName pColumn, ESqlClause pLocation)
Parameters
pColumnTObjectNamepLocationESqlClause
Returns
linkToFirstTable(TObjectName, int)
protected virtual bool linkToFirstTable(TObjectName pColumn, int pCandidateTableCnt)
Parameters
pColumnTObjectNamepCandidateTableCntint
Returns
locateVariableOrParameter(TObjectName)
public virtual bool locateVariableOrParameter(TObjectName cr)
Parameters
crTObjectName
Returns
parseerrormessagehandle(TSyntaxError)
Log error messages if syntax errors found while parsing this statement.
public virtual EActionOnParseError parseerrormessagehandle(TSyntaxError se)
Parameters
seTSyntaxErrorsyntax error structure.
Returns
- EActionOnParseError
type of error
parsestatement(TCustomSqlStatement, bool)
Parse this statement.
public virtual int parsestatement(TCustomSqlStatement pparentsql, bool isparsetreeavailable)
Parameters
pparentsqlTCustomSqlStatementisparsetreeavailablebool
Returns
- int
parse result, zero means no syntax error found.
scanOracleHint(TSourceToken)
protected void scanOracleHint(TSourceToken pStartToken)
Parameters
pStartTokenTSourceToken
searchCTEList()
protected virtual TCTEList searchCTEList()
Returns
setEndlabelName(TObjectName)
used for backward compatibility only, please use property EndLabelName instead.
[Obsolete("use EndLableName instead")]
public void setEndlabelName(TObjectName n)
Parameters
setLabelName(TObjectName)
used for backward compatibility only, please use property LabelName instead.
[Obsolete("use LableName instead")]
public void setLabelName(TObjectName n)