Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time column type string formatting and test coverage #891

Merged
merged 3 commits into from
Jun 18, 2024

Conversation

jnewmano
Copy link
Contributor

This PR improves the string formatting of time type columns, FormatBinaryTime does not return properly formatted time strings in all cases.

In the zero value case, it was incorrectly returning a date formatted string instead of the expected zero time of 00:00:00. For positive times there was a leading null byte in the returned []byte.

CREATE TABLE time_test (ts TIME);
INSERT INTO time_test (ts) VALUES ("00:00:00"), ("06:12:10");

Reading the values out (using a statement as direct queries don't use FormatBinaryTime)

SELECT * FROM %s WHERE ts > ?
with query parameter -5 or some other number

resulted in

"0000-00-00"
"\x0006:12:10"

when the expected result is

"00:00:00"
"06:12:10"

}

for _, test := range tests {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  mysql/util_test.go:42:30: unnecessary leading newline (whitespace)

from CI ⬆️

Copy link
Collaborator

@lance6716 lance6716 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rest lgtm. Thank you!

for _, test := range tests {
n := len(test.Data)

// binary.LittleEndian.PutUint32(data[1:], uint64(test.Seconds))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove this comment?

got, err := FormatBinaryTime(n, test.Data)
if test.Error {
require.Error(t, err)
} else if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use

... else {
require.NoError(t. err)
}

here

@lance6716 lance6716 merged commit 7ee1864 into go-mysql-org:master Jun 18, 2024
13 checks passed
@jnewmano jnewmano deleted the time-formatting-tests branch June 18, 2024 17:06
willdonnelly added a commit to estuary/connectors that referenced this pull request Aug 6, 2024
This is past the latest tagged release version of `v1.8.0` because
we need go-mysql-org/go-mysql#891 which
fixed a bug with zero-valued `time` columns when using prepared
statements.

If/when a new version is tagged we can move to that, the only
reason we're naming a specific commit is because it's the current
HEAD of that repository.
willdonnelly added a commit to estuary/connectors that referenced this pull request Aug 9, 2024
This is past the latest tagged release version of `v1.8.0` because
we need go-mysql-org/go-mysql#891 which
fixed a bug with zero-valued `time` columns when using prepared
statements.

If/when a new version is tagged we can move to that, the only
reason we're naming a specific commit is because it's the current
HEAD of that repository.
willdonnelly added a commit to estuary/connectors that referenced this pull request Aug 19, 2024
This is past the latest tagged release version of `v1.8.0` because
we need go-mysql-org/go-mysql#891 which
fixed a bug with zero-valued `time` columns when using prepared
statements.

If/when a new version is tagged we can move to that, the only
reason we're naming a specific commit is because it's the current
HEAD of that repository.
willdonnelly added a commit to estuary/connectors that referenced this pull request Aug 19, 2024
This is past the latest tagged release version of `v1.8.0` because
we need go-mysql-org/go-mysql#891 which
fixed a bug with zero-valued `time` columns when using prepared
statements.

If/when a new version is tagged we can move to that, the only
reason we're naming a specific commit is because it's the current
HEAD of that repository.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants