Skip to content

Fix/sqlite column comment parsing #6989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 4.3.x
Choose a base branch
from

Conversation

homersimpsons
Copy link

@homersimpsons homersimpsons commented Jun 11, 2025

Q A
Type bug
Fixed issues

Summary

Issue found in #6897 (comment)

When a table and its column share the same name and they both have a comment DBAL will return the table comment instead of the column comment.

Example:

CREATE TABLE "user" --table comment
(
    "user" INT --column comment
)

From the above link, here is the change:

-{[\s(,](?:\Wuser\W|\W"user"\W)(?:\([^)]*?\)|[^,(])*?,?((?:(?!\n))(?:\s*--[^\n]*\n?)+)}i
+{[\s(,](?:\Wuser\W|\W"user"\W)\s(?:\([^)]*?\)|[^,(])*?,?((?:(?!\n))(?:\s+--[^\n]*\n?)+)}i
                                   ^^ require a space                        ^ require at least a space

Note that I made the fix for DBAL 5.0 but the issue also exists in 4.2: This now targets 4.2

. '(?:\([^)]*?\)|[^,(])*?,?((?:(?!\n))(?:\s*--[^\n]*\n?)+)}i';

@homersimpsons homersimpsons changed the base branch from 4.2.x to 5.0.x June 11, 2025 18:18
@morozov
Copy link
Member

morozov commented Jun 12, 2025

Note that I made the fix for DBAL 5.0 but the issue also exists in 4.2

Could you try retargeting it against 4.2.x then? I don't think this code has changed significantly between these versions.

@homersimpsons homersimpsons force-pushed the fix/sqlite-column-comment-parsing branch from a54e80c to e05c6aa Compare June 13, 2025 07:33
@homersimpsons homersimpsons changed the base branch from 5.0.x to 4.2.x June 13, 2025 07:33
@homersimpsons
Copy link
Author

homersimpsons commented Jun 13, 2025

Note that I made the fix for DBAL 5.0 but the issue also exists in 4.2

Could you try retargeting it against 4.2.x then? I don't think this code has changed significantly between these versions.

Done

I'm also asking myself if regex is the best approach vs parsing the statement.

@morozov
Copy link
Member

morozov commented Jun 13, 2025

As I understand, this patch requires a space right after the table name in a CREATE TABLE statement. But SQLite doesn't require it.

The following is a valid SQLite query:

CREATE TABLE "user"--table comment
(
    "user" INT--column comment
)

Note that GitHub's code colorizer parses it correctly.

@morozov
Copy link
Member

morozov commented Jun 13, 2025

I'm also asking myself if regex is the best approach vs parsing the statement.

Parsing is definitely better. A simple regular expression cannot accommodate the entire SQL syntax, so it will be prone to errors in edge cases.

I tried using a parser some time ago (see #5694). It worked but it didn't justify bringing in a new dependency back then. I'm curious if we can find some common ground and write a simpler parser that wouldn't require external dependencies, would solve only a relevant subset of the problems, and which we could maintain ourselves.

UPD: looking at the syntax, I don't think writing a parser manually is easy and even feasible. Another alternative might be to generate a parser and then remove all unused code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants