Bug #96588 BIGINT column data truncated using prepared statements with C extension
Submitted: 19 Aug 2019 17:12 Modified: 1 Mar 2022 18:59
Reporter: Will Miles Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Severity:S2 (Serious)
Version:8.0.17 OS:Windows (Python 3.6)
Assigned to: CPU Architecture:Any

[19 Aug 2019 17:12] Will Miles
Description:
When SELECTing BIGINT columns, data appears to be retrieved using a buffer of MYSQL_TYPE_LONG instead of MYSQL_TYPE_LONGLONG.   This causes data values to be truncated unexpectedly, as Python fully supports long integers.

This problem does not apply to pure mode -- it is only relevant to the new feature of the C extension.

How to repeat:
import mysql.connector
cnx = mysql.connector.connect(use_pure=False)
cursor = cnx.cursor(prepared=True)
cursor.execute("SELECT 922337203685477580")
result = cursor.fetchall()
print(result)

Expected:
[(922337203685477580,)]

Returned:
[(-858993460,)]

Suggested fix:
Use a 'long long' element in column_info.small_buffer for retrieving integral values instead of a 'long'.   sizeof(long long) is usually smaller than sizeof(double) anyways, so it won't typically increase the buffer size.
[20 Aug 2019 8:43] MySQL Verification Team
Hello Will Miles,

Thank you for the report.

regards,
Umesh
[1 Mar 2022 4:43] Dan Ruley
This bug is still present as of 2/28/2022.  If you select or insert a bigint type using prepared statements it will convert it to a normal int.
[1 Mar 2022 18:59] Philip Olson
Posted by developer:
 
Fixed as of the upcoming MySQL Connector/Python 8.0.29 release, and here's the proposed changelog entry from the documentation team:

On Windows, and with the C extension with prepared=True, BIGINT data was
seen as MYSQL_TYPE_LONG instead of MYSQL_TYPE_LONGLONG; this raised an
overflow error with values over 2147483647.

Thank you for the bug report.

Related Bug: MySQL Bug #105254