Package com.alibaba.druid.sql.parser

Examples of com.alibaba.druid.sql.parser.ParserException


        } else if (lexer.token() == Token.IDENTIFIER) {
            if (expr instanceof SQLHexExpr) {
                if ("USING".equalsIgnoreCase(lexer.stringVal())) {
                    lexer.nextToken();
                    if (lexer.token() != Token.IDENTIFIER) {
                        throw new ParserException("syntax error, illegal hex");
                    }
                    String charSet = lexer.stringVal();
                    lexer.nextToken();
                    expr.getAttributes().put("USING", charSet);

                    return primaryRest(expr);
                }
            } else if ("COLLATE".equalsIgnoreCase(lexer.stringVal())) {
                lexer.nextToken();

                if (lexer.token() != Token.IDENTIFIER) {
                    throw new ParserException("syntax error");
                }

                String collate = lexer.stringVal();
                lexer.nextToken();

                SQLBinaryOpExpr binaryExpr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.COLLATE, new SQLIdentifierExpr(collate));

                expr = binaryExpr;

                return primaryRest(expr);
            } else if (expr instanceof SQLVariantRefExpr) {
                if ("COLLATE".equalsIgnoreCase(lexer.stringVal())) {
                    lexer.nextToken();

                    if (lexer.token() != Token.IDENTIFIER) {
                        throw new ParserException("syntax error");
                    }

                    String collate = lexer.stringVal();
                    lexer.nextToken();

                    expr.putAttribute("COLLATE", collate);

                    return primaryRest(expr);
                }
            } else if (expr instanceof SQLIntegerExpr) {
                SQLIntegerExpr intExpr = (SQLIntegerExpr) expr;
                String binaryString = lexer.stringVal();
                if (intExpr.getNumber().intValue() == 0 && binaryString.startsWith("b")) {
                    lexer.nextToken();
                    expr = new MySqlBinaryExpr(binaryString.substring(1));

                    return primaryRest(expr);
                }
            }
        }

        if (lexer.token() == Token.LPAREN && expr instanceof SQLIdentifierExpr) {
            SQLIdentifierExpr identExpr = (SQLIdentifierExpr) expr;
            String ident = identExpr.getName();

            if ("EXTRACT".equalsIgnoreCase(ident)) {
                lexer.nextToken();

                if (lexer.token() != Token.IDENTIFIER) {
                    throw new ParserException("syntax error");
                }

                String unitVal = lexer.stringVal();
                MySqlIntervalUnit unit = MySqlIntervalUnit.valueOf(unitVal);
                lexer.nextToken();

                accept(Token.FROM);

                SQLExpr value = expr();

                MySqlExtractExpr extract = new MySqlExtractExpr();
                extract.setValue(value);
                extract.setUnit(unit);
                accept(Token.RPAREN);

                expr = extract;

                return primaryRest(expr);
            } else if ("SUBSTRING".equalsIgnoreCase(ident)) {
                lexer.nextToken();
                SQLMethodInvokeExpr methodInvokeExpr = new SQLMethodInvokeExpr(ident);
                for (;;) {
                    SQLExpr param = expr();
                    methodInvokeExpr.getParameters().add(param);

                    if (lexer.token() == Token.COMMA) {
                        lexer.nextToken();
                        continue;
                    } else if (lexer.token() == Token.FROM) {
                        lexer.nextToken();
                        SQLExpr from = expr();
                        methodInvokeExpr.putAttribute("FROM", from);

                        if (lexer.token() == Token.FOR) {
                            lexer.nextToken();
                            SQLExpr _for = expr();
                            methodInvokeExpr.putAttribute("FOR", _for);
                        }
                        break;
                    } else if (lexer.token() == Token.RPAREN) {
                        break;
                    } else {
                        throw new ParserException("syntax error");
                    }
                }

                accept(Token.RPAREN);
                expr = methodInvokeExpr;

                return primaryRest(expr);
            } else if ("TRIM".equalsIgnoreCase(ident)) {
                lexer.nextToken();
                SQLMethodInvokeExpr methodInvokeExpr = new SQLMethodInvokeExpr(ident);

                if (lexer.token() == Token.IDENTIFIER) {
                    String flagVal = lexer.stringVal();
                    if ("LEADING".equalsIgnoreCase(flagVal)) {
                        lexer.nextToken();
                        methodInvokeExpr.getAttributes().put("TRIM_TYPE", "LEADING");
                    } else if ("BOTH".equalsIgnoreCase(flagVal)) {
                        lexer.nextToken();
                        methodInvokeExpr.getAttributes().put("TRIM_TYPE", "BOTH");
                    } else if ("TRAILING".equalsIgnoreCase(flagVal)) {
                        lexer.nextToken();
                        methodInvokeExpr.putAttribute("TRIM_TYPE", "TRAILING");
                    }
                }

                SQLExpr param = expr();
                methodInvokeExpr.getParameters().add(param);

                if (lexer.token() == Token.FROM) {
                    lexer.nextToken();
                    SQLExpr from = expr();
                    methodInvokeExpr.putAttribute("FROM", from);
                }

                accept(Token.RPAREN);
                expr = methodInvokeExpr;

                return primaryRest(expr);
            } else if ("MATCH".equalsIgnoreCase(ident)) {
                lexer.nextToken();
                MySqlMatchAgainstExpr matchAgainstExpr = new MySqlMatchAgainstExpr();

                if (lexer.token() == Token.RPAREN) {
                    lexer.nextToken();
                } else {
                    exprList(matchAgainstExpr.getColumns());
                    accept(Token.RPAREN);
                }

                acceptIdentifier("AGAINST");

                accept(Token.LPAREN);
                SQLExpr against = primary();
                matchAgainstExpr.setAgainst(against);

                if (lexer.token() == Token.IN) {
                    lexer.nextToken();
                    if (identifierEquals("NATURAL")) {
                        lexer.nextToken();
                        acceptIdentifier("LANGUAGE");
                        acceptIdentifier("MODE");
                        if (identifierEquals("WITH")) {
                            lexer.nextToken();
                            acceptIdentifier("QUERY");
                            acceptIdentifier("EXPANSION");
                            matchAgainstExpr.setSearchModifier(SearchModifier.IN_NATURAL_LANGUAGE_MODE_WITH_QUERY_EXPANSION);
                        } else {
                            matchAgainstExpr.setSearchModifier(SearchModifier.IN_NATURAL_LANGUAGE_MODE);
                        }
                    } else {
                        throw new ParserException("TODO");
                    }
                } else if (identifierEquals("WITH")) {
                    throw new ParserException("TODO");
                }

                accept(Token.RPAREN);

                expr = matchAgainstExpr;

                return primaryRest(expr);
            } else if ("CONVERT".equalsIgnoreCase(ident)) {
                lexer.nextToken();
                SQLMethodInvokeExpr methodInvokeExpr = new SQLMethodInvokeExpr(ident);

                if (lexer.token() != Token.RPAREN) {
                    exprList(methodInvokeExpr.getParameters());
                }

                if (identifierEquals("USING")) {
                    lexer.nextToken();
                    if (lexer.token() != Token.IDENTIFIER) {
                        throw new ParserException("syntax error");
                    }
                    String charset = lexer.stringVal();
                    lexer.nextToken();
                    methodInvokeExpr.putAttribute("USING", charset);
                }
View Full Code Here


            return primaryRest(methodInvokeExpr);
        } else {
            SQLExpr value = expr();

            if (lexer.token() != Token.IDENTIFIER) {
                throw new ParserException("Syntax error");
            }

            String unit = lexer.stringVal();
            lexer.nextToken();
View Full Code Here

            break;
        }

        if (lexer.token() == (Token.ON)) {
            throw new ParserException("TODO");
        }

        if (lexer.token() == (Token.SELECT)) {
            SQLSelect query = new MySqlSelectParser(this.lexer).select();
            createTable.setQuery(query);
View Full Code Here

            accept(Token.RPAREN);

            return primaryKey;
        }

        throw new ParserException("TODO");
    }
