branch: elpa/pg
commit a8b6f338d6b8031a45c707c6c5137744aeb48b3a
Author: Eric Marsden <[email protected]>
Commit: Eric Marsden <[email protected]>
Rename internal pg-read* functions pg--read*
---
CHANGELOG.md | 8 ++-
pg-lo.el | 56 +++++++++---------
pg.el | 186 +++++++++++++++++++++++++++++------------------------------
3 files changed, 126 insertions(+), 124 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5a8755d7c87..f692eb4e24c 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,12 +4,14 @@
## [0.62] - Unreleased
- Rename functions `pg-read-attributes`, `pg-read-tuple`, `pg-read-char`,
`pg-unread-char`,
- `pg-read-net-int`, `pg-read-int`, `pg-read-chars`, `pg-read-string` to use
the naming convention
- for internal functions (`pg--` prefix).
+ `pg-read-net-int`, `pg-read-int`, `pg-read-chars`, `pg-read-string`,
`pg-send-char`,
+ `pg-send-string`, `pg-send-octets`, `pg-send-uint`, `pg-send-net-uint` to
use the naming convention for
+ internal functions (`pg--` prefix).
- Microsoft Windows: add additional sleep using `sleep-for` when waiting for
network data. The
existing calls to `accept-process-output` with a timeout are insufficient on
this platform when
- reading large resultsets.
+ reading large resultsets. Further testing is needed to determine whether
this is also necessary on
+ other non-Linux platforms like MS-DOS and Darwin.
## [0.61] - 2025-11-22
diff --git a/pg-lo.el b/pg-lo.el
index 4d4a04efcee..b3df76f1995 100644
--- a/pg-lo.el
+++ b/pg-lo.el
@@ -26,17 +26,17 @@
(require 'cl-lib)
(require 'hex-util)
-(declare-function pg-read-string "pg" (con maxbytes))
-(declare-function pg-read-char "pg" (con))
-(declare-function pg-read-chars "pg" (con count))
-(declare-function pg-read-net-int "pg" (con bytes))
+(declare-function pg--read-string "pg" (con maxbytes))
+(declare-function pg--read-char "pg" (con))
+(declare-function pg--read-chars "pg" (con count))
+(declare-function pg--read-net-int "pg" (con bytes))
(declare-function pg-read-error-response "pg" (con))
(declare-function pg-handle-error-response "pg" (con &optional context))
(declare-function pg-flush "pg" (con))
-(declare-function pg-send "pg" (con str &optional bytes))
-(declare-function pg-send-uint "pg" (con num bytes))
-(declare-function pg-send-char "pg" (con char))
-(declare-function pg-send-octets "pg" (con octets))
+(declare-function pg--send "pg" (con str &optional bytes))
+(declare-function pg--send-uint "pg" (con num bytes))
+(declare-function pg--send-char "pg" (con char))
+(declare-function pg--send-octets "pg" (con octets))
(declare-function pg-connection-set-busy "pg" (con busy))
(declare-function pg-result "pg" (result what &rest arg))
(declare-function pg-exec "pg" (con &rest args))
@@ -94,53 +94,53 @@
(let ((msg (format "Unknown builtin function %s" fn)))
(signal 'pg-user-error (list msg)))))))
;; https://www.postgresql.org/docs/17/protocol-message-formats.html
- (pg-send-char con ?F)
+ (pg--send-char con ?F)
(let* ((arg-len (length args))
(msg-len (+ 4 4 2 (* 2 arg-len) 2
(cl-loop for arg in args
sum (+ 4 (if (integerp arg) 4 (length arg))))
2)))
- (pg-send-uint con msg-len 4))
- (pg-send-uint con fnid 4)
+ (pg--send-uint con msg-len 4))
+ (pg--send-uint con fnid 4)
; The number of argument format codes that follow
- (pg-send-uint con (length args) 2)
+ (pg--send-uint con (length args) 2)
;; The argument format codes, either zero for text or 1 for binary.
(dolist (arg args)
(cond ((integerp arg)
- (pg-send-uint con 1 2))
+ (pg--send-uint con 1 2))
((stringp arg)
- (pg-send-uint con 0 2))
+ (pg--send-uint con 0 2))
(t
(let ((msg (format "Unknown fastpath type %s" arg)))
(signal 'pg-user-error (list msg))))))
;; Send the number of arguments being specified to the function
- (pg-send-uint con (length args) 2)
+ (pg--send-uint con (length args) 2)
;; Send length/value for each argument
(dolist (arg args)
(cond ((integerp arg)
- (pg-send-uint con 4 4)
- (pg-send-uint con arg 4))
+ (pg--send-uint con 4 4)
+ (pg--send-uint con arg 4))
((stringp arg)
- (pg-send-uint con (length arg) 4)
- (pg-send-octets con arg))))
+ (pg--send-uint con (length arg) 4)
+ (pg--send-octets con arg))))
;; Int16: the format code for the function result. Must presently be zero
(text) or one (binary).
(if integer-result
- (pg-send-uint con 1 2)
- (pg-send-uint con 0 2))
+ (pg--send-uint con 1 2)
+ (pg--send-uint con 0 2))
(pg-flush con)
(cl-loop with result = nil
- for c = (pg-read-char con) do
+ for c = (pg--read-char con) do
(cl-case c
;; ErrorResponse
(?E (pg-handle-error-response con "in pg-fn"))
;; FunctionCallResult
(?V
- (let ((_msg-len (pg-read-net-int con 4))
- (value-len (pg-read-net-int con 4)))
+ (let ((_msg-len (pg--read-net-int con 4))
+ (value-len (pg--read-net-int con 4)))
(setq result (if integer-result
- (pg-read-net-int con value-len)
- (pg-read-chars con value-len)))))
+ (pg--read-net-int con value-len)
+ (pg--read-chars con value-len)))))
;; NoticeResponse
(?N
@@ -153,8 +153,8 @@
;; ReadyForQuery message
(?Z
- (let ((_msglen (pg-read-net-int con 4))
- (status (pg-read-char con)))
+ (let ((_msglen (pg--read-net-int con 4))
+ (status (pg--read-char con)))
(when (eql ?E status)
(message "PostgreSQL ReadyForQuery message with error
status"))
(pg--trim-connection-buffers con)
diff --git a/pg.el b/pg.el
index 48d7cc78d8e..e75fded3485 100644
--- a/pg.el
+++ b/pg.el
@@ -711,19 +711,19 @@ Uses database DBNAME, user USER and password PASSWORD."
(1+ (length "client_encoding"))
(1+ (length "UTF8"))
1)))
- (pg-send-uint con packet-octets 4)
- (pg-send-uint con 3 2) ; Protocol major version = 3
- (pg-send-uint con 0 2) ; Protocol minor version = 0
- (pg-send-string con "user")
- (pg-send-string con user)
- (pg-send-string con "database")
- (pg-send-string con dbname)
- (pg-send-string con "application_name")
- (pg-send-string con pg-application-name)
- (pg-send-string con "client_encoding")
- (pg-send-string con "UTF8")
+ (pg--send-uint con packet-octets 4)
+ (pg--send-uint con 3 2) ; Protocol major version = 3
+ (pg--send-uint con 0 2) ; Protocol minor version = 0
+ (pg--send-string con "user")
+ (pg--send-string con user)
+ (pg--send-string con "database")
+ (pg--send-string con dbname)
+ (pg--send-string con "application_name")
+ (pg--send-string con pg-application-name)
+ (pg--send-string con "client_encoding")
+ (pg--send-string con "UTF8")
;; A zero byte is required as a terminator after the last name/value pair.
- (pg-send-uint con 0 1)
+ (pg--send-uint con 0 1)
(pg-flush con))
(when (pgcon-connect-timer con)
(cancel-timer (pgcon-connect-timer con)))
@@ -809,9 +809,9 @@ Uses database DBNAME, user USER and password PASSWORD."
(let ((password-string (if (functionp password)
(funcall password)
password)))
- (pg-send-char con ?p)
- (pg-send-uint con (+ 5 (length password-string)) 4)
- (pg-send-string con password-string))
+ (pg--send-char con ?p)
+ (pg--send-uint con (+ 5 (length password-string)) 4)
+ (pg--send-string con password-string))
(pg-flush con))
;; AUTH_REQ_CRYPT
@@ -1037,8 +1037,8 @@ to use the updated protocol features introduced with
PostgreSQL version
(unless (gnutls-available-p)
(signal 'pg-error '("Connecting over TLS requires GnuTLS support
in Emacs")))
;; send the SSLRequest message
- (pg-send-uint con 8 4)
- (pg-send-uint con 80877103 4)
+ (pg--send-uint con 8 4)
+ (pg--send-uint con 80877103 4)
(pg-flush con)
(let ((ch (pg--read-char con)))
(unless (eql ?S ch)
@@ -1498,9 +1498,9 @@ Return a result structure which can be decoded using
`pg-result'."
(let ((len (length encoded)))
(when (> len (- (expt 2 32) 5))
(signal 'pg-user-error (list "Query is too large")))
- (pg-send-char con ?Q)
- (pg-send-uint con (+ 4 len 1) 4)
- (pg-send-string con encoded)
+ (pg--send-char con ?Q)
+ (pg--send-uint con (+ 4 len 1) 4)
+ (pg--send-string con encoded)
(pg-flush con))
(cl-loop for c = (pg--read-char con) do
;; (message "pg-exec message-type = %c" c)
@@ -1788,13 +1788,13 @@ Returns the prepared statement name (a string)."
(len (+ 4 (1+ (length name)) (1+ (length query/enc)) 2 (* 4 (length
oids)))))
;; send a Parse message
(pg-connection-set-busy con t)
- (pg-send-char con ?P)
- (pg-send-uint con len 4)
- (pg-send-string con name)
- (pg-send-string con query/enc)
- (pg-send-uint con (length oids) 2)
+ (pg--send-char con ?P)
+ (pg--send-uint con len 4)
+ (pg--send-string con name)
+ (pg--send-string con query/enc)
+ (pg--send-uint con (length oids) 2)
(dolist (oid oids)
- (pg-send-uint con oid 4))
+ (pg--send-uint con oid 4))
(pg-flush con))
name))
@@ -1833,38 +1833,38 @@ Uses PostgreSQL connection CON."
(when (> len (expt 2 32))
(signal 'pg-user-error (list "Field is too large")))
;; send a Bind message
- (pg-send-char con ?B)
- (pg-send-uint con len 4)
+ (pg--send-char con ?B)
+ (pg--send-uint con len 4)
;; the destination portal
- (pg-send-string con portal)
- (pg-send-string con statement-name)
- (pg-send-uint con (length argument-types) 2)
+ (pg--send-string con portal)
+ (pg--send-string con statement-name)
+ (pg--send-uint con (length argument-types) 2)
(cl-loop for (_ . binary-p) in serialized-values
- do (pg-send-uint con binary-p 2))
- (pg-send-uint con (length argument-values) 2)
+ do (pg--send-uint con binary-p 2))
+ (pg--send-uint con (length argument-values) 2)
(cl-loop
for (v . _) in serialized-values
do (if (null v)
;; for a null value, send -1 followed by zero octets for the value
- (pg-send-uint con -1 4)
+ (pg--send-uint con -1 4)
(let ((len (length v)))
(when (> len (expt 2 32))
(signal 'pg-user-error (list "Field is too large")))
- (pg-send-uint con len 4)
- (pg-send-octets con v))))
+ (pg--send-uint con len 4)
+ (pg--send-octets con v))))
;; the number of result-column format codes: we use zero to indicate that
result columns can use
;; text format
- (pg-send-uint con 0 2)
+ (pg--send-uint con 0 2)
(pg-flush con)
portal))
(defun pg-describe-portal (con portal)
(let ((len (+ 4 1 (1+ (length portal)))))
;; send a Describe message for this portal
- (pg-send-char con ?D)
- (pg-send-uint con len 4)
- (pg-send-char con ?P)
- (pg-send-string con portal)
+ (pg--send-char con ?D)
+ (pg--send-uint con len 4)
+ (pg--send-char con ?P)
+ (pg--send-string con portal)
(pg-flush con)))
(cl-defun pg-execute (con portal &key (max-rows 0))
@@ -1872,12 +1872,12 @@ Uses PostgreSQL connection CON."
(pn/encoded (if ce (encode-coding-string portal ce t) portal))
(len (+ 4 (1+ (length pn/encoded)) 4)))
;; send an Execute message
- (pg-send-char con ?E)
- (pg-send-uint con len 4)
+ (pg--send-char con ?E)
+ (pg--send-uint con len 4)
;; the destination portal
- (pg-send-string con pn/encoded)
+ (pg--send-string con pn/encoded)
;; Maximum number of rows to return; zero means "no limit"
- (pg-send-uint con max-rows 4)
+ (pg--send-uint con max-rows 4)
(pg-flush con)))
(cl-defun pg-fetch (con result &key (max-rows 0))
@@ -1894,12 +1894,12 @@ Returns a pgresult structure (see function
`pg-result')."
;; to retrieve more rows on the next call to pg-fetch.
(cond ((zerop max-rows)
;; send a Sync message
- (pg-send-char con ?S)
- (pg-send-uint con 4 4))
+ (pg--send-char con ?S)
+ (pg--send-uint con 4 4))
(t
;; send a Flush message
- (pg-send-char con ?H)
- (pg-send-uint con 4 4)))
+ (pg--send-char con ?H)
+ (pg--send-uint con 4 4)))
(pg-flush con)
;; In the extended query protocol, the Execute phase is always terminated
by the appearance of
;; exactly one of these messages: CommandComplete, EmptyQueryResponse (if
the portal was created
@@ -1974,8 +1974,8 @@ Returns a pgresult structure (see function `pg-result')."
(setf (pgresult-incomplete result) nil)
(when (> max-rows 0)
;; send a Sync message to close the portal and request the
ReadyForQuery
- (pg-send-char con ?S)
- (pg-send-uint con 4 4)
+ (pg--send-char con ?S)
+ (pg--send-uint con 4 4)
(pg-flush con)))
;; EmptyQueryResponse -- the response to an empty query string
@@ -2090,13 +2090,13 @@ the query plan."
Uses PostgreSQL connection CON."
(let ((len (+ 4 1 (1+ (length portal)))))
;; send a Close message
- (pg-send-char con ?C)
- (pg-send-uint con len 4)
- (pg-send-char con ?P)
- (pg-send-string con portal)
+ (pg--send-char con ?C)
+ (pg--send-uint con len 4)
+ (pg--send-char con ?P)
+ (pg--send-string con portal)
;; send a Sync message
- (pg-send-char con ?S)
- (pg-send-uint con 4 4)
+ (pg--send-char con ?S)
+ (pg--send-uint con 4 4)
(pg-flush con)
(cl-loop
for c = (pg--read-char con) do
@@ -2150,9 +2150,9 @@ can be decoded using `pg-result'."
(len (length query)))
(when (> len (expt 2 32))
(signal 'pg-user-error (list "Query is too large")))
- (pg-send-char con ?Q)
- (pg-send-uint con (+ 4 len 1) 4)
- (pg-send-string con query)
+ (pg--send-char con ?Q)
+ (pg--send-uint con (+ 4 len 1) 4)
+ (pg--send-string con query)
(pg-flush con)
(let ((more-pending t))
(while more-pending
@@ -2217,13 +2217,13 @@ can be decoded using `pg-result'."
(data (buffer-substring-no-properties chunk-start chunk-end))
(encoded (if ce (encode-coding-string data ce t) data)))
;; a CopyData message with the encoded data
- (pg-send-char con ?d)
- (pg-send-uint con (+ 4 (length encoded)) 4)
- (pg-send-octets con encoded)
+ (pg--send-char con ?d)
+ (pg--send-uint con (+ 4 (length encoded)) 4)
+ (pg--send-octets con encoded)
(pg-flush con)))))
;; send a CopyDone message
- (pg-send-char con ?c)
- (pg-send-uint con 4 4)
+ (pg--send-char con ?c)
+ (pg--send-uint con 4 4)
(pg-flush con)
;; Backend sends us either CopyDone or CopyFail, followed by
CommandComplete + ReadyForQuery
(cl-loop
@@ -2290,9 +2290,9 @@ can be decoded using `pg-result', but with data in BUF."
(signal 'pg-programming-error (list "COPY command must contain 'TO
STDOUT'")))
(pg-connection-set-busy con t)
(let ((result (make-pgresult :connection con)))
- (pg-send-char con ?Q)
- (pg-send-uint con (+ 4 (length query) 1) 4)
- (pg-send-string con query)
+ (pg--send-char con ?Q)
+ (pg--send-uint con (+ 4 (length query) 1) 4)
+ (pg--send-string con query)
(pg-flush con)
(let ((more-pending t))
(while more-pending
@@ -2412,8 +2412,8 @@ can be decoded using `pg-result', but with data in BUF."
(setq-local pgcon--position (point-max)))
(when (member (pgcon-server-variant con) '(datafusion))
(cl-return-from pg-sync nil))
- (pg-send-char con ?S)
- (pg-send-uint con 4 4)
+ (pg--send-char con ?S)
+ (pg--send-uint con 4 4)
(pg-flush con)
(when (fboundp 'thread-yield)
(thread-yield))
@@ -2520,12 +2520,12 @@ The cancellation request concerns the command requested
over connection CON."
(set-buffer-multibyte nil)
(buffer-disable-undo)
(setq-local pgcon--position 1))
- (pg-send-uint ccon 16 4)
- (pg-send-uint ccon 80877102 4)
- (pg-send-uint ccon (pgcon-pid con) 4)
+ (pg--send-uint ccon 16 4)
+ (pg--send-uint ccon 80877102 4)
+ (pg--send-uint ccon (pgcon-pid con) 4)
;; From PostgreSQL v18 and version 3.2 of the wire protocol, the "cancel
request keys" can
;; be variable in length, up to 256 bits. Previously, they were only 32
bits in length.
- (pg-send-octets ccon (pgcon-secret con))
+ (pg--send-octets ccon (pgcon-secret con))
(pg-flush ccon)
(pg-disconnect ccon)))
@@ -2540,8 +2540,8 @@ PostgreSQL and Emacs. CON should no longer be used."
;; mode), PostgreSQL can close the network connection before we have
finished flushing the output.
;; This triggers an Emacs error, which we don't want to propagate to the
caller here.
(ignore-errors
- (pg-send-char con ?X)
- (pg-send-uint con 4 4)
+ (pg--send-char con ?X)
+ (pg--send-uint con 4 4)
(pg-flush con))
(let ((process (pgcon-process con)))
(delete-process process)
@@ -3548,9 +3548,9 @@ zero-argument function that returns a string."
(salt (pg--read-chars con 4))
(pwdhash (md5 (concat password-string user)))
(hash (concat "md5" (md5 (concat pwdhash salt)))))
- (pg-send-char con ?p)
- (pg-send-uint con (+ 5 (length hash)) 4)
- (pg-send-string con hash)
+ (pg--send-char con ?p)
+ (pg--send-uint con (+ 5 (length hash)) 4)
+ (pg--send-string con hash)
(pg-flush con)))
@@ -3628,11 +3628,11 @@ Authenticate as USER with PASSWORD, a string."
;; packet length doesn't include the initial ?p message type indicator
(len-packet (+ 4 (1+ (length mechanism)) 4 len-cf)))
;; send the SASLInitialResponse message
- (pg-send-char con ?p)
- (pg-send-uint con len-packet 4)
- (pg-send-string con mechanism)
- (pg-send-uint con len-cf 4)
- (pg-send-octets con client-first)
+ (pg--send-char con ?p)
+ (pg--send-uint con len-packet 4)
+ (pg--send-string con mechanism)
+ (pg--send-uint con len-cf 4)
+ (pg--send-octets con client-first)
(pg-flush con)
(let ((c (pg--read-char con)))
(cl-case c
@@ -3675,9 +3675,9 @@ Authenticate as USER with PASSWORD, a string."
(signal 'pg-protocol-error
(list "SASL response doesn't include correct client
nonce")))
;; we send a SASLResponse message with SCRAM client-final-message
as content
- (pg-send-char con ?p)
- (pg-send-uint con (+ 4 (length client-final-msg)) 4)
- (pg-send-octets con client-final-msg)
+ (pg--send-char con ?p)
+ (pg--send-uint con (+ 4 (length client-final-msg)) 4)
+ (pg--send-octets con client-final-msg)
(pg-flush con)
(let ((c (pg--read-char con)))
(cl-case c
@@ -4477,7 +4477,7 @@ that will be read."
(insert octets)))
;; higher order bits first / little endian
-(defun pg-send-uint (con num bytes)
+(defun pg--send-uint (con num bytes)
(declare (speed 3))
(let ((str (make-string bytes 0))
(i (- bytes 1)))
@@ -4488,7 +4488,7 @@ that will be read."
(pg--buffered-send con str)))
;; big endian
-(defun pg-send-net-uint (con num bytes)
+(defun pg--send-net-uint (con num bytes)
(declare (speed 3))
(let ((str (make-string bytes 0)))
(dotimes (i bytes)
@@ -4496,18 +4496,18 @@ that will be read."
(setq num (floor num 256)))
(pg--buffered-send con str)))
-(defun pg-send-char (con char)
+(defun pg--send-char (con char)
(pg--buffered-send con (char-to-string char)))
-(defun pg-send-string (con string)
+(defun pg--send-string (con string)
(pg--buffered-send con string)
;; the null-terminator octet
(pg--buffered-send con (unibyte-string 0)))
-(defun pg-send-octets (con octets)
+(defun pg--send-octets (con octets)
(pg--buffered-send con octets))
-(defun pg-send (con str &optional bytes)
+(defun pg--send (con str &optional bytes)
(declare (speed 3))
(let ((padding (if (and (numberp bytes) (> bytes (length str)))
(make-string (- bytes (length str)) 0)