initial commit
[squeep-indie-auther] / src / db / sqlite / sql / scope-in-use.sql
diff --git a/src/db/sqlite/sql/scope-in-use.sql b/src/db/sqlite/sql/scope-in-use.sql
new file mode 100644 (file)
index 0000000..1129caf
--- /dev/null
@@ -0,0 +1,13 @@
+-- return whether a scope is currently in use, either a profile setting or on a token
+SELECT EXISTS (
+       SELECT 1 FROM scope s
+               INNER JOIN profile_scope ps USING (scope_id)
+               WHERE s.scope = :scope
+       UNION All
+       SELECT 1 FROM scope s
+               INNER JOIN token_scope ts USING (scope_id)
+               WHERE s.scope = :scope
+       UNION All
+       SELECT 1 FROM scope s
+               WHERE s.scope = :scope AND s.is_permanent
+) AS in_use