PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → Lookup Multiple data in Database Table
Lookup Multiple data in Database Table
Débuté par Ruan, 23 oct. 2014 11:14 - 12 réponses
Membre enregistré
208 messages
Popularité : +1 (1 vote)
Posté le 23 octobre 2014 - 11:14
Good day

I have a USER_RIGHTS table. It has a USER Column, PAGE Column and RIGHTS Column. How would I lookup to see that a user has the rights to look at a page? I know how to Find 1 bu using:

HReadSeekFirst(USER_RIGHTS,ID,EDT_USER
IF HFound(USER_RIGHTS) THEN
.......
END


How will I then tell it that now that you found the user look in that same table for the requested page, if that is found what is the RIGHTS....

IF rights = 1 THEN "Go to that page"
ELSE
Info("You do not have rights to view this page"
END


Thanks
Posté le 23 octobre 2014 - 11:55
Hi Ruan,

As far as I can understand you just have to merge your two pieces of code:

HReadSeekFirst(USER_RIGHTS,ID,EDT_USER
IF HFound(USER) THEN // Your table is named 'User'
IF USER.Rights = 1 THEN // If a record is found, the different elements are read also and therefore accessible
"Go to that page"
ELSE
Info("You do not have rights to view this page"
END
END


Or did you mean something else?

With kind regards,
Rudolf
Membre enregistré
208 messages
Popularité : +1 (1 vote)
Posté le 23 octobre 2014 - 12:18
Rudolf van Roosmalen wrote:
Hi Ruan,

As far as I can understand you just have to merge your two pieces of code:

HReadSeekFirst(USER_RIGHTS,ID,EDT_USER
IF HFound(USER) THEN // Your table is named 'User'
IF USER.Rights = 1 THEN // If a record is found, the different elements are read also and therefore accessible
"Go to that page"
ELSE
Info("You do not have rights to view this page"
END
END


Or did you mean something else?

With kind regards,
Rudolf


Hi

My Table is called USER_RIGHTS it has 3 columns called USER Column, PAGE Column and RIGHTS Column. I can find the user with the HReadSeekFirst Function but there are multiple lines for a user. It will say for "page MAIN" He has Rights and for "page TEST" he doesn't. When I click on the button to say I want to view "page MAIN" it must the look in the USER_RIGHTS table and say I FOUND you as User now can you access that page.....that's what I am struggling with. How do I tell it to Hreadseekfirst the user in that table if you find the user then look if the requested page has rights or not.

Hope this makes sense.

Thanks
Posté le 23 octobre 2014 - 14:11
Hi, Ruan,

In this case it is really a merge of your pieces of code

HReadSeekFirst(USER_RIGHTS,ID,EDT_USER)
IF HFound(USER_RIGHTS) THEN // Your table is named 'User_Rights' and you have found the user
IF USER_RIGHTS.Rights = 1 THEN // If the user_rights record is found, also the field USER_RIGHTS.RIGHTS is available (because HReadSeekFirst reads the whole record USER_RIGHTS)
"Go to that page"
ELSE
Info("You do not have rights to view this page"
END
Info ("You are unknown (we couldn't find you in the USER_RIGHTS-table")
END


So, if you have ONE record for a user and ONE definition of rights, the HReadSeekFirst finds the user and in USER_RIGHTS.RIGHTS you find the rights of that user. Then it is only a matter of definition. If USER_RIGHTS.RIGHTS = 1 then you allow this ELSE if USER_RIGHTS.RIGHTS = 2 then you allow that and so on.

With kind regards,
Rudolf
Membre enregistré
208 messages
Popularité : +1 (1 vote)
Posté le 23 octobre 2014 - 14:41
Rudolf van Roosmalen wrote:
Hi, Ruan,

In this case it is really a merge of your pieces of code

HReadSeekFirst(USER_RIGHTS,ID,EDT_USER)
IF HFound(USER_RIGHTS) THEN // Your table is named 'User_Rights' and you have found the user
IF USER_RIGHTS.Rights = 1 THEN // If the user_rights record is found, also the field USER_RIGHTS.RIGHTS is available (because HReadSeekFirst reads the whole record USER_RIGHTS)
"Go to that page"
ELSE
Info("You do not have rights to view this page"
END
Info ("You are unknown (we couldn't find you in the USER_RIGHTS-table")
END


So, if you have ONE record for a user and ONE definition of rights, the HReadSeekFirst finds the user and in USER_RIGHTS.RIGHTS you find the rights of that user. Then it is only a matter of definition. If USER_RIGHTS.RIGHTS = 1 then you allow this ELSE if USER_RIGHTS.RIGHTS = 2 then you allow that and so on.

With kind regards,
Rudolf


Hi Rudolf

You see that is just the problem there is more than one record per user - i.e if the code could do something like this:

HReadSeekFirst(USER_RIGHTS,ID,EDT_USER "AND" USER_RIGHTS,PAGE,EDT_PAGE_REQUESTED)
IF HFound(USER_RIGHTS) THEN // Your table is named 'User_Rights' and you have found the user
IF USER_RIGHTS.Rights = 1 THEN
"Go to that page"
ELSE
Info("You do not have rights to view this page"
END
Info ("You are unknown (we couldn't find you in the USER_RIGHTS-table")
END


It's getting it to look or find the right combination of the multiple records in that table.

Thanks
Posté le 23 octobre 2014 - 15:56
Hi Ruan,

Then the 'problem' is in the fact you only look for and only will find the first record with 'HreadSeekFirst'. You have to browse the table with something like (from the help-text):

HReadFirst(Customer, Name)
WHILE HOut(Customer) = False
// Process the record
HReadNext(Customer, Name)
END


Hope this helps,
Kind regards,
Rudolf
Posté le 23 octobre 2014 - 16:14
Hi Ruan

you need to declare a composite key on USER+Page

this way, a simple hreadseek(MyFile,MyCompositeKey,[File,Page]) will
give you thre precise record you are looking for

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

NEW: WXReplication, your open source replication system is available on
my web site!!!
WXShowroom.com: Show your projects!
More information on http://www.fabriceharari.com


On 10/23/2014 6:41 AM, Ruan wrote:
Rudolf van Roosmalen wrote:
Hi, Ruan,

In this case it is really a merge of your pieces of code

HReadSeekFirst(USER_RIGHTS,ID,EDT_USER)
IF HFound(USER_RIGHTS) THEN // Your table is named 'User_Rights' and
you have found the user
IF USER_RIGHTS.Rights = 1 THEN // If the user_rights record is found,
also the field USER_RIGHTS.RIGHTS is available (because HReadSeekFirst
reads the whole record USER_RIGHTS)
"Go to that page"
ELSE
Info("You do not have rights to view this page"
END
Info ("You are unknown (we couldn't find you in the USER_RIGHTS-table")
END


So, if you have ONE record for a user and ONE definition of rights,
the HReadSeekFirst finds the user and in USER_RIGHTS.RIGHTS you find
the rights of that user. Then it is only a matter of definition. If
USER_RIGHTS.RIGHTS = 1 then you allow this ELSE if USER_RIGHTS.RIGHTS
= 2 then you allow that and so on.

With kind regards,
Rudolf

Hi Rudolf

You see that is just the problem there is more than one record per user
- i.e if the code could do something like this:

HReadSeekFirst(USER_RIGHTS,ID,EDT_USER "AND"
USER_RIGHTS,PAGE,EDT_PAGE_REQUESTED) IF HFound(USER_RIGHTS) THEN // Your
table is named 'User_Rights' and you have found the user
IF USER_RIGHTS.Rights = 1 THEN "Go to that page"
ELSE
Info("You do not have rights to view this page"
END
Info ("You are unknown (we couldn't find you in the USER_RIGHTS-table")
END


It's getting it to look or find the right combination of the multiple
records in that table.
Thanks
Membre enregistré
208 messages
Popularité : +1 (1 vote)
Posté le 23 octobre 2014 - 17:13
Fabrice Harari wrote:
Hi Ruan

you need to declare a composite key on USER+Page

this way, a simple hreadseek(MyFile,MyCompositeKey,[File,Page]) will
give you thre precise record you are looking for

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

NEW: WXReplication, your open source replication system is available on
my web site!!!
WXShowroom.com: Show your projects!
More information on http://www.fabriceharari.com


On 10/23/2014 6:41 AM, Ruan wrote:
Rudolf van Roosmalen wrote:
Hi, Ruan,

In this case it is really a merge of your pieces of code

HReadSeekFirst(USER_RIGHTS,ID,EDT_USER)
IF HFound(USER_RIGHTS) THEN // Your table is named 'User_Rights' and
you have found the user
IF USER_RIGHTS.Rights = 1 THEN // If the user_rights record is found,
also the field USER_RIGHTS.RIGHTS is available (because HReadSeekFirst
reads the whole record USER_RIGHTS)
"Go to that page"
ELSE
Info("You do not have rights to view this page"
END
Info ("You are unknown (we couldn't find you in the USER_RIGHTS-table")
END


So, if you have ONE record for a user and ONE definition of rights,
the HReadSeekFirst finds the user and in USER_RIGHTS.RIGHTS you find
the rights of that user. Then it is only a matter of definition. If
USER_RIGHTS.RIGHTS = 1 then you allow this ELSE if USER_RIGHTS.RIGHTS
= 2 then you allow that and so on.

With kind regards,
Rudolf

Hi Rudolf

You see that is just the problem there is more than one record per user
- i.e if the code could do something like this:

HReadSeekFirst(USER_RIGHTS,ID,EDT_USER "AND"
USER_RIGHTS,PAGE,EDT_PAGE_REQUESTED) IF HFound(USER_RIGHTS) THEN // Your
table is named 'User_Rights' and you have found the user
IF USER_RIGHTS.Rights = 1 THEN "Go to that page"
ELSE
Info("You do not have rights to view this page"
END
Info ("You are unknown (we couldn't find you in the USER_RIGHTS-table")
END


It's getting it to look or find the right combination of the multiple
records in that table.
Thanks

Rudolf van Roosmalen wrote:
Hi Ruan,

Then the 'problem' is in the fact you only look for and only will find the first record with 'HreadSeekFirst'. You have to browse the table with something like (from the help-text):

HReadFirst(Customer, Name)
WHILE HOut(Customer) = False
// Process the record
HReadNext(Customer, Name)
END


Hope this helps,
Kind regards,
Rudolf



Hi Rudolf

This makes sense I will give it a try and let you know.

Thanks
Membre enregistré
208 messages
Popularité : +1 (1 vote)
Posté le 23 octobre 2014 - 17:15
Fabrice Harari wrote:
Hi Ruan

you need to declare a composite key on USER+Page

this way, a simple hreadseek(MyFile,MyCompositeKey,[File,Page]) will
give you thre precise record you are looking for

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

NEW: WXReplication, your open source replication system is available on
my web site!!!
WXShowroom.com: Show your projects!
More information on http://www.fabriceharari.com


On 10/23/2014 6:41 AM, Ruan wrote:
Rudolf van Roosmalen wrote:
Hi, Ruan,

In this case it is really a merge of your pieces of code

HReadSeekFirst(USER_RIGHTS,ID,EDT_USER)
IF HFound(USER_RIGHTS) THEN // Your table is named 'User_Rights' and
you have found the user
IF USER_RIGHTS.Rights = 1 THEN // If the user_rights record is found,
also the field USER_RIGHTS.RIGHTS is available (because HReadSeekFirst
reads the whole record USER_RIGHTS)
"Go to that page"
ELSE
Info("You do not have rights to view this page"
END
Info ("You are unknown (we couldn't find you in the USER_RIGHTS-table")
END


So, if you have ONE record for a user and ONE definition of rights,
the HReadSeekFirst finds the user and in USER_RIGHTS.RIGHTS you find
the rights of that user. Then it is only a matter of definition. If
USER_RIGHTS.RIGHTS = 1 then you allow this ELSE if USER_RIGHTS.RIGHTS
= 2 then you allow that and so on.

With kind regards,
Rudolf

Hi Rudolf

You see that is just the problem there is more than one record per user
- i.e if the code could do something like this:

HReadSeekFirst(USER_RIGHTS,ID,EDT_USER "AND"
USER_RIGHTS,PAGE,EDT_PAGE_REQUESTED) IF HFound(USER_RIGHTS) THEN // Your
table is named 'User_Rights' and you have found the user
IF USER_RIGHTS.Rights = 1 THEN "Go to that page"
ELSE
Info("You do not have rights to view this page"
END
Info ("You are unknown (we couldn't find you in the USER_RIGHTS-table")
END


It's getting it to look or find the right combination of the multiple
records in that table.
Thanks



Hi Fabrice

Not sure what this means? Can you help me a bit more please.

Thanks
Posté le 23 octobre 2014 - 17:45
Some documentation that could help you :

http://doc.windev.com/en-US/…
http://doc.windev.com/en-US/…

If you don't know composite-keys, you cannot do efficient job.

For example, when you create your file with user+PageName+right, you can declare that User+PageName is a UNIQUE composite-key.
So database will prevent you for inserting duplicate rows for one and the same user / PageName.

This concept of Composite-Key is not something specific to Windev, it exists for all databases.
Posté le 23 octobre 2014 - 19:16
Hi Ruan

if you do not understand what I meant, it means that you NEED to START
by reading in details the TUTORIAL that comes with windev. This will ou
give you a lot of basic information that you clearly need

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

NEW: WXReplication, your open source replication system is available on
my web site!!!
WXShowroom.com: Show your projects!
More information on http://www.fabriceharari.com


On 10/23/2014 9:15 AM, Ruan wrote:
Fabrice Harari wrote:
Hi Ruan

you need to declare a composite key on USER+Page

this way, a simple hreadseek(MyFile,MyCompositeKey,[File,Page]) will
give you thre precise record you are looking for

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

NEW: WXReplication, your open source replication system is available on
my web site!!!
WXShowroom.com: Show your projects!
More information on http://www.fabriceharari.com


On 10/23/2014 6:41 AM, Ruan wrote:
Rudolf van Roosmalen wrote:
Hi, Ruan,

In this case it is really a merge of your pieces of code

HReadSeekFirst(USER_RIGHTS,ID,EDT_USER)
IF HFound(USER_RIGHTS) THEN // Your table is named 'User_Rights' and
you have found the user
IF USER_RIGHTS.Rights = 1 THEN // If the user_rights record is found,
also the field USER_RIGHTS.RIGHTS is available (because HReadSeekFirst
reads the whole record USER_RIGHTS)
"Go to that page"
ELSE
Info("You do not have rights to view this page"
END
Info ("You are unknown (we couldn't find you in the USER_RIGHTS-table")
END


So, if you have ONE record for a user and ONE definition of rights,
the HReadSeekFirst finds the user and in USER_RIGHTS.RIGHTS you find
the rights of that user. Then it is only a matter of definition. If
USER_RIGHTS.RIGHTS = 1 then you allow this ELSE if USER_RIGHTS.RIGHTS
= 2 then you allow that and so on.

With kind regards,
Rudolf

Hi Rudolf

You see that is just the problem there is more than one record per user
- i.e if the code could do something like this:

HReadSeekFirst(USER_RIGHTS,ID,EDT_USER "AND"
USER_RIGHTS,PAGE,EDT_PAGE_REQUESTED) IF HFound(USER_RIGHTS) THEN // Your
table is named 'User_Rights' and you have found the user
IF USER_RIGHTS.Rights = 1 THEN "Go to that page"
ELSE
Info("You do not have rights to view this page"
END
Info ("You are unknown (we couldn't find you in the USER_RIGHTS-table")
END


It's getting it to look or find the right combination of the multiple
records in that table.
Thanks


Hi Fabrice
Not sure what this means? Can you help me a bit more please.

Thanks
Membre enregistré
208 messages
Popularité : +1 (1 vote)
Posté le 23 octobre 2014 - 21:58
Joel wrote:
Some documentation that could help you :

http://doc.windev.com/en-US/…
http://doc.windev.com/en-US/…

If you don't know composite-keys, you cannot do efficient job.

For example, when you create your file with user+PageName+right, you can declare that User+PageName is a UNIQUE composite-key.
So database will prevent you for inserting duplicate rows for one and the same user / PageName.

This concept of Composite-Key is not something specific to Windev, it exists for all databases.


Hi

Unfortunately this is now the first time I see this, I have never had the need for Composite-Keys until now. I read up on your links and thanks a lot - that is exactly what I need.

Thanks
Posté le 24 octobre 2014 - 16:33
Ruan a écrit :

Hi

Unfortunately this is now the first time I see this, I have never had the need for Composite-Keys until now. I read up on your links and thanks a lot - that is exactly what I need.

Thanks


Hi ,
I suggest you to read documentation. 1 hour per week.
Very often, I read Help.
Just read the list of titles in help ; it is enough.
By this, I don't know how to do something. But I know that it exists something, and I can find the help if I need.
And when I see a chapter with a word that I don't understand , I open this chapter, to memorize the topic of this chapter.