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

mysql: improve fields type info text resultset. #291

Merged
merged 6 commits into from
Jul 9, 2018

Conversation

avdva
Copy link
Contributor

@avdva avdva commented Jul 5, 2018

According to the current algorithm, field type is determined by the type of the first row.
If it's nullable and is null, the type will be MYSQL_TYPE_NULL. However, other rows can have non-null value, so their type info is lost.
Thus, the resultset can have different types for fields depending of what actual value was first. For example, MySQL Workbench uses this info, and if the type is MYSQL_TYPE_NULL, it shows null for all rows, despite the fact, that there are non-null values.

// the case, when old value was null, and the new one isn't null, so we can update
// type info for fields.
oldIsNull, newIsNull := r.Fields[j].Type == MYSQL_TYPE_NULL, typ == MYSQL_TYPE_NULL
if oldIsNull {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we use

if oldIsNull && !newIsNull {
    // format
} else if !oldIsNull && !newIsNull {
    // return err
}

to simplify the indent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, the code looks cleaner.

@siddontang siddontang merged commit 03f9030 into go-mysql-org:master Jul 9, 2018
@siddontang
Copy link
Collaborator

Thank you @avdva

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