Skip to content

Commit

Permalink
Fix MySQL VARBINARY column creation
Browse files Browse the repository at this point in the history
Some versions of MySQL/MariaDB auto-convert large VARBINARY() to BLOB,
others return errors. Knowing current MAX_SCRIPT gets converted to
MEDIUMBLOB, explicitly convert VARBINARY(MAX_SCRIPT) to MEDIUMBLOB.

Fixes #227
  • Loading branch information
dermoth committed Aug 15, 2017
1 parent 3e3a1ee commit 5d58665
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Abe/DataStore.py
Expand Up @@ -95,10 +95,9 @@
PUBKEY_ID_NETWORK_FEE = NULL_PUBKEY_ID

# Size of the script and pubkey columns in bytes.
MAX_SCRIPT = 1000000
MAX_PUBKEY = 65

NO_CLOB = 'BUG_NO_CLOB'
MAX_SCRIPT = SqlAbstraction.MAX_SCRIPT
MAX_PUBKEY = SqlAbstraction.MAX_PUBKEY
NO_CLOB = SqlAbstraction.NO_CLOB

# XXX This belongs in another module.
class InvalidBlock(Exception):
Expand Down
12 changes: 12 additions & 0 deletions Abe/SqlAbstraction.py
Expand Up @@ -19,6 +19,8 @@
import re
import logging

MAX_SCRIPT = 1000000
MAX_PUBKEY = 65
NO_CLOB = 'BUG_NO_CLOB'
STMT_RE = re.compile(r"([^']+)((?:'[^']*')?)")

Expand Down Expand Up @@ -197,6 +199,9 @@ def ret(x):
pass
elif val == 'mysql':
transform_stmt = sql._transform_concat(transform_stmt)
# Also squeeze in MySQL VARBINARY length fix
# Some MySQL version do not auto-convert to BLOB
transform_stmt = sql._transform_varbinary(transform_stmt)

transform_stmt = sql._append_table_epilogue(transform_stmt)

Expand Down Expand Up @@ -430,6 +435,13 @@ def ret(stmt):
return fn(concat_re.sub(repl, stmt))
return ret

def _transform_varbinary(sql, fn):
varbinary_re = re.compile(r"VARBINARY\(" + str(MAX_SCRIPT) + "\)")
def ret(stmt):
# Suitable for prefix+length up to 16,777,215 (2^24 - 1)
return fn(varbinary_re.sub("MEDIUMBLOB", stmt))
return ret

def _append_table_epilogue(sql, fn):
epilogue = sql.config.get('create_table_epilogue', "")
if epilogue == "":
Expand Down

0 comments on commit 5d58665

Please sign in to comment.