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_u ser)
.....
End Function
Can you please help me?
Thanks 3 2001
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_u ser) .... 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.
I think I've some missing configuration in my outlook express, that's why
you see "Microsoft"
"Dave Anderson" <GT**********@s pammotel.com> ha scritto nel messaggio
news:ON******** ******@TK2MSFTN GP14.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_u ser) .... 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.
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_u ser) .... 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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 a sequence of spaces;
recursive function 2 uses input to display ascending sequence of digits;
likewise, recursive function 3 uses input to display descending sequence of
digits.
I have not followed the instructions completely regarding the...
|
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, opt1=opt1, opt2=opt2, opt3=opt3)
return
if type(arg2) is ListType:
|
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. However, it is not as
straightforward to determine the base address for my stack space. The
approach I have taken is to save the address of an automatic variable
in main( ), and assume this is a fairly good indicator of my base
address. Then, I can...
|
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 stack and continue execution at the point of
the initial call. Is that possible?
Thanks,
Bill
|
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 type='text/javascript'>
function myFunc(lev) {
// if (lev) return myFunc(lev-1);
var aStack=;
nextFunc = arguments.callee;
| |
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 are that no local variable or global variable should be
used.I have to use recursive functions.
|
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 search....would any of you be so
kind to explain it to me...maybe include some examples.
I would GREATLY appreciate it!!!
|
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 <conio.h>
#include <iostream>
using namespace std;
|
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 reference, which means
it is only collected by the mark-and-sweep collector, not by reference
counting. Here is some code that demonstrates it:
===
def outer():
|
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 other choice?
For example,
def func(self, x, y, A, B, C):
#x, y change in recursive call
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |