kostafey / ejc-sql

Emacs SQL client uses Clojure JDBC.
278 stars 29 forks source link

company completion never completes #151

Open codygman opened 3 years ago

codygman commented 3 years ago

I installed it via melpa per the instructions and the completions just never seem to happen.

I'm using GNU Emacs 28.0.50 on NixOS 21.05.20210222.c7d0dbe.

kostafey commented 1 year ago
  1. Can you still reproduce the issue?
  2. Can you run M-x company-mode [RET] to ensure company minor-mode is active.
  3. Can you see at least ansi sql words, like SELECT?
gnakic commented 1 year ago

I'm kinda getting the same thing. No completion whatsoever. Using postgres and this is the driver I'm on :dependencies [[org.postgresql/postgresql "42.6.0"]] I can see the company backend registered as intended, but no activity with completion, not even keywords.

kostafey commented 1 year ago

@gnakic Can you execute any SQL queries? Could you try this configuration:

(require 'ejc-company)
(defun ejc-after-emacs-init-hook ()
  (push 'ejc-company-backend company-backends))
(add-hook 'after-init-hook 'ejc-after-emacs-init-hook)
gnakic commented 1 year ago

@kostafey Of course. That works for me as intended. I'm able to run queries when doing C-c C-c in a SQL buffer.

If I do anything to try to trigger company (I'm just writing a simple SELECT), such as pressing tab or just typing, nothing happens.

This is all I get from the *Messages* buffer

Connection started...
[nREPL] Starting server via /opt/homebrew/bin/lein update-in :dependencies conj \[nrepl/nrepl\ \"1.0.0\"\] -- update-in :plugins conj \[cider/cider-nrepl\ \"0.37.0\"\] -- repl :headless :host localhost
Starting nREPL server for ejc-sql...
[nREPL] server started on 49471
[nREPL] Establishing direct connection to localhost:49471 ...
[nREPL] Direct connection to localhost:49471 established
Connected! Showtime!
Connected -> db/local.

I even added this but to no effect

(setq ejc-complete-on-dot t)

What's strange though is that when I inspect the company-backends variable, I can see it registered

Value in #<buffer test.sql>
(company-capf company-yasnippet ejc-company-backend)
gnakic commented 1 year ago

Okay, I made progress 😄 Now company triggers when I type something, but I get this error

Company: An error occurred in auto-begin
Company: backend ejc-company-backend error "Execution error (NullPointerException) at ejc-sql.structure/get-user (structure.clj:533).
Cannot invoke "Object.getClass()" because "target" is null

Not sure if it matters but I do use :connection-uri instead of specifying connection values separately. (I need to do sslmode=disable, and I only know how to specify it if I pass a full connection string)

EDIT:

I've tried connecting to mysql to see how it behaves but the error is the same with company. This is what I've used

(ejc-create-connection
 "mysql/local"
 :dependencies [[com.mysql/mysql-connector-j "8.0.33"]]
 :connection-uri "jdbc:mysql://localhost:3306/?user=root&password=admin&allowPublicKeyRetrieval=true&useSSL=false")

EDIT: Works!

I had to provide :user and :password in my config. There is some completion now. Screenshot 2023-09-09 at 17 37 14

So far am getting keyword and tables completion, but no completion on columns.

EDIT:

I do get column completion but it's a hit and miss. Not sure if postgres use of double quotes is messing that up a bit.

kostafey commented 1 year ago

Can you successfully execute columns obtaining SQL in your database:

SELECT column_name
FROM information_schema.columns
WHERE UPPER(table_name) = 'MY_TABLE'
ORDER BY column_name

Could you provide trivial example of your use case, e.g.:

SELECT a.| FROM MY_TABLE a
gnakic commented 1 year ago

So if I use that exact query, I get empty results. But If I remove UPPER from the WHERE clause, I get results for my table. My table name is in format MyTable (.NET is used to manage the schema, so names are pascal cased). So, this works

SELECT column_name
FROM information_schema.columns
WHERE table_name = 'MyTable'
ORDER BY column_name;

I do have to note that column names of my table are also pascal cased.

So what I do usually is start with this to see what columns I have

SELECT * FROM "MyTable";

company completion does not automatically wrap it in double quotes so I do it myself (otherwise I get a complaint that mytable is not found as you would expect). Then I remove the * and start typing to get autocompletion on columns

SELECT | FROM "MyTable";

but that doesn't do anything, so I do this

SELECT tbl."|" FROM "MyTable" tbl;

and sometimes I get some autocompletion results, sometimes I don't. It also sometimes autocompletes a bunch of stuff but columns are not to be found in autocomplete results.

gnakic commented 12 months ago

Can confirm after a few days of usage that company works as intended as long as table and column names are not pascal case.