SQL parser in C

前端 未结 9 1550
悲&欢浪女
悲&欢浪女 2020-12-29 11:59

I want to parse and store the columns and values of a SQL DML (INSERT, UPDATE, DELETE) statement in C. Need the URL of the open source code or a library with which I can lin

相关标签:
9条回答
  • 2020-12-29 12:03

    ANTLR can target C, among other languages, and its catalog of premade grammars has a bunch of SQL dialects - notably MySQL and Oracle.

    0 讨论(0)
  • 2020-12-29 12:04

    Have you looked at SQLite ? It certainly does have the code to parse SQL, so maybe you could avoid reimplementing it..

    0 讨论(0)
  • 2020-12-29 12:07

    You can have a look at the source code for SQLite. It uses a parser called Lemon.

    Links:

    SQLite architecture

    Lemon parser

    You can also look at the source code for postgresql-plpython3. Looks like it has a pure C based SQL parser.

    Link:

    postgresql-plpython3 @ github

    0 讨论(0)
  • 2020-12-29 12:19

    I would suggest to start from the real parser of a real DBMS. There are several in free software. For instance, the parser of PostgreSQL is in the directory src/backend/parser of the distribution and is written in C and Yacc.

    0 讨论(0)
  • 2020-12-29 12:21

    Not sure is there any mature C sql parser can do that easily.

    Here is a Java version SQL library can do what you need exactly, it can be used to Retrieve/Refactor table & column name from a complex SQL query easily.

    0 讨论(0)
  • 2020-12-29 12:21

    Have you considered writing your own using lex and yacc? (the hacker - hardcore approach)

    Not trivial .. but this site might help you get started

    0 讨论(0)
提交回复
热议问题