# HG changeset patch # User František Kučera # Date 1409598535 -7200 # Node ID 9963cf89ffd7f6dd20c7aef1ebe80e9f08f21e8b # Parent 0f6df6850ba6d5e7a479d170ba38b8f8595d018a prototyp: users_groups fixed: getpwent/getgrent needs setpwent/setgrent and endpwent/endgrent if we want to call them multiple times diff -r 0f6df6850ba6 -r 9963cf89ffd7 prototyp/prototyp.sql --- a/prototyp/prototyp.sql Mon Sep 01 20:03:39 2014 +0200 +++ b/prototyp/prototyp.sql Mon Sep 01 21:08:55 2014 +0200 @@ -82,8 +82,6 @@ -- user groups: -------------------------------------------------------------- DROP VIEW IF EXISTS users_groups; -DROP VIEW IF EXISTS users_groups_primary; -DROP VIEW IF EXISTS users_groups_secondary; DROP VIEW IF EXISTS groups; DROP FUNCTION IF EXISTS groups(); @@ -104,17 +102,15 @@ my $i = 0; + setgrent(); while (my $group = getgrent()) { return_next({ id => $group->gid, name => $group->name, members => [@{$group->members}] }); - elog(NOTICE, "skupina je schizoidní " . $i++); } - elog(NOTICE, "XXX skupina je schizoidní " . $i++); - - elog(NOTICE, "members field does not contain users who have this group as primary one"); + endgrent(); return undef; $$ LANGUAGE plperlu; @@ -122,7 +118,7 @@ CREATE OR REPLACE VIEW groups AS SELECT * FROM groups() ; -COMMENT ON COLUMN groups.members IS 'does not contain users who have this group as primary one'; +COMMENT ON COLUMN groups.members IS 'does not contain users who have this group as primary one – see view: users_groups'; -- users: -------------------------------------------------------------------- @@ -152,6 +148,7 @@ my $i = 0; + setpwent(); while (my $user = getpwent()) { return_next({ id => $user->uid, @@ -163,10 +160,8 @@ shell => $user->shell, # expire => $user->expire }); - elog(NOTICE, "uživatel je schizoidní " . $i++); } - - elog(NOTICE, "XXX uživatel je schizoidní " . $i++); + endpwent(); return undef; $$ LANGUAGE plperlu; @@ -178,22 +173,20 @@ -- users_groups: ------------------------------------------------------------- -CREATE OR REPLACE VIEW users_groups_primary AS +CREATE OR REPLACE VIEW users_groups AS SELECT u1.id AS uid, u1.gid AS gid, u1.name AS user, g1.name AS group, - true AS primary + true AS initial FROM users AS u1 JOIN groups AS g1 ON (u1.gid = g1.id) -; - -CREATE OR REPLACE VIEW users_groups_secondary AS + UNION SELECT u2.id AS uid, g2.*, - false AS primary + false AS initial FROM (SELECT id AS gid, @@ -202,10 +195,5 @@ FROM groups) AS g2 JOIN users AS u2 ON (u2.name = g2.user) ; +COMMENT ON COLUMN users_groups.initial IS 'whether this group is the „initial login group“ of given user (the primary group)'; -CREATE OR REPLACE VIEW users_groups AS - SELECT * FROM users_groups_primary - UNION - SELECT * FROM users_groups_secondary -; -