Search in sources :

Example 1 with Sql_stmtContext

use of com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Sql_stmtContext in project kripton by xcesco.

the class SQLiteSchemaVerifierHelper method extractCommands.

static List<String> extractCommands(SQLiteDatabase database, InputStream inputStream) {
    final List<String> result = new ArrayList<>();
    final String input = IOUtils.readText(inputStream);
    JqlLexer lexer = new JqlLexer(CharStreams.fromString(input));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    JqlParser parser = new JqlParser(tokens);
    ParserRuleContext parseContext = parser.parse();
    ParseTreeWalker walk = new ParseTreeWalker();
    walk.walk(new JqlBaseListener() {

        @Override
        public void enterSql_stmt(Sql_stmtContext ctx) {
            int start = ctx.getStart().getStartIndex();
            int stop = ctx.getStop().getStopIndex() + 1;
            if (start == stop)
                return;
            result.add(input.substring(start, stop));
        }
    }, parseContext);
    return result;
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) JqlLexer(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlLexer) ArrayList(java.util.ArrayList) JqlBaseListener(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlBaseListener) JqlParser(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser) Sql_stmtContext(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Sql_stmtContext) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker)

Example 2 with Sql_stmtContext

use of com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Sql_stmtContext in project kripton by xcesco.

the class SQLiteUpdateTestHelper method readSQLFromFile.

public static List<String> readSQLFromFile(String sqlDefinitionFile) {
    try {
        final List<String> executionList = new ArrayList<>();
        File f = new File(sqlDefinitionFile);
        final String ddl = IOUtils.toString(new FileInputStream(f), Charset.forName("utf-8"));
        MigrationSQLChecker.getInstance().analyze(ddl, new JqlBaseListener() {

            public void enterSelect_stmt(Select_stmtContext ctx) {
            }

            public void enterSql_stmt(Sql_stmtContext ctx) {
                ;
                int start = ctx.getStart().getStartIndex();
                int stop = ctx.getStop().getStopIndex() + 1;
                if (start == stop)
                    return;
                String statement = ddl.substring(start, stop).trim();
                executionList.add(statement);
            }
        });
        return executionList;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) JqlBaseListener(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlBaseListener) IOException(java.io.IOException) File(java.io.File) Sql_stmtContext(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Sql_stmtContext) FileInputStream(java.io.FileInputStream) Select_stmtContext(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Select_stmtContext)

Aggregations

JqlBaseListener (com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlBaseListener)2 Sql_stmtContext (com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Sql_stmtContext)2 ArrayList (java.util.ArrayList)2 JqlLexer (com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlLexer)1 JqlParser (com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser)1 Select_stmtContext (com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Select_stmtContext)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)1 ParseTreeWalker (org.antlr.v4.runtime.tree.ParseTreeWalker)1