From 383bff9b0b2230ec0e1a8af5ad17948303384786 Mon Sep 17 00:00:00 2001 From: Barbz Date: Mon, 27 Apr 2020 20:52:24 +0200 Subject: feat: Dealing with SQL files and FLAGS (#55) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Dealing with SQL files and FLAGS How to remove, add or invert flags in SQL * Update Dealing-with-SQL-files.md Co-authored-by: Francesco Borzì --- docs/Dealing-with-SQL-files.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/Dealing-with-SQL-files.md b/docs/Dealing-with-SQL-files.md index b25fc18..69a97f2 100644 --- a/docs/Dealing-with-SQL-files.md +++ b/docs/Dealing-with-SQL-files.md @@ -58,6 +58,25 @@ Good: UPDATE `table_1` SET `field_1` = 'someValue' WHERE `entry` IN (1000, 2000, 3000); ``` +#### Flags + +For flags (2^) columns, when you remove or add a flag, it is better not to override the existing value as flags are combined values. + +For example, given a flag with value `128`, this is how it would be to add, remove and invert it: + +```sql +-- ADD AN EXTRA FLAG (|) +UPDATE `table_1` SET `field_1` = `field_1` | 128 WHERE `entry` = 1000; + +-- REMOVE AN EXTRA FLAG (& ~) +UPDATE `table_1` SET `field_1` = `field_1` & ~128 WHERE `entry` = 1000; + +-- INVERT A FLAG (if present = removed, if absent = added) (^) +UPDATE `table_1` SET `field_1` = `field_1` ^ 128 WHERE `entry` = 1000; +``` + +This way, you will make sure that your query will only affect that specific flag, leaving all the other flags unchanged. + ### DELETE Bad: -- cgit