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

Returning after Insert statement not parsing in sqlite #1028

Open
1 task done
earthboundkid opened this issue Dec 2, 2024 · 4 comments
Open
1 task done

Returning after Insert statement not parsing in sqlite #1028

earthboundkid opened this issue Dec 2, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@earthboundkid
Copy link

earthboundkid commented Dec 2, 2024

What would you like to see?

If I have more than one statement in a .sql file, sqruff only lints the first statement.

Checked issues

  • I have checked this request in the issues.
@earthboundkid earthboundkid added the enhancement New feature or request label Dec 2, 2024
@gvozdvmozgu
Copy link
Collaborator

gvozdvmozgu commented Dec 3, 2024

Could you please provide an example of the SQL query and the configuration, if available? The issue is likely with the parser.

@benfdking benfdking added bug Something isn't working and removed enhancement New feature or request labels Dec 3, 2024
@earthboundkid
Copy link
Author

.sqruff

[sqruff]
dialect = sqlite
rules = all

[sqruff:indentation]
indent_unit = space
tab_space_size = 2
indented_joins = True

[sqlfluff:rules:capitalisation.keywords]
# Keywords
capitalisation_policy = upper
# Comma separated list of words to ignore for this rule
ignore_words = None
ignore_words_regex = None

[sqlfluff:rules:capitalisation.identifiers]
# Unquoted identifiers
extended_capitalisation_policy = lower
# Comma separated list of words to ignore for this rule
ignore_words = None
ignore_words_regex = None

[sqlfluff:rules:capitalisation.functions]
# Function names
extended_capitalisation_policy = lower
# Comma separated list of words to ignore for this rule
ignore_words = None
ignore_words_regex = None

[sqlfluff:rules:capitalisation.literals]
# Null & Boolean Literals
capitalisation_policy = upper

comment.sql

-- name: CreateComment :one
INSERT INTO
comment (
  name, contact, subject, cc, message, ip, user_agent, referrer, host_page
)
VALUES
(
  ?, ?, ?, ?, ?, ?, ?, ?, ?
)
RETURNING * ;

-- name: ListComments :many
SELECT *
FROM comment
ORDER BY modified_at DESC
LIMIT ?
OFFSET ? ;

If I swap the statements, it unindents the insert columns and question marks.

@benfdking benfdking changed the title Support multiple statements in one file Returning after Insert statement not parsing in sqlite Dec 3, 2024
@benfdking
Copy link
Collaborator

I'm sorry, but I've renamed this because the issue is not quite what you've said.

The error is two-fold:

  1. We don't parse the following syntaxes yet RETURNING *.
  2. Your statements are not valid SQL that's why in parts it's struggling. ? isn't valid SQL. You're looking for the placeholder templater
-- name: CreateComment :one
INSERT INTO
comment (
  name, contact, subject, cc, message, ip, user_agent, referrer, host_page
)
VALUES
(
  ?, ?, ?, ?, ?, ?, ?, ?, ?
);

-- name: ListComments :many
SELECT *
FROM comment
ORDER BY modified_at DESC
LIMIT ?
OFFSET ?;
[sqruff]
dialect = sqlite
rules = all
templater = placeholder

[sqruff:templater:placeholder]
param_style = question_mark

[sqruff:indentation]
indent_unit = space
tab_space_size = 2
indented_joins = True

[sqlfluff:rules:capitalisation.keywords]
# Keywords
capitalisation_policy = upper
# Comma separated list of words to ignore for this rule
ignore_words = None
ignore_words_regex = None

[sqlfluff:rules:capitalisation.identifiers]
# Unquoted identifiers
extended_capitalisation_policy = lower
# Comma separated list of words to ignore for this rule
ignore_words = None
ignore_words_regex = None

[sqlfluff:rules:capitalisation.functions]
# Function names
extended_capitalisation_policy = lower
# Comma separated list of words to ignore for this rule
ignore_words = None
ignore_words_regex = None

[sqlfluff:rules:capitalisation.literals]
# Null & Boolean Literals
capitalisation_policy = upper

@earthboundkid
Copy link
Author

In that case, it seems like a bug if it thinks the syntax is invalid but it doesn’t return an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants