mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-24 17:30:44 +02:00
add support for MySQL 8
This commit is contained in:
@@ -13,10 +13,10 @@
|
||||
|
||||
|
||||
#include "Poco/Data/MySQL/Extractor.h"
|
||||
|
||||
#include "Poco/Data/Date.h"
|
||||
#include "Poco/Data/Time.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace MySQL {
|
||||
@@ -240,10 +240,10 @@ bool Extractor::realExtractFixed(std::size_t pos, enum_field_types type, void* b
|
||||
MYSQL_BIND bind = {0};
|
||||
my_bool isNull = 0;
|
||||
|
||||
bind.is_null = &isNull;
|
||||
bind.buffer_type = type;
|
||||
bind.buffer = buffer;
|
||||
bind.is_unsigned = isUnsigned;
|
||||
bind.is_null = &isNull;
|
||||
bind.buffer_type = type;
|
||||
bind.buffer = buffer;
|
||||
bind.is_unsigned = isUnsigned;
|
||||
|
||||
if (!_stmt.fetchColumn(pos, &bind))
|
||||
return false;
|
||||
@@ -637,5 +637,4 @@ bool Extractor::extract(std::size_t , std::list<Dynamic::Var>& )
|
||||
}
|
||||
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::MySQL
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "Poco/Data/MySQL/MySQLStatementImpl.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace MySQL {
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
#include "Poco/Data/MySQL/MySQLException.h"
|
||||
#include <cstring>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
class ResultMetadataHandle
|
||||
/// Simple exception-safe wrapper
|
||||
{
|
||||
public:
|
||||
|
||||
explicit ResultMetadataHandle(MYSQL_STMT* stmt)
|
||||
{
|
||||
h = mysql_stmt_result_metadata(stmt);
|
||||
@@ -42,7 +42,6 @@ namespace
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
MYSQL_RES* h;
|
||||
};
|
||||
|
||||
@@ -140,6 +139,7 @@ namespace Poco {
|
||||
namespace Data {
|
||||
namespace MySQL {
|
||||
|
||||
|
||||
void ResultMetadata::reset()
|
||||
{
|
||||
_columns.resize(0);
|
||||
@@ -149,6 +149,7 @@ void ResultMetadata::reset()
|
||||
_isNull.resize(0);
|
||||
}
|
||||
|
||||
|
||||
void ResultMetadata::init(MYSQL_STMT* stmt)
|
||||
{
|
||||
ResultMetadataHandle h(stmt);
|
||||
@@ -199,41 +200,48 @@ void ResultMetadata::init(MYSQL_STMT* stmt)
|
||||
_row[i].buffer_length = len;
|
||||
_row[i].buffer = (len > 0) ? (&_buffer[0] + offset) : 0;
|
||||
_row[i].length = &_lengths[i];
|
||||
_row[i].is_null = &_isNull[i];
|
||||
_row[i].is_null = reinterpret_cast<my_bool*>(&_isNull[i]); // workaround to make it work with both MySQL 8 and earlier
|
||||
_row[i].is_unsigned = (fields[i].flags & UNSIGNED_FLAG) > 0;
|
||||
|
||||
offset += _row[i].buffer_length;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::size_t ResultMetadata::columnsReturned() const
|
||||
{
|
||||
return static_cast<std::size_t>(_columns.size());
|
||||
}
|
||||
|
||||
|
||||
const MetaColumn& ResultMetadata::metaColumn(std::size_t pos) const
|
||||
{
|
||||
return _columns[pos];
|
||||
}
|
||||
|
||||
|
||||
MYSQL_BIND* ResultMetadata::row()
|
||||
{
|
||||
return &_row[0];
|
||||
}
|
||||
|
||||
|
||||
std::size_t ResultMetadata::length(std::size_t pos) const
|
||||
{
|
||||
return _lengths[pos];
|
||||
}
|
||||
|
||||
|
||||
const unsigned char* ResultMetadata::rawData(std::size_t pos) const
|
||||
{
|
||||
return reinterpret_cast<const unsigned char*>(_row[pos].buffer);
|
||||
}
|
||||
|
||||
|
||||
bool ResultMetadata::isNull(std::size_t pos) const
|
||||
{
|
||||
return (_isNull[pos] != 0);
|
||||
}
|
||||
|
||||
}}} // namespace Poco::Data::MySQL
|
||||
|
||||
} } } // namespace Poco::Data::MySQL
|
||||
|
||||
@@ -20,6 +20,11 @@
|
||||
#endif
|
||||
|
||||
|
||||
#if LIBMYSQL_VERSION_ID >= 80000
|
||||
typedef bool my_bool; // Workaround to make library work with MySQL client 8.0 as well as earlier versions
|
||||
#endif
|
||||
|
||||
|
||||
#define POCO_MYSQL_VERSION_NUMBER ((NDB_VERSION_MAJOR<<16) | (NDB_VERSION_MINOR<<8) | (NDB_VERSION_BUILD&0xFF))
|
||||
|
||||
|
||||
@@ -187,4 +192,4 @@ void SessionHandle::reset()
|
||||
}
|
||||
|
||||
|
||||
}}} // Poco::Data::MySQL
|
||||
} } } // namespace Poco::Data::MySQL
|
||||
|
||||
@@ -129,12 +129,14 @@ void SessionImpl::open(const std::string& connect)
|
||||
else if (!options["auto-reconnect"].empty())
|
||||
throw MySQLException("create session: specify correct auto-reconnect option (true or false) or skip it");
|
||||
|
||||
#ifdef MYSQL_SECURE_AUTH
|
||||
if (options["secure-auth"] == "true")
|
||||
_handle.options(MYSQL_SECURE_AUTH, true);
|
||||
else if (options["secure-auth"] == "false")
|
||||
_handle.options(MYSQL_SECURE_AUTH, false);
|
||||
else if (!options["secure-auth"].empty())
|
||||
throw MySQLException("create session: specify correct secure-auth option (true or false) or skip it");
|
||||
#endif
|
||||
|
||||
if (!options["character-set"].empty())
|
||||
_handle.options(MYSQL_SET_CHARSET_NAME, options["character-set"].c_str());
|
||||
@@ -282,4 +284,4 @@ void SessionImpl::setConnectionTimeout(std::size_t timeout)
|
||||
}
|
||||
|
||||
|
||||
}}}
|
||||
} } } // namespace Poco::Data::MySQL
|
||||
|
||||
@@ -146,4 +146,4 @@ int StatementExecutor::getAffectedRowCount() const
|
||||
}
|
||||
|
||||
|
||||
}}}
|
||||
} } } // namespace Poco::Data::MySQL
|
||||
|
||||
Reference in New Issue
Block a user