1

windows 10, emacs 26.1

I has file my_test.sql. This file content SQLite query. Is it possible to execute this sql query and get results?

  1. I has sqlite db file test.db

  2. It has table notification_invoice

  3. I create file my_test.sql with one sql query:

    select * from notification_invoice order by notificationDate

So here my steps:

  1. Open my_test.sql enter image description here

  2. M-x sql-set-product RET sqlite

  3. sql-product-interactive

enter image description here

  1. in the sql-mode buffer) to call sql-send-buffer enter image description here

As you can see I not get sql result.

What is wrong with my steps?

a_subscriber
  • 3,854
  • 1
  • 17
  • 47

2 Answers2

3
  • Open my_test.sql (this buffer is in sql-mode; aka "SQL")
  • M-x sql-set-product RET sqlite
  • C-cTAB to call sql-product-interactive to connect to the database (this new buffer is in sql-interactive-mode; aka "SQLi")
  • C-cC-b (in the sql-mode buffer) to call sql-send-buffer, sending the whole buffer as a query

Use C-hm in the sql-mode buffer to see the other sql-send-* commands and key bindings for sending queries.

phils
  • 48,657
  • 3
  • 76
  • 115
  • I update my post. But nothing happened. I'm not get sql result.. – a_subscriber Dec 16 '18 at 09:42
  • Is it a valid query? (Does it work verbatim in a different client?) – phils Dec 16 '18 at 10:08
  • Yes, this is a valid sql query. I success executed them on another application (squirrel-sql) – a_subscriber Dec 16 '18 at 10:17
  • When I connect to a sqlite database I have 3 lines of output including a prompt in the SQLi buffer: `SQLite version 2.8.17`, `Enter ".help" for instructions`, `sqlite> `. I don't see anything like that in your SQLi buffer, which makes me wonder whether something is amiss with that connection (even though that "Login...done" in the echo area matches what I see, and suggests that all is well). Is `C-h v sql-sqlite-program` correct? – phils Dec 16 '18 at 11:02
  • If you start over and enter `.help` in the SQLi buffer, does that work? – phils Dec 16 '18 at 11:07
  • .help - yes it show help. But nothing work. I can't run any sql query. – a_subscriber Dec 16 '18 at 12:48
  • My initial *guess* is that the Emacs code needs there to be a prompt, and is getting tripped up by there not being one. That's pure speculation, but you might try to figure out why there is no prompt, and if you can make the sqlite program display one, and then find out whether the Emacs functionality starts working. – phils Dec 16 '18 at 13:55
  • You can presumably also run the query in the SQLi buffer? Just not by trying to send it from the `sql-mode` buffer? At this point I'd also suggest explicitly terminating the query with a semicolon (even though that is apparently optional for sqlite). – phils Dec 16 '18 at 13:58
2

I think something is wrong with SQL-mode, sqlite3 and Emacs on Windows. As seen in your screenshot, you can't see the sqlite> prompt, and the same happens for me when I run sql-mode with sqlite3 on Windows. From what I can see the sql querys are sent to the sql-process but the output from sqlite3 is not shown.

I found the following solution. What you need to add is:

(setq sql-sqlite-options '("-interactive")))
Andrew Swann
  • 3,436
  • 2
  • 15
  • 43
Trisk3lion
  • 21
  • 2