TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

A C parser for CREATE and ALTER TABLE SQLite statements

58 点作者 marcobambini将近 2 年前

5 条评论

simonw将近 2 年前
Huh, weirdly enough I&#x27;ve been hoping for exactly this kind of thing - albeit easily called from Python.<p>My use-case is that with SQLite there are aspects of the table - things like generated columns - which aren&#x27;t yet available via the regular SQLite PRAGMAs for introspecting tables.<p>For those things, the only way to introspect them is to read the CREATE TABLE statement out of the &quot;sqlite_master&quot; table and parse it.<p>But you need a very robust parser!<p>I&#x27;ve been investigating tree-sitter recently for this, notes here: <a href="https:&#x2F;&#x2F;til.simonwillison.net&#x2F;python&#x2F;tree-sitter" rel="nofollow noreferrer">https:&#x2F;&#x2F;til.simonwillison.net&#x2F;python&#x2F;tree-sitter</a><p>If anyone needs an implementation of that advanced ALTER TABLE mechanism (where you create a new table with the new schema, copy the data cross from the old one and then swap the names) my sqlite-utils CLI tool and Python library implements that, as described here: <a href="https:&#x2F;&#x2F;simonwillison.net&#x2F;2020&#x2F;Sep&#x2F;23&#x2F;sqlite-advanced-alter-table&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;simonwillison.net&#x2F;2020&#x2F;Sep&#x2F;23&#x2F;sqlite-advanced-alter-...</a>
评论 #37131592 未加载
评论 #37131307 未加载
评论 #37133658 未加载
评论 #37130863 未加载
评论 #37132211 未加载
gfody将近 2 年前
don&#x27;t you need a full parse even just for create and alter statements since you could always encounter an &quot;as&quot; followed by arbitrarily complex sql?
crabbone将近 2 年前
What was the reason for a hand-written lexer and parser vs using Flex &#x2F; Bison?
评论 #37132581 未加载
tedunangst将近 2 年前
The section that says sqlite doesn&#x27;t support drop column links to documentation that says it&#x27;s supported?
评论 #37129969 未加载
评论 #37130471 未加载
kyberias将近 2 年前
So this is more than just on parser for those statements. Very confusing.