473,322 Members | 1,403 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,322 software developers and data experts.

recursive function


I've a table of users like this

id_user id_ref flg_enabled
1 0 1
2 1 1
3 1 0
4 2 1

id_user 1 created id_user 2 and 3
id_user 2 created id_user 4

This rule can by infinite

I need a recursive function that tells me when a user and all his "fathers"
are enabled
If one of its father is disabled (flg_enabled=0) the function have to return
0
If all the father (till id_ref=0) are enabled (flg_enabled=1) the function
have to return 1

function is_enabled(id_user)
.....
End Function

Can you please help me?

Thanks

Nov 23 '05 #1
3 1980
I would think one of your many employees could do this for you, Microsoft.

Microsoft wrote:
I've a table of users like this

id_user id_ref flg_enabled
1 0 1
2 1 1
3 1 0
4 2 1

id_user 1 created id_user 2 and 3
id_user 2 created id_user 4

This rule can by infinite

I need a recursive function that tells me when a user and all his
"fathers" are enabled
If one of its father is disabled (flg_enabled=0) the function have to
return 0
If all the father (till id_ref=0) are enabled (flg_enabled=1) the
function have to return 1

function is_enabled(id_user)
....
End Function


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Nov 23 '05 #2

I think I've some missing configuration in my outlook express, that's why
you see "Microsoft"
"Dave Anderson" <GT**********@spammotel.com> ha scritto nel messaggio
news:ON**************@TK2MSFTNGP14.phx.gbl...

I would think one of your many employees could do this for you, Microsoft.

Microsoft wrote:
I've a table of users like this

id_user id_ref flg_enabled
1 0 1
2 1 1
3 1 0
4 2 1

id_user 1 created id_user 2 and 3
id_user 2 created id_user 4

This rule can by infinite

I need a recursive function that tells me when a user and all his
"fathers" are enabled
If one of its father is disabled (flg_enabled=0) the function have to
return 0
If all the father (till id_ref=0) are enabled (flg_enabled=1) the
function have to return 1

function is_enabled(id_user)
....
End Function


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message.
Use of this email address implies consent to these terms. Please do not
contact me directly or ask me to contact you directly for assistance. If
your question is worth asking, it's worth posting.


Nov 23 '05 #3
Microsoft wrote:
I've a table of users like this

id_user id_ref flg_enabled
1 0 1
2 1 1
3 1 0
4 2 1

id_user 1 created id_user 2 and 3
id_user 2 created id_user 4

This rule can by infinite

I need a recursive function that tells me when a user and all his
"fathers" are enabled
If one of its father is disabled (flg_enabled=0) the function have to
return 0
If all the father (till id_ref=0) are enabled (flg_enabled=1) the
function have to return 1

function is_enabled(id_user)
....
End Function


If you are using MS SQL Server, you can use a user-defined function:

CREATE FUNCTION dbo.is_enabled(
@ID INT
) RETURNS BIT AS
BEGIN
DECLARE @Product INT, @Parent INT

SELECT @Product = flg_enabled,
@Parent = id_ref
FROM YourTable
WHERE id_user = @ID

IF @Parent > 0 SET @Product = @Product * dbo.is_enabled(@Parent)
RETURN @Product
END

Test your results:

SELECT *, dbo.is_enabled(id_user) AS is_enabled FROM YourTable

Results:

id_user id_ref flg_enabled is_enabled
1 0 1 1
2 1 1 1
3 1 0 0
4 2 1 1
5 3 1 0
6 2 0 0
7 4 1 1
Be aware that SQL Server "only" allows 32 levels of recursion, so if an
element has 32 "fathers", this will fail.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Nov 28 '05 #4

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

Similar topics

2
by: | last post by:
OK: Purpose: Using user's input and 3 recursive functions, construct an hour glass figure. Main can only have user input, loops and function calls. Recursive function 1 takes input and displays...
4
by: Nicolas Vigier | last post by:
Hello, I have in my python script a function that look like this : def my_function(arg1, arg2, opt1=0, opt2=1, opt3=42): if type(arg1) is ListType: for a in arg1: my_function(a, arg2,...
4
by: Victor | last post by:
Hello, I've got a situation in which the number of (valid) recursive calls I make will cause stack overflow. I can use getrlimit (and setrlimit) to test (and set) my current stack size. ...
9
by: Bill Borg | last post by:
Hello, I call a function recursively to find an item that exists *anywhere* down the chain. Let's say I find it five layers deep. Now I've got what I need and want to break out of that whole...
9
by: Csaba Gabor | last post by:
Inside a function, I'd like to know the call stack. By this I mean that I'd like to know the function that called this one, that one's caller and so on. So I thought to do: <script...
41
by: Harry | last post by:
Hi all, 1)I need your help to solve a problem. I have a function whose prototype is int reclen(char *) This function has to find the length of the string passed to it.But the conditions...
10
by: AsheeG87 | last post by:
Hello Everyone! I have a linked list and am trying to include a recursive search. However, I am having trouble understanding how I would go about that. I don't quite understand a recursive...
4
by: ThEoNeAnDOnLy | last post by:
I recently had an issue with my recursive project in class. Here is the code. // Recursion.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include...
3
by: from.future.import | last post by:
Hi, I encountered garbage collection behaviour that I didn't expect when using a recursive function inside another function: the definition of the inner function seems to contain a circular...
3
by: Davy | last post by:
Hi all, Sometimes I need to pass same parameter in recursive function. From my point of view, the style is redundant, and I don't what to use some global style like self.A, self.B, Is there any...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.