Article View: borland.public.cppbuilder.database.ado
Article #3899Re: Client/Server Database Scenario Question
From: David Johnson
Date: Tue, 18 Jun 2002 04:00
Date: Tue, 18 Jun 2002 04:00
130 lines
6998 bytes
6998 bytes
Steve Kothenbeutel wrote:
> (1) several customers come into the store to purchase the same item
> unknowing of each other's desire for the same product. They all go to
> seperate salespeople and each salesperson brings the inventory up. Each
> customer then decides to purchase the same item The salesperson realizes
> there is only one left. So, he sets up the transaction. However, the other
> sales personnel are doing the same thing. So, here is my question... how do
> I commit the product to a sales person while he fills out pertinent
> information about the customer? How do I ensure that the item will be there
> once all information is filled out and stored in the server? If I use
> transactions for this, how would I implement this measure?
databse.startTransaction
CanReserve.ParamByname ('CatalogNo').Value := aCatalogNo;
CanReserve.ExecSql;
{ select onhand, committed
from inventory
where CatalogNo = :CatalogNo
with cs
// with cs is DB2 for with cursor stability - this establishes a record lock
until commit
// Interbase may have another switch
}
if reserveitem.committed >= ReserveItem.onhand then
begin
databse.commit; // commit is faster than rollback. No changes have been
made
raise Exception.Create ('Insufficient stock');
end
else begin
reserveitem.ParamByname ('CatalogNo').Value := aCatalogNo;
Reserveitem.ExecSql
{ update inventory
set committed = (committed+1)
where CatalogNo = :CatalogNo
}
database.Commit; // This commits the changes and frees the record so others
can use it
end;
//-------------------
// To convert take the reserved items out of inventory
database.starttransaction
try
for each item in the invoice do
begin
removeReserved.Params.ParamByname ('reserveCount').value := xxx;
removeReserved.Params.ParamByname ('CatalogNo').Value := aCatalogNo;
removeReserved.ExecSql;
{ update inventory
set committed = committed - :ReserveCount,
onhand = onhand = :ReserveCount
where CatalogNo = :CatalogNo
}
end;
database.Commit
except
on E:Exception do
database.Rollback;
raise;
end;
end;
Hint: To prevent deadlock always lock/update tables in alphabetical order
within a transaction. Why alphabetical? It's easy to remember.
(2) lets say that I have 5 salespeople employed by this store. One sales
> person is fired. Within the database, there is a record of all sales
> completed by that employee. In creating the database, should I invoke a
> relationship between the employee's id in a seperate employee's table with
> that of the transaction? Or should I just store the identity of the
> employee in the transaction without any relationship established between the
> two tables? If I decide to delete the salesperson from the database and if
> a relationship exists between the two tables, wouldnt that also force a
> delete of all sales made by the employee? And if it doesnt force the
> deletion of transactions, then would the salesperson's ID field within the
> table be left empty?
>
In a commercial application NEVER delete a record except as a last resort to
fix data that has been incorrectly submitted, or as the last part of a
warehousing transaction. Mark the records as inactive instead. I use a
timestamp to mark the records as inactive so I not only know it is inactive but
when it was inactivated. An employee has a hire date and a termination date.
The termination date may differ from the inactivation timestamp. An employee
is only active if his termination date is NULL or less than the current date.
Hint: Convert all timestamps to UTC (Grenwich time) using Window's time
settings. This will aid in synchronizing application data across time zones.
>
> (3) When packing is necessary, should I take the middleware server offline
> or can I execute a pack procedure while sales personnel have access to the
> database?
Database maintenance operations should always be carried out "off line". If
your site is 24x7 then you may want to consider transferring transaction data
from a "current" database to a "warehouse" database whenever it is more than a
certain age. We use two weeks as our age, and run the warehouse job nightly.
Our shop is 24x7.
>
> (4) Lets say that I have data on my sales personnel in the same database
> file as all transactions and related information. Is there a way to lock
> tables in the database from being deleted while I execute mass deletion
> routines?
Interbase and other serious DBMS' permit databases and tables to cross file
spaces, so the concept of "file" has no meaning in this context.
Since your transaction is entirely through SQL, you can only delete a table by
submitting the SQL "delete table xxx from database". You can't accidentally
delete a table.
Why would you ever, apart from warehousing and fixing faulty data from an
application bug, delete data from a commercial database? Auditability
requirements (taxation, etcetera) require that the information be kept on file
for seven years, and disk space is cheap. In Access you start to worry when
your DB gets over 100K. With interbase I don't know what the limit is, but
each file may get up to 2 GB, and each database may span several files. In DB2
I support a database that is 8 terabytes in size and runs about a million
transactions per hour.
With good indexing, you should be able to keep query access times down to two
to three I/O's on even the largest tables.
Technical Details
Message-ID:
<3D0EB073.81375BBA@worldnet.att.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!supernews.com!nntp2.aus1.giganews.com!nntp.giganews.com!news.maxwell.syr.edu!news-han1.dfn.de!news-koe1.dfn.de!news.rwth-aachen.de!news.uni-stuttgart.de!nntp.cs.uni-magdeburg.de!PeerFeed.KWeb.on.ca!dnewsReferences:
<3d09fdce_2@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fcd2b,106f0349709b129a X-Google-Attributes: gidfcd2b,public X-Google-Thread: f6386,106f0349709b129a X-Google-Attributes: gidf6386,public X-Google-Thread: 10698b,106f0349709b129a X-Google-Attributes: gid10698b,public X-Google-Thread: 10b980,106f0349709b129a X-Google-Attributes: gid10b980,public X-Google-ArrivalTime: 2002-06-17 21:01:40 PST Message-ID: <3D0EB073.81375BBA@worldnet.att.net> Date: Mon, 17 Jun 2002 23:00:51 -0500 From: David Johnson <swift99@worldnet.att.net> X-Mailer: Mozilla 4.75 [en] (X11; U; Linux 2.2.16-22 i686) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.database.ado,borland.public.cppbuilder.database.multi-tier,borland.public.delphi.database.interbaseexpress,borland.public.delphi.database.multi-tier Subject: Re: Client/Server Database Scenario Question References: <3d09fdce_2@dnews> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 12.74.162.149 X-Trace: dnews 1024372698 12.74.162.149 (17 Jun 2002 20:58:18 -0700) Lines: 131 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!supernews.com!nntp2.aus1.giganews.com!nntp.giganews.com!news.maxwell.syr.edu!news-han1.dfn.de!news-koe1.dfn.de!news.rwth-aachen.de!news.uni-stuttgart.de!nntp.cs.uni-magdeburg.de!PeerFeed.KWeb.on.ca!dnews