sql-formatter-org / sql-formatter

A whitespace formatter for different query languages
https://sql-formatter-org.github.io/sql-formatter/
MIT License
2.37k stars 405 forks source link

[FORMATTING] Formatting SQLITE with `identifierCase: "preserve"` converts "result" to "RESULT" while it's an identifier. #795

Closed Auios closed 3 weeks ago

Auios commented 3 weeks ago

Input data

Which SQL and options did you provide as input?

const config: FormatOptionsWithLanguage = {
  tabWidth: 2,
  useTabs: false,
  keywordCase: "upper",
  identifierCase: "preserve",
  dataTypeCase: "upper",
  functionCase: "upper",
  indentStyle: "standard",
  logicalOperatorNewline: "before",
  // expressionWidth: number,
  linesBetweenQueries: 1,
  denseOperators: false,
  newlineBeforeSemicolon: false,
  // params?: ParamItems | string[],
  // paramTypes?: ParamTypes,
};

Expected Output

CREATE TABLE steamLoginLogs (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    createdAt DATETIME DEFAULT CURRENT_TIMESTAMP,
    ipAddress TEXT DEFAULT NULL,
    clientId TEXT DEFAULT NULL,
    actualId TEXT DEFAULT NULL,
    fbid INTEGER DEFAULT NULL,
    username TEXT DEFAULT NULL,
    publisherBanned BOOLEAN DEFAULT NULL,
    vacbanned BOOLEAN DEFAULT NULL,
    result TEXT CHECK(result IN ('ERROR', 'FAIL', 'NEW', 'SUCCESS'))
);

Actual Output

CREATE TABLE steamLoginLogs (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  createdAt DATETIME DEFAULT CURRENT_TIMESTAMP,
  ipAddress TEXT DEFAULT NULL,
  clientId TEXT DEFAULT NULL,
  actualId TEXT DEFAULT NULL,
  fbid INTEGER DEFAULT NULL,
  username TEXT DEFAULT NULL,
  publisherBanned BOOLEAN DEFAULT NULL,
  vacbanned BOOLEAN DEFAULT NULL,
  RESULT TEXT CHECK (RESULT IN ('ERROR', 'FAIL', 'NEW', 'SUCCESS'))
);

Usage

nene commented 3 weeks ago

Thanks for reporting.

This is the same fundamental problem as #740. See that issue for details and for a possible alternative formatting library to use.

I'll close this as duplicate.