SQLiteCpp icon indicating copy to clipboard operation
SQLiteCpp copied to clipboard

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

Open MacroUniverse opened this issue 10 months ago • 4 comments

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

MacroUniverse avatar Mar 26 '24 05:03 MacroUniverse

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?

tamaskenez avatar Mar 30 '24 05:03 tamaskenez

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.

MacroUniverse avatar Mar 30 '24 23:03 MacroUniverse

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.

tamaskenez avatar Mar 31 '24 10:03 tamaskenez

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

UnixY2K avatar May 04 '24 20:05 UnixY2K