Subject: bug#60872: 29.0.60; emacsql broken after Jan 12 change

From: Robert Pluim <[email-masked]>
Date: Tue, 17 Jan 2023 11:02:29 +0100

>>>>> On Mon, 16 Jan 2023 20:50:00 -0800, Richard Kim <[email-masked]> said:

    Richard> On Jan 12 Eli checked in cfd2b3504ab on emacs-29 branch on Jan 12 which seemed to have broken emacssql used by org-roam package. Following is the stack trace I get using emacs-29 built after cfd2b3504ab was checked in.

    Richard> ,----
    Richard> | Debugger entered--Lisp error: (error "Selecting deleted buffer")
    Richard> |   #f(compiled-function (connection) "Return true if the end of the buffer has a properly-formatted prompt." #<bytecode 0x192bbe2fe99c5127>)(#<emacsql-sqlite-connection emacsql-sqlite-connection-15656bd9678a>)
    Richard> |   apply(#f(compiled-function (connection) "Return true if the end of the buffer has a properly-formatted prompt." #<bytecode 0x192bbe2fe99c5127>) #<emacsql-sqlite-connection emacsql-sqlite-connection-15656bd9678a> nil)

I can reproduce this, itʼs because the sqlite process is dying
almost straight away in emacsql-sqlite.el:

    (cl-defmethod initialize-instance :after
      ((connection emacsql-sqlite-connection) &rest _rest)
      (emacsql-sqlite-ensure-binary)
      (let* ((process-connection-type nil)  ; use a pipe
             (coding-system-for-write 'utf-8-auto)
             (coding-system-for-read 'utf-8-auto)
             (file (slot-value connection 'file))
             (buffer (generate-new-buffer " *emacsql-sqlite*"))
             (fullfile (if file (expand-file-name file) ":memory:"))
             (process (start-process  <== dies
                       "emacsql-sqlite" buffer emacsql-sqlite-executable fullfile)))
        (setf (slot-value connection 'process) process)
        (setf (process-sentinel process)
              (lambda (proc _) (kill-buffer (process-buffer proc))))
        (emacsql-wait connection)
        (emacsql connection [:pragma (= busy-timeout $s1)]
                 (/ (* emacsql-global-timeout 1000) 2))
        (emacsql-register connection)))

If I use

             (coding-system-for-read 'utf-8)

instead it all works fine.

Eli, what debug would you like? If I donʼt kill the " *emacsql-sqlite*"
buffer it contains

--begin--
((150))
success
#
()
success
#
error 1 "middleware parsing error"
--end--

Robert
--