Table of Contents

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

dbvendor EDbVendor

Fields

isparsed

protected bool isparsed

Field Value

bool

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

TJoinList

parser

Parser used to parse this statement.

public TCustomParser parser

Field Value

TCustomParser

plsqlparser

PLSQL parser used to parse this statement.

public TCustomParser plsqlparser

Field Value

TCustomParser

rootNode

Original Parse tree node from parser

public TParseTreeNode rootNode

Field Value

TParseTreeNode

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

TSourceTokenList

sqlstatementtype

Type of this statement.

public ESqlStatementType sqlstatementtype

Field Value

ESqlStatementType

stmtDummyTag

Tag used by parser internally.

public int stmtDummyTag

Field Value

int

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

TTableList

Properties

AncestorStmt

the topmost level statement which includes this statement

public virtual TCustomSqlStatement AncestorStmt { get; }

Property Value

TCustomSqlStatement

CteList

common table list

public virtual TCTEList CteList { get; set; }

Property Value

TCTEList

DatabaseObjects

public List<TObjectName> DatabaseObjects { get; }

Property Value

List<TObjectName>

EndLabelName

end label of SQL

public virtual TObjectName EndLabelName { get; set; }

Property Value

TObjectName

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

TTable

Hint

public virtual string Hint { get; set; }

Property Value

string

LabelName

label of this SQL

public virtual TObjectName LabelName { get; set; }

Property Value

TObjectName

OracleHint

public virtual string OracleHint { get; set; }

Property Value

string

OrphanColumns

public virtual TObjectNameList OrphanColumns { get; }

Property Value

TObjectNameList

OutputClause

output clause

public virtual TOutputClause OutputClause { get; set; }

Property Value

TOutputClause

ParentStmt

top level statement which includes this statement

public virtual TCustomSqlStatement ParentStmt { get; set; }

Property Value

TCustomSqlStatement

ResultColumnList

refer to select list if statement is select.

public virtual TResultColumnList ResultColumnList { get; set; }

Property Value

TResultColumnList

ReturningClause

returning clause

public virtual TReturningClause ReturningClause { get; set; }

Property Value

TReturningClause

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

TStatementList

SymbolTable

symbol table used to store variable insdie stored procedure.

public virtual Stack SymbolTable { get; }

Property Value

Stack

TargetTable

target table in the delete/insert/update/create table statement.

public virtual TTable TargetTable { get; set; }

Property Value

TTable

TopClause

top clause of sql server

public virtual TTopClause TopClause { get; set; }

Property Value

TTopClause

TopStatement

return level topmost statement which include this statement.

public virtual TCustomSqlStatement TopStatement { get; }

Property Value

TCustomSqlStatement

WhereClause

where predicate

public virtual TWhereClause WhereClause { get; set; }

Property Value

TWhereClause

Methods

OracleStatementCanBeSeparatedByBeginEndPair()

public virtual bool OracleStatementCanBeSeparatedByBeginEndPair()

Returns

bool

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

pTable TTable

addWhereClause(string)

this method was temporary disabled.

public virtual TWhereClause addWhereClause(string condition)

Parameters

condition string

Returns

TWhereClause

analyzeFromTable(TFromTable, bool?)

public virtual TTable analyzeFromTable(TFromTable pfromTable, bool? addToTableList)

Parameters

pfromTable TFromTable
addToTableList bool?

Returns

TTable

analyzeJoin(TJoinExpr, TJoin, bool?)

public virtual TJoin analyzeJoin(TJoinExpr pJoinExpr, TJoin pJoin, bool? isSub)

Parameters

pJoinExpr TJoinExpr
pJoin TJoin
isSub bool?

Returns

TJoin

analyzeTablename(TObjectName)

return a TTable instance based on tableName

public virtual TTable analyzeTablename(TObjectName tableName)

Parameters

tableName TObjectName

Returns

TTable

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

crf TObjectName
sameLevelOnly bool

Returns

bool

clearError()

public virtual void clearError()

doParseStatement(TCustomSqlStatement)

analyze SQL

public virtual int doParseStatement(TCustomSqlStatement psql)

Parameters

psql TCustomSqlStatement

Returns

int

dochecksyntax(TCustomSqlStatement)

check syntax of this statement.

protected virtual int dochecksyntax(TCustomSqlStatement psql)

Parameters

psql TCustomSqlStatement

Returns

int

findTable(ETableEffectType)

public virtual TTable findTable(ETableEffectType pTableEffectType)

Parameters

pTableEffectType ETableEffectType

Returns

TTable

fireOnMetaDatabaseTableColumn(string, string, string, string, string)

protected virtual bool fireOnMetaDatabaseTableColumn(string pServer, string pDatabase, string pSchema, string pTable, string pColumn)

Parameters

pServer string
pDatabase string
pSchema string
pTable string
pColumn string

Returns

bool

isTableACTE(TTable)

check whether a table is an CTE

protected virtual bool isTableACTE(TTable pTable)

Parameters

pTable TTable

Returns

bool

isnzplsql()

public virtual bool isnzplsql()

Returns

bool

isoracleplsql()

public virtual bool isoracleplsql()

Returns

bool

ispgplsql()

public virtual bool ispgplsql()

Returns

bool

linkColumnReferenceToTable(TObjectName, ESqlClause)

[Obsolete("use linkColumnToTable instead")]
public virtual void linkColumnReferenceToTable(TObjectName cr, ESqlClause plocation)

Parameters

cr TObjectName
plocation ESqlClause

linkColumnToTable(TObjectName, ESqlClause)

public virtual bool linkColumnToTable(TObjectName pColumn, ESqlClause pLocation)

Parameters

pColumn TObjectName
pLocation ESqlClause

Returns

bool

linkToFirstTable(TObjectName, int)

protected virtual bool linkToFirstTable(TObjectName pColumn, int pCandidateTableCnt)

Parameters

pColumn TObjectName
pCandidateTableCnt int

Returns

bool

locateVariableOrParameter(TObjectName)

public virtual bool locateVariableOrParameter(TObjectName cr)

Parameters

cr TObjectName

Returns

bool

parseerrormessagehandle(TSyntaxError)

Log error messages if syntax errors found while parsing this statement.

public virtual EActionOnParseError parseerrormessagehandle(TSyntaxError se)

Parameters

se TSyntaxError

syntax error structure.

Returns

EActionOnParseError

type of error

parsestatement(TCustomSqlStatement, bool)

Parse this statement.

public virtual int parsestatement(TCustomSqlStatement pparentsql, bool isparsetreeavailable)

Parameters

pparentsql TCustomSqlStatement
isparsetreeavailable bool

Returns

int

parse result, zero means no syntax error found.

scanOracleHint(TSourceToken)

protected void scanOracleHint(TSourceToken pStartToken)

Parameters

pStartToken TSourceToken

searchCTEList()

protected virtual TCTEList searchCTEList()

Returns

TCTEList

setEndlabelName(TObjectName)

used for backward compatibility only, please use property EndLabelName instead.

[Obsolete("use EndLableName instead")]
public void setEndlabelName(TObjectName n)

Parameters

n TObjectName

setLabelName(TObjectName)

used for backward compatibility only, please use property LabelName instead.

[Obsolete("use LableName instead")]
public void setLabelName(TObjectName n)

Parameters

n TObjectName