Re: BUG #4053: libpq documentation should express clearly, that integers are passed in network octet order - Mailing list pgsql-bugs

From Bruce Momjian
Subject Re: BUG #4053: libpq documentation should express clearly, that integers are passed in network octet order
Date
Msg-id 200806232111.m5NLBZe12886@momjian.us
Whole thread Raw
In response to BUG #4053: libpq documentation should express clearly, that integers are passed in network octet order  ("Aleksej Saushev" <asau@inbox.ru>)
List pgsql-bugs
Aleksej Saushev wrote:
>
> The following bug has been logged online:
>
> Bug reference:      4053
> Logged by:          Aleksej Saushev
> Email address:      asau@inbox.ru
> PostgreSQL version: 8.3
> Operating system:   NetBSD, but this does no matter
> Description:        libpq documentation should express clearly, that
> integers are passed in network octet order
> Details:
>
> The documentation on PQexecParams is silent about the precise format,
> expected by server for binary parameters, it should be more explicit
> and note that integers are expected in network octet order.

I have added this libpq documentation paragraph about how to determine
how to pass binary values.  I also added a few comments to the libpq C
code.

Thanks for the report;  please let me know if I can improve it more.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +
Index: doc/src/sgml/libpq.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v
retrieving revision 1.258
diff -c -c -r1.258 libpq.sgml
*** doc/src/sgml/libpq.sgml    1 Jun 2008 16:23:08 -0000    1.258
--- doc/src/sgml/libpq.sgml    23 Jun 2008 21:09:39 -0000
***************
*** 1397,1402 ****
--- 1397,1410 ----
              If the array pointer is null then all parameters are presumed
              to be text strings.
             </para>
+            <para>
+             Values passed in binary format require knowlege of
+             the internal representation expected by the backend.
+             For example, integers must be passed in network byte
+             order.  Passing <type>numeric</> values requires
+             knowledge of the server storage format, as implemented
+             in <filename>src/backend/utils/adt/numeric.c</>.
+            </para>
            </listitem>
           </varlistentry>

Index: src/interfaces/libpq/fe-exec.c
===================================================================
RCS file: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v
retrieving revision 1.195
diff -c -c -r1.195 fe-exec.c
*** src/interfaces/libpq/fe-exec.c    29 May 2008 22:02:44 -0000    1.195
--- src/interfaces/libpq/fe-exec.c    23 Jun 2008 21:09:39 -0000
***************
*** 976,987 ****
              goto sendFailed;
      }

!     /* construct the Bind message */
      if (pqPutMsgStart('B', false, conn) < 0 ||
          pqPuts("", conn) < 0 ||
          pqPuts(stmtName, conn) < 0)
          goto sendFailed;

      if (nParams > 0 && paramFormats)
      {
          if (pqPutInt(nParams, 2, conn) < 0)
--- 976,988 ----
              goto sendFailed;
      }

!     /* Construct the Bind message */
      if (pqPutMsgStart('B', false, conn) < 0 ||
          pqPuts("", conn) < 0 ||
          pqPuts(stmtName, conn) < 0)
          goto sendFailed;

+     /* Send parameter formats */
      if (nParams > 0 && paramFormats)
      {
          if (pqPutInt(nParams, 2, conn) < 0)
***************
*** 1001,1006 ****
--- 1002,1008 ----
      if (pqPutInt(nParams, 2, conn) < 0)
          goto sendFailed;

+     /* Send parameters */
      for (i = 0; i < nParams; i++)
      {
          if (paramValues && paramValues[i])

pgsql-bugs by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: BUG #4027: backslash escaping not disabled in plpgsql
Next
From: Bruce Momjian
Date:
Subject: Re: BUG #4109: Typo in documentation