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

Feature Request: Add a --bracket Option #2

Open
Merokz opened this issue Dec 6, 2024 · 0 comments
Open

Feature Request: Add a --bracket Option #2

Merokz opened this issue Dec 6, 2024 · 0 comments
Assignees

Comments

@Merokz
Copy link

Merokz commented Dec 6, 2024

Feature Request: Add a --bracket Option

Description:

When working with MSSQL, certain object names may be reserved keywords (e.g. USER, GROUP), which can cause conflicts or errors when generating and running the SQL scripts. Currently, qss does not automatically wrap object names in square brackets. As a result, developers must manually edit the generated scripts or avoid using keywords as object names, which may not always be feasible.

Request:

Introduce a --bracket (or similar) command-line argument. When enabled, qss would wrap all object names (tables, columns, triggers, stored procedures, and foreign keys) in square brackets for MSSQL. This would ensure that even reserved keywords are treated as identifiers rather than reserved words, preventing SQL parsing errors and saving time on manual script edits.

Justification:

  • Reserved Keywords in MSSQL:
    Certain words cannot be used as identifiers unless properly escaped. By adding square brackets (e.g., [USER], [GROUP]), you can safely create objects with these names.

  • Consistency and Automation:
    With a --bracket / --br option, users don’t have to worry about manually editing generated scripts to add brackets. This ensures consistent naming conventions and reduces the chance of errors.


Example:

Command without --bracket:

qss mssql User sp:* c:USERNAME,nvarchar(50),nnu c:EMAIL,nvarchar(255),nnu

Might generate procedures and references like:

CREATE TABLE USER (...);
CREATE PROCEDURE USERInsert (...);`

If USER is considered a reserved keyword in this environment, this might cause issues.


Command with --bracket:

qss mssql User --bracket sp:* c:USERNAME,nvarchar(50),nnu c:EMAIL,nvarchar(255),nnu

Would generate:

CREATE TABLE [USER] (...); 
CREATE PROCEDURE [USERInsert] (...);

And when referencing this table from another:

ALTER TABLE [SomeOtherTable] ADD CONSTRAINT [FK_SomeOtherTable_USER] 
FOREIGN KEY ([USERID]) REFERENCES [USER]([USERID]);

This ensures that the generated scripts run smoothly even if reserved words are used as identifiers.

@Grisgram Grisgram self-assigned this Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants