def prepare(cls, value, type_code=type_codes.CHAR): pfield = struct.pack('b', type_code) if value is None: # length indicator pfield += struct.pack('B', 255) else: if not isinstance(value, string_types): # Value is provided e.g. as integer, but a string is actually required. Try proper casting into string: value = text_type(value) value = value.encode('cesu-8') length = len(value) # length indicator if length <= 245: pfield += struct.pack('B', length) elif length <= 32767: pfield += struct.pack('B', 246) pfield += struct.pack('H', length) else: pfield += struct.pack('B', 247) pfield += struct.pack('I', length) pfield += value return pfield
def to_sql(cls, _): return text_type("NULL")
def to_sql(cls, value): return text_type(value)