Saving and parsing boolean expressions in a database

this is the next question for my previous question which design template is suitable for this flow requirement? . I would like to know that it is best to store a boolean expression in a database and then evaluate it at runtime with little effort. I have a requirement when a set of tasks should be performed from the screen every month, and the decision on whether the task can be performed depends on the results of previous tasks. therefore, I should be able to save the expression in the database as E = (A or B) and (C or D) (there can be any complex nested expression). which means that E can work if A or B is successful and C or D is successful. how can this be presented in the database and analyzed and the condition will be evaluated later?

think about how to do it (not yet verified)
if "Work E = (A and B) or (C and D)". save it as a tree structure in a table

JobId DependentJobId SuccessJobId FailureJobId
Eabc              
ECD 0
ED 1 0
EB 1 0

this means that "if A succeeds, check B still check C", "if C successfully checks D". the process begins with the highest node, which does not have a value of "DependentJobId" and stops at the node sheet. I use dummy work identifiers “1” for success and “0” for failure. if the node leaf is zero, then the job is allowed to run. I don’t know how I can evaluate this in T-sql. I may have to use a recursive function.

Technology Used: ASP.NET 3.5, C # 3.0, SQL Server 2008

+3
source share
4 answers

, , . - , , , . , , . , . .

0

, , , . :

FLEE ( )

Linq

, Dynamic Linq , where, Linq/# . FLEE , , , , , Dynamic Linq.

+6

, - . , , . , .. MSDB. , SQL, , , . proc , - TSQL .

& (Bitwise AND) (Transact-SQL) 
~ (Bitwise NOT) (Transact-SQL) 
| (Bitwise OR) (Transact-SQL) 
^ (Bitwise Exclusive OR) (Transact-SQL)

E = (A B) (C D)

Select @E=(@A & @B) | (@C & @D)

, -.

declare @E bit
declare @Bit1 bit
declare @Bit2 bit
declare @Bit3 bit
declare @Bit4 bit
declare @Bit5 bit
SET @Bit1 = 1
SET @Bit2 = 0
SET @Bit3 = 1
SET @Bit4 = 'fALSE'
SET @Bit5 = 0

SELECT @Bit1, @Bit2, @Bit3, @Bit4, @Bit5

SELECT @Bit1 & @Bit2


 Select @E=(@Bit1 & @Bit2) | (@Bit3 & @Bit4)
 Select @E as [E value]
+1

Both macros and RC_Cleland have excellent answers. The only thing I would like to add is the ability to use the Windows Workflow Foundation to write a workflow for processing requirements.

+1
source

Source: https://habr.com/ru/post/1774933/


All Articles