473,396 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Permissions, should I use an Int, long or binary datatype?

Hello,

in my web application, I have to create permissions for each user. So
what I am doing is that for each role (using sqlmembership in .net) I
am creating a column in the database to hold a group of permissions
which I will then do some 'bit banging' in my web application to see
if the permission is set or not.

An int is 32 bits, and a long is 64.

I guess making the data type a long is smarter since it doesn't take
that much more space in the database, and it gives me 64 instead of 32
possible permissions correct?

What datatype in sql server would a long map too? And int is an int,
but long?
Dec 28 '07 #1
6 3237
DotNetNewbie wrote:
in my web application, I have to create permissions for each user. So
what I am doing is that for each role (using sqlmembership in .net) I
am creating a column in the database to hold a group of permissions
which I will then do some 'bit banging' in my web application to see
if the permission is set or not.

An int is 32 bits, and a long is 64.

I guess making the data type a long is smarter since it doesn't take
that much more space in the database, and it gives me 64 instead of 32
possible permissions correct?

What datatype in sql server would a long map too? And int is an int,
but long?
A C# long matches a SQLServer bigint.

You could use bitmaps as described.

But it is not a very relational way of storing data.

Arne
Dec 29 '07 #2
On Dec 28, 9:46*pm, Arne Vajhøj <a...@vajhoej.dkwrote:
DotNetNewbie wrote:
in my web application, I have to create permissions for each user. *So
what I am doing is that for each role (using sqlmembership in .net) I
am creating a column in the database to hold a group of permissions
which I will then do some 'bit banging' in my web application to see
if the permission is set or not.
An int is 32 bits, and a long is 64.
I guess making the data type a long is smarter since it doesn't take
that much more space in the database, and it gives me 64 instead of 32
possible permissions correct?
What datatype in sql server would a long map too? *And int is an int,
but long?

A C# long matches a SQLServer bigint.

You could use bitmaps as described.

But it is not a very relational way of storing data.

Arne
Yeah, that is the downside.

For example, if I wanted to do a SQL query for all users with a
particular permission, I'm guessing it would result in a complete
table scan.

ie. select * from users where permissions = (permissions & 0x02) (or
something like that).

One option would be to store each permission in a seperate table, and
then create a 'summary column' in the users table, this way I don't
have to do seperate queries for each user in my web application.
Dec 29 '07 #3
It probably will result in a table scan, which isn't going to help you
much.

Why not have one table which has the definitions of the permissions, and
then another which has the permissions that are assigned to the appropriate
user? That way, you can have as many permissions as you need, and to be
quite honest, it's much easier to query and process in querying the
permissions (it's just two joins, and you just cycle through the permissions
in the client side code).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"DotNetNewbie" <sn***********@yahoo.comwrote in message
news:7e**********************************@d21g2000 prf.googlegroups.com...
On Dec 28, 9:46 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
DotNetNewbie wrote:
in my web application, I have to create permissions for each user. So
what I am doing is that for each role (using sqlmembership in .net) I
am creating a column in the database to hold a group of permissions
which I will then do some 'bit banging' in my web application to see
if the permission is set or not.
An int is 32 bits, and a long is 64.
I guess making the data type a long is smarter since it doesn't take
that much more space in the database, and it gives me 64 instead of 32
possible permissions correct?
What datatype in sql server would a long map too? And int is an int,
but long?

A C# long matches a SQLServer bigint.

You could use bitmaps as described.

But it is not a very relational way of storing data.

Arne
Yeah, that is the downside.

For example, if I wanted to do a SQL query for all users with a
particular permission, I'm guessing it would result in a complete
table scan.

ie. select * from users where permissions = (permissions & 0x02) (or
something like that).

One option would be to store each permission in a seperate table, and
then create a 'summary column' in the users table, this way I don't
have to do seperate queries for each user in my web application.

Dec 29 '07 #4
On Dec 29, 9:55 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
It probably will result in a table scan, which isn't going to help you
much.

Why not have one table which has the definitions of the permissions, and
then another which has the permissions that are assigned to the appropriate
user? That way, you can have as many permissions as you need, and to be
quite honest, it's much easier to query and process in querying the
permissions (it's just two joins, and you just cycle through the permissions
in the client side code).

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"DotNetNewbie" <snowman908...@yahoo.comwrote in message

