def quote(value):
    """Quote a value unambigously w.r.t. its data type.

    The result can be used during import into a relational database.

    :param value: The value to transform.

    :return: ``'null'`` if ``value`` is ``None``, ``'true'`` if it is ``True``,
        ``'false' if it is ``False``.  For numeric values, the result is the
        corresponding string representation.  Infinite values are represented by
        ``'inf'`` and ``'-inf'``, respectively;  not-a-number is represented by
        ``'nan'``.  For strings, the result is the string itself, surrounded by
        ``'"'``, and with the characters ``'"'``, ``'\\'``, ``'\\b'``,
        ``'\\t'``, ``'\\n'``, ``'\\v'``, ``'\\f'`` and ``'\\r'`` escaped using
        ``'\\'``.
    
    :raises TypeError: If ``value`` is neither ``None`` nor of type ``bool``,
            ``int``, ``float`` or ``str``.

    """
    if value is None:
        return 'null'
    if isinstance(value, bool):
        return 'true' if value else 'false'
    if isinstance(value, int) or isinstance(value, float):
        return str(value)
    if isinstance(value, str):
        # Use double quotation marks around all strings (and only around
        # strings), so that strings can be identified by them, and the special
        # values ``null``, ``false``, ``true``, ``inf``, ``-inf`` and ``nan``
        # can be identified by the absence of quotations marks.
        return ('"' + value.replace('\\', '\\\\').replace('"', '\\"').replace('\b', '\\b').replace('\t', '\\t').replace('\n', '\\n').replace('\v', '\\v').replace('\f', '\\f').replace('\r', '\\r') + '"')
    raise TypeError('Unable to quote value of type %r'
                    % (type(value).__name__,))