⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch15.htm

📁 好书《C++ Builder高级编程技术》
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>

<HEAD>
	<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">
	<META NAME="Author" Content="Steph Mineart">
	<TITLE>Ch 15 -- Working with the Local InterBase Server</TITLE>

</HEAD>

<BODY BACKGROUND="bg1.gif" tppabs="http://pbs.mcp.com/ebooks/0672310228/buttonart/bg1.gif" BGCOLOR="#FFFFFF">

<P ALIGN="CENTER"><IMG SRC="sams.gif" tppabs="http://pbs.mcp.com/ebooks/0672310228/buttonart/sams.gif" WIDTH="75" HEIGHT="24" ALIGN="BOTTOM"
BORDER="0"><BR>
<BR>
<A HREF="index-3.htm" tppabs="http://pbs.mcp.com/ebooks/0672310228/index.htm"><IMG SRC="toc.gif" tppabs="http://pbs.mcp.com/ebooks/0672310228/buttonart/toc.gif" WIDTH="40" HEIGHT="40" 
ALIGN="BOTTOM"
ALT="TOC" BORDER="0" NAME="toc4"></A><A HREF="ch14.htm" tppabs="http://pbs.mcp.com/ebooks/0672310228/ch14.htm"><IMG SRC="back-1.gif" tppabs="http://pbs.mcp.com/ebooks/0672310228/buttonart/back.gif"
WIDTH="40" HEIGHT="40" ALIGN="BOTTOM" ALT="BACK" BORDER="0" NAME="toc1"></A><A HREF="ch16.htm" tppabs="http://pbs.mcp.com/ebooks/0672310228/ch16.htm"><IMG
SRC="forward.gif" tppabs="http://pbs.mcp.com/ebooks/0672310228/buttonart/forward.gif" WIDTH="40" HEIGHT="40" 
ALIGN="BOTTOM" ALT="FORWARD" BORDER="0"
NAME="toc2"></A><BR>
</P>
<H2 ALIGN="CENTER"><FONT COLOR="#000077">Charlie Calvert's C++ Builder Unleashed</FONT></H2>
<P>
<H2 ALIGN="CENTER"><A NAME="Heading1"></A>- <FONT COLOR="#000077">15 -</FONT></H2>
<H2 
ALIGN="CENTER"><A NAME="Heading2"></A><FONT COLOR="#000077">Working with the
Local InterBase Server</FONT></H2>
<P>
<H3><A NAME="Heading3"></A><FONT COLOR="#000077">Overview</FONT></H3>
<P>BCB ships with the Local InterBase Server, which is sometimes 
simply called LIBS.
This tool provides all the capabilities of the full InterBase server, but it runs
on a local machine. You do not need to be connected to a network to be able to run
the Local InterBase Server.</P>
<P>The client software you get 
with BCB will talk to either LIBS or the standard
version of the InterBase Server. From your point of view as a programmer, you will
find no difference at all between talking to LIBS and talking to an InterBase server
across a network. The only way to 
tell which server you're connected to is by examining
the path in your current alias. In short, LIBS is the perfect tool for learning or
practicing real client/server database programming even if you're not connected to
a LAN.</P>
<P>The goal of this 
chapter is to provide you with a useful introduction to LIBS
and also a brief overview of transactions. In particular, you will see how to do
the following:

<UL>
	<LI>Connect to local InterBase tables
	<P>
	<LI>Connect without having to specify a 
password
	<P>
	<LI>Create databases
	<P>
	<LI>Work with <TT>TDatabase</TT> objects
	<P>
	<LI>Create tables
	<P>
	<LI>Commit and roll back transactions in both local and InterBase tables
	<P>
	<LI>Maintain the data you have created
	<P>
	<LI>Work with 
cached updates
	<P>
	<LI>Create many-to-many relationships
</UL>

