Filling some data
In order to have some "dummy" data, fill in the following 4 records in the Type table: "Game", "Database", "Internet", "Graphics" Graphics)". These values will be used when selecting the application type stored in the applications table (applications). Next, add a row in the author table (Authors): 'Delphi Guide', '[email protected]', 'http://delphi.about.com'. Finally, add a row to the Applications table: 'Zoom', 'Zooming the Destop', 'Delphi Guide', 'Graphics', 10, 0, 02/20/2001, and make the last field (Photo ) is empty.
How to deal with these "blank" databases... will be explained in the remaining chapters of this tutorial.
Chapter 2 Connecting to the database, using ADO? BDE?
Section 1 Delphi Database Connectivity
As shown in the previous chapter, a database is a collection of one or more tables that store data in a structured format. These tables contain data in the form of rows and columns. When a database contains one or more tables, the tables typically hold discrete but related data. MS access, Interbase, and SQL Server use one file to represent a complete database (MS Access is a *.mdb file). Paradox and dBase, on the other hand, are defined by separate tables and files that represent indexes and table relationships. All files describing the Paradox database are usually stored in one directory. Of course, Delphi can work both ways.
Using Delphi, we can connect to different types of databases: local or C/S (remote server) database. The local database is stored on a local drive or in the local area network. The remote database server is usually located on a remote machine. Types of local databases include Paradox, dBase and MS Access. C/S database includes MS SQL Server, Interbase or Oracle.
Local databases are often referred to as single-tier databases. A single-tier database responds to any changes—editing data, inserting records, or deleting records—immediately. A single-tier database has limitations on the amount of data the table can hold and the number of users the application can support. When the database contains information about complex relationships between several tables, or when the number of clients increases, you need to use a two-tier or multi-tier application. The client application runs on the local machine; the application server often runs on the server, and the database may be located on another server. The idea behind a multi-tier architecture is that the client program can be very small because the application server can do a lot of the work. This allows you to write so-called thin client applications.
When we write a database application in Delphi, we need to use some database engine to access the data in the database. Databases allow you to focus on what data you are accessing, rather than how to access it. Since the first version, Delphi has provided BDE (Borland Database Engine) for database developers. In addition to BDE, starting from the fifth edition, Delphi provides support for Microsoft's ADO database interface.
This tutorial will focus on developing single-tier database applications with MSAccess local database.
Section 2 Borland Database Engine (BDE)
BDE is the common data access layer for all Borland products—including Delphi and C++Builder. BDE is a collection of DLLs (Dynamic Link Libraries) and tools. The beauty of it is that all data processing is transparent to the developer. BDE comes with a set of drivers that enable your application to communicate with many different types of databases. These drivers convert high-level database commands (such as open or post) and tasks (record locking or SQL structures) into specific commands required by a special database type: Paradox, dBase, MS Access or any ODBC data source. The BDE API (Application PROgramming Interface) contains more than 200 procedures and functions, which are available from the BDE unit. Fortunately, you almost never need to call these programs directly. Instead, you use BDE through the Data Access component of the VCL (Translator: Visual Component Library)—the Data Access page located in the Component Panel. In order to access a particular database, an application only needs to know the database alias (Alias) to access all data in that database. The alias is created in the BDE Administrator and specifies the drive parameters and database location. BDE comes with a set of database drivers that can access a wide range of different types of data elements. Standard BDE drivers include Paradox, dBase, MS Access, and ASCII text. Of course, any ODBC driver can also be used by BDE through the ODBC Administrator.
Delphi applications that use BDE to access databases require BDE to be distributed for the application. When configuring an application's BDE, you must use InstallShield Express or another Borland-specific installer.
BDE as a database engine has its advantages and disadvantages. However, why and when you should (or shouldn't) use BDE methods instead of certain non-BDE techniques will not be discussed in this tutorial.
Since this tutorial discusses ADO/MSAccess, the remainder of the tutorial will focus on this non-BDE approach to databases.
December 22, 2002