0

I am able to connect to PostgreSQL server on linux via the app "pgAdmin III". Here is the picture

Succesful PostgreSQL connection on Linux via the "pgAdmin III"

But when I try to connect Emacs to this database using the command M-x sql-postgres, the output says string-prefix-p: Wrong type argument: stringp, nil.

I think it might be because of two reasons.

  1. I typed in the wrong login information to the server. To be clear, here is the info I typed in based on the server connection from the picture attached above, "User": postgres, "Database": postgres, "Server": PostgreSQL 10, "Port": 5433.

  2. Another reason might be I didn't include the server path in my .emacs file. The server is install in the directory /home/myname/Postgresql/ Here is what I added in .emacs but it still doesn't work, (add-to-list 'load-path "/home/myname/Postgresql/").

Can someone help me out? The same thing happens when I tried to connect to a mysql server. Both mysql and postsql including the servers work well outside Emacs on linux. But I just can't figure out how to connect my Emacs to those servers.


Error update after updating "Server" to "localhost" using M-x toggle-debug-on-error

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  compare-strings(" " nil nil nil 0 1 nil)
  string-prefix-p(" " nil)
  sql-buffer-hidden-p(nil)
  (or (sql-buffer-hidden-p buf) (not sql-display-sqli-buffer-function))
  (if (or (sql-buffer-hidden-p buf) (not sql-display-sqli-buffer-function)) nil (make-progress-reporter message min-value max-value current-value min-change min-time))
  sql-make-progress-reporter(nil "Login")
  (setq rpt (sql-make-progress-reporter nil "Login"))
  (let ((start-buffer (current-buffer)) new-sqli-buffer rpt) (apply (function sql-get-login) (sql-get-product-feature product :sqli-login)) (setq rpt (sql-make-progress-reporter nil "Login")) (let ((sql-user (default-value (quote sql-user))) (sql-password (default-value (quote sql-password))) (sql-server (default-value (quote sql-server))) (sql-database (default-value (quote sql-database))) (sql-port (default-value (quote sql-port))) (default-directory (or sql-default-directory default-directory))) (funcall (sql-get-product-feature product :sqli-comint-func) product (sql-get-product-feature product :sqli-options) (cond ((not new-name) (sql-generate-unique-sqli-buffer-name product nil)) ((consp new-name) (sql-generate-unique-sqli-buffer-name product (read-string "Buffer name (\"*SQL: XXX*\"; enter `XXX'): " (sql-make-alternate-buffer-name product)))) ((or (string-prefix-p " " new-name) (string-match-p "\\`[*].*[*]\\'" new-name)) new-name) ((stringp new-name) (sql-generate-unique-sqli-buffer-name product new-name)) (t (sql-generate-unique-sqli-buffer-name product nil))))) (let ((sql-interactive-product product)) (sql-interactive-mode)) (setq new-sqli-buffer (current-buffer)) (set (make-local-variable (quote sql-buffer)) (buffer-name new-sqli-buffer)) (save-current-buffer (set-buffer start-buffer) (if (derived-mode-p (quote sql-mode)) (progn (setq sql-buffer (buffer-name new-sqli-buffer)) (run-hooks (quote sql-set-sqli-hook))))) (let ((proc (get-buffer-process new-sqli-buffer)) (secs sql-login-delay) (step 0.3)) (while (and (memq (process-status proc) (quote (open run))) (or (accept-process-output proc step) (<= 0.0 (setq secs (- secs step)))) (progn (goto-char (point-max)) (not (re-search-backward sql-prompt-regexp 0 t)))) (sql-progress-reporter-update rpt))) (goto-char (point-max)) (if (re-search-backward sql-prompt-regexp nil t) (progn (run-hooks (quote sql-login-hook)))) (sql-progress-reporter-done rpt) (goto-char (point-max)) (let ((sql-display-sqli-buffer-function t)) (sql-display-buffer new-sqli-buffer)) (get-buffer new-sqli-buffer))
  (if (and buf (or (not new-name) (and (stringp new-name) (string-match-p (regexp-quote new-name) buf)))) (sql-display-buffer buf) (let ((start-buffer (current-buffer)) new-sqli-buffer rpt) (apply (function sql-get-login) (sql-get-product-feature product :sqli-login)) (setq rpt (sql-make-progress-reporter nil "Login")) (let ((sql-user (default-value (quote sql-user))) (sql-password (default-value (quote sql-password))) (sql-server (default-value (quote sql-server))) (sql-database (default-value (quote sql-database))) (sql-port (default-value (quote sql-port))) (default-directory (or sql-default-directory default-directory))) (funcall (sql-get-product-feature product :sqli-comint-func) product (sql-get-product-feature product :sqli-options) (cond ((not new-name) (sql-generate-unique-sqli-buffer-name product nil)) ((consp new-name) (sql-generate-unique-sqli-buffer-name product (read-string "Buffer name (\"*SQL: XXX*\"; enter `XXX'): " ...))) ((or (string-prefix-p " " new-name) (string-match-p "\\`[*].*[*]\\'" new-name)) new-name) ((stringp new-name) (sql-generate-unique-sqli-buffer-name product new-name)) (t (sql-generate-unique-sqli-buffer-name product nil))))) (let ((sql-interactive-product product)) (sql-interactive-mode)) (setq new-sqli-buffer (current-buffer)) (set (make-local-variable (quote sql-buffer)) (buffer-name new-sqli-buffer)) (save-current-buffer (set-buffer start-buffer) (if (derived-mode-p (quote sql-mode)) (progn (setq sql-buffer (buffer-name new-sqli-buffer)) (run-hooks (quote sql-set-sqli-hook))))) (let ((proc (get-buffer-process new-sqli-buffer)) (secs sql-login-delay) (step 0.3)) (while (and (memq (process-status proc) (quote (open run))) (or (accept-process-output proc step) (<= 0.0 (setq secs ...))) (progn (goto-char (point-max)) (not (re-search-backward sql-prompt-regexp 0 t)))) (sql-progress-reporter-update rpt))) (goto-char (point-max)) (if (re-search-backward sql-prompt-regexp nil t) (progn (run-hooks (quote sql-login-hook)))) (sql-progress-reporter-done rpt) (goto-char (point-max)) (let ((sql-display-sqli-buffer-function t)) (sql-display-buffer new-sqli-buffer)) (get-buffer new-sqli-buffer)))
  (let ((buf (sql-find-sqli-buffer product sql-connection))) (if (and buf (or (not new-name) (and (stringp new-name) (string-match-p (regexp-quote new-name) buf)))) (sql-display-buffer buf) (let ((start-buffer (current-buffer)) new-sqli-buffer rpt) (apply (function sql-get-login) (sql-get-product-feature product :sqli-login)) (setq rpt (sql-make-progress-reporter nil "Login")) (let ((sql-user (default-value (quote sql-user))) (sql-password (default-value (quote sql-password))) (sql-server (default-value (quote sql-server))) (sql-database (default-value (quote sql-database))) (sql-port (default-value (quote sql-port))) (default-directory (or sql-default-directory default-directory))) (funcall (sql-get-product-feature product :sqli-comint-func) product (sql-get-product-feature product :sqli-options) (cond ((not new-name) (sql-generate-unique-sqli-buffer-name product nil)) ((consp new-name) (sql-generate-unique-sqli-buffer-name product ...)) ((or ... ...) new-name) ((stringp new-name) (sql-generate-unique-sqli-buffer-name product new-name)) (t (sql-generate-unique-sqli-buffer-name product nil))))) (let ((sql-interactive-product product)) (sql-interactive-mode)) (setq new-sqli-buffer (current-buffer)) (set (make-local-variable (quote sql-buffer)) (buffer-name new-sqli-buffer)) (save-current-buffer (set-buffer start-buffer) (if (derived-mode-p (quote sql-mode)) (progn (setq sql-buffer (buffer-name new-sqli-buffer)) (run-hooks (quote sql-set-sqli-hook))))) (let ((proc (get-buffer-process new-sqli-buffer)) (secs sql-login-delay) (step 0.3)) (while (and (memq (process-status proc) (quote ...)) (or (accept-process-output proc step) (<= 0.0 ...)) (progn (goto-char ...) (not ...))) (sql-progress-reporter-update rpt))) (goto-char (point-max)) (if (re-search-backward sql-prompt-regexp nil t) (progn (run-hooks (quote sql-login-hook)))) (sql-progress-reporter-done rpt) (goto-char (point-max)) (let ((sql-display-sqli-buffer-function t)) (sql-display-buffer new-sqli-buffer)) (get-buffer new-sqli-buffer))))
  (progn (let ((buf (sql-find-sqli-buffer product sql-connection))) (if (and buf (or (not new-name) (and (stringp new-name) (string-match-p (regexp-quote new-name) buf)))) (sql-display-buffer buf) (let ((start-buffer (current-buffer)) new-sqli-buffer rpt) (apply (function sql-get-login) (sql-get-product-feature product :sqli-login)) (setq rpt (sql-make-progress-reporter nil "Login")) (let ((sql-user (default-value ...)) (sql-password (default-value ...)) (sql-server (default-value ...)) (sql-database (default-value ...)) (sql-port (default-value ...)) (default-directory (or sql-default-directory default-directory))) (funcall (sql-get-product-feature product :sqli-comint-func) product (sql-get-product-feature product :sqli-options) (cond (... ...) (... ...) (... new-name) (... ...) (t ...)))) (let ((sql-interactive-product product)) (sql-interactive-mode)) (setq new-sqli-buffer (current-buffer)) (set (make-local-variable (quote sql-buffer)) (buffer-name new-sqli-buffer)) (save-current-buffer (set-buffer start-buffer) (if (derived-mode-p (quote sql-mode)) (progn (setq sql-buffer ...) (run-hooks ...)))) (let ((proc (get-buffer-process new-sqli-buffer)) (secs sql-login-delay) (step 0.3)) (while (and (memq ... ...) (or ... ...) (progn ... ...)) (sql-progress-reporter-update rpt))) (goto-char (point-max)) (if (re-search-backward sql-prompt-regexp nil t) (progn (run-hooks (quote sql-login-hook)))) (sql-progress-reporter-done rpt) (goto-char (point-max)) (let ((sql-display-sqli-buffer-function t)) (sql-display-buffer new-sqli-buffer)) (get-buffer new-sqli-buffer)))))
  (if (sql-get-product-feature product :sqli-comint-func) (progn (let ((buf (sql-find-sqli-buffer product sql-connection))) (if (and buf (or (not new-name) (and (stringp new-name) (string-match-p ... buf)))) (sql-display-buffer buf) (let ((start-buffer (current-buffer)) new-sqli-buffer rpt) (apply (function sql-get-login) (sql-get-product-feature product :sqli-login)) (setq rpt (sql-make-progress-reporter nil "Login")) (let ((sql-user ...) (sql-password ...) (sql-server ...) (sql-database ...) (sql-port ...) (default-directory ...)) (funcall (sql-get-product-feature product :sqli-comint-func) product (sql-get-product-feature product :sqli-options) (cond ... ... ... ... ...))) (let ((sql-interactive-product product)) (sql-interactive-mode)) (setq new-sqli-buffer (current-buffer)) (set (make-local-variable (quote sql-buffer)) (buffer-name new-sqli-buffer)) (save-current-buffer (set-buffer start-buffer) (if (derived-mode-p ...) (progn ... ...))) (let ((proc ...) (secs sql-login-delay) (step 0.3)) (while (and ... ... ...) (sql-progress-reporter-update rpt))) (goto-char (point-max)) (if (re-search-backward sql-prompt-regexp nil t) (progn (run-hooks ...))) (sql-progress-reporter-done rpt) (goto-char (point-max)) (let ((sql-display-sqli-buffer-function t)) (sql-display-buffer new-sqli-buffer)) (get-buffer new-sqli-buffer))))))
  (if product (if (sql-get-product-feature product :sqli-comint-func) (progn (let ((buf (sql-find-sqli-buffer product sql-connection))) (if (and buf (or (not new-name) (and ... ...))) (sql-display-buffer buf) (let ((start-buffer ...) new-sqli-buffer rpt) (apply (function sql-get-login) (sql-get-product-feature product :sqli-login)) (setq rpt (sql-make-progress-reporter nil "Login")) (let (... ... ... ... ... ...) (funcall ... product ... ...)) (let (...) (sql-interactive-mode)) (setq new-sqli-buffer (current-buffer)) (set (make-local-variable ...) (buffer-name new-sqli-buffer)) (save-current-buffer (set-buffer start-buffer) (if ... ...)) (let (... ... ...) (while ... ...)) (goto-char (point-max)) (if (re-search-backward sql-prompt-regexp nil t) (progn ...)) (sql-progress-reporter-done rpt) (goto-char (point-max)) (let (...) (sql-display-buffer new-sqli-buffer)) (get-buffer new-sqli-buffer)))))) (user-error "No default SQL product defined: set `sql-product'"))
  sql-product-interactive(postgres nil)
  sql-postgres(nil)
  call-interactively(sql-postgres record nil)
  command-execute(sql-postgres record)
  execute-extended-command(nil "sql-postgres")
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)
Lawerance
  • 131
  • 6
  • Please don't tag unrelated DBMS. PostgreSQL and SQL Server are very different products. – Thom A Oct 28 '18 at 15:04
  • "Server" should be `localhost` based on the screenshot. – phils Oct 28 '18 at 20:03
  • And if that still produces an error, use `M-x toggle-debug-on-error` and paste the resulting stack trace into the question text. – phils Oct 28 '18 at 20:05
  • @phils Yes, `localhost` still gives the same output. I posted the error message. – Lawerance Oct 28 '18 at 20:35
  • Thanks. You need to do that again, because the formatting of what you've pasted is unreadable. Copy and paste it verbatim (without filling/breaking lines), and indent the entire text by four spaces (which you can do in Emacs with `M-4 C-x C-i` after marking the region). Then paste that into the question. – phils Oct 28 '18 at 21:11
  • @phils Thanks for teaching me the formatting. I reposted it. – Lawerance Oct 28 '18 at 21:16
  • I don't seem to have a `sql-buffer-hidden-p` function in Emacs 26.1. Which version are you using? (Ah, you tagged this with `emacs24`, but the exact version might be useful too). Does this happen if you start Emacs with `emacs -Q` ? – phils Oct 28 '18 at 21:33
  • @phils I'm using GNU Emacs 24.5.1. If I do `emacs -Q`, I can connect to the database. Don't know why. – Lawerance Oct 28 '18 at 21:39
  • 1
    This means that something in your personal config is causing the problem, so you'll probably need to figure that out yourself. Typically you would use the recursive bisection approach, but I think here you could start with `C-h f sql-buffer-hidden-p` to find out which library implements that, and then disable that library -- I can't see that function in Emacs 24 code, so I suspect it's something you've installed. – phils Oct 28 '18 at 22:15

0 Answers0