<P>Everything that is said about the local InterBase in this chapter applies equally
to the full server version of InterBase. As a result, this chapter will also be of
interest to 
people who use InterBase on a network. In particular, this chapter shows
how you can use a local system to create a database that is fully compatible with
the network version of InterBase. To convert a LIBS database to a real client/server
application 
on a network, you just have to copy your database onto another machine:</P>
<PRE><FONT COLOR="#0066FF">copy MyDatabase.gdb p:\remote\nt\drive

</FONT></PRE>
<P>You just copy the one file onto the network. No other steps are necessary, other
than 
changing the path in your alias. Of course, you will also need a real copy of
the InterBase server.</P>
<P>Note that some versions of BCB ship with at least two licenses for the InterBase
server. The real InterBase server runs on most platforms, 
including Windows 95, Windows
NT, and a wide range of UNIX platforms.</P>
<P>Many readers of this book will come from the world of &quot;big iron,&quot; where
the only kinds of databases that exist are servers such as Oracle, Sybase, InterBase,
AS400, 
or DB2. Other readers come from the world of PCs, where tools such as dBASE,
Paradox, Access, or FoxPro are considered to be the standard database tools. Overemphasizing
the huge gap that exists between these two worlds is almost impossible.</P>

<P>Readers who are familiar with &quot;big iron&quot; and large network-based servers
are likely to find the Local InterBase Server very familiar. Readers who come from
the world of PCs are likely to find InterBase very strange indeed, especially at

first.</P>
<P>InterBase is meant to handle huge numbers of records, which are stored on servers.
It does not come equipped with many of the amenities of a tool such as dBASE or Paradox.
In fact, InterBase supplies users with only the most minimal 
interface and instead
expects you to create programs with a client-side tool such as BCB. However, you
will find that InterBase is not a particularly difficult challenge, after you get
some of the basics under your belt.
<H3><A 
NAME="Heading4"></A><FONT COLOR="#000077">Databases and the Job Market</FONT></H3>
<P>Having been in this business for a while, I know that most of the readers of this
book probably work inside a corporation or at a small company. However, if you are

a student or someone who wants to enter the computer programming world, you should
pay special attention to the material in this, and other, chapters on InterBase.</P>
<P>Perhaps 80 percent of the applications built in America today use databases in

one form or another. Indeed, most of these applications revolve around, and are focused
on, manipulating databases. Furthermore, client/server databases such as InterBase,
Oracle, or MS SQL Server form the core of this application development.</P>

<P>If you want to enter the programming world, getting a good knowledge of databases
is one of the best ways to get started. Right now, there is virtually an endless
need for good database programmers.</P>
<P>One note of caution should perhaps be 
added here. I happen to enjoy database programming.
However, it is not the most romantic end of the computer business. If you're primarily
interested in systems programming or games programming, then you should hold out
for jobs in those fields rather 
than focus your career in an area of only minor interest
to you.</P>
<P>Databases, however, offer the greatest opportunity for employment. In particular,
client/server database programmers are almost always in demand. Because LIBS ships
with your copy 
of BCB, you have a great chance to learn the ins and outs of this
lucrative field.
<H3><A NAME="Heading5"></A><FONT COLOR="#000077">Setting Up the Local InterBase</FONT></H3>
<P>LIBS is installed for you automatically when you install BCB. In most 
cases, InterBase
will run smoothly without any need for you to worry about setup. However, you should
take several key steps to ensure that all is as it should be.</P>
<P>First, find out if LIBS is running. By default, it will load into memory every

