Skip to content

Commit

Permalink
Handle prepared statements with floats
Browse files Browse the repository at this point in the history
The value returned from the server differs between MySQL 5.7 and MySQL 8.
With MySQL 5.7 we get back a float, with MySQL 8 we get back a double.
  • Loading branch information
adrianna-chang-shopify committed Jun 8, 2023
1 parent 5ccb8ea commit 26422f9
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion test/blocking_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,20 @@ TEST test_blocking_stmt_execute_float() {
err = trilogy_stmt_read_full_row(&conn, &stmt, columns, values);
ASSERT_OK(err);

ASSERT_EQ(values[0].as.flt, float_val);
const char *mysql_version = getenv("MYSQL_VERSION");

if (mysql_version == NULL) {
// Could not find the MYSQL_VERSION environment variable
FAIL();
}

// With MySQL 5.7, the value is returned from the server as a float.
// With MySQL 8, the value is returned from the server as a double.
if (strcmp(mysql_version, "5.7") == 0) {
ASSERT_EQ(values[0].as.flt, float_val);
} else if (strcmp(mysql_version, "8") == 0) {
ASSERT_EQ(values[0].as.dbl, float_val);
}

err = trilogy_stmt_read_full_row(&conn, &stmt, columns, values);
ASSERT_EOF(err);
Expand Down

0 comments on commit 26422f9

Please sign in to comment.