Linux Programming--CD album Application (seventh chapter)

Source: Internet
Author: User

7.4 CD Application This is the seventh chapter of the CD application code that is downloaded in the CD application code. We use the DBM database to store data and improve the previous CD application.
7.4.1 Update Design Although storing information in a comma-delimited variable in a file is a very easy way to implement it in the shell, it is very limited because many CD titles and tracks contain commas. This method can be improved by using the DBM database.
Divide the CD data into two sections of titles and tracks and save them with different files.
There is a problem with the previous implementation, where the data access section of the application is mixed with the user Interface section, which is very much related to the full implementation of the program in a file. In this new implementation, a header file is used to describe the data and the routines used to access it, and the user interface code and the data processing code are placed in two files respectively.
Although you cannot use SQL statements in dbm code, you can use SQL terminology to describe a new database in a more formal way. The table can be described in the following code:
CREATE TABLE Cdc_entry (
Catalog CHAR (PRIMARY) KEY REFERENCES cdt_entry (catalog),
Title CHAR (70),
Type CHAR (30),
Artist CHAR (70)
);
CREATE TABLE Cdt_entry (
Catalog CHAR (REFERENCES) cdc_entry (catalog),
Track_no INTEGER,
Track_txt CHAR (70),
PRIMARY KEY (catalog, Track_no)
);
Each record in the Cdc_entry table has a unique catalog column. The track number in the Cdt_entry table cannot be 0, and the combination of catalog and trach_no two columns is unique.
7.4.2 the CD application using the DBM database re-implements the application by using the DBM database to store information. There are 3 files in the entire application, which are cd_data.h, APP_UI.C, and CD_ACCESS.C
Rewrite the user interface as a command-line program, later in this book, using different client/server mechanisms to implement the application, and eventually implementing it as an application that can be accessed across the network through a Web browser. Converting an interface into a simple command-line driver interface makes it easier to focus on the most important parts of the application, rather than on the user interface.
Writing CD_DATA.H defines the structure of the data and the routines used to access the data.
Write the APP_UI.C user interface, which is implemented in a separate file, using it to access database functions
Writing CD_ACCESS.C
Finally, all programs are combined with the following makefile file, and the contents of typing it are saved as makefile files:
All:application
include=/usr/include/gdbm
libs=gdbm
#On Some distributions need to change the above line to include the Compatability library, as show Belown.
#LIBS =-lgdbm_compat-lgdbm
cflags=
APP_UI.O:APP_UI.C cd_data.h
GCC $ (CFLAGS)-C APP_UI.C

ACCESS.O:ACCESS.C cd_data.h
GCC $ (CFLAGS)-i$ (INCLUDE)-C ACCESS.C

APPLICATION:APP_UI.O ACCESS.O
GCC $ (CFLAGS)-O application app_ui.o access.o-l$ (LIBS)

Clean
RM 0f Application *.O

Nodbmfiles:
Rm-f *.dir *.pag
Enter make, if the successful executable application will be compiled and placed in the current directory.
7.5 Summary This section, the first to learn the Linux memory system is only, although the on-demand paging virtual memory internal implementation is very complex, but its use is very simple. Learn how it protects the operating system and other processes against illegal memory access.
Second, this chapter describes how the file locking feature allows multiple programs to coordinate their work when accessing data. The first is a simple binary semaphore mechanism, then a shared lock and an exclusive lock to lock different parts of the same file.
The article then describes the DBM database, which has the ability to store and efficiently retrieve arbitrary chunks of data using a very flexible index layout.
Finally, the CD application was redesigned and implemented using DBM database for data storage technology.

Linux Programming--CD album Application (seventh chapter)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.