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

Reading BLOB from SQLite3 no longer working #1173

Open
Tectu opened this issue Oct 22, 2024 · 2 comments
Open

Reading BLOB from SQLite3 no longer working #1173

Tectu opened this issue Oct 22, 2024 · 2 comments

Comments

@Tectu
Copy link
Contributor

Tectu commented Oct 22, 2024

Hi,

I've updated an application using SOCI from 9bcc5f8a9181886f4c73ea5b4671b35d8722cb3a to a55c80984a447bf8c788a7d6a23ff93c022069fa.

The only problem I encountered so far is with regards of reading a BLOB from an SQLite3 database.
Previously, the application did this (inside of a custom/user type conversion):

std::string str = v.get<std::string>("my_column");

Where:

  • my_column is an SQLite3 column of type BLOB
  • v is an lvalue reference to soci::base_type

This used to work well. However, after the update the code is throwing an std::bad_cast in soci::details::holder::get() (called by soci::row::get()).

According to the git log there have been some activities around blob support.

What is the new, correct way of reading (and writing!) a blob to/from SQLite3?

@vadz
Copy link
Member

vadz commented Oct 22, 2024

Thanks for reporting this, it's definitely a regression and should be fixed because I don't see anything wrong with this code.

I thought we had some testing code doing essentially the same thing, but I was clearly wrong. It would be great if you could please make a patch adding the (now) failing test case, this will help debug/bisect it and will ensure that it remains fixed in the future.

@Tectu
Copy link
Contributor Author

Tectu commented Oct 22, 2024

Sure, I'll look into adding a test. Will take a while to get familiar with your testing setup tho.

I think the underlying "issue" or "cause" is that soci::details::holder::get() is clearly intentionally throwing when the type is db_blob:

case db_double:
return soci_cast<T, double>::cast(*val_.d);
case db_date:
return soci_cast<T, std::tm>::cast(*val_.t);
case db_blob:
// blob is not copyable
break;
case db_xml:
case db_string:
return soci_cast<T, std::string>::cast(*val_.s);
}
throw std::bad_cast();
}

There's a comment indicating that this is due to blob being non-copyable.

Seems like this was introduced in commit ae07cd5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants