diff --git a/src/MariaResultPrep.cpp b/src/MariaResultPrep.cpp index 1e92815c..3946f028 100644 --- a/src/MariaResultPrep.cpp +++ b/src/MariaResultPrep.cpp @@ -252,7 +252,8 @@ void MariaResultPrep::cache_metadata() { bool binary = fields[i].charsetnr == 63; bool length1 = fields[i].length == 1; - MariaFieldType type = variable_type_from_field_type(fields[i].type, binary, length1); + bool is_unsigned = (fields[i].flags & UNSIGNED_FLAG ) != 0; + MariaFieldType type = variable_type_from_field_type(fields[i].type, binary, length1, is_unsigned); types_.push_back(type); LOG_VERBOSE << i << " -> " << fields[i].name << "(" << fields[i].type << ", " << binary << ") => " << type_name(type); diff --git a/src/MariaTypes.cpp b/src/MariaTypes.cpp index edeb154a..fa1abd03 100644 --- a/src/MariaTypes.cpp +++ b/src/MariaTypes.cpp @@ -4,12 +4,19 @@ bool all_raw(SEXP x); -MariaFieldType variable_type_from_field_type(enum_field_types type, bool binary, bool length1) { +MariaFieldType variable_type_from_field_type(enum_field_types type, bool binary, bool length1, bool is_unsigned) { + if (type == MYSQL_TYPE_LONG) { + if (is_unsigned) { + // For unsigned ints, promote it to a double + return MY_DBL; + } else { + return MY_INT32; + } + } switch (type) { case MYSQL_TYPE_TINY: case MYSQL_TYPE_SHORT: - case MYSQL_TYPE_LONG: case MYSQL_TYPE_INT24: case MYSQL_TYPE_YEAR: return MY_INT32; diff --git a/src/MariaTypes.h b/src/MariaTypes.h index 7c84d14a..5f6924c5 100644 --- a/src/MariaTypes.h +++ b/src/MariaTypes.h @@ -13,7 +13,7 @@ enum MariaFieldType { MY_LGL // for BIT(1) }; -MariaFieldType variable_type_from_field_type(enum_field_types type, bool binary, bool length1); +MariaFieldType variable_type_from_field_type(enum_field_types type, bool binary, bool length1, bool is_unsigned); std::string type_name(MariaFieldType type); SEXPTYPE type_sexp(MariaFieldType type);