0

Based on the article here: https://emacsredux.com/blog/2013/06/13/using-emacs-as-a-database-client/ I wish to have a .sql buffer to edit my queries and once prepared send it by (C-c C-r) to an already open sql connection buffer. My database is postgresql. First of all I open a connection by M-x sql-postgres I enter username, database name and the server host accordingly. Everything works pretty well and I can run queries directly in the new psql shell without any problem. For the sake of this example I renamed this psql shell to django_sql by M-x rename-buffer : django_sql

Just as an example, this could be my sql file which I wish to edit and run in Emacs by using (C-c C-r), that is by sending the region to the already open psql buffer (that is, django_sql), the file name is myscript.sql:

select t1.first_name, t1.last_name, t1.salary from hr_employees as t1 where t1.department_id = 100; 

Being inside myscript.sql, here is I how I proceed:

  1. I run M-x sql-set-product and then I typed postgres
  2. Afterwards I did M-x sql-set-sqli-buffer and I selected the name of the connection buffer (psql buffer that I named django_sql)
  3. Then I simply selected my SQL query in the file myscript.sql and I did (C-c C-r) to send the selected region to psql buffer (django_sql)

But when I run this I got the following error message:

Wrong type argument: processp, nil 

Could you kindly tell me what did I do wrong, it seems that I proceeded exactly as the above article.


Edit (01):

As it was asked in the comments, I added the debug message so that it might be helpful:

Debugger entered--Lisp error: (wrong-type-argument processp nil) process-buffer(nil) sql-input-sender(nil "select\n t1.first_name,\n t1.last_name,*\n t1.salary\nfrom\n hr_employees as t1\nwhere\n t1.department_id = 100;") sql-send-string("select\n t1.first_name,\n t1.last_name,*\n t1.salary\nfrom\n hr_employees as t1\nwhere\n t1.department_id = 100;\n") sql-send-region(1 122) funcall-interactively(sql-send-region 1 122) call-interactively(sql-send-region nil nil) command-execute(sql-send-region) 
6
  • Set debug-on-error to t, to see which function is expecting the process argument and received nil instead, and see what function called that function, passing it the nil value instead of a process arg. Etc. Commented Dec 6, 2018 at 1:12
  • Does emacswiki.org/emacs/SqlQueryBuffer work for you? Commented Dec 6, 2018 at 2:06
  • @phils: I added the code to my Emacs init file. I opened a connected SQL buffer (usinf sql-postgres) and when in that buffer I invoked the function it opened a new buffer for me to edit. Yet, C-c C-r generates the same error. Commented Dec 6, 2018 at 19:08
  • M-x emacs-version ? Commented Dec 6, 2018 at 19:57
  • M-x emacs-version = GNU Emacs 26.1 (GTK+ Version 3.18.9) Commented Dec 6, 2018 at 20:04

1 Answer 1

1

Finally I found the problem although I cannot explain it. The problem as it seems to me, is due to renaming the psql buffer in Emacs, that is, once I have a psql buffer open and connected to the database, if I run M-x rename-buffer, even if I specify the new name later by runing M-x sql-set-sqli-buffer it seems that Emacs loses somehow the link to the psql buffer when it tries to connect it to my sql script buffer.

What I did instead, was to do C-u sql-postgres, this way emacs prints "*SQL: XXX" and I can then type my desired name which will be prefixed with SQL:

Therefore instead of django_sql-01, the buffer name will be *SQL: django_sql-01* Now I'm really a beginner in this field, so either I completely misunderstand the concept or actually Emacs respects and seeks some pattern in terms of naming the SQL connection buffers (that is, buffers containins a psql prompt)

All I know, is that, by using C-u sql-postgres instead of renaming an already open psql buffer later by M-x rename-buffer, everything works pretty well. I even tested a SQL script with two separate psql buffers (of course with two distinct names) and I run different queries in each of them, and each conntected buffer (each time after doing M-x sql-set-sqli-buffer) provided the expected result.

So, although I cannot explain the true concept and I'm not sure about that, I thought that maybe this could at least be helpful for others who may have encountered the same problem.

1
  • Please M-x report-emacs-bug Commented Dec 7, 2018 at 1:26

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.