code: def _to_sql_value(value, noquote=False):
          
          # Convert to string the values that the database adapter can't adapt
          # to a SQL type.
          # [http://initd.org/psycopg/docs/usage.html#query-parameters]
          if not isinstance(value, (types.NoneType, bool, int, long, float, basestring)):
              value = obj.stringify(value)
  
          if noquote:
              return value
  
          # @warning: do not use ``psycopg2.extensions.adapt(value).getquoted()``
          #     because it returns ``str`` object, which is expected as adaptation
          #     is taking a Python object and converting it into a SQL
          #     representation: this is always a bytes string, as it has to be
          #     sent to the socket.  However the caller might not use the quoted
          #     value to immediately sent it to the database server, but it can
          #     use it for rewriting an SQL statement, which will break the text
          #     encoding.
          return 'NULL' if value is None \
                  else '%s' % str(value) if isinstance(value, (bool, int, long, float)) \
                  else "e'%s'" % unicode(value).replace("'", "''").replace('\\', '\\\\').replace('%', '%%')
docs: Return the SQL string representation of the specified value.
  
  
          @param value: a value to convert into its SQL string representation.
  
          @param noquote: indicate whether to quote or not the specified value.
  
  
          @return: a SQL string representation of the specified value.