Re: [postmodern-devel] Patch: {} syntax for arrays should be inside ''

2011-02-14 Thread Stas Boukarev
Stas Boukarev stass...@gmail.com writes:

 According  to
 http://www.postgresql.org/docs/current/static/arrays.html#ARRAYS-INPUT
 arrays should look like '{ val1 delim val2 delim ... }', but cl-postgres
 sends them as {val1 ...}, the attached patch corrects this.
Well, that was too soon, I forgot to attach the patch itself:
VC backend : Git
Working dir: ~/lisp/site/postmodern/
Branch : master
Remote : http://marijn.haverbeke.nl/git/postmodern
Stash  : Nothing stashed

 ./
 cl-postgres/
  *  edited  cl-postgres/sql-string.lisp


-- 
With Best Regards, Stas.
___
postmodern-devel mailing list
postmodern-devel@common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel


Re: [postmodern-devel] Patch: {} syntax for arrays should be inside ''

2011-02-14 Thread Stas Boukarev
Stas Boukarev stass...@gmail.com writes:

 Stas Boukarev stass...@gmail.com writes:

 According  to
 http://www.postgresql.org/docs/current/static/arrays.html#ARRAYS-INPUT
 arrays should look like '{ val1 delim val2 delim ... }', but cl-postgres
 sends them as {val1 ...}, the attached patch corrects this.

Aw, now I hit C-x C-w in the wrong buffer, that's what you  get for
being in a hurry.
Sorry for the noise, here's the patch for real.
diff --git a/cl-postgres/sql-string.lisp b/cl-postgres/sql-string.lisp
index 7555cc9..d88 100644
--- a/cl-postgres/sql-string.lisp
+++ b/cl-postgres/sql-string.lisp
@@ -55,12 +55,12 @@ whether the string should be escaped before being put into a query.)
 (if (typep arg '(vector (unsigned-byte 8)))
 (values (escape-bytes arg) t)
 (with-output-to-string (out)
-  (write-char #\{ out)
+  (write-string '{ out)
   (loop :for sep :=  :then #\, :for x :across arg :do
  (princ sep out)
  (multiple-value-bind (string escape) (to-sql-string x)
(if escape (write-quoted string out) (write-string string out
-  (write-char #\} out
+  (write-string }' out
   (:method ((arg array))
 (with-output-to-string (out)
   (labels ((recur (dims off)
@@ -75,7 +75,9 @@ whether the string should be escaped before being put into a query.)
 (multiple-value-bind (string escape) (to-sql-string (row-major-aref arg i))
   (if escape (write-quoted string out) (write-string string out)
  (write-char #\} out)))
-  (recur (array-dimensions arg) 0
+(write-char #\' out)
+(recur (array-dimensions arg) 0)
+(write-char #\' out
   (:method ((arg integer))
 (princ-to-string arg))
   (:method ((arg float))

-- 
With Best Regards, Stas.
___
postmodern-devel mailing list
postmodern-devel@common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel


Re: [postmodern-devel] Patch: {} syntax for arrays should be inside ''

2011-02-14 Thread Marijn Haverbeke
Hi Stas,

What happens when, with your patch, you try to pass an array as a
query parameter? ($1, etc) I suspect the correct thing to do would be
to return T as a second value from to-sql-string (which indicates that
the string should be escaped when put into a query), rather than
putting quotes into the returned string. Also, do you know what the
correct syntax is when the array contains a string containing a single
quote? I suspect it should be escaped, which will also be handled by
returning a second t value. If you could test this for me, I'd be
thankful.

Cheers,
Marijn

___
postmodern-devel mailing list
postmodern-devel@common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel