Skip to content

Instantly share code, notes, and snippets.

@abg
Last active October 30, 2015 05:09
Show Gist options
  • Save abg/4c1a6ffc314816721be0 to your computer and use it in GitHub Desktop.
Save abg/4c1a6ffc314816721be0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os
import pprint
import random
import MySQLdb
c = MySQLdb.connect(read_default_file=os.path.abspath('my.sandbox.cnf'), db='test')
cursor = c.cursor()
## Output the version this is being run against
cursor.execute('select @@version')
pprint.pprint(list(cursor))
## Test case
cursor.execute('DROP TABLE IF EXISTS mdev_8865')
cursor.execute('CREATE TABLE mdev_8865 (value bigint unsigned)')
cursor.execute('INSERT INTO mdev_8865 VALUES(%s)', random.randint(0, 2**64 -1))
cursor.execute('SELECT IFNULL(value, NULL) AS `x` FROM mdev_8865')
# Just to show the (column_name, type_code<int>, ...)
# This should be '8' if it's a bigint or 246 if its a decimal
# see: https://dev.mysql.com/doc/internals/en/com-query-response.html#packet-Protocol::ColumnType
pprint.pprint(cursor.description)
# output the results. affected versions will show [Decimal('<value>')]
# ex: [(Decimal('9110983828083886002'),)]
pprint.pprint(list(cursor))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment