Re: Retrieve data from DB
Re: Retrieve data from DB
- Subject: Re: Retrieve data from DB
- From: Chuck Hill <email@hidden>
- Date: Mon, 4 Dec 2006 17:35:33 -0800
On Dec 4, 2006, at 5:26 PM, email@hidden wrote:
Hi *,
I'm totally new to both, WO and this list
Welcome!
and am unfortunately about to make a rather unglamorous debut with
a complete noobie question.
I've tried to google, tried to find the information in the apple-
developer-docs...all to no avail. :(
Thank you for trying, it is appreciated.
Here goes:
Inside the logic of my little login algorithm i do:
EOEnterpriseObject aUser = EOUtilities.objectMatchingValues(ec,
"user", bindings);
This is all working fine and i can login when the user exists and
the correct password has been given.
But I also would like to check, whether or not the user logging in
is a site admin or not. For that, my 'user' entity has a third
attribute (besides "username" and "password") that is "admin".
Now...from what I've read I could apparently fetch all objects from
my db that have "admin = 1" and then see if my username appears
anywhere in that list but this seems insanely wrong since I already
have the object of interest in 'aUser'!?
So my noobness boils down to this question:
How do I get the value of the column "admin" for the
EOEnterpriseObject that's stored in 'aUser'?
Thank you all for your patience with noobs like me.
We tend to be pretty friendly.
I think you will like the answer to your question when you see it.
The problem you are running into is that
EOUtilities.objectMatchingValues returns an EOEnterpriseObject, not a
User. EOEnterpriseObject obviously knows nothing about user names,
password, or admin flags. The solution is simply to cast the result
so that the Java compiler knows what kind of object you have:
User aUser = (User) EOUtilities.objectMatchingValues(ec, "user",
bindings);
And then, ask it about admin
if (aUser.admin().booleanValue())
{
// code for admin users here
}
if the admin column is a character you will need something like this:
if (aUser.admin().equals("Y"))
{
// code for admin users here
}
Also, it is customary to make entity names start with an upper case
letter, so if you update your model, your code would say
User aUser = (User) EOUtilities.objectMatchingValues(ec, "User",
bindings);
Chuck
--
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems.
http://www.global-village.net/products/practical_webobjects
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden