English 中文(简体)
Users need to create dynamic rules that apply to other users access to the group
原标题:

Okay so here is "in a nutshell" what I m trying to accomplish...

Users of my application can go and create a new group. They can specify criteria about other users which they will allow/deny to determine who is allowed to join the group.

Example: Age: 12 - 16 yrs old Height: 5 - 6 feet

The data table that stores the rules would be like: Allow or Deny Flag (Y/N) AgeStart: 12 AgeEnd: 16 HeightStart: 5 HeightEnd: 6

We would then need to check if the user meets the criteria to determine if they are allowed to join the group.

Does this make sense? There can also be EXCEPTION rules which go against it... such as first "Allow: Y" might be Ages 12 to 30 but a second record might be added to Deny ages 25 to 28 so the user would have to meet both criteria to enter.

Any takers on this one?

问题回答

Yes, you can store the rules in your database using whatever kind of DSL makes sense to you, but SQL is not a solution for interpreting or enforcing the rules.

It ll be far easier to fetch the rules field into your app and interpret it there. You ll have access to feature-rich parser libraries to interpret the rule, and easier ways to write OO code to apply it.

Since you only need to run the rule as a user tries to join a group, it shouldn t be a great performance cost to run a query to fetch the rule definition. It ll certainly be a lot less costly than trying to implement a rule parser and enforcer in SQL!

Another way of thinking about this is: a database stores data, not code. You can fudge this by storing the definition of rules as strings in the database, but let the database treat these as verbatim strings, not try to integrate them as code that the RDBMS can execute.





相关问题
How to write this T-SQL WHERE condition?

I ve got two tables: TableA Col1 Col2 TableB Col3 Col4 I want to join them together: SELECT * from TableA join TableB ON (...) Now, in place of ... I need to write an expression ...

Customer and Order Sql Statement

TSQL query to select all records from Customer that has an Order and also select all records from customer that does not have an Order. The table Customer contains a primary key of CustomerID. The ...

Recommended way of querying multiple Versioned tables

Have a win 2003 box with MSSQL 2005 running on it. There is a database which is populated every morning with new/modified SalesOrder made the previous day. The database has several tables: SalesOrder, ...

update duplicate record

I have a table with the following fields Id Name IsPublic i need to write a sql query that updates IsPublic to false where name has a duplicate. Only one of the duplicates should have IsPublic = ...

Define variable to use with IN operator (T-SQL)

I have a Transact-SQL query that uses the IN operator. Something like this: select * from myTable where myColumn in (1,2,3,4) Is there a way to define a variable to hold the entire list "(1,2,3,4)"? ...

Selecting records during recursive stored procedure

I ve got a content management system that contains a hierarchical structure of categories, with sub-categories subject to different ordering options at each level. Currently, that s retrieved by a (...

热门标签