All Projects → bkiers → Sqlite Parser

bkiers / Sqlite Parser

Licence: mit
An ANTLR4 grammar for SQLite statements.

Labels

Projects that are alternatives of or similar to Sqlite Parser

Pg permission
A simple set of views to see ALL permissions in a PostgreSQL database
Stars: ✭ 92 (-22.69%)
Mutual labels:  plpgsql
Aws Database Migration Samples
A set of sample database and associated items to allow customers to among other things follow along with published database migration recipes.
Stars: ✭ 105 (-11.76%)
Mutual labels:  plpgsql
Node Sqlcipher
SQLCipher bindings for Node
Stars: ✭ 114 (-4.2%)
Mutual labels:  plpgsql
Totp
RFC6238 TOTP implementation in pure PostgreSQL plpgsql
Stars: ✭ 98 (-17.65%)
Mutual labels:  plpgsql
Postgraphile Lambda Example
Simple serverless / Lambda example with caching and lightweight bundle
Stars: ✭ 104 (-12.61%)
Mutual labels:  plpgsql
Panda Cloud
Base on SpringCloud MicroService Framework
Stars: ✭ 108 (-9.24%)
Mutual labels:  plpgsql
Postgresql Anyarray
PostgeSQL extension adding highly desirable, data-type independent array functionality.
Stars: ✭ 91 (-23.53%)
Mutual labels:  plpgsql
Pg2go
PostgreSQL script that generates Go struct definitions for all tables in a database
Stars: ✭ 116 (-2.52%)
Mutual labels:  plpgsql
Serverless Postgraphql
Serverless GraphQL endpoint for PostgresSQL using AWS, serverless and PostGraphQL
Stars: ✭ 105 (-11.76%)
Mutual labels:  plpgsql
Bible Database
Bible databases as XML, JSON, SQL & SQLITE3 Database format for various languages. Developers can download it freely for their development works. Freely received, freely give.
Stars: ✭ 111 (-6.72%)
Mutual labels:  plpgsql
Periods
PERIODs and SYSTEM VERSIONING for PostgreSQL
Stars: ✭ 101 (-15.13%)
Mutual labels:  plpgsql
Plpgunit
PostgreSQL Unit Testing Framework
Stars: ✭ 102 (-14.29%)
Mutual labels:  plpgsql
Common schema
DBA's framework for MySQL
Stars: ✭ 108 (-9.24%)
Mutual labels:  plpgsql
Qt Client
This repository contains the source code for the Desktop client. The Desktop client is built using the Qt framework for C++. The client can be extended or customized using JavaScript. This client is used by all editions of xTuple ERP.
Stars: ✭ 93 (-21.85%)
Mutual labels:  plpgsql
Vocabulary V5.0
PALLAS: Build process for OMOP Standardized Vocabularies. Currently not available as independent release. Therefore, do not clone or try to replicate. It is work in progress and not ready for replication.
Stars: ✭ 114 (-4.2%)
Mutual labels:  plpgsql
Pg Semver
A semantic version data type for PostgreSQL
Stars: ✭ 91 (-23.53%)
Mutual labels:  plpgsql
Screampay
screamPay聚合支付,一个强大到让你尖叫的聚合支付系统,使用Java开发,spring-boot架构,已接入环讯、九派、杉德等主流支付渠道,可直接用于生产环境。
Stars: ✭ 107 (-10.08%)
Mutual labels:  plpgsql
Pg Auth
A complete authentication system built in Postgres using schemas and functions
Stars: ✭ 117 (-1.68%)
Mutual labels:  plpgsql
Scaledger
A double-entry accounting database with a typed GraphQL API
Stars: ✭ 115 (-3.36%)
Mutual labels:  plpgsql
Triprecord
咔咔出行——基于高德地图API,Vue+Express实现的移动端webapp,服务器受到攻击网站暂时下掉了
Stars: ✭ 1,495 (+1156.3%)
Mutual labels:  plpgsql

SQLite parser

An ANTLR4 grammar for SQLite 3.8.x based on the official specs.

Install

To install this library, do the following:

git clone https://github.com/bkiers/sqlite-parser
cd sqlite-parser
mvn clean install -DskipTests=true

Test

The generated parser has been tested by approximately 30000 SQLite statements scraped from the test suite of the SQLite repository. Running these tests, which can take quite a few minutes, can be done as follows:

mvn clean test

If running the tests takes too long for your liking, try increasing the max heap space as follows:

export JAVA_TOOL_OPTIONS="-Xmx4096m" && mvn clean test

Example

Let's say you would like to record all the names of functions used in an select-statement:

SELECT log AS x FROM t1
GROUP BY x
HAVING count(*) >= 4
ORDER BY max(n) + 0

This can be done by attaching a listener to the parse tree that listens when the parse tree enters an SQL expression, and the function name inside this expression is not null:

import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        // The list that will hold our function names.
        final List<String> functionNames = new ArrayList<String>();

        // The select-statement to be parsed.
        String sql = "SELECT log AS x FROM t1 \n" +
                "GROUP BY x                   \n" +
                "HAVING count(*) >= 4         \n" +
                "ORDER BY max(n) + 0          \n";

        // Create a lexer and parser for the input.
        SQLiteLexer lexer = new SQLiteLexer(new ANTLRInputStream(sql));
        SQLiteParser parser = new SQLiteParser(new CommonTokenStream(lexer));

        // Invoke the `select_stmt` production.
        ParseTree tree = parser.select_stmt();

        // Walk the `select_stmt` production and listen when the parser
        // enters the `expr` production.
        ParseTreeWalker.DEFAULT.walk(new SQLiteBaseListener(){

            @Override
            public void enterExpr(@NotNull SQLiteParser.ExprContext ctx) {
                // Check if the expression is a function call.
                if (ctx.function_name() != null) {
                    // Yes, it was a function call: add the name of the function
                    // to out list.
                    functionNames.add(ctx.function_name().getText());
                }
            }
        }, tree);

        // Print the parsed functions.
        System.out.println("functionNames=" + functionNames);
    }
}

which will print:

functionNames=[count, max]
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].