[prog] tables & mysql

Jacinta Richardson jarich at perltraining.com.au
Thu Feb 19 17:34:59 EST 2004


On Wed, 18 Feb 2004, Anthony Gorecki wrote:

> On February 18, 2004 9:09 pm, wolf wrote:
> > permissions, it would follow the same idea as permissions on a file in
> > linux.  Basically,
> > I would like the idea to work out that each class has a calendar and
> > only the instructor
> > to the class may edit it, but each student in the class would be
> > allowed to view it.
> 
> The easiest method would be to create an integer field and assign a certain 
> set of permissions to any given number. If you then needed to set multiple 
> permissions for the same item, you could substitute the integer field for a 
> varchar field and treat each character as a separate permission.

Alternately if you use binary representational bits you can get a more
useful indication of additional permissions, 555 vs 644 etc.  :) 

I'm sure that 90% of people know what those numbers mean and how they're
made up, and if you already know please ignore the rest of this mail.  For
those people who've worked out that 7 means read/write/execute but not
why, I'll explain briefly.

Permissions are actually represented in binary but we can ignore that for
the first bit.  Each permission of read, write or execute can be written
as one number:
	1 - execute
	2 - write
	4 - read.

You'll notice that any distinct addition of each of those values gives a
unique resulting value:
	1 - execute only	5 - read + execute
	2 - write only		6 - write + read
	3 - execute+write	7 - execute + write + read
	4 - read only

Those with a moderate grasp of binary will realise that the next number in
the sequence is 8.  Not only because 7 is the highest we can go but
because 1, 2, 4... we're counting in binary:

	000001	-	1
	000010	-	2
	000100	-	4
	001000	-	8

Note that in each row above we only have one 1.  This means that if we
"or" any 2 (or more) single rows of the above together we get a unique
result (as in you can't create it by "or"ing a different combination of
rows together.  The same as we weren't able to get any of the decimal
permission bits by adding a different set of the numbers together.

So:	000001 | 000010  =  000011   (1 + 2 = 3)
        000011 | 000100  =  000111   (1 + 2 + 4 = 7)

Anyway, I've explained this rather poorly, but I hope it helps someone...

	Jacinta

--
   ("`-''-/").___..--''"`-._          |  Jacinta Richardson         |
    `6_ 6  )   `-.  (     ).`-.__.`)  |  Perl Training Australia    |
    (_Y_.)'  ._   )  `._ `. ``-..-'   |      +613 9354 6001         |  
  _..`--'_..-_/  /--'_.' ,'           | contact at perltraining.com.au |
(il),-''  (li),'  ((!.-'              |   www.perltraining.com.au   |



More information about the Programming mailing list