vapor / mysql-nio

🐬 Non-blocking, event-driven Swift client for MySQL.
MIT License
87 stars 28 forks source link

Exception when reading MySQLTime formatted as text #71

Closed samalone closed 1 year ago

samalone commented 2 years ago

Describe the bug

The getter for MySQLData.time assumes the data is in .binary format. However, MariaDB 10.5 returns data from timestamp fields in .text format "2008-12-29 12:59:59", which leads to a fatal error unwrapping nil.

To Reproduce

  1. Run a Docker container with mariadb:10.5 and these command-line arguments:
    • --max-allowed-packet=512M
    • --sql-mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
    • --default-time-zone=America/New_York
  2. Query the MariaDB server with:
let rows = try db.simpleQuery("SELECT CURRENT_TIMESTAMP();").wait()
print(rows)

Expected behavior

The current timestamp should be returned. Instead, there is a fatal error at MySQLData.swift:458.

Environment

framework: 4.55.0 toolbox: 18.3.3 OS version: macOS 12.2.1

Additional context

I think the fix is straightforward, and I hope to have a pull request to fix the problem soon.