Closed alf-mindshift closed 4 years ago
Ok, looks like I should explain ejc-sql
separators usage a little bit. ejc-sql
attempts to be 2 things simultaneously: easy ad-hoc client for databases like h2 or SQLite and full-fledged client for databases like Oracle. There are 2 meanings of separators in ejc-sql
.
First is a border to determine the area in Emacs buffer should be passed to evaluation. e.g.:
SELECT * FROM one_table
/
SELECT * FROM other_table
So, you don't need to select SQL snippet, simply put point (cursor) into code snippet and press C-c C-c (or desired keybinding). Borders of SQL will be found by Emacs buffer begin/end or this /
separator.
Second meaning is actually delimiter ;
of SQL statements inside SQL snippet passed to evaluation. They are evaluated sequentially (one by one) as separate SQL statements (independent transactions).
E.g. you can easily fill you h2 database:
INSERT INTO product (name, price) VALUES ('socks', 1.25);
INSERT INTO product (name, price) VALUES ('sweater', 14.56);
INSERT INTO product (name, price) VALUES ('jeans', 25.30);
/
SELECT * FROM other_table
Here, the first part is a single snippet passed to ejc-sql
backend but evaluated by 3 independent SQL statements. Furthermore, you can change the delimiter inside this snippet, e.g. for MySQL:
DELIMITER $$
CREATE PROCEDURE GetAllProducts()
BEGIN
SELECT * FROM products;
END $$
/
CALL GetAllProducts();
Anyway, we can't use ;
for Oracle to separate SQL statements since it's a part of its procedures syntax:
CREATE OR REPLACE PROCEDURE welcome_msg (p_name IN VARCHAR2)
IS
BEGIN
dbms_output.put_line ('Welcome '|| p_name);
END;
/
EXEC welcome_msg ('John Doe')
That's why :separator "/"
is used for Oracle db connections configuration examples, to seperate SQL statements only by this /
symbol (https://github.com/kostafey/ejc-sql#oracle-connection).
Probably, this behavior should be reconsidered. @alf-mindshift, what do you think?
Anyway, the last commit should fix the problem with division in SQL for connections, configured with :separator
parameter:
SELECT 10/2 math FROM dual
Being able to do math solves my issue perfectly. Thank you for the quick turn around time.
While I do find the separator-stuff a bit confusing, my feeling is that this issue was more a bug than a user error.
I suggest the following change: