Skip to content
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

Updating a boolean column in sqlite results in "true"/"false" strings being inserted, instead of integers #234

Closed
sgmihai opened this issue Jun 8, 2023 · 0 comments · Fixed by #245

Comments

@sgmihai
Copy link
Contributor

sgmihai commented Jun 8, 2023

Using the code below, updating a column created with boolean type (tinyint in sqlite), results in the string value of the boolean being in the database, instead of 0/1. Insert works as expected. I am not familiar with the structure of this library to check the source of this behaviour myself. It's possible that it's a wider bug and this is just one of the consequences.

sqlite> SELECT * FROM mytable;
1|false
2|1
3|1
4|1
5|false

https://play.nim-lang.org/#ix=4xLn

import allographer/[connection, schema_builder, query_builder]
import asyncdispatch, json
from db_common import DbError

proc createTable(myDb: Rdb) {.async.} =
  myDb.create([
    table("mytable", [
      Column.increments("id"),
      Column.boolean("mybool").nullable()
    ])
  ])

proc main() {.async.} =
  let myDb = dbOpen(Sqlite3, "my.db", maxConnections=10, timeout=30)
  await createTable(myDb)

  var insertData: seq[JsonNode] 
  for i in 1..5:
    insertData.add(
      %*{
        "id": i,
        "mybool": true
        })

  myDb.table("mytable").insert(insertData).await

  myDb.table("mytable").where("id", "=", 1).update(%*{"mybool": false}).await
  myDb.table("mytable").where("id", "=", 5).update(%*{"mybool": false}).await

waitFor main()
@sgmihai sgmihai changed the title Updating a boolean column results in "true"/"false" strings being inserted, instead of integers Updating a boolean column in sqlite results in "true"/"false" strings being inserted, instead of integers Jun 8, 2023
@itsumura-h itsumura-h linked a pull request Jul 17, 2023 that will close this issue
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 a pull request may close this issue.

1 participant