Insert Pattern

mwightman

Member
Joined
Aug 18, 2007
Messages
9
Programming Experience
10+
For inserts into a table with defined constriants is it proper to test the consraints prior to inserting a new record or just catch the exception.


Option 1

Data Layer psudo code

Function Exists(Item) boolean
Sub Add(Item)

UI

If Not Exists(item) then
Add(Item)
Else
Show Message


Option 2

Data Layer
Sub Add(Item)

UI

Try

Add(Item)

Catch

Show Message
 
For bulk loading, test first, thereby saving the network resources required to upload data to a DB that the DB is only going to choke on.

For single edits, the simplicity of catching the error outweighs the resource consumption advantage of checking ahead of time
 
Back
Top