Fix string escaping
[hcoop/smlsql.git] / libpq / pg.sml
index de1a9e8..09c761a 100644 (file)
@@ -104,7 +104,11 @@ struct
                            let
                                fun build (~1, acc) = acc
                                  | build (j, acc) =
-                                   build (j-1, makeValue (F_PQgetvalue.f' (roRes, i, j)) :: acc)
+                                   build (j-1,
+                                          if F_PQgetisnull.f' (roRes, i, j) <> 0 then
+                                              NONE :: acc
+                                          else
+                                              makeValue (F_PQgetvalue.f' (roRes, i, j)) :: acc)
                            in
                                builder (i+1, f (build (nf-1, []), acc))
                            end
@@ -154,7 +158,7 @@ struct
              | xch #"\r" = "\\r"
              | xch c = str c
        in
-           foldl (fn (c, s) => s ^ xch c) "'" (String.explode s) ^ "'"
+           foldl (fn (c, s) => s ^ xch c) "E'" (String.explode s) ^ "'"
        end
     val stringFromSql = valueOf
 
@@ -280,4 +284,4 @@ struct
     fun boolFromSql v = boolFromSql' (valueOf v)
 end
 
-structure PgClient = SqlClient(PgDriver)
\ No newline at end of file
+structure PgClient = SqlClient(PgDriver)