Skip to content

fix: parsing DDL with TAB between column name and the column type#222

Merged
jinzhu merged 1 commit intogo-gorm:masterfrom
ljwun:master
Jan 31, 2026
Merged

fix: parsing DDL with TAB between column name and the column type#222
jinzhu merged 1 commit intogo-gorm:masterfrom
ljwun:master

Conversation

@ljwun
Copy link
Copy Markdown
Contributor

@ljwun ljwun commented Dec 2, 2025

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

Remove tab character (\t) from sqliteSeparator.

sqlite/ddlmod.go

Lines 58 to 79 in 7818dfd

if sc := string(c); separatorRegexp.MatchString(sc) {
if c == next {
buf += sc // Skip escaped quote
idx++
} else if quote > 0 {
quote = 0
} else {
quote = c
}
} else if quote == 0 {
if c == '(' {
bracketLevel++
} else if c == ')' {
bracketLevel--
} else if bracketLevel == 0 {
if c == ',' {
result.fields = append(result.fields, strings.TrimSpace(buf))
buf = ""
continue
}
}
}

When a tab character (\t) is present between the identifier and its type, separatorRegexp.MatchString(sc) can match and the code toggles the quote state incorrectly. The incorrect quote state causes the parser to ignore commas and therefore fail to split fields properly.

User Case Description

When parsing DDL that uses a tab character (\t) as whitespace between an identifier and its type, the parser can misinterpret the column list and return the wrong number of columns.

Reproduction DDL:

CREATE TABLE `test-e` (`field1`\ttext NOT NULL,`field2`\tinteger NOT NULL)

Expected result should have two columns:

  • field1
  • field2

Only one column is actually returned (the parser fails to split the column definitions correctly):

  • field1

Copy link
Copy Markdown
Contributor

@Shion1305 Shion1305 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug in the DDL parser where tab characters between column names and types were incorrectly treated as quote delimiters, causing the parser to fail to split column definitions properly.

Changes:

  • Removed \t from sqliteSeparator to prevent tabs from being treated as quote characters
  • Added a test case to verify that DDL with tabs between column identifiers and types is parsed correctly

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
ddlmod.go Removed \t from sqliteSeparator variable to fix tab character handling
ddlmod_test.go Added test case for parsing DDL with tab characters between column names and types

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jinzhu jinzhu merged commit 75dbf08 into go-gorm:master Jan 31, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants