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

cannot bind to long long (64 bit signed integer)? #462

Open
MacroUniverse opened this issue Mar 26, 2024 · 4 comments
Open

cannot bind to long long (64 bit signed integer)? #462

MacroUniverse opened this issue Mar 26, 2024 · 4 comments
Assignees

Comments

@MacroUniverse
Copy link

MacroUniverse commented Mar 26, 2024

Hi, I was trying to bind an SQLite::Statement with ? to the type long long, with member function bind(1, i). But there's a compiler error, I had to cast the integer to 32bit int to make it work. Is this a limitation of sqlite3 itself or just SQLiteCpp?

I'm using version 3.2.1

@tamaskenez
Copy link

This works for me (with apple clang 15)

            int64_t i64 = 0;
            statement.bind(1, i64);

Can you provide more information, code, platform, compiler, actual error?

@MacroUniverse
Copy link
Author

MacroUniverse commented Mar 30, 2024

I see, I think the problem is using long long instead of int64_t. The compiler says it's ambiguous with candidates:

void SQLite::Statement::bind(int, int32_t)
void SQLite::Statement::bind(int, uint32_t)
void SQLite::Statement::bind(int, int64_t)
void SQLite::Statement::bind(int, double)

It would be nice to have a version explicitly for long long and use some template programming to redirect to one of the above.

I'm using g++ 11.4 on Ubuntu 22.04.

@tamaskenez
Copy link

I see and I agree. I'd simply start with this:

void SQLite::Statement::bind(int index, long long value) {
	static_assert(sizeof(long long) == sizeof(int64_t));
	bind(index, int64_t(value));
}

And improve it only if there's a demand supporting platforms where sizeof(long long) is different.

@UnixY2K
Copy link
Contributor

UnixY2K commented May 4, 2024

I think the user should be aware of how sqlite expects the types, probably using some templates/concepts could help, however this should be optional as it will break for some users

@SRombauts SRombauts self-assigned this Aug 17, 2024
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

4 participants