View Full Code Here

            constaints.add(nullable);
            return true;
        }

        if (lexer.token() == (Token.UNIQUE)) {
            throw new ParserException("TODO");
        }

        if (lexer.token() == (Token.REFERENCE)) {
            throw new ParserException("TODO");
        }

        if (lexer.token() == (Token.FOREIGN)) {
            lexer.nextToken();
            accept(Token.KEY);

            OracleForeignKey foreignKey = new OracleForeignKey();

            foreignKey.setName(constaintName);

            accept(Token.LPAREN);
            this.exprParser.names(foreignKey.getColumns());
            accept(Token.RPAREN);

            accept(Token.REFERENCES);
            foreignKey.setRefObject(this.exprParser.name());

            if (lexer.token() == (Token.LPAREN)) {
                lexer.nextToken();
                this.exprParser.names(foreignKey.getRefColumns());
                accept(Token.RPAREN);
            }

            foreignKey.setState(parseConstraintState());

            constaints.add(foreignKey);
            return true;
        }

        if (lexer.token() == (Token.SCHEMA)) {
            throw new ParserException("TODO");
        }

        if (lexer.token() == (Token.PRIMARY)) {
            lexer.nextToken();
            accept(Token.KEY);

            OraclePrimaryKey primaryKey = new OraclePrimaryKey();
            primaryKey.setName(constaintName);

            if (lexer.token() == (Token.LPAREN)) {
                lexer.nextToken();
                this.exprParser.names(primaryKey.getColumns());
                accept(Token.RPAREN);
            }

            primaryKey.setState(parseConstraintState());

            constaints.add(primaryKey);

            return true;
        }

        if (identifierEquals("Scope")) {
            lexer.nextToken();

            if (lexer.token() == (Token.IS)) {
                throw new RuntimeException("TODO");
            }
            if (lexer.token() == (Token.FOR)) {
                throw new ParserException("TODO");
            }
            throw new ParserException("TODO");
        }

        if (identifierEquals("REF")) {
            throw new ParserException("TODO");
        }

        if (lexer.token() == (Token.REFERENCES)) {
            lexer.nextToken();
            OracleReferencesConstaint ref = new OracleReferencesConstaint();
View Full Code Here

    }

    protected OracleConstraintState parseConstraintState() throws ParserException {
        OracleConstraintState state = null;
        while (true) {
            if (identifierEquals("DEFERRABLE")) throw new ParserException("TODO");
            if (identifierEquals("INITIALY")) throw new ParserException("TODO");
            if (identifierEquals("RELY")) throw new ParserException("TODO");
            if (identifierEquals("NORELY")) throw new ParserException("TODO");
            if (identifierEquals("USING")) throw new ParserException("TODO");
            if (identifierEquals("ENABLE")) throw new ParserException("TODO");
            if (!(identifierEquals("DISABLE"))) break;
            if (state == null) {
                state = new OracleConstraintState();
            }

            lexer.nextToken();
            if (identifierEquals("CASCADE")) {
                lexer.nextToken();
                state.getStates().add(new SQLIdentifierExpr("DISABLE CASCADE"));
            }
            state.getStates().add(new SQLIdentifierExpr("DISABLE"));
        }

        if (identifierEquals("VALIDATE")) throw new ParserException("TODO");
        if (identifierEquals("NOVALIDATE")) throw new ParserException("TODO");
        if (identifierEquals("EXCEPTIONS")) {
            throw new ParserException("TODO");
        }

        return state;
    }
View Full Code Here

        return state;
    }

    protected void parsePhysicalAttributesClause() throws ParserException {
        if (identifierEquals("PCTREE")) throw new ParserException("TODO");
        if (identifierEquals("PCTUSED")) throw new ParserException("TODO");
        if (identifierEquals("INITRANS")) throw new ParserException("TODO");
        if (identifierEquals("STORAGE")) throw new ParserException("TODO");
    }
View Full Code Here

            lexer.nextToken();
            column.setDefaultValue(this.exprParser.expr());
        }

        if (identifierEquals("ENCTRYPT")) {
            throw new ParserException("TODO");
        }
        return column;
    }
View Full Code Here

            }

            return parseCreateView();
        }

        throw new ParserException("TODO " + lexer.token());
    }
View Full Code Here

                lexer.nextToken();
            } else if (identifierEquals("HASH")) {
                stmt.setUsing("HASH");
                lexer.nextToken();
            } else {
                throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
            }
        }
    }
View Full Code Here

TOP

Related Classes of com.alibaba.druid.sql.parser.ParserException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.