SQL parser in C

2019-02-07 00:57发布

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 link my C program. The platform is SUSE Linux. Have tried to make and use libSQL unsuccessfully. A detailed answer is appreciated. Thanks.

Additional Notes: Please suggest a library/code that I can link with my C program. In my program I want to use the functions of this library to parse and use the tokens for further processing.

标签: sql c parsing
8条回答
SAY GOODBYE
2楼-- · 2019-02-07 01:26

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

查看更多
该账号已被封号
3楼-- · 2019-02-07 01:31

µSQL for C++

What is µSQL ?

µSQL is a SQL parser engine for C++ to develop SQL based applications easily, and it supports other SQL like domain specific languages such as UnQL and GQL too. Because µSQL is written only in old standard C++ library such as STL with ANTLR, then you can use it with many C++ compilers and platforms.

Repo on Github

查看更多
Root(大扎)
4楼-- · 2019-02-07 01:33

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

查看更多
不美不萌又怎样
5楼-- · 2019-02-07 01:36

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.

查看更多
混吃等死
6楼-- · 2019-02-07 01:38
混吃等死
7楼-- · 2019-02-07 01:42

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

查看更多
登录 后发表回答