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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

database server supports, unless you <strong>in</strong>tend for the result set to be updatable. If you want an<br />

updatable result set, you must use Local SQL syntax so that the database eng<strong>in</strong>e can<br />

determ<strong>in</strong>e which database tables to actually update.<br />

The SQL statement can be a static SQL statement or one that <strong>in</strong>cludes parameters that are<br />

dynamically replaced with real values. A query that uses replaceable parameters (known as a<br />

dynamic SQL query) uses a colon to del<strong>in</strong>eate those parameters, like so:<br />

SELECT * FROM ORDERS<br />

WHERE CustomerNumber=:CustNo<br />

In this example, CustNo is the name of the replaceable parameter. You supply these named<br />

parameters us<strong>in</strong>g TQuery’s Params property.<br />

TIP<br />

When edit<strong>in</strong>g TQuery’s SQL property, you can edit your SQL us<strong>in</strong>g<br />

<strong>C++</strong>Builder’s full-blown Code Editor. You do this by click<strong>in</strong>g the Code<br />

Editor button from with<strong>in</strong> the SQL property editor. You’ll f<strong>in</strong>d<br />

<strong>C++</strong>Builder’s Code Editor to be much more versatile than the TMemo<br />

component that’s used to edit the property by default.<br />

The Constra<strong>in</strong>ed property enables you to control what updates may be made to a live result<br />

set. If you set Constra<strong>in</strong>ed to true, updates that would cause a row to be excluded from the<br />

result set are not permitted. That is, if you set up a Query component to return only those<br />

customers whose last names beg<strong>in</strong> with A, an attempt to change the LastName column <strong>in</strong> a row<br />

to start with B will fail. This works much the same as the WITH CHECK option on SQL VIEWs.<br />

Tasks<br />

To establish a live, or updatable, result set, two th<strong>in</strong>gs must happen. First, you must set<br />

TQuery’s RequestLive property to true. Second, the SQL you use to def<strong>in</strong>e the query must<br />

conform to certa<strong>in</strong> rules. These rules are different, depend<strong>in</strong>g on whether you are query<strong>in</strong>g<br />

local tables. For local tables, the SQL must<br />

■ Use Local SQL syntax only.<br />

■ Involve only one table.<br />

■ Not have an ORDER BY clause.<br />

■ Not conta<strong>in</strong> aggregate functions.<br />

■ Not conta<strong>in</strong> calculated fields.<br />

■ Use a WHERE clause <strong>in</strong>volv<strong>in</strong>g comparisons of column names to scalar constants<br />

only. Operators supported <strong>in</strong>clude LIKE, >, =, and

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

Saved successfully!

Ooh no, something went wrong!