Example #1
0
 def val_py2sql(self, pyval):
     """
     Convert a python variable into something we can insert into an pgSQL statement.
     
     @type pyval: object
     @param pyval: object represnting column value to be inserted .
     
     @rtype: str
     """        
     if pyval is None:
         return None
     elif self.isarray:
         return array_as_text (pyval)
     elif self.type == "bit":
         if pyval: return 1
         else: return 0
     elif self.type == 'macaddr':
         if not pyval: return None
         if not isinstance(pyval, (str, unicode)): return None
         if len(pyval) != 12: return None
         return pyval
     elif isinstance(pyval, (str, unicode)):
         try:
             return pyval.encode ( 'utf-8')
         except UnicodeDecodeError:
             return pyval.decode ( 'utf-8' ).encode ( 'utf-8' )                
     else:
         return str(pyval)
Example #2
0
 def val_py2sql(self, pyval):
     """
     Convert a python variable into something we can insert into an pgSQL statement.
     
     @type pyval: object
     @param pyval: object represnting column value to be inserted .
     
     @rtype: str
     """
     if pyval is None:
         return None
     elif self.isarray:
         return array_as_text(pyval)
     elif self.type == "bit":
         if pyval: return 1
         else: return 0
     elif self.type == 'macaddr':
         if not pyval: return None
         if not isinstance(pyval, (str, unicode)): return None
         if len(pyval) != 12: return None
         return pyval
     elif isinstance(pyval, (str, unicode)):
         try:
             return pyval.encode('utf-8')
         except UnicodeDecodeError:
             return pyval.decode('utf-8').encode('utf-8')
     else:
         return str(pyval)
Example #3
0
 def val_py2txt(self, pyval):
     """
     Convert a python variable to text that can be displayed in an input widget.
     @type pyval: object
     @param pyval: object represnting column value to be inserted .
     
     @rtype: str
     """
     if self.isarray:
         return "array:" + array_as_text(pyval)
     if pyval is None:
         return ''
     elif isinstance(pyval, unicode):
         return pyval
     elif isinstance(pyval, str):
         return pyval.decode('utf-8')
     else:
         return str(pyval)
Example #4
0
 def val_py2txt(self, pyval):
     """
     Convert a python variable to text that can be displayed in an input widget.
     @type pyval: object
     @param pyval: object represnting column value to be inserted .
     
     @rtype: str
     """
     if self.isarray:
         return "array:" + array_as_text(pyval)
     if pyval is None:
         return ''
     elif isinstance(pyval, unicode):
         return pyval
     elif isinstance(pyval, str):
         return pyval.decode('utf-8')
     else:
         return str(pyval)