Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 def to_sql(cls, _):
     return text_type("NULL")
Ejemplo n.º 4
0
 def to_sql(cls, value):
     return text_type(value)
Ejemplo n.º 5
0
 def to_sql(cls, _):
     return text_type("NULL")
Ejemplo n.º 6
0
 def to_sql(cls, value):
     return text_type(value)