Repository navigation
Conversation
The SQLite engine keeps declared arguments in the column type name, so CHAR(255), BOOLEAN(2), NUMERIC(10,2), FLOAT(8) and INT(11) missed the exact-name switch in sqliteType and came out as any. Strip the argument list before matching, and treat bare char as a text type. Fixes sqlc-dev#3754
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The SQLite engine keeps the declared arguments in the column type name, so
CHAR(255),BOOLEAN(2),NUMERIC(10,2),FLOAT(8)andINT(11)missed the exact-name switch insqliteTypeand were generated asany. A bareCHARwas also missing from the text family.This strips the argument list (everything from the first
() before matching, and addscharto the text case. The existing case lists and the nullable/pointer handling are unchanged, andvarchar(36)still maps tostringas before. I did not touch the affinity rules, so types such asBIGINT UNSIGNEDbehave as they did.This is a visible codegen change. It applies to any SQLite type with an argument list whose base name sqlc already maps, not only the ones in the issue. For example,
BLOB(16)now generates[]byteandTEXT(20)generatesstring, where both wereanybefore. Sized date and time types such asDATETIME(3)stayany. SQLite drivers (ncruces/go-sqlite3, mattn, modernc) only parse a column intotime.Timewhen the declared type is exactlyDATE,DATETIMEorTIMESTAMP, sotime.Timewould fail to scan the string they return. The opt-in core analyzer already passesDATETIME(3)through asdatetimewith a separate length, so it maps that column totime.Timethe same way it does on main. I left that path alone, so the core replay of the new case differs onk_dt.The
integer primary key autoincrementexample from the comments already generatesint64on main, so this covers the remaining cases in the issue.Tests: I added the endtoend case
internal/endtoend/testdata/sqlite_sized_types/sqlite. The schema coversCHAR(255),CHAR(16) NOT NULL,CHAR,VARCHAR(36),BOOLEAN(2),NUMERIC(10,2),NUMERIC(10, 2),FLOAT(8),INT(11)(nullable and not null),DATETIME(3)(which staysany) andBLOB(16). It has one package with default settings and one withemit_pointers_for_null_types: true. With the code change reverted the case fails and the models come out asany.Commands run:
go test ./internal/endtoend -run 'TestReplay/base/sqlite_sized_types'go test ./internal/codegen/... ./internal/endtoend/...(database-backed contexts skip without databases)go veton the codegen package, andgofmt -lon the changed filesNo other golden files changed.
Fixes #3754