code: def value_to_sql_str(v):
      
      if v is None:
          return 'null'
  
      if type(v) in (types.IntType, types.FloatType, types.LongType):
          return str(v)
  
      if type(v) in (types.StringType, types.UnicodeType):
          return "'%s'" %(v.replace(u"'", u"\\'"))
  
      if isinstance(v, datetime):
          return "'%s'" %(v.strftime("%Y-%m-%d %H:%M:%S"))
  
      if isinstance(v, date):
          return "'%s'" %(v.strftime("%Y-%m-%d"))
  
      return str(v)
docs: transform a python variable to the appropriate representation in SQL