news:7e**********************************@d21g2000 prf.googlegroups.com...
On Dec 28, 9:46 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
DotNetNewbie wrote:
in my web application, I have to create permissions for each user. So
what I am doing is that for each role (using sqlmembership in .net) I
am creating a column in the database to hold a group of permissions
which I will then do some 'bit banging' in my web application to see
if the permission is set or not.
An int is 32 bits, and a long is 64.
I guess making the data type a long is smarter since it doesn't take
that much more space in the database, and it gives me 64 instead of 32
possible permissions correct?
What datatype in sql server would a long map too? And int is an int,
but long?
A C# long matches a SQLServer bigint.
You could use bitmaps as described.
But it is not a very relational way of storing data.
Arne

Yeah, that is the downside.

For example, if I wanted to do a SQL query for all users with a
particular permission, I'm guessing it would result in a complete
table scan.

ie. select * from users where permissions = (permissions & 0x02) (or
something like that).

One option would be to store each permission in a seperate table, and
then create a 'summary column' in the users table, this way I don't
have to do seperate queries for each user in my web application.
Nicholas,

The problem with that approach is that if I applying/checking for
permissions from INSIDE a stored procedure, it makes the subquery much
more combersome (as oppose to it being a simple bit check).
Dec 29 '07 #5
So you go back to having to remember what the values are for the
enumeration,
Just an aside; when you *do* have bitwise flags columns (which should
be rare), I find that the extended properties in SQL Server (such as
MS_Description) are a good place to note down what each bit means...
that way it will show automatically in a number of tools, and is
queryable via TSQL

Marc
Jan 7 '08 #6
On Jan 7, 3:23 am, "Marc Gravell" <marc.grav...@gmail.comwrote:
So you go back to having to remember what the values are for the
enumeration,

Just an aside; when you *do* have bitwise flags columns (which should
be rare), I find that the extended properties in SQL Server (such as
MS_Description) are a good place to note down what each bit means...
that way it will show automatically in a number of tools, and is
queryable via TSQL

Marc
Ok if I store the permissions in a normalized database way, how will I
be referencing the columns in my code.

ideally I want to do something like:
Permissions[userRoleID].AllowRead

Will I just have to map my class to the permissions table, or is there
a dynamic way of doing things? I could use a hashtable, that way I
won't have to keep updating my codebase when a new permission is
created...thoughts?
Jan 8 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: bart plessers | last post by:
Hello, For a while I am working with ThumbsPlus ( http://www.cerious.com/ ) as manager for pics. The benefit of the program is that it stores all kind of information in a central Microsoft...
1
by: bart plessers | last post by:
Hello, For a while I am working with ThumbsPlus ( http://www.cerious.com/ ) as manager for pics. The benefit of the program is that it stores all kind of information in a central Microsoft...
5
by: travelling_nerd | last post by:
Hi, I'm trying to write a script that will allow validated users to download a file that has specific ntfs permissions. Here's a summary: Scenario: 1) The name of the file is "binary.zip"....
3
by: Randy | last post by:
I have heard that access 2003 has functions for dealing with Long Binary Data. Does anyone know if this is true? Background: I am using 2000 with a table linked to a SQL server. One of the fields...
8
by: Jerry | last post by:
I have an off-the-shelf app that uses an Access database as its backend. One of the tables contains a field with an "OLE Object" datatype. I'm writing some reports against this database, and I...
4
by: Jens Mittag | last post by:
Hi! In my code, I have an array of a structure, which I want to save to a binary file. When the array is just created, everything works fine, but when I change contents of the array, saving...
5
by: Marc Gravell | last post by:
Short version: is it possible to control the endian-ness of BitConverter? - or are there any /framework/ methods like BigEndianBitConverter.GetBytes(long) and .ToInt64()? (I am not after...
0
by: S Wheeler | last post by:
Hi All - I am creating a upgrade utility that transfers an bin / exe image over an xml stream. But I can not seem to get the deserialization of the binary field to work correctly. What I have is...
35
by: fermineutron | last post by:
For a while now i have been "playing" with a little C program to compute the factorial of large numbers. Currently it takes aboy 1 second per 1000 multiplications, that is 25000P1000 will take...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.