Click here to Skip to main content
15,891,253 members
Articles / Programming Languages / Visual Basic

Object-Oriented database design with the DatabaseObjects library

Rate me:
Please Sign up or sign in to vote.
4.00/5 (6 votes)
31 Jan 20076 min read 110.1K   3.9K   64  
Demonstrates creating object-oriented database systems with the DatabaseObjects library.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><!-- InstanceBegin template="/templates/function.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Database Objects</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
<link href="default.css" rel="stylesheet" type="text/css">
</head>

<body>
<h1>

<h1><!-- InstanceBeginEditable name="heading" -->DatabaseObjects<!-- InstanceEndEditable --></h1>
<h3><!-- InstanceBeginEditable name="subheader" --> ObjectSave(<span class="keyword">ByVal</span>    objCollection <span class="keyword">As</span> IDatabaseObjects, 
  <span class="keyword">ByVal</span> objItem <span class="keyword">As</span> IDatabaseObject)<!-- InstanceEndEditable --><br>
</h3>
</h1>

<!-- InstanceBeginEditable name="text" -->
<p> ObjectSave extracts the fields to save to the database from the SaveFields
  function. ObjectSave then writes the object's record to the database. If the
  object has
  not yet been
  saved to the database then a new record
  is inserted. If the
  object has already been saved then the record is amended.
  The objCollection argument is the collection associated with
  the
  objItem.
  If the collection has implemented <a href="IDatabaseObjects_KeyFieldName.htm">DatabaseObjects_KeyFieldName</a> then
  objItem's key is checked to ensure it is not null and  is unique within
  the collection. If the objCollection has implemented the <a href="IDatabaseObjects_Subset.htm">IDatabaseObjects_Subset</a> function
  then  objItem should exist within objCollection. If not, a duplicate
  key error may occur if the obItem's key is being used in another subset in
  the
  same table. </p>
<p>If a record is being amended (<a href="IDatabaseObject_IsSaved">IDatabaseObject_IsSaved </a>returns
    true) then the function will  AND the collection's <a href="IDatabaseObjects_Subset.htm">IDatabaseObjects_Subset</a> conditions
    and the objItem's <a href="IDatabaseObject_DistinctValue.htm">IDatabaseObject_DistinctValue</a> value
    to create the WHERE clause in the UPDATE statement. Therefore, the combination
    of the <a href="IDatabaseObjects_Subset.htm">IDatabaseObjects_Subset</a> and <a href="IDatabaseObject_DistinctValue.htm">IDatabaseObject_DistinctValue</a> conditions
    MUST  identify only one record in the table. Otherwise multiple records will
    be updated with the same data. If data is only inserted
    and not amended (usually
    a rare occurance) then
    this requirement
    is
    unnecessary.</p>
<!-- InstanceEndEditable --><font face="Courier New, Courier, mono">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td bgcolor="#f6f6f6"><pre><!-- InstanceBeginEditable name="example" -->
<span class="comment">'<font face="Courier New, Courier, mono">T</font>his is typ<font face="Courier New, Courier, mono">ically </font>how the Object<font face="Courier New, Courier, mono">Save function is used.
</font>'i<font face="Courier New, Courier, mono">.e. in the Product class the </font>following would be used:
</span>
<span class="keyword">Public Sub </span>Save()

    <span class="comment">'Save this product to the products table</span>
    <font face="Courier New, Courier, mono">DBO</font>.ObjectSave gobjGlobalProdu<font face="Courier New, Courier, mono">ctsInstance</font>, Me<font face="Courier New, Courier, mono">

<span class="keyword">End Sub</span></font>

<!-- InstanceEndEditable --></pre></td>
  </tr>
</table>
</font>

<p>&nbsp;</p>
<p align="center"><font size="1">�  Hi Integrity Systems 2005. All rights reserved.</font></p>
</body>

<!-- InstanceEnd --></html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions