12.12.2012 Views

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>C++</strong>Builder Database Architecture<br />

A good application of cached updates is <strong>in</strong> data-entry forms. There are three basic types of<br />

database forms: decision-support forms, transaction-process<strong>in</strong>g forms, and data-entry forms.<br />

Because users of data-entry forms will typically add several rows <strong>in</strong> succession, it makes sense<br />

to cache these additions locally and then save them <strong>in</strong> one pass. This will reduce table lock<strong>in</strong>g<br />

on your database and speed up the application.<br />

Updat<strong>in</strong>g read-only TDatasets is covered <strong>in</strong> the discussion of the UpdateSQL component later<br />

today.<br />

On...Error<br />

The OnEditError, OnDeleteError, and OnPostError events allow you to react to errors that<br />

occur while modify<strong>in</strong>g the data <strong>in</strong> a TDataset. These events all send the same three parameters<br />

to handlers you def<strong>in</strong>e for them: the TDataset <strong>in</strong> which the error occurred, the exception class<br />

raised by the error, and a var parameter that lets you specify what action to take once the<br />

handler f<strong>in</strong>ishes. Here’s a sample of the method handler that <strong>C++</strong>Builder generates for the<br />

On...Error events:<br />

void __fastcall TForm1::Table1DeleteError(TDataset *TDataset,<br />

EDatabaseError *E, TDataAction &Action)<br />

{<br />

}<br />

You can set Action to one of three values: daFail, daAbort, or daRetry.<br />

TQuery<br />

Module: DBTables Class ancestor: TDBDataSet<br />

Like TTable, TQuery is a direct descendant of the DBDataSet class and an <strong>in</strong>direct descendant<br />

of the TDataset class. You use TQuery to send explicit SQL statements to the database eng<strong>in</strong>e.<br />

This SQL either operates on local tables or is passed directly to your database server. You<br />

execute a query that returns a result set us<strong>in</strong>g TQuery’s Open method or by sett<strong>in</strong>g its Active<br />

property to true. Provided that the query adheres to <strong>C++</strong>Builder’s restrictions on “live”<br />

queries, you can then treat the result set as if it were a table, which is similar to the way a SQL<br />

VIEW works on many database servers. You can update, add to, and delete the rows <strong>in</strong> this live<br />

result set, just as you can when us<strong>in</strong>g a TTable component.<br />

Table 12.11 lists the key properties, Table 12.12 lists the key methods, and Table 12.13 lists<br />

the key events for the TQuery component.<br />

451<br />

12

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!