Skip to content

Bug _mysql.c - binary flag? #343

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

Closed
lonestarr86 opened this issue Mar 14, 2019 · 11 comments
Closed

Bug _mysql.c - binary flag? #343

lonestarr86 opened this issue Mar 14, 2019 · 11 comments

Comments

@lonestarr86
Copy link

Hi,

Thanks for your effort providing us this driver.

However, I think there is a bug in _mysql.c. In the function "_mysql_field_to_python" there is a switch statement. In this statement the binary flag is always overwritten by the default block.
As a consequence I'm getting trouble processing binary data because the binary data is treated as text leading into conversion trouble.
I wanted to let you know about the problem, because you might want to check.

Thanks and regards!

@lonestarr86 lonestarr86 changed the title Bug _mysql.c? Bug _mysql.c - binary flag? Mar 14, 2019
@methane
Copy link
Member

methane commented Mar 14, 2019

It is not a bug, as comment describes.
What field type do you using?

@lonestarr86
Copy link
Author

Are you really sure about that?
I'm not an expert in C, but since there is no break after setting binary to 1, binary is always overwritten to 0 due to the default. The comment does not explain any implicit meaning behind that.

@methane
Copy link
Member

methane commented Mar 14, 2019

You're right. But I don't have failing test case. What type do you use?

@lonestarr86
Copy link
Author

I think it depends on the configuration. I use my own converter callbacks with the option "use_unicode=0"

conv = {
	252: ((128 ,_BINARYCONV  ),(None,_STRINGCONV)),
	250: ((128 ,_BINARYCONV  ),(None,_STRINGCONV)),
	251: ((128 ,_BINARYCONV  ),(None,_STRINGCONV)),
	253: ((128 ,_BINARYCONV  ),(None,_STRINGCONV)),
	254: ((128 ,_BINARYCONV  ),(None,_STRINGCONV)),
	....
}
MySQLdb.connect(
	...
	conv        = conv,
	use_unicode = 0,
	...
)

Hope this information is helpful...

@methane
Copy link
Member

methane commented Mar 15, 2019

Uh, that's API I hate.... conv waste my hundreds hours. It's broken design.
Why you need it?

@lonestarr86
Copy link
Author

Sorry to hear that. We tend to manage any encoding operations on our own. The conv seems to be a reasonable tool. Of course, we can workaround that with use_unicode, but that doesn't solve the bug.

@methane
Copy link
Member

methane commented Mar 15, 2019

Of course, we can workaround that with use_unicode, but that doesn't solve the bug.

If you didn't override these types, this switch statement is not used.
That's why only you are affected by this bug.

https://github.com/PyMySQL/mysqlclient-python/blob/1a67ae2cc2da1a2bf511cf70b20dcd5fca5ba7fe/MySQLdb/_mysql.c#L1110-L1123

@lonestarr86
Copy link
Author

I was already wondering why no others were affected. Thanks for your attention.

@fried
Copy link
Contributor

fried commented Mar 19, 2019

I just hit this same bug today, and have pull request.

@fried
Copy link
Contributor

fried commented Mar 19, 2019

So if this is broken it becomes really hard to deal with databases that have bad charsets or what have you. The example I have is we have some really old db's where the charset is utf8, but some bad C++ code was committing truncated data to the table, and thus was not possible to decode it, The team fixed the C++, but it might be still possible that some of this data still exists, so they have a converter that opens a task for a human to resolve, but returns the value by doing a decode(utf8, 'ignore')

@methane
Copy link
Member

methane commented Mar 19, 2019

Even though this bug is fixed, I won't guarantee the callback is supported in such ways.
Use only use_unicode=False. Don't override callbacks for strs.

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

No branches or pull requests

3 participants