time you boot up the system. If you're running Windows 95 or NT 4.0, you should see
LIBS as a little splash of green on the system tray to the right of the toolbar.
On Windows NT 3.51, an icon appears at the bottom of your screen. Whatever shape
it 
takes on your system, just click this green object, and you will see a report
on the Local InterBase Server configuration.</P>
<P>You need to know where your copy of LIBS is installed. Most likely, it is in the
<TT>..\PROGRAM 
FILES\BORLAND\INTRBASE</TT> subdirectory on the boot drive of your
computer. For example, my copy of the local InterBase is in <TT>C:\PROGRAM FILES\BORLAND\INTRBASE</TT>.
To find out for sure, open the InterBase Configuration applet that ships with 
BCB.
It will report on the InterBase root subdirectory and enable you to change that directory
if need be.</P>
<P>To find this same information in the Registry, run <TT>REGEDIT.EXE</TT> and open
<TT>HKEY_LOCAL_MACHINE/SOFTWARE/BORLAND/INTERBASE</TT>. 
Several nodes report on the
location of your server and other related information.</P>
<P>In the <TT>INTRBASE</TT> subdirectory, you will find a copy of a file called <TT>INTERBAS.MSG</TT>.
You should also be able to locate a copy of 
<TT>GDS32.DLL</TT> somewhere on your
system, most likely in the <TT>..\WINDOWS\SYSTEM</TT> subdirectory, but possibly
in either your <TT>BDE</TT> or <TT>INTRBASE</TT> subdirectory.</P>
<P>A common problem occurs when InterBase users end up with more 
than one copy of
<TT>GDS32.DLL</TT>. If you work with the networked version of InterBase, you probably
already have a copy of the InterBase Client on your system. If this is the case,
you should make sure that you don't have two sets of the file 
<TT>GDS32.DLL</TT>
on your path. On my system, I use the copy of <TT>GDS32.DLL</TT> that comes with
the local InterBase. These tools communicate with both LIBS and the full networked
version of InterBase. This setup works fine for me. However, the 
point is not which
version you use, but only that you know which version is on your path and that you
have only one version on your system at a time.</P>
<P>To find out which version you are currently using, run the InterBase Communications

Diagnostics Tool that ships with BCB. Use the Browse button to find the <TT>EMPLOYEE.GDB</TT>
file, which is probably located in the <TT>..PROGRAM FILES\BORLAND\INTRBASE\EXAMPLES</TT>
subdirectory. Enter <TT>SYSDBA</TT> as the user name and 
<TT>masterkey</TT> as the
password, all lowercase. (This example assumes that you have not changed the password
from its default value.) You should get the following readout, or something like
it:</P>
<PRE><FONT COLOR="#0066FF">Path Name      = 
C:\WINDOWS\SYSTEM\gds32.dll

Size           = 348672 Bytes

File Time      = 04:10:00

File Date      = 12/18/1995

Version        = 4.1.0.6

This module has passed the version check.

Attempting to attach to C:\Borland\Intrbase\EXAMPLES\Employee.gdb

    
Attaching      ...Passed!

    Detaching      ...Passed!

InterBase versions for this connection:

InterBase/Windows NT (access method), version &quot;WI-B4.1.0&quot;

on disk structure version 8.0

InterBase Communication Test Passed!

</FONT></PRE>

<P>The key piece of information you're getting here is the location of <TT>GDS32.DLL</TT>.

<DL>
	<DT></DT>
</DL>



<BLOCKQUOTE>
	<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>Readers who want to connect to the
	full server version of 
InterBase will find that the procedure I have just outlined
	works fine, except that you must have a network protocol such as TCP/IP loaded first.
	This book includes a description of the wizardry needed to set up a TCP/IP network
	protocol 
successfully in Chapter 8, &quot;Database Basics and Database Tools.&quot;
	As I explained in that chapter, this task is usually handled automatically by either
	Windows 95 or Windows NT, though it helps to have a few extra tips to guide you through
	
the process. I should add that setting up an InterBase connection is usually a fairly
	straightforward process when compared to setting up other servers. 
<HR>


</BLOCKQUOTE>

<P>The most obvious thing that can go wrong with an InterBase connection 
is simply
that it is not being started automatically when you start Windows. If you are having
trouble, try simply pointing the Explorer to the <TT>IntrBase/bin</TT> subdirectory
and clicking the <TT>IBServer.exe</TT> icon. The trouble could be that 
all is set
up correctly, but for some reason the server is not currently running on your machine!
<H3><A NAME="Heading7"></A><FONT COLOR="#000077">Setting Up an InterBase Alias</FONT></H3>
<P>In the preceding section, you learned how to run a 
diagnostic tool to be sure
you are connected to InterBase. This section deals with the issue of making sure
that the BDE is connected to InterBase. In other words, that section dealt with making
sure that InterBase was running correctly on your 
machine; this section deals with
making sure BCB is connected to InterBase. You should also check the readme file
on the CD that accompanies this book for general information about setting up aliases
for the programs supplied in this book.</P>

