[FIX] sql_db: port fix from psycopg/psycopg2#459
NUL characters must not be used in query parameters, as they will be ignored by libpq, being end-of-string characters. Preventing NULs avoids unexpected results from queries. It is only necessary with psycopg2 versions before 2.7, which includes the upstream fix.
This commit is contained in:
parent
46263eb398
commit
eb8d919015
|
@ -63,6 +63,19 @@ psycopg2.extensions.register_type(psycopg2.extensions.new_type((700, 701, 1700,)
|
|||
|
||||
|
||||
import tools
|
||||
|
||||
from tools import parse_version as pv
|
||||
if pv(psycopg2.__version__) < pv('2.7'):
|
||||
from psycopg2._psycopg import QuotedString
|
||||
def adapt_string(adapted):
|
||||
"""Python implementation of psycopg/psycopg2#459 from v2.7"""
|
||||
if '\x00' in adapted:
|
||||
raise ValueError("A string literal cannot contain NUL (0x00) characters.")
|
||||
return QuotedString(adapted)
|
||||
|
||||
psycopg2.extensions.register_adapter(str, adapt_string)
|
||||
psycopg2.extensions.register_adapter(unicode, adapt_string)
|
||||
|
||||
from tools.func import frame_codeinfo
|
||||
from datetime import datetime as mdt
|
||||
from datetime import timedelta
|
||||
|
|
Loading…
Reference in New Issue