Skip to content

SQLite: integers above 2147483647 are displayed wrapped to 32 bits (3000000000 shows as -1294967296) #1636

Done

Description

@sronix

SQL file that shows the bug

index.sql in an empty folder, default embedded SQLite:

create table if not exists big(v integer);
delete from big;
insert into big(v) values (3000000000);

select 'json' as component;
select v, cast(v as text) as v_text, typeof(v) as v_type, v + 0 as v_expr from big;

What happens

$ curl http://localhost:8080/
[
{"v":-1294967296,"v_text":"3000000000","v_type":"integer","v_expr":-1294967296}
]

v comes back as -1294967296. The database holds the right value (v_text is "3000000000", v_type is integer). Other values follow the same rule, the value modulo 2^32 read as signed: 2147483648 shows as -2147483648, 4102444800000 (a millisecond timestamp) as 751032320, 9223372036854775807 as -1.

The table and csv components show the same wrapped number, and so do values passed on: sqlpage.link('item.sql', json_object('id', v)) builds a link with the wrong id, and set x = (select v from big) gives the string '-1294967296'.

REAL and TEXT columns are fine. A single-column select 3000000000 as v with no FROM also displays correctly.

What you expected

"v":3000000000, as stored. The docs say "Numbers, booleans, text, and NULL map naturally." (https://sql-page.com/extensions-to-sql, "From the database to SQLPage")

Database

SQLite

Database version

SQLite 3.54.1 (embedded in the v0.48.0 macOS binary)

SQLPage version

v0.48.0 (sqlpage-macos.tgz, macOS 27.2.1 arm64)

Last SQLPage version where it worked

Not tested on 0.47.0.

Anything else

Found by an AI agent's scripted checks while testing a CSV import and export app built from the docs. The page above was re-run as written on three fresh servers, two requests each, with the same output every time.

Activity

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