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

sql double event #11

Closed
thewillyan opened this issue May 9, 2023 · 2 comments
Closed

sql double event #11

thewillyan opened this issue May 9, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@thewillyan
Copy link
Contributor

Currently, it is possible to insert an event two times in the database, causing waste of memory in the DB for having two events with the same values and making it impossible to get the event ID since it has two possible IDs for the given event values.

My suggestion is to only insert if there is no other event with the given values. We can do so by using a IF NOT EXISTS SQL statement:

IF NOT EXISTS(SELECT id FROM evento WHERE nome='event' AND data='01/01/2001')
  BEGIN
     INSERT INTO evento (nome, data, img) VALUES ('event', '01/01/2001', 'img.png');
  END

Also, it is possible to set the @evid variable otherwise with a ELSE, although it is unclear if that has some optimization improvement or not.

@thewillyan thewillyan added the bug Something isn't working label May 9, 2023
@thewillyan thewillyan self-assigned this May 9, 2023
@thewillyan thewillyan pinned this issue May 9, 2023
@thewillyan
Copy link
Contributor Author

To make this issue simpler the columns nome, data e img are now unique, in other words, you can not have two events with the same combination of those columns.

@thewillyan
Copy link
Contributor Author

fixed at 7be7103, closing this issue.

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

When branches are created from issues, their pull requests are automatically linked.

1 participant