fix: preserve SQLITE_NULL type for NULL values in BOOLEAN / DATETIME columns - #883
Open
antoineleclair wants to merge 1 commit into
Open
fix: preserve SQLITE_NULL type for NULL values in BOOLEAN / DATETIME columns#883antoineleclair wants to merge 1 commit into
antoineleclair wants to merge 1 commit into
Conversation
When encoding query results, value_type() remaps certain column types (BOOLEAN, DATETIME) to dqlite-specific type codes. However, it was also doing this for NULL values, causing them to be encoded as their "zero" values (0 for BOOLEAN, "" for DATETIME) instead of NULL. This makes it impossible for clients to distinguish: - BOOLEAN NULL vs FALSE - DATETIME NULL vs empty string SQLite's sqlite3_column_type() correctly returns SQLITE_NULL for NULL values regardless of declared column type. This change preserves that behavior by returning early when the value is NULL. Example demonstrating SQLite's behavior: CREATE TABLE t (b BOOLEAN, d DATETIME); INSERT INTO t VALUES (NULL, NULL); INSERT INTO t VALUES (0, ''); -- sqlite3_column_type() returns: -- Row 1: NULL (5), NULL (5) <- both are SQLITE_NULL -- Row 2: INTEGER (1), TEXT (3) <- actual types Before this fix, dqlite would return: -- Row 1: BOOLEAN (11) with 0, ISO8601 (10) with "" -- Row 2: BOOLEAN (11) with 0, ISO8601 (10) with "" After this fix: -- Row 1: NULL (5), NULL (5) -- Row 2: BOOLEAN (11) with 0, ISO8601 (10) with ""
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.
Fixes #882.
value_type()insrc/query.cwas remapping NULL values toDQLITE_BOOLEAN/DQLITE_ISO8601based on the column's declared type,so a NULL in a
BOOLEANcolumn was sent on the wire asBOOLEAN(11)with value 0 (indistinguishable from
FALSE) and a NULL in aDATETIME/
DATE/TIMESTAMPcolumn was sent asISO8601(10)with"". Thefix returns early when
sqlite3_column_type()reportsSQLITE_NULL,matching plain SQLite's behaviour.
Adds a regression test
(
test/integration/test_client.c::client/nullPreservedAcrossDeclaredTypes)that asserts every column of a row of NULLs comes back with
type == SQLITE_NULL, coveringBOOLEAN,DATETIME,DATE,TIMESTAMPas well as the unaffected types as a sanity check.
Running the same code samples that reproduced the issue in #882
shows that all types appear correctly as
NULL.C (
null_types_repro.c):Go (
main.go, via go-dqlite):Python (
null_types_repro.py, via dqlite-client / dqlite-wire):