Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PGHOST doc/code mismatch #117

Open
progman1 opened this issue Dec 30, 2021 · 0 comments
Open

PGHOST doc/code mismatch #117

progman1 opened this issue Dec 30, 2021 · 0 comments

Comments

@progman1
Copy link

the README says it will be taken as a unix socket if PGHOST has a 1st char of /.
that doesn't work because the code (describe_connection) only does the check on ~host parameter values, not both.
so, in fact, pgocaml's interception of PGHOST prevents it from being set with a socket directory since an exception is raised trying to open it as a network address.

here's my fix:

diff --git a/src/PGOCaml_generic.ml b/src/PGOCaml_generic.ml
index a1a0567..536ee79 100644
--- a/src/PGOCaml_generic.ml
+++ b/src/PGOCaml_generic.ml
@@ -291,0 +291,0 @@ type uuid = string
@@ -1022,7 +1019,11 @@ let describe_connection ?host ?port ?user ?password ?database
       `Unix_domain_socket_dir s
     | None, None ->
       try
-        `Hostname (Sys.getenv "PGHOST")
+        let h=Sys.getenv "PGHOST" in
+        if String.length h > 0 && String.get h 0 = '/' then
+          `Unix_domain_socket_dir h
+        else
+          `Hostname h
       with
         Not_found -> (* fall back on Unix domain socket. *)
           `Unix_domain_socket_dir PGOCaml_config.default_unix_domain_socket_dir

I also found a problem in my installation with the generated cfg file
PGOCaml_config.ml which confounded the above issue.
installing via opam gave this:

let default_unix_domain_socket_dir = "/tmp"

bizarre as the /var/run/postgresql directory does exist.
deleting this cfg file in the dune _build directory under opam and rebuilding/reinstalling regenerated it correctly!

on another note a source of great frustration was the unchanging behaviour of the test executable when changing PGXXX vars.
even after I grokked it I still tripped up again and again.
eventually I added this to the test dune stanza:

 (preprocessor_deps 
  (env_var PGHOST)
  (env_var PGUSER)
  (env_var PGDATABASE)
  (env_var PGPASSWORD)
  (env_var PGPORT)
  (env_var PGPROFILING)
  (env_var PGCUSTOM_CONVERTERS_CONFIG)
  (env_var PGCOMMENT_SRC_LOC)
 )

... and the ppx stage of db access worked reliably during experimentation/dev/test without further stumbling! I recommend this or a cut-down version is added to the test case and highlighted to potential users!

lastly, note the PGCOMMENT_SRC_LOC - the README.md lists it without the PG prefix incorrectly.

@progman1 progman1 changed the title PGHOST doc/code mistmatch PGHOST doc/code mismatch Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant