vscode-sqltools icon indicating copy to clipboard operation
vscode-sqltools copied to clipboard

[BUG] preserve empty line between SQL blocks

Open loynoir opened this issue 1 year ago • 2 comments

Describe the bug linesBetweenQueries: preserve but empty lines are removed.

To Reproduce

  "sqltools.format": {
    "linesBetweenQueries": "preserve"
  }
CREATE TABLE `bar` (
  `id` int NOT NULL,
  `name` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE `foo` (
  `id` int NOT NULL,
  `name` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE `qaz` (
  `id` int NOT NULL,
  `name` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

Expected behavior Empty line preserved when linesBetweenQueries: preserve

Actual behavior Empty line removed when linesBetweenQueries: preserve

CREATE TABLE `bar` (
  `id` int NOT NULL,
  `name` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;
CREATE TABLE `foo` (
  `id` int NOT NULL,
  `name` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;


CREATE TABLE `qaz` (
  `id` int NOT NULL,
  `name` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • SQLTools Version 0.23.0
  • VSCode Version: 1.59.1
  • OS: Linux
  • Driver:
    • [ ] PostgreSQL/Redshift
    • [x] MySQL/MariaDB
    • [ ] MSSQL/Azure
    • [ ] SQLite
    • [ ] Other? Which...
  • Database version: mysql 8.0.29

Additional context DBeaver > select > Generate SQL > DDL

loynoir avatar Jul 17 '22 00:07 loynoir

https://github.com/mtxr/vscode-sqltools/issues/507

loynoir avatar Jul 17 '22 00:07 loynoir

Does https://github.com/mtxr/vscode-sqltools/discussions/887#discussioncomment-3009193 help you?

gjsjohnmurray avatar Jul 22 '22 21:07 gjsjohnmurray

I'm finding the same. Trying to keep the line count preserved has very unpredictable behaviour, but always ends up in all blank lines being removed after a few saves.

martijnarts avatar Sep 23 '22 09:09 martijnarts

Simple case:

SELECT 1 FROM contacts;

SELECT 2 FROM contacts;

SELECT 3 FROM contacts;

SELECT 4 FROM contacts;

After first format:

SELECT 1
FROM contacts;
SELECT 2
FROM contacts;

SELECT 3
FROM contacts;


SELECT 4
FROM contacts;

After second format:

SELECT 1
FROM contacts;
SELECT 2
FROM contacts;
SELECT 3
FROM contacts;



SELECT 4
FROM contacts;

gjsjohnmurray avatar Sep 28 '22 15:09 gjsjohnmurray