Skip to content

NULL values in BIT(1) columns are returned as TRUE #201

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

Closed
dirkschumacher opened this issue Mar 26, 2021 · 2 comments · Fixed by #203
Closed

NULL values in BIT(1) columns are returned as TRUE #201

dirkschumacher opened this issue Mar 26, 2021 · 2 comments · Fixed by #203

Comments

@dirkschumacher
Copy link
Contributor

It seems that with version 1.1.0 BIT(1) columns that have NULL values return TRUE instead of NA. This might be a bug introduced in #192.

library(RMariaDB)
con <- dbConnect(MariaDB(), dbname = "test")
dbWriteTable(con, "test", data.frame(a = c(NA_integer_, 0:1)), field.types = c(a = "BIT(1)"), overwrite = TRUE)
dbReadTable(con, "test")$a
#> [1] TRUE FALSE TRUE

The dbWriteTable call creates a table with the below CREATE statement. The table on the server does contain the values NULL, 0 and 1 on my MySQL instance (version 8).

CREATE TABLE `test` (
  `a` BIT(1) NULL DEFAULT NULL
)

The problem might be here, where NA_INTEGER is mapped to 1 it seems.

RMariaDB/src/MariaRow.cpp

Lines 216 to 218 in 5241355

case MY_LGL:
LOGICAL(x)[i] = value_int(j) ? 1 : 0;
break;

Happy to contribute a fix and thanks for all your work!

@krlmlr
Copy link
Member

krlmlr commented Mar 26, 2021

Good catch, what an evil glitch. I agree with your analysis, happy to review a PR!

krlmlr added a commit that referenced this issue Apr 11, 2021
- Map `NULL` to `NA` for `bit(1)` columns (#201, @dirkschumacher).
@github-actions
Copy link
Contributor

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants