Re: DatabaseAccess
Re: DatabaseAccess
- Subject: Re: DatabaseAccess
- From: Arturo PĂ©rez <email@hidden>
- Date: Wed, 12 May 2004 08:25:12 -0400
On May 12, 2004, at 12:30 AM, WELEMSKI wrote:
Hi, I am new to webObjects I have this problem which I havn't figured
out yet. I am a php programmer before I switch to webObjects...
There's a lot of things you will need to unlearn from php to transition
successfully to WebObjects. Your question below illustrates one of
them.
How am I able to fetch all the data on the database in to an array
type of variable so I can compare the data in the future.
You almost never want to do this. What if you had 1 million users in
the database?
e.g. in php we have " mysql_fetch_array($result_query) " where the
"$result_query" is the result of the mysql queries ;
$result_query=mysql_query("SELECT * FROM tblname");
Usually, to do anything related to the database with WebObjects you
need to model the database with EoModeller. Have you done that yet?
So I could compare the data in the future when the value of the
database if the data are already fetched in the variable.
The database performs this type of comparison much better than you
could. Just taking your sample code above you should be doing (in
php-speak)
$result_query=mysql_query("SELECT * FROM tblname where
username=$user");
But until you model your database with EOModeller there's not much for
WebObjects to offer you in this respect.
I am making a database where the username is unique I want the
webObjects to identify if the username is in use or not and redirected
to another page or else save the data in to the database..
My WebObjects code for this would look like (assuming I've modeled the
database)
NSArray array =
EOUtilities.objectsMatchingKeyAndValue(session().defaultEditingContext()
, "Customers", "username", enteredUserName);
if (array.count() > 0)
return pageWithName("UserNameAlreadyTaken");
else
return pageWithName("UsersHomePage");
You really really need to read the documentation.
----
WO in philadelphia - wanna cheesesteak with that?
Please visit webobjects.meetup.com.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.