📄 ch08.htm
字号:
the Data page to view the contents of the table, as shown in Fig-
ure 8.8.<BR>
<BR>
<A NAME="Heading25"></A><A HREF="08ebu08.jpg" tppabs="http://pbs.mcp.com/ebooks/0672310228/art/08/08ebu08.jpg">FIGURE 8.8.</A><FONT COLOR="#000077">
</FONT><I>Exploring the <TT>BioLife</TT> table in the Database Explorer.</I></P>
<P><BR>
Click the little plus symbol in front of the
<TT>BioLife.db</TT> node, and you will
see a list of properties for the <TT>BioLife</TT> table. The properties listed are
<TT>Fields</TT>, <TT>Indices</TT>, <TT>Validity Checks</TT>, <TT>Referential Constraints</TT>,
<TT>Security Specs</TT>, and
<TT>Family Members</TT>. You can expand each of these
nodes to view their properties. For instance, if you select the <TT>Fields</TT> node,
you will see a list of all the fields in the table. As you select each individual
field, you will see a
description of its primary characteristics.
<DL>
<DT></DT>
</DL>
<BLOCKQUOTE>
<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>The Database Explorer provides a
means for viewing the text of stored procedures and triggers. You cannot
edit these
values, but you can view their code.
<HR>
</BLOCKQUOTE>
<P>The Database Explorer is a fairly complex tool with a number of powerful traits,
many of which will undoubtedly be expanded in future versions of the product. In
particular,
you should note that it contains a <TT>DataDictionary</TT> that enables
you to define a new alias or modify existing aliases.</P>
<P>At this stage, I want to show you only one key trait of the Database Explorer.
Arrange your screen so you can view
both the Explorer and <TT>Form1</TT> at the same
time. Select the <TT>BioLife</TT> table in the Explorer with the mouse, and then
drag and drop it onto <TT>Form1</TT>. If you want, you can experiment further by
expanding the <TT>BioLife</TT> node in
the Explorer and dragging and dropping individual
fields of the table onto <TT>Form1</TT>, just as you did when using the Fields Editor.</P>
<P>If you start a new application, and then drag and drop the <TT>BioLife</TT> table
onto <TT>Form1</TT> from
the Explorer, you will find that the <TT>TTable</TT> and
<TT>TDataSource</TT> objects are placed on <TT>Form1</TT>. If you want to move them
off the form, you can add a <TT>TDataModule</TT> object to the project, and then
select both the
<TT>TTable</TT> and <TT>TDataSource</TT> objects and choose Edit
| Cut from the menu. Now select the <TT>TDataModule</TT> object and choose Edit |
Paste. Make sure <TT>Form1</TT> contains a reference (<TT>#include</TT>) to the unit
that contains the
<TT>TDataModule</TT>, and then hook up the grid to the <TT>TDataSource</TT>
object in the <TT>TDataModule</TT>. This sounds like a fairly complicated process
when written out, but you can perform this task in just a few seconds using BCB's
visual
tools.</P>
<P>Once again, the last few paragraphs have done nothing more than introduce you
to the Database Explorer. This is a complex tool that will prove useful to you in
many different ways, some of which might not even have been apparent to its
creator.
For now, the key point to grasp is that it gives you an overview of all the data
in a database and enables you to drag and drop fields and tables onto your forms.
<H3><A NAME="Heading27"></A><FONT COLOR="#000077">Working with the SQL
Monitor</FONT></H3>
<P>The SQL Monitor is an advanced tool that enables you to see exactly what SQL statements
are being generated by your application when you are running queries against SQL
databases such as InterBase. The SQL Monitor only works
when you are using an ODBC
connection or SQL links to access real databases such as InterBase, Oracle, Sybase,
or Informix. In other words, it is not useful when you are using the <TT>TTable</TT>
object, or when you are accessing Paradox or dBASE
tables.</P>
<P>There is no trick to using the SQL Monitor. If it ships with your version of BCB,
you can simply select the SQL monitor from the Database menu, run your program, and
then browse through the SQL Monitor to see the specific statements
generated by your
program.</P>
<P>Here is code produced from a simple SQL request for all the rows from the <TT>Customer</TT>
table from the <TT>IBLOCAL</TT> alias. Note that in this case I am using an InterBase
table. InterBase is an ANSI 92
SQL-compatible database server:</P>
<PRE><FONT COLOR="#0066FF">1 18:49:40 SQL Prepare: INTRBASE - select * from Customer
2 18:49:40 SQL Vendor: INTRBASE - isc_dsql_allocate_statement
3 18:49:40 SQL Vendor: INTRBASE -
isc_start_transaction
4 18:49:40 SQL Vendor: INTRBASE - isc_dsql_prepare
5 18:49:40 SQL Vendor: INTRBASE - isc_dsql_sql_info
6 18:49:40 SQL Vendor: INTRBASE - isc_vax_integer
7 18:49:40 SQL Transact: INTRBASE - XACT
(UNKNOWN)
8 18:49:40 SQL Vendor: INTRBASE - isc_commit_retaining
9 18:49:40 SQL Execute: INTRBASE - select * from Customer
10 18:49:40 SQL Vendor: INTRBASE - isc_dsql_execute
11 18:49:40 SQL Stmt: INTRBASE - Fetch
12
18:49:40 SQL Vendor: INTRBASE - isc_dsql_fetch
13 18:49:40 SQL Stmt: INTRBASE - Fetch
14 18:49:40 SQL Vendor: INTRBASE - isc_dsql_fetch
15 18:49:40 SQL Stmt: INTRBASE - Fetch
16 18:49:40 SQL Vendor: INTRBASE -
isc_dsql_fetch
17 18:49:40 SQL Stmt: INTRBASE - Fetch
18 18:49:40 SQL Vendor: INTRBASE - isc_dsql_fetch
19 18:49:40 SQL Stmt: INTRBASE - Fetch
20 18:49:40 SQL Vendor: INTRBASE - isc_dsql_fetch
21 18:49:40 SQL Stmt:
INTRBASE - Fetch
22 18:49:40 SQL Vendor: INTRBASE - isc_dsql_fetch
23 18:49:40 SQL Stmt: INTRBASE - Fetch
24 18:49:40 SQL Vendor: INTRBASE - isc_dsql_fetch
25 18:49:40 SQL Stmt: INTRBASE - Fetch
26 18:49:40 SQL
Vendor: INTRBASE - isc_dsql_fetch
27 18:49:40 SQL Stmt: INTRBASE - Fetch
28 18:49:40 SQL Vendor: INTRBASE - isc_dsql_fetch
29 18:49:40 SQL Stmt: INTRBASE - Fetch
30 18:49:40 SQL Vendor: INTRBASE - isc_dsql_fetch
31
18:49:40 SQL Stmt: INTRBASE - Fetch
32 18:49:40 SQL Vendor: INTRBASE - isc_dsql_fetch
</FONT></PRE>
<P>All this information can be a bit overwhelming at times. To simplify the output
from the SQL Monitor, select Options | Trace Options from
the SQL Monitor menu. The
dialog shown in Figure 8.9 is launched. You can then select just the first two, or
perhaps only the second option. The output from the same test run previously then
looks like this:</P>
<PRE><FONT COLOR="#0066FF">2
04:54:44 Log started for: Project1
3 04:55:02 SQL Prepare: INTRBASE - select * from customer
4 04:55:03 SQL Execute: INTRBASE - select * from customer
</FONT></PRE>
<P>Now you see only the prepare and execute statements, which is
probably all the
information you needed. A screen shot of the SQL Monitor with this simple information
in it is shown in Figure 8.10.</P>
<P>Once again, the SQL Monitor is only for use with powerful databases such as InterBase
or Oracle. I will
present in-depth discussions of InterBase later in this section
of the book.<BR>
<BR>
<A NAME="Heading28"></A><A HREF="08ebu09.jpg" tppabs="http://pbs.mcp.com/ebooks/0672310228/art/08/08ebu09.jpg">FIGURE 8.9.</A><FONT COLOR="#000077">
</FONT><I>The SQL Monitor Trace Options dialog is accessible from one of
the program's
speed buttons.</I>
<H6></H6>
<P><A NAME="Heading29"></A><A HREF="08ebu10.jpg" tppabs="http://pbs.mcp.com/ebooks/0672310228/art/08/08ebu10.jpg">FIGURE 8.10.</A><FONT COLOR="#000077">
</FONT><I>The SQL Monitor showing prepared and executed SQL statements.</I>
<H3 ALIGN="CENTER"></H3>
<H3><A
NAME="Heading30"></A><FONT COLOR="#000077">Understanding the BDE and Aliases</FONT></H3>
<P>The BDE is the Borland Database Engine, which used to be called IDAPI. This engine
is the gateway to all the databases accessed from BCB, except under certain
unusual
circumstances.</P>
<P>The BDE gives you direct access to Paradox and dBASE tables. If you own a copy
of Paradox or dBASE, you already have the BDE installed on your system. The brains
behind these two products is the BDE. Paradox and dBASE are
merely wrappers around
the BDE, in much the same way that the BCB IDE is a wrapper around a C++ compiler.</P>
<P>Besides giving you access to Paradox and dBASE, the BDE also uses Borland's SQL
Links technology to give you fast access to client/server
databases. In particular,
BCB ships with SQL Links drivers for InterBase, Oracle, Sybase, MS SQL Server, DB2,
and Informix.</P>
<P>The list of available client/server databases changes depending on the version
of the BDE you are using. To check the
current list, open up the BDE Configuration
application that ships with BCB and look at the available list of drivers. (See Figure
8.11.)<BR>
<BR>
<A NAME="Heading31"></A><A HREF="08ebu11.jpg" tppabs="http://pbs.mcp.com/ebooks/0672310228/art/08/08ebu11.jpg">FIGURE 8.11.</A><FONT COLOR="#000077">
</FONT><I>The Borland Database Configuration utility (<TT>BDECFG32.exe</TT>) provides
a list of available SQL Links drivers.</I></P>
<P><BR>
The BDE Configuration utility lists the actual files that contain the SQL Links drivers.
For instance, the SQL
Links driver for Oracle is called <TT>SQLORA32.dll</TT>. The
driver for InterBase is called <TT>SQLINT32.dll</TT>, and so on, as shown in Table
8.1. <BR>
<BR>
<B>Table 8.1. DLLs associated with various SQL drivers. </B>
<TABLE BORDER="1">
<TR
ALIGN="LEFT" rowspan="1">
<TD WIDTH="101" ALIGN="LEFT"><B>Database</B></TD>
<TD ALIGN="LEFT"><B>SQL Links driver names</B></TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="101" ALIGN="LEFT">DB2</TD>
<TD
ALIGN="LEFT"><TT>SQLDB232.dll</TT></TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="101" ALIGN="LEFT">Informix</TD>
<TD ALIGN="LEFT"><TT>SQLINF32.dll</TT></TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="101"
ALIGN="LEFT">InterBase</TD>
<TD ALIGN="LEFT"><TT>SQLINT32.dll</TT></TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="101" ALIGN="LEFT">MS SQL</TD>
<TD ALIGN="LEFT"><TT>SQLMSS32.dll</TT></TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD
WIDTH="101" ALIGN="LEFT">Oracle</TD>
<TD ALIGN="LEFT"><TT>SQLORA32.dll</TT></TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="101" ALIGN="LEFT">Sybase</TD>
<TD ALIGN="LEFT"><TT>SQLSSC32.dll</TT></TD>
</TR>
</TABLE>
<BR>
<BR>
The mere
presence of the preceding DLLs is not enough, however, to connect you to
a client/ server database. You will also need to be running a network protocol such
as TCP/IP, and you will need local drivers and tools for the database supplied by
the database
vendor. The next section of this chapter discusses setting up TCP/IP
on your computer.</P>
<P>Each vendor will have a different set of local drivers and tools for you to use.
For instance, if you want to connect to Oracle, you need to install the
Oracle SQL
Net tools.</P>
<P>Your copy of BCB comes with a local version of InterBase. If you look at the right-hand
portion of the taskbar at the bottom of your copy of Windows 95 or Windows NT, you
should see the green and gray icon for the
InterBase Server Properties applet. Other
InterBase applets include the InterBase Server Manager (<TT>IBMGR32.exe</TT>) and
InterBase Windows SQL (<TT>WISQL32.exe</TT>). (When reading these cryptic and inadvertently
humorous 8/3 executable names, you
should break the abbreviations up like this: <TT>IB-MGR-32.exe</TT>,
not like this: <TT>IBM-GR-32.exe</TT>.)</P>
<P>If you are running BCB, your connection to InterBase will be set up automatically
during program install. However, if you want to
connect to Oracle, Sybase, or some
other SQL server, you can be in for a rather complicated ordeal. The difficult part
of these installs is almost always setting up the third-party tools. Borland's half
of the equation is usually automatic, and occurs
without effort on your part during
BCB's install.</P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -