Skip to content

Handling of 64bit integers  #243

Description

@anderic1

I just ran into an issue with RSQLite and 64bit integers from the bit64 package.

Here is a simplified example:

library(DBI)
library(bit64)
dbcon = dbConnect(RSQLite::SQLite(), ":memory:")

df = data.frame(int64=as.integer64("12345678901234567"))

dbWriteTable(dbcon, "table", df)
dbReadTable(dbcon, "table")
#          int64
#1 7.749004e-308

A version with dbBind yields similar results:

dbExecute(dbcon, "create table 'b' ('int64' INTEGER)")
dbres = dbSendStatement(dbcon, "insert into b(int64) values (?)")
dbBind(dbres, as.integer64(1))
dbGetRowsAffected(dbres)
dbClearResult(dbres)
dbGetQuery(dbcon, "select * from b")
#          int64
#1 4.940656e-324

A remedy is of course to as.character or as.numeric the offending values, but it would be nice if cases like these could be handled transparently.

I ran into this when transferring data from one sqlite-db to another via R, where one column marked as integer had one very large value>2^32, thus making the whole column a bit64::integer64 column in R. If I hadn't been careful I wouldn't have noticed it immediately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions