![]() |
Introduction to Databases |
|
List-Based Applications |
An application is referred to as list-based when its primary purpose is to let a user create and store one or more lists of items. The items can be of various kinds and the information they constitute is referred to as data. For this reason, this type of application is also called a database. A list that is part of a database application can be made of regular strings. Here is an example: |
Here is another example:
A list can also be a combination of various lists. Here is an example:
This type of list is called a table. As you can see, this table includes a list for the formats of the videos that seems to present categories of items. A technique used to create this type of table consists of "connecting" disparate lists that can exchange information with each other. An application that includes tables that are connected is referred to as a relational database.
Borland C++ Builder provides a (very) high level of support for database applications. It comes with an application called Database Desktop that allows you to create Paradox or dBase tables necessary for your database. Paradox and dBase tables are the easiest and the most accessible you can use in a VCL application. You can also use an external application such as Microsoft Access, FoxPro, etc. These two types of systems are usually referred to as desktop databases because they would be installed on users individual computers. Borland C++ Builder also support server-based, also referred to as enterprise, databases. These are databases that reside on a server and users must connect to them to use the application. The systems used to create these types of databases include InterBase, Microsoft SQL Server, Sybase, Oracle, DB2, etc. To make sure that we have everything we need for our lessons, we will use only Paradox and Microsoft SQL Server 2000 Desktop Engine, which will be referred to as MSDE for the rest of our lessons. The advantage of Database Desktop, as we mentioned already, is that it is already available with C++ Builder so you don't have to install or download it from somewhere. To launch Database Desktop, you can click the Start button on the taskbar -> (All) Programs -> Borland C++ Builder 6 -> Database Desktop. If C++ Builder is already opened, on the main menu of C++ Builder, you can click Tools -> Database Desktop. The advantages of MSDE include the fact that it is freely available and also it tremendously allows you to experiment with external databases. The techniques we will use for the MSDE can also be applied to an enterprise database such as Microsoft SQL Server. If you want to experiment with Microsoft SQL Server, you can down a trial version from the Microsoft web site. To get MSDE, go to the Microsoft web site and do a search on MSDE. A link will guide to the free download. After downloading it, make sure you install it.
The Database Desktop is an application used to create Paradox or dBase tables and other files to use in a VCL application. Before creating these tables and/or files, you must designate a folder where you would save them. A folder used to hold he objects of a Database Desktop application is called a Working Directory. When you start creating a database application, you would need to know where the tables reside. A working directory can also be shared so that many people who work in the same project can store the common files in it. When you install C++ Builder, it automatically creates various folders, both in Drive:\Program Files\Borland and in Drive:\Program Files\Common Files. It also creates a working directory named WorkDir as Drive:\Program Files\Common Files\Borland Shared\Database Desktop\WorkDir. You also can create a folder of your choice to hold your tables and files.
If you work in a multi-user environment, you may want to hold some of your files privately while testing them so that other people cannot corrupt them. To do this, you can create and use a folder of your choice. When C++ Builder gets installed, it also creates a private directory named PrivDir as Drive:\Program Files\Common Files\Borland Shared\Database Desktop\\PrivDir.
Because the full path of your working directory could be long to remember at times, you can create a name used to identity that directory. Such a name is called an alias. For example, instead of always trying to remember that your files are stored in Drive:\Customers Projects\Database Applications\College Park Auto Parts\Store Items, you can define a simple name such as cpap that you can use to identify this long path. To create an alias, in Database Desktop, you can click Tools -> Alias Manager from the main menu and click New. To proceed, in the Alias Manager dialog box, you must provide a name and specify the full path of the folder that the alias will represent. If you have created an alias that you don't need or don't use anymore, to delete it, display the Alias Manager dialog box. In the Database Alias combo box, select the alias and click Remove.
A database starts from a list of items. The list is also called a table. In a VCL application, probably the easiest way to create a table is by using Database Desktop. Because the tables created with Database Desktop are mostly Paradox and dBase objects, their tables are considered as files. As a file, the primary characteristic of a table is its name. The name must follow the rules of the operating system's file. Although the name of a table can start with a digit or an underscore, you should avoid using fancy names for tables as this can cause confusion when you start involving the names of these tables in your expressions.
To create a table, on the main menu of the Database Desktop window, you can click File -> New -> Table... This would display the Create Table dialog box. It allows you to specify the type of table you want to create. By default, it present you the option to create a Paradox 7 table. If you prefer another version of Paradox or you want to create a dBase table, you can click the arrow of the Table type combo box and select from the list: ![]() If you have Corel WordPerfect, you can also use its version of Paradox to create a table. To do this, when the Welcome dialog box of Paradox displays, you can first click New Database ![]() Second, you must specify the name and location of the new database. If you were not ready to create a database, you could close the Welcome dialog box. In both cases, once in Paradox, on the main menu, you could click File -> New -> Table... or, from the Project Viewer, you could right-click the Tables node and click New... When you select to create a new table, you can use a wizard to guide you.
Earlier, in our introduction, we saw that a table was a good technique to arrange a list of items by their categories. Here is the same example seen above:
The categories of items of a table are also referred to as columns. In this example, the first column, from left is labeled Video Title. The second column is labeled Director. The label in the top section of a column is also called its caption. In VCL applications, a column is also called a field. To reduce confusion and to synchronize the rest of these lessons with the VCL documentation, a column will be referred to as a field.
As an integral part of a table, every field must be explicitly created. The primary information you must provide for a field is a name and there are rules you must follow. If you are creating a Paradox table:
After respecting these rules, you can define your own. In our databases, here are the rules we will follow:
To specify the name of a field, under the Field Name, type the desired name and press either Enter or Tab.
When you have created a table and present it to the users for data entry, it is a good idea to control and know the kind of data that a user can enter for each category. For example, it is certainly a good idea to prevent the user from entering a first name where a salary is expected. The type of data that can be entered under a field is referred to as its data type. To specify the data type used for a field, under the Type column, if you are using Database Desktop, you can right-click or press the Space bar. If you are using Corel Paradox, you can click the arrow of the combo box under Field: ![]() To be able to exercise a great deal of control on the type of information that a user can enter in a table, you can apply an appropriate data type. Some data types are very explicit while some other can be vague. To support these types, both Paradox and dBase provide a list of available data types. The data types of a Paradox table are:
When performing data entry, you may want to control the number of characters that a user can enter enter a certain field. This is referred to as the size of a field. Most fields have a size but you can control only the size of string-based fields. This means that, only if you are creating an Alpha field should you pay attention to the size. Ignore this information for all the other type. To specify the size of a field, under Size, type the desired number.
Data entry consists of populating a table with the necessary values for its different fields. There are at least three techniques you can use to perform this operation: The Database Desktop, graphical objects created using a Borland C++ Builder application, or SQL.
To enter new data in a table using the Database Desktop, you can first open the table by clicking File -> Open -> Table... from the main menu and selecting the table. After selecting the desired table, you must first put it into edit mode. To do this, you can press F9 or click Table -> Edit Data from the main menu.
Probably the best option for data entry is to create a Windows application using Borland C++ Builder. This allows you to add visual controls that are more indicative and user-friendly. Fortunately, Borland C++ Builder makes this process particularly easy so much that you don't even have to write a single line of code but you can create a completely functional user interface using rapid application development RAD.
|
| Previous | Copyright © 2004-2007 Yevol | Next |