Skip to content

added scan string type #976

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

Merged
merged 4 commits into from
Oct 21, 2019
Merged

added scan string type #976

merged 4 commits into from
Oct 21, 2019

Conversation

j-forster
Copy link
Contributor

@j-forster j-forster commented Jun 27, 2019

Description

The changes cover multiple issues:
#366
#407
jmoiron/sqlx#349

The ScanType for VARCHAR, TEXT, TINYTEXT and other string-like types correctly scans to go internal string type.

Checklist

  • Code compiles correctly
  • Created tests which fail without the change (if possible)
  • All tests passing
  • Extended the README / documentation, if necessary
  • Added myself / the copyright holder to the AUTHORS file

fields.go Outdated
fieldTypeMediumBLOB, fieldTypeLongBLOB, fieldTypeBLOB,
fieldTypeVarString, fieldTypeString, fieldTypeGeometry, fieldTypeJSON,
fieldTypeTime:
case fieldTypeVarChar, fieldTypeString, fieldTypeVarString:
Copy link
Member

Choose a reason for hiding this comment

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

Both of VARBINARY and VARCHAR uses VARCHAR field type.
This case statement should be merged in the next case.

fields.go Outdated
if mf.charSet == collations[defaultCollation] {
return scanTypeString
}
fallthrough
Copy link
Member

Choose a reason for hiding this comment

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

See https://dev.mysql.com/doc/refman/8.0/en/c-api-data-structures.html

To distinguish between binary and nonbinary data for string data types, check whether the charsetnr value is 63.

So correct code is this:

// charsetnr == 63 means this column is binary.
// https://dev.mysql.com/doc/refman/8.0/en/c-api-data-structures.html
if mf.charSet == 63 {
    return scanTypeRawBytes
}
return scanTypeString

Added scanTypeString and scanTypeNullString.
@j-forster
Copy link
Contributor Author

j-forster commented Jun 27, 2019

I added the changes that @methane noted.
The tests have been updated to reflect scanTypeString and scanTypeNullString.

Checklist

  • Code compiles correctly
  • Created tests which fail without the change (if possible)
  • All tests passing
  • Extended the README / documentation, if necessary
  • Added myself / the copyright holder to the AUTHORS file

@methane
Copy link
Member

methane commented Oct 9, 2019

Would you merge master branch?
I think the Travis fail was fixed in master branch already.

@methane methane merged commit 5ee934f into go-sql-driver:master Oct 21, 2019
@julienschmidt
Copy link
Member

Uuuhm. This is a breaking change!
We're not going to do that right before a release.

julienschmidt added a commit that referenced this pull request Oct 22, 2019
@julienschmidt julienschmidt added this to the v1.6.0 milestone Oct 22, 2019
julienschmidt added a commit that referenced this pull request Oct 22, 2019
tz70s pushed a commit to tz70s/mysql that referenced this pull request Sep 5, 2020
ColumnTypeScanType() now returns string and sql.NullString.
tz70s pushed a commit to tz70s/mysql that referenced this pull request Sep 5, 2020
tz70s pushed a commit to tz70s/mysql that referenced this pull request Sep 5, 2020
ColumnTypeScanType() now returns string and sql.NullString.
tz70s pushed a commit to tz70s/mysql that referenced this pull request Sep 5, 2020
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.

3 participants