Skip to content

Bug related to 32 bit Integers? #207

Description

@bramtayl

I think there might be a bug in SQLite related to 32 bit integers. You can trigger it by running this code with QuerySQLite on master on 32 bit Linux

using Test: @test
using QuerySQLite
using Query: @map
using DataValues: DataValue
database = Database(joinpath(pathof(QuerySQLite) |> dirname |> dirname, "test", "Chinook_Sqlite.sqlite"));
result = database.Track |> @map({a = rand(BySQL(_), Int)});
@test collect(result)[1].a isa DataValue{Int}

Here's the stacktrace I get:

│ ERROR: InexactError: trunc(Int32, -342205098811609859)
│ Stacktrace:
│  [1] throw_inexacterror(::Symbol, ::Type{Int32}, ::Int64) at ./boot.jl:560
│  [2] checked_trunc_sint at ./boot.jl:582 [inlined]
│  [3] toInt32 at ./boot.jl:619 [inlined]
│  [4] Type at ./boot.jl:709 [inlined]
│  [5] convert at ./number.jl:7 [inlined]
│  [6] sqlitevalue(::Type{Int32}, ::Ptr{Nothing}, ::Int32) at /home/runner/.julia/packages/SQLite/6uY89/src/SQLite.jl:273
│  [7] getvalue(::QuerySQLite.SQLiteCursor{NamedTuple{(:a,),Tuple{DataValue{Int32}}}}, ::Int32, ::Type{DataValue{Int32}}) at /home/runner/work/QuerySQLite.jl/QuerySQLite.jl/src/iterate.jl:53
│  [8] macro expansion at /home/runner/work/QuerySQLite.jl/QuerySQLite.jl/src/iterate.jl:0 [inlined]
│  [9] generate_namedtuple(::Type{NamedTuple{(:a,),Tuple{DataValue{Int32}}}}, ::QuerySQLite.SQLiteCursor{NamedTuple{(:a,),Tuple{DataValue{Int32}}}}) at /home/runner/work/QuerySQLite.jl/QuerySQLite.jl/src/iterate.jl:2
│  [10] iterate at /home/runner/work/QuerySQLite.jl/QuerySQLite.jl/src/iterate.jl:62 [inlined]
│  [11] _collect(::UnitRange{Int32}, ::QuerySQLite.SQLiteCursor{NamedTuple{(:a,),Tuple{DataValue{Int32}}}}, ::Base.HasEltype, ::Base.SizeUnknown) at ./array.jl:555
│  [12] collect(::QuerySQLite.SQLiteCursor{NamedTuple{(:a,),Tuple{DataValue{Int32}}}}) at ./array.jl:544
│  [13] collect(::QuerySQLite.SourceCode{SQLite.DB}) at /home/runner/work/QuerySQLite.jl/QuerySQLite.jl/src/iterate.jl:90
│  [14] top-level scope at /home/runner/work/QuerySQLite.jl/QuerySQLite.jl/test/runtests.jl:12

Activity

  1. bramtayl commented on Feb 26, 2020

    @bramtayl
    Author

    Apologies in advance if this is a bug in QuerySQLite instead

  2. quinnj commented on Feb 27, 2020

    @quinnj
    Member

    Can you explain what result = database.Track |> @map({a = rand(BySQL(_), Int)}); is doing? In particular the rand(BySQL(_), Int)? If there was a way to see the generated SQL statement, that would also be ideal.

  3. bramtayl commented on Mar 29, 2020

    @bramtayl
    Author

    Sorry I kept forgetting about this. You can see the generated SQL like this:

    > database.Track |> @map({a = rand(BySQL(_), Int)}) |> get_sql
    SELECT RANDOM() AS a FROM (Track)
    

    The BySQL bit is to specify that we want the rand function from SQL, not julia. Admittedly kinda a hack.

  4. quinnj commented on Mar 3, 2021

    @quinnj
    Member

    Sorry for the delay here; fix is up: #234.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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