I'm just wondering what are some best practices for returning values after
an actual database operation. I have a data layer object that handles doing
things such as inserts and updates to actual database records. For instance,
I have a InsertPage(Page) method that takes an instance of a 'Page' object
and does a database insert. What should I be returning from the InsertPage()
method? Should it be:


1. a boolean indicating success of failure
2. id of new record
3. a structure containing the following keys:
        - status (success or failure)
        - error (structure with type and message keys)
        - obj (the updated object)
        - timestamp
4. something else?


For me, it's #4 -- something else.


I wrap my method calls themselves in a cftry/cfcatch statement and trap for any errors (read: not the query itself). If the database throws an exception, then it's up to me to account for the different ways it might fail (i.e., duplicate primary key) in my calling code and trap the returned error code accordingly. That's obviously for inserts, updates, and deletes. If it's a select statement, then I use a returntype of query and go from there.

If you use cftry/cfcatch, then everything you'd want out of #3 is available to you is the cfcatch structure that's generated.

That's just the way I do it. Others may have their own preferences.

Regards,
Dave.

_________________________________________________________________
Help protect your PC. Get a FREE computer virus scan online from McAfee. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' in the message of the email.


CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]

Reply via email to