Skip to content

Statement::bind truncates long integer to 32 bits on x86_64 Linux #155

@tszypenbejl

Description

@tszypenbejl

Binding long values (which are 64-bit on x86_64 Linux) to a statement yields a surprising result.
Here is a minimal program to reproduce the problem:

//#include <climits>
#include <iostream>
#include <SQLiteCpp/SQLiteCpp.h>

int main()
{
	SQLite::Database db(":memory:", SQLite::OPEN_READWRITE);
	SQLite::Statement query(db, "SELECT ?");
	query.bind(1, 4294967297L);
	while (query.executeStep()) {
		std::cout << query.getColumn(0).getInt64() << std::endl;
	}
	return 0;
}

The value bound to the query in this example program is 2^32+1. However, if you build and run the program on x86_64 Linux, you will see that the output of the program is '1' instead of the expected '4294967297'.

Uncommenting the first line (#include <climits>) makes the program behave as expected.

The easiest way to fix the bug would probably be to include the climits header in SQLiteCpp/Statement.h (climits provides definitions of LONG_MAX and INT_MAX which are used in some preprocessor directives in that file).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions