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

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

Closed
tszypenbejl opened this issue Feb 22, 2018 · 4 comments
Closed
Assignees

Comments

@tszypenbejl
Copy link

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).

@SRombauts
Copy link
Owner

Woa, thanks for diging into this, and reporting it so clearly! I bet this particular case is not on my unit test suite :(

I am away from my computer, but I will look into this asap

@SRombauts SRombauts self-assigned this Feb 22, 2018
@SRombauts
Copy link
Owner

So I easily reproduced the problem with a dedicated unit test using your code sample.

Then I fixed the bug by adding the appropriate include as you stated.

Thanks again @tszypenbejl for the clear analysis and the fix.

@tszypenbejl
Copy link
Author

Thank you for taking care of the problem @SRombauts . I did a git pull and verified that the bug is no longer reproducible :)

@SRombauts
Copy link
Owner

Thank you again

dhillondeep pushed a commit to wio-pm/wio-sqlitecpp that referenced this issue Nov 22, 2018
…n x86_64 Linux

Reproduced the problem with a dedicated unit test, then fixed the bug.

Thanks @tszypenbejl for the clear analysis and the fix.
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

No branches or pull requests

2 participants