Skip to content

Commit

Permalink
Copy protocol: decode data received from PostgreSQL before insertion …
Browse files Browse the repository at this point in the history
…into buffer
  • Loading branch information
emarsden committed Mar 6, 2024
1 parent 74023b3 commit 877dc5c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pg.el
Original file line number Diff line number Diff line change
Expand Up @@ -1284,16 +1284,17 @@ can be decoded using `pg-result'."
(signal 'pg-protocol-error (list msg))))))))
;; Backend sends us CopyData, CopyDone or CopyFail, followed by CommandComplete + ReadyForQuery
(with-current-buffer buf
(set-buffer-multibyte t)
;; TODO: set the buffer to CSV mode?
(cl-loop
for c = (pg-read-char con) do
(cl-case c
;; CopyData
(?d
(let* ((msglen (pg-read-net-int con 4))
(payload (pg-read-chars con (- msglen 4))))
(insert payload)))
(payload (pg-read-chars-old con (- msglen 4)))
(ce (pgcon-client-encoding con))
(decoded (if ce (decode-coding-string payload ce t) payload)))
(insert decoded)))

;; CopyDone
(?c
Expand Down

0 comments on commit 877dc5c

Please sign in to comment.