SQL数据库外文翻译
- 格式:doc
- 大小:90.00 KB
- 文档页数:27
Working with Databases
This chapter describes how to use SQL statements in embedded applications to control databases. There are three database statements that set up and open databases for access: SET DATABASE declares a database handle, associates the handle with an actual database file, and optionally assigns operational parameters for the database.
SET NAMES optionally specifies the character set a client application uses for CHAR, VARCHAR, and text Blob data. The server uses this information to
transli terate from a database’s default character set to the client’s character set on SELECT operations, and to transliterate from a client application’s character set to the database character set on INSERT and UPDATE operations.
g CONNECT opens a database, allocates system resources for it, and optionally assigns operational parameters for the database.All databases must be closed before a program ends. A database can be closed by using DISCONNECT, or by appending the RELEASE option to the final COMMIT or ROLLBACK in a program. Declaring a database
Before a database can be opened and used in a program, it must first be declared with SET DATABASE to:
CHAPTER 3 WORKING WITH DATABASES. Establish a database handle. Associate the database handle with a database file stored on a local or remote node.A database handle is a unique, abbreviated alias for an actual database name. Database handles are used in subsequent CONNECT, COMMIT RELEASE, and ROLLBACK RELEASE statements to specify which databases they should affect. Except in dynamic SQL (DSQL) applications, database handles can also be used inside transaction blocks to qualify, or differentiate, table names when two or more open databases contain identically named tables.
Each database handle must be unique among all variables used in a program. Database handles cannot duplicate host-language reserved words, and cannot be InterBase reserved words.The following statement illustrates a simple database declaration:
EXEC SQL
SET DATABASE DB1 = ’employee.gdb’;
This database declaration identifies the database file, employee.gdb, as a database the program uses, and assigns the database a handle, or alias, DB1.
If a program runs in a directory different from the directory that contains the database file, then the file name specification in SET DATABASE must include a full path name, too. For example, the following SET DATABASE declaration specifies the full path to employee.gdb:
EXEC SQL
SET DATABASE DB1 = ’/interbase/examples/employee.gdb’;
If a program and a database file it uses reside on different hosts, then the file name specification must also include a host name. The following declaration illustrates how a Unix host name is included as part of the database file specification on a TCP/IP network:
EXEC SQL
SET DATABASE DB1 = ’jupiter:/usr/interbase/examples/employee.gdb’;
On a Windows network that uses the Netbeui protocol, specify the path as follows: EXEC SQL
SET DATABASE DB1 = ’//venus/C:/Interbase/examples/employee.gdb’; DECLARING A DATABASE
EMBEDDED SQL GUIDE 37
Declaring multiple databases
An SQL program, but not a DSQL program, can access multiple databases at the same time. In multi-database programs, database handles are required. A handle is used to:
1. Reference individual databases in a multi-database transaction.
2. Qualify table names.
3. Specify databases to open in CONNECT statements.
Indicate databases to close with DISCONNECT, COMMIT RELEASE, and ROLLBACK RELEASE.