Make dollar sign support check '8.1' specific #4300

pull/4308/head
Javier Jaramago Fernández 3 years ago
parent 1039dfa747
commit 600ddfa154

@ -211,33 +211,6 @@ std::string generate_multi_rows_query(int rows, int params);
void close_all_non_term_fd(std::vector<int> excludeFDs);
/**
* @brief Suggested implementation of 'mismatch_' from ['cppreference'](https://en.cppreference.com/w/cpp/algorithm/mismatch).
*
* @param first1 begin of the first range of the elements.
* @param last1 end of the first range of the elements.
* @param first2 begin of the second range of the elements.
* @param last2 end of the second range of the elements.
* @param p binary predicate which returns `true` if the elements should be treated as equal.
*
* @return std::pair with iterators to the first two non-equal elements.
*/
template<class InputIt1, class InputIt2, class BinaryPredicate>
std::pair<InputIt1, InputIt2> mismatch_(
InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, BinaryPredicate p
) {
while (first1 != last1 && first2 != last2 && p(*first1, *first2)) {
++first1, ++first2;
}
return std::make_pair(first1, first2);
}
/**
* @brief Returns a sorted copy in ascending order of the supplied version numbers.
* @details Expected version numbers formats are: ['N', 'N.N', 'N.N.N', ...]
*/
std::vector<std::string> sort_versions(std::vector<std::string> versions);
/**
* @brief Returns the expected error for query 'SELECT $$'.
* @param version The 'server_version' for which the error should match.

@ -433,29 +433,6 @@ void close_all_non_term_fd(std::vector<int> excludeFDs) {
}
}
vector<string> sort_versions(vector<string> versions) {
std::sort(
versions.begin(), versions.end(),
[](const string& v1, const string& v2) {
const auto result =
mismatch_(
v1.cbegin(), v1.cend(), v2.cbegin(), v2.cend(),
[](const unsigned char lhs, const unsigned char rhs) {
return tolower(lhs) == tolower(rhs);
}
);
const bool not_equal = result.second != v2.cend();
const bool fst_shorter = result.first == v1.cend();
const bool fst_lesser = std::tolower(*result.first) < std::tolower(*result.second);
return not_equal && (fst_shorter || fst_lesser);
}
);
return versions;
}
std::pair<int,const char*> get_dollar_quote_error(const char* version) {
const char* ER_PARSE_MSG {
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server"
@ -465,9 +442,7 @@ std::pair<int,const char*> get_dollar_quote_error(const char* version) {
if (strcasecmp(version,"8.1.0") == 0) {
return { ER_PARSE_ERROR, ER_PARSE_MSG };
} else {
const vector<string> sorted { sort_versions({"8.1.0", version}) };
if (sorted[0] == "8.1.0") {
if (strncasecmp(version, "8.1", 3) == 0) {
// SQLSTATE: 42000
return { ER_PARSE_ERROR, ER_PARSE_MSG };
} else {

@ -25,7 +25,7 @@
using std::vector;
using std::string;
const vector<string> versions { "5.6", "5.7", "8.0", "8.1.0", "8.1", "8.2" };
const vector<string> versions { "5.6", "5.7", "8.0", "8.1.0", "8.1", "8.1.4" };
int test_supports_dollar_quote(MYSQL* conn, int v_idx, int v8_1_0_idx) {
int rc = mysql_query_t(conn, "SELECT $$");

Loading…
Cancel
Save