Only support extracting JSON fields when the SDK supports it (#3717)

* Added preprocessor defined to detect support for JSON

* Only support extracting JSON fields when the SDK supports it

* Fix version comparison
This commit is contained in:
Hernan Martinez
2022-07-27 14:23:34 -06:00
committed by GitHub
parent 459f1ea19c
commit 0f63862059
8 changed files with 36 additions and 8 deletions

View File

@@ -128,12 +128,16 @@ bool Extractor::extract(std::size_t pos, std::string& val)
//mysql reports TEXT types as FDT_BLOB when being extracted
MetaColumn::ColumnDataType columnType = _metadata.metaColumn(static_cast<Poco::UInt32>(pos)).type();
#ifdef POCO_MYSQL_JSON
if (columnType != Poco::Data::MetaColumn::FDT_STRING && columnType != Poco::Data::MetaColumn::FDT_BLOB && columnType != Poco::Data::MetaColumn::FDT_JSON)
#else
if (columnType != Poco::Data::MetaColumn::FDT_STRING && columnType != Poco::Data::MetaColumn::FDT_BLOB)
#endif
throw MySQLException("Extractor: not a string");
#ifdef POCO_MYSQL_JSON
if (columnType == Poco::Data::MetaColumn::FDT_JSON && !extractJSON(pos))
return false;
#endif
if (columnType == Poco::Data::MetaColumn::FDT_BLOB && !extractLongLOB(pos))
return false;
@@ -291,6 +295,7 @@ bool Extractor::extractLongLOB(std::size_t pos)
return true;
}
#ifdef POCO_MYSQL_JSON
bool Extractor::extractJSON(std::size_t pos)
{
// JSON columns are fetched with a zero-length
@@ -306,6 +311,7 @@ bool Extractor::extractJSON(std::size_t pos)
return true;
}
#endif
//////////////
// Not implemented

View File

@@ -72,7 +72,9 @@ namespace
case MYSQL_TYPE_MEDIUM_BLOB:
case MYSQL_TYPE_LONG_BLOB:
case MYSQL_TYPE_BLOB:
#ifdef POCO_MYSQL_JSON
case MYSQL_TYPE_JSON:
#endif
return field.length;
default: