π `db::encodeToBlob` doesn't work with `db::preparedStmt`
zach2good opened this issue Β· comments
I affirm:
- I understand that if I do not agree to the following points by completing the checkboxes my issue will be ignored.
- I have read and understood the Contributing Guide and the Code of Conduct.
- I have searched existing issues to see if the issue has already been opened, and I have checked the commit log to see if the issue has been resolved since my server was last updated.
OS / platform the server is running (if known)
All
Branch affected by issue
base
Steps to reproduce
As mentioned here:
https://github.com/LandSandBoat/server/wiki/Database-Library-Upgrade
#4601
Something in the binding process stops encoded blob strings from being bound correctly, and the '?' character is sent in its place.
Expected behavior
db::preparedStmt("UPDATE chars SET set_blue_spells = '?' WHERE charid = ? LIMIT 1",
db::encodeToBlob(PChar->m_SetBlueSpells), PChar->id);
It appears as though preparedStmt
won't take std::string
inline. Need to test with const char*
and friends, but it's good to know it isn't specifically a problem with encodeToBlob
. Maybe something about the lifetimes of strings being passed in?
Taking everything out of my automatic binding code:
struct TestStruct
{
int i = 42;
};
TestStruct testStruct;
auto stmt = std::unique_ptr<sql::PreparedStatement>(connection->prepareStatement("UPDATE chars SET titles = ? WHERE charid = ?"));
stmt->setString(1, db::encodeToBlob(testStruct));
stmt->setInt(2, 1);
stmt->execute();
This works as intended. So I need to do some research as to why the binding doesn't work completely inline