Skip to content

MySQL: cannot bind to 'long' data type on Windows/Visual C++ #157

@simon-graham

Description

@simon-graham

On Windows Visual C++ 'long' is 4-bytes. In /Data/MySQL/src/Binder.cpp (1.5.x) we have the following code:

#ifndef POCO_LONG_IS_64_BIT
void Binder::bind(std::size_t pos, const long& val, Direction dir)
{
    poco_assert(dir == PD_IN);
    realBind(pos, MYSQL_TYPE_LONGLONG, &val, 0);
}


void Binder::bind(std::size_t pos, const unsigned long& val, Direction dir)
{
    poco_assert(dir == PD_IN);
    realBind(pos, MYSQL_TYPE_LONGLONG, &val, 0);
}
#endif

So if POCO_LONG_IS_64_BIT is not defined (i.e. long is 4-bytes, which is the case in Windows MSVC) we bind long values as MYSQL_TYPE_LONGLONG.

However, according to the MySQL documentation here MYSQL_TYPE_LONGLONG is 8 bytes. Therefore if you bind any long values to your statement using use(), it incorrectly interprets these as being 8 bytes wide, and binds to garbage/uninitialized memory.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions