Next: string external representation, Up: Strings [Contents][Index]
Starting with PostgreSQL 8.2, there is a configuration file and runtime
parameter standard_conforming_strings
that controls how strictly the
server parses SQL string syntax. When its value is on
, strings that
include the ‘\’ (backslash) character must be prefixed with ‘E’.
Even when it is off, the server may emit a warning, anyway. To avoid such
unpleasantness, Guile-PG provides sql-quote-auto-E?
.
When non-#f
, sql-quote
will prefix a ‘E’
if it detects any ‘\’ (backslash) characters in its arg.
For example:
(define (e.g.) (display (sql-quote "a\\b"))) (fluid-ref sql-quote-auto-E?) ⇒ #f (e.g.) -| 'a\134b' (with-fluids ((sql-quote-auto-E? #t)) (e.g.)) -| E'a\134b'
If there are no backslash characters, this has no effect.
The typical way to use this is to set the fluid soon after you make the connection and forget about it:
(and (pg-parameter-status CONN 'standard_conforming_strings) ;; Don't bother checking the parameter value; ;; enable functionality unconditionally. (fluid-set! sql-quote-auto-E? #t))
This can get hairy if you maintain more than one connection at a time to
servers with mixed support for standard_conforming_strings
, however
(i.e., pre-8.2 and 8.2+ together). In that case, it is better to use
with-fluids
to enable the functionality completely dynamically.