Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Upcoming (TBD)
==============

Bug Fixes
--------
* Fix timediff output when the result is a negative value (#1113).


1.46.0 (2026/01/22)
==============

Expand Down
4 changes: 2 additions & 2 deletions mycli/sqlexecute.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pymysql
from pymysql.connections import Connection
from pymysql.constants import FIELD_TYPE
from pymysql.converters import conversions, convert_date, convert_datetime, convert_timedelta, decoders
from pymysql.converters import conversions, convert_date, convert_datetime, convert_time, decoders
from pymysql.cursors import Cursor

from mycli.packages.special import iocommands
Expand Down Expand Up @@ -257,7 +257,7 @@ def connect(
conv.update({
FIELD_TYPE.TIMESTAMP: lambda obj: convert_datetime(obj) or obj,
FIELD_TYPE.DATETIME: lambda obj: convert_datetime(obj) or obj,
FIELD_TYPE.TIME: lambda obj: convert_timedelta(obj) or obj,
FIELD_TYPE.TIME: lambda obj: convert_time(obj) or obj,
FIELD_TYPE.DATE: lambda obj: convert_date(obj) or obj,
})

Expand Down
17 changes: 17 additions & 0 deletions test/test_sqlexecute.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# type: ignore

from datetime import time
import os

import pymysql
Expand All @@ -25,6 +26,22 @@ def assert_result_equal(result, title=None, rows=None, headers=None, status=None
assert result == [fields]


@dbtest
def test_timediff_negative_value(executor):
sql = "select timediff('2020-11-11 01:01:01', '2020-11-11 01:02:01')"
result = run(executor, sql)
# negative value comes back as str
assert result[0]["rows"][0][0] == "-00:01:00"


@dbtest
def test_timediff_positive_value(executor):
sql = "select timediff('2020-11-11 01:02:01', '2020-11-11 01:01:01')"
result = run(executor, sql)
# positive value comes back as datetime.time
assert result[0]["rows"][0][0] == time(0, 1)


@dbtest
def test_get_result_status_without_warning(executor):
sql = "select 1"
Expand Down