summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorBarbz <BarbzYHOOL@users.noreply.github.com>2020-04-27 20:52:24 +0200
committerGitHub <noreply@github.com>2020-04-27 20:52:24 +0200
commit383bff9b0b2230ec0e1a8af5ad17948303384786 (patch)
tree0df04e9375203df57c95336dcc19f78e60c9b866 /docs
parent07a8f6bf4c35d053383af8dac094d10bd469f7b4 (diff)
downloadwiki-383bff9b0b2230ec0e1a8af5ad17948303384786.tar.gz
wiki-383bff9b0b2230ec0e1a8af5ad17948303384786.tar.bz2
wiki-383bff9b0b2230ec0e1a8af5ad17948303384786.zip
feat: Dealing with SQL files and FLAGS (#55)
* 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ì <borzifrancesco@gmail.com>
Diffstat (limited to 'docs')
-rw-r--r--docs/Dealing-with-SQL-files.md19
1 files changed, 19 insertions, 0 deletions
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: