Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLcl command FORMAT FILE not work #23

Open
AlexandrSimonenko opened this issue Oct 31, 2020 · 12 comments
Open

SQLcl command FORMAT FILE not work #23

AlexandrSimonenko opened this issue Oct 31, 2020 · 12 comments
Labels
enhancement New feature or request

Comments

@AlexandrSimonenko
Copy link

SQLcl: Release 20.2 Production on Сб окт 31 15:32:26 2020

Copyright (c) 1982, 2020, Oracle.  All rights reserved.

SQL> host type test.sql
BEGIN
    SELECT
        *
    FROM
        dual;
END;

SQL> FORMAT RULES c:\oracle\format_setting.xml
Formatter rules loaded
SQL> FORMAT file test.sql test6.sql
SQL> host type test6.sql
BEGIN
    SELECT
        *
    FROM
        dual;

END;

No changes after formatting.
Formatting happens but not according to my rules.
It looks like the loaded rules don't affect the result.
But if you do formatting via the buffer without changing the formatting rules ...

SQL> get test.sql
  1  BEGIN
  2      SELECT
  3          *
  4      FROM
  5          dual;
  6* END
SQL> FORMAT buffer
  1  BEGIN
  2    SELECT
  3      *
  4      FROM
  5      dual;
  6* END;

В этом случае похоже правила сработали.

@mickeypearce
Copy link
Owner

mickeypearce commented Oct 31, 2020

This is seems a sqlcl bug. Have you tried version 20.3?

@AlexandrSimonenko
Copy link
Author

SQLcl: Release 20.3 Production on Сб окт  31 18:17:34 2020

Copyright (c) 1982, 2020, Oracle.  All rights reserved.

SQL> FORMAT file test.sql test6.sql
SQL> host type test6.sql
BEGIN
    SELECT
        *
    FROM
        dual;

END;

SQL> get test.sql
  1  BEGIN
  2      SELECT
  3          *
  4      FROM
  5          dual;
  6* END
SQL> FORMAT buffer
  1  BEGIN
  2    SELECT
  3      *
  4      FROM
  5      dual;
  6* END;
SQL>

20.3 didn't change anything.
The file formatting does not use the loaded rules.

@AlexandrSimonenko
Copy link
Author

@steveduffy
Copy link

steveduffy commented Dec 4, 2020

Having the same issue.

Could you load format_temp.sql to the buffer via a get, format it in the buffer, then SAV format_temp.sql REPLACE to work
around the sqlcl issue?

@mickeypearce
Copy link
Owner

That would great if it could be done. We could make it as a setting option. @steveduffy you are kindly invited to open a PR if you feel like contributing.

@mickeypearce mickeypearce added the enhancement New feature or request label Jul 6, 2021
@fdawans
Copy link

fdawans commented Jul 10, 2021

"Fixed" it by downgrading to SQLcl 19.2.1 (included in SQL Developer 19.2.0)
Here is the download link for SQL Developer (need to make an account and start a first download to accept the license terms).
Link

@mickeypearce
Copy link
Owner

Thanks @fdawans for sharing!

@fdawans
Copy link

fdawans commented Jul 10, 2021

Well... Actually no, it seemed to work a few times but it's broken again.
In SQLcl 19.2.1, format buffer and format file both seem to work as intended (instead of only format buffer in sqlcl 20.x).
But then the extension still uses the default settings.

Edit: I think it's an issue in the escape characters of the file path for the .xml and/or the sql.exe.
I replaced in settings.json (for both user and workspace, not sure how that works).
C:\\Users\\xxxx\\sql_formatting.xml by C:/Users/xxxx/sql_formatting.xml
I used a path without spaces and it works again.
I am on Windows but it looks like it might be related to #5 .

@philpalnau
Copy link

I just wanted to update, I tested the newest version of SQLcl and the format sees to work again (sqlcl-21.2.1.195.1252.zip) . Good Luck!

@fdawans
Copy link

fdawans commented Oct 12, 2021

I have a new issue with the having + group by keywords within a CTE, for both versions.
It works in sqlcl-21.3.0.278.1045, see below, but not in vscode.

Can someone try to format this on his version ?
WITH test AS ( SELECT 1 FROM dual WHERE 1 = 1 HAVING 1 = 1 GROUP BY 1 ) SELECT * FROM test

image

@mickeypearce
Copy link
Owner

With SQLcl: Release 19.2.1 I get "parse error"... haven't tried with 21 yet.

@fdawans
Copy link

fdawans commented Oct 12, 2021

I went back to SQLcl 19.2.1, I liked that formatting better (I probably need to update my formatting rules for 21)
Yes, I have the same 'parse error' in vscode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants