001package gudusoft.gsqlparser;
002
003
004import gudusoft.gsqlparser.nodes.TObjectAccess;
005import gudusoft.gsqlparser.nodes.TObjectName;
006import gudusoft.gsqlparser.nodes.TObjectNameList;
007
008/**
009 * Detailed information about syntax error.
010 */
011
012public class TSyntaxError {
013//    public TSyntaxError(TSourceToken sourceToken,String hint, EErrorType errortype, int errorno, TCustomSqlStatement sql){
014//        this.tokentext = sourceToken.toString();
015//        this.lineNo = sourceToken.lineNo;
016//        this.columnNo = sourceToken.columnNo;
017//        this.posInList  = sourceToken.posinlist;
018//
019//        this.hint = hint;
020//        this.errortype = errortype;
021//        this.errorno = errorno;
022//        this.sqlStatement = sql;
023//        this.tokencode = sourceToken.tokencode;
024//
025//    }
026
027    public TSyntaxError(TSourceToken pSt, String hint, EErrorType errortype, int errorno, TCustomSqlStatement sql){
028        TSourceToken st = pSt;
029        if ((pSt.tokencode == 0) && (pSt.container != null)){
030            st = pSt.container.get(pSt.container.size()-1);
031        }
032
033        this.tokentext = st.astext;
034        this.lineNo = st.lineNo;
035        this.columnNo = st.columnNo;
036        this.posInList  = st.posinlist;
037
038        this.hint = hint;
039        this.errortype = errortype;
040        this.errorno = errorno;
041        this.sqlStatement = sql;
042    }
043
044    public TSyntaxError(String tokentext,long lines,long columns,String hint, EErrorType errortype, int errorno, TCustomSqlStatement sql, int posInList){
045        this.tokentext = tokentext;
046        this.lineNo = lines;
047        this.columnNo = columns;
048        this.posInList  = posInList;
049
050        this.hint = hint;
051        this.errortype = errortype;
052        this.errorno = errorno;
053        this.sqlStatement = sql;
054    }
055
056    public TSyntaxError(String tokentext,long lines,long columns,String hint, EErrorType errortype, int errorno, TCustomSqlStatement sql, int posInList,TObjectName objectName){
057        this.tokentext = tokentext;
058        this.lineNo = lines;
059        this.columnNo = columns;
060        this.posInList  = posInList;
061
062        this.hint = hint;
063        this.errortype = errortype;
064        this.errorno = errorno;
065        this.sqlStatement = sql;
066        this.objectName  = objectName;
067    }
068
069    public TSyntaxError(TSyntaxError n){
070        this.tokentext = n.tokentext;
071        this.lineNo = n.lineNo;
072        this.columnNo = n.columnNo;
073        this.hint = n.hint;
074        this.errortype = n.errortype;
075        this.errorno = n.errorno;
076        this.sqlStatement = n.sqlStatement;
077        this.posInList = n.posInList;
078        this.tokencode = n.tokencode;
079    }
080
081    /**
082     * Text of token where syntax error occurs.
083     */
084    public String tokentext;
085    /**
086     * the line number of the first character for error token.
087     */
088    public long lineNo;
089    /**
090     * the column number of the first character for error token.
091     */
092    public long columnNo;
093    public String hint;
094    public EErrorType errortype;
095    public int errorno;
096    public TCustomSqlStatement sqlStatement;
097    public int posInList;
098    public int tokencode;
099
100    public TObjectName objectName;
101
102    public long getLineNo() {
103        return lineNo;
104    }
105
106    public long getColumnNo() {
107        return columnNo;
108    }
109
110    public String getErrorMessage(){
111        return "Error: " + tokentext + " at line " + lineNo + ", column " + columnNo + ".";
112    }
113}