<P>After you have the local InterBase set up, you should take a few minutes to make
sure the connection to the BDE is working correctly. In particular, you should make
sure an alias points to one of the sample tables that ship with LIBS. For example,

after a normal full installation of BCB, you should have an alias called <TT>IBLOCAL</TT>
that points to the <TT>EMPLOYEE.GDB</TT> file.</P>
<P>In the next few paragraphs, I describe how to set up an alias identical to the
<TT>IBLOCAL</TT> alias, 
except you can give it a different name. To begin, open the
Database Explorer and turn to the Databases page. Select the first node in the tree,
the one that's called <TT>Databases</TT>. Choose Database | New, and then select
IntrBase as the Database 
Driver Name in the New Database Alias page dialog. Click
OK.</P>
<P>Name the new alias <TT>TESTGDB</TT>, or give it whatever name you prefer. The
<TT>ServerName</TT> property for this alias should be set to</P>
<PRE><FONT COLOR="#0066FF">c:\program 
files\borland\intrbase\examples\employee.gdb

</FONT></PRE>
<P>You can adjust the drive letter and path to reflect the way you have set up the
files on your machine.</P>
<P>The user name should be set to <TT>SYSDBA</TT>, and the default password you 
will
use is <TT>masterkey</TT>. (If someone has changed the password on your system, then
use the new password.) All the other settings in the Database Explorer can have their
default values, as shown in Figure 15.1. After you have everything set up 
correctly,
choose Database | Apply.<BR>
<BR>
<A NAME="Heading8"></A><A HREF="15ebu01.jpg" tppabs="http://pbs.mcp.com/ebooks/0672310228/art/15/15ebu01.jpg">FIGURE 15.1.</A><FONT COLOR="#000077">
</FONT><I>A sample InterBase alias as it appears in the Database Explorer.</I></P>
<P>After you have set up and 
saved your alias, you can connect to the <TT>TESTGDB</TT>
alias exactly as you would with any other set of data. From inside the Explorer,
just click the plus symbol before the <TT>TESTGDB</TT> node. A dialog will pop up
prompting you for a password. 
Make sure the user name is set to <TT>SYSDBA</TT>,
and then enter <TT>masterkey</TT> as the password. Everything else will then be the
same as when working with a Paradox table, except that you will find many new features
such as stored procedures and 
triggers. Most of these new features will be described
in this chapter and the next.</P>
<P>To connect to the database from inside BCB proper, first drop a table onto a form,
and set its <TT>DatabaseName</TT> property to <TT>TESTGDB</TT>. When you try 
to drop
down the list of <TT>TableNames</TT>, you will be prompted for a password. You should
enter <TT>masterkey</TT> at this point, all in lowercase. Now drop down the list
again and select a table. After taking these steps, you can set the 
<TT>Active</TT>
property for <TT>Table1</TT> to <TT>True</TT>. If this call succeeds, everything
is set up correctly, and you can begin using the local InterBase to create BCB database
programs. If you can't set <TT>Active</TT> to <TT>True</TT>, you 
should go over the
steps outlined previously and see whether you can correct the problem.

<DL>
	<DT></DT>
</DL>



<BLOCKQUOTE>
	<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>I usually use <TT>SYSDBA</TT> and
	<TT>masterkey</TT> as the 
user name and password combination for the InterBase databases
	in this book. However, I sometimes work with <TT>USER1</TT> and <TT>USER1</TT> instead,
	simply because typing <TT>USER1</TT> is easier than typing <TT>masterkey</TT>. One
	way to change 
the sign on criteria for InterBase is via the InterBase Server Manager.
	This, and other tools, will be discussed in Chapter 16, &quot;Advanced InterBase
	Concepts.&quot; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -