Solved

General C++/Database Programming Question

Posted on 1998-08-08
2
241 Views
Last Modified: 2010-04-02
I am using SQL Server 6.5, Visual C++, and COM to tackle a personal project.  I understand the use of Primary Keys, Foreign Keys nad other referential integrity mechanisms when designing a database.  But, in the COM world, where the business logic is often sandwiched between the data layer and the application layer, are referential integrity mechanisms commonly used?
My direct point is that it seems redundant for me to implement foreign keys in a SQL database design only to code the knowledge of these table relationships into my business COM objects.  I've consulted various texts and can find no information that helps me understand this area.
I'm not looking for a two page explanation, I'm a fairly sharp guy, but in six sentences or less could someone point me in the right direction?
Thanks.
0
Comment
Question by:Neil Kiser
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Expert Comment

by:yonat
ID: 1169745
See http://www.kinetica.com/ootips/persistent-objects.html for:
* A two-page explanation of the problems involved
* A list of commercial products that provide solutions
* Many links that can help you tailor your own solution
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 100 total points
ID: 1169746
You should still use the referential integrity mechanism in the database for a number of reasons :-

1. Are you sure that the COM code will be the only code that will ever access the database ?  For example if you do dataloads or reports on the database directly ever, or even might do, then this would be a big advantage.

2. Are you sure that the COM code will be right first time ?  If you're not (how could you be ? <g>) then adding constraints (and checking return values in your functions) will help you debug your COM code (for example if breaks a uniqueness constraint).  I would especially recommend this if you are writing the COM code in C or C++, but regardless of language this applies.

3. Are you sure that the COM code can not be "mis-used" ?  Unless you define your interfaces perfectly, could somebody in 1 year or 5 years time develop an application that used the COM functions in an unexpected order or with unexpected parameters that messed up your database ?

4. Are you sure that the COM code can never fail part way through a "logical" transaction ?  If the COM code crashes or fails half way through an operation the database code be left in a undefined state (example: orphaned records).  Using DB Transactions/Roll-back can help, but doesn't 100% prevent problems of this type, as how you use the database (or write your COM code) may not exactly fit in all cases "logical" transactions to the transactions as implemented through the database API.

Bottom line: use database integrity mechanisms for additional security, doing so will also help you debug & verify the COM code as correct.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question