1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu Oracle Unleashed- P18 ppt

50 200 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

■ Reducing Oracle Communication Overhead ■ Reducing Processing Overhead ■ New Features in Version 1.4 ■ Summary 50 Oracle Precompilers Extracting and manipulating data from a relational database would be very difficult if not for tools such as precompilers. The precompiler allows SQL statements to be embedded within procedural languages. Applications developed with this tool can use the best features of SQL, combined with the best features of the procedural language, creating a powerful module. This chapter discusses Oracle precompilers, creating a source program and some of the new features that Version 1.4 precompilers have. Oracle Precompilers The precompiler is a mechanism that allows SQL statements to be embedded within procedural languages. This tool provides the programmer with unlimited capabilities. To fully understand all the benefits of this tool, this chapter will focus on why we precompile, general features of the precompiler, what languages source code can be written in, how standardized are the precompilers, what options do they have, how to precompile your source code, and what is conditional precompiling. Why Precompile Source Code? Embedded SQL statements are not something a high-level language understands. The precompiler must therefore take the SQL statements and translate them into something the high-level language will understand. Libraries contain data structures that help guide the translation process for consistency. This general concept will help in understanding the precompiler features. General Precompiler Features One of the primary reasons to use a precompiler is to have the capability of utilizing SQL statements in a high-level language. Oracle precompilers offer many benefits and features that can help in this development. These features include the following: ● Source code can be written in six different high-level languages, which all have ANSI/ISO precompilers. ● Using a precomplier enables a user to take advantage of dynamic SQL, which allows for a more highly customized application. ● [lb] Precompilers enable a user to process PL/SQL transaction blocks and use host arrays to process large amounts of data quickly; both dramatically improve performance. ● Precompilers make conversions between Oracle internal datatypes and language datatypes, and check syntax and semantics. ● Precompilers may also include conditional parameters to enable the program to be executed in different environments. ● Direct interfaces with SQL*Forms can be done using user exits. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ● Precompilers provide variables to handle warning and error conditions, which are included in the ORACLE Communication Area (ORACA). Each of these features will be discussed in further detail later in the chapter. But you should know how many precompilers Oracle has before too much more detail is given. Precompiler Languages There are six procedural languages for which Oracle has precompilers available. During installation of Oracle, the host language is determined and the appropriate compiler is installed. The six languages include the following: ● Ada ● C ● COBOL ● FORTRAN ● Pascal ● PL/I With Oracle precompilers, you have the capabilities of precompiling and compiling several host programs, then linking them together into one module. Each program does not need to be written in the same language to be linked together, so standardization is a must. Oracle precompilers do meet national standards and will be discussed in the next section. ANSI/IO Standards Because SQL has become the standard language for relational databases, standardization has become an important issue. Oracle precompilers have taken exceptional efforts to meet standards set by the following organizations: ● American National Standards Institute (ANSI) ● International Standards Organization (ISO) ● U.S. National Institute of Standards and Technology (NIST) Compliance for these requirements is measured by NIST, which uses over 300 test programs. Oracle precompilers have conformed to these standards by checking the SQL statements that are being embedded for standard syntax and semantics. But there is much more to precompiler function than syntax checking. Precompiler Options To increase flexibility among applications, Oracle precompilers have options that can be manipulated by the programmer to allow for certain conditions. For example, if a line of the source program exceeds 80 characters, an error occurs while precompiling. There is a precompiler option that allows the programmer to extend that line to 132 characters. These controls, along with others, are outlined in Table 50.1. The * character next to an item indicates that it can be entered inline. Table 50.1. Precompiler options. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Syntax Default Specifies COMMON_NAME=block_name Name of FORTRAN common blocks DEFINE=symbol Symbol used in conditional precompilation ERRORS=YES|No* YES Whether errors are sent to the terminal FORMAT=ANSI|TERMINAL ANSI Format of COBOL or FORTRAN input line HOLD_CURSOR=YES|NO* NO How a cursor cache handles SQL statements HOST=C COB74 COBOL FORTRAN PASCAL PLI Host language INAME=path and filename Name of input file INCLUDE=path * Directory path for the INCLUDEd files IRECLEN=integer 80 Record length of input file LINES=YES|NO NO Whether C #line directives are generated LITDELIM=APOST QUOTE* QUOTE Delimiter for COBOL strings LNAME=path and filename Name of listing file Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. LRECLEN=integer 132 Record length of listing file LTYPE=LONG SHORT NONE LONG Type of listing MAXLITERAL=integer* Maximum length of string MAXOPENCURSORS=integer* 10 Maximum number of cursors cached MODE=ORACLE ASNI ANSI13 ANSI14 ISO ISO13 ISO14 ORACLE Compliance with ANSI/ISO standard ONAME=path and filename Name of output file ORACA=YES|NO NO Whether the ORACA is used ORECLEN=integer 80 Record length of output file PAGELEN=integer 66 Lines per page in listing RELEASE_CURSOR=YES|NO* NO How cursor cache handles SQL statements SELECT_ERROR=YES|NO* YES How SELECT errors are handled SQLCHECK=SEMANTICS Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. FULL SYNTAX LIMITED NONE * SYNTAX Extent of syntax and/or semantic checking USERID=username/password Valid Oracle username and password XREF=YES|NO* YES Cross-reference section in listing A precompiler command line might look something like the following: proc iname=example.pc include=ora_pcc: include=clib: ireclen=132 There is only one required argument, INAME. This argument tells the precompiler what the input filename is. So the minimum requirements for any precompiler command line could look like the following: proc iname=example.pc All of these precompiler options can be accessed online. Just enter the precompiler option without any argument at your operating system prompt. This help feature will display the name, syntax, default value and purpose of each option. There are some general guidelines to follow when setting options for precompiling: ● When you precompile the program module that CONNECTs to Oracle, specify a value for MAXOPENCURSORS that is high enough for any of the program modules that will be linked together. ● If you want to use just one SQLCA, you must declare it as a global in one of the program modules and as an external in the other modules. In C, for example, this is done by using the external storage class, which tells the precompiler to look for the SQLCA in another program module. Unless you declare the SQLCA as external, each program module will use its own local SQLCA. ● You cannot DECLARE a cursor in one file and reference it in another. All these options can be utilized in several ways when precompiling your program, but what is the best way to precompile, compile, and link your source program? How to Precompile a Program In Version 1.4 of the precompilers, executables exists for each of the six languages previously mentioned. So each host language has a different command to run the precompiler. Table 50.2 shows which command to use for a specific language. Table 50.2. Precompiler commands. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Host Language Precompiler Command C PROC COBOL PROCOB FORTRAN PROFOR Pascal PROPAS PL/I PROPLI There are several ways an embedded SQL program can be precompiled, compiled, and linked. Compiling multiple embedded SQL programs can become very time consuming if each step is done per program. This approach of issuing individual commands can lead to inconsistency between program modules. Executing each step of the compilation process should probably be used when it doesn't matter if standardization is met. For example, it doesn't matter if a common library is linked into your program but all other programs for this system depend on it. Therefore, utilizing a control file simplifies compiling your source program. This control file will evaluate what tasks need to be accomplished while adhering to company standards. Depending upon the platform that you are working on an executable file such as a . BAT or .COM can be created to accept parameters. The following example shows what a command line using a control file might look like. @PCL TEST TEST100 PCL. Control Filename: @PCL System Name: TEST Host Program: TEST100 Options: P(recompile) C(compile) L(ink) After receiving the parameters to evaluate, the control file can determine what needs to be done. This approach helps keep all the programs consistent with others in terms of linking current libraries, objects, or other files. The following PCL.COM file is an example taken from a VAX platform to show how executable files can be created to control precompiling, compiling, and linking host programs. $ write sys$output "PCL.COM Version 2.3" $ $ write sys$output " " $ set noverify Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. $ assign $disk7:[vaxprod.com.ccom],$disk7:[vaxprod.'P1'.c'P1'] clib $ if "''P1'" .eqs "" then goto USAGE $ if "''P2'" .eqs "" then goto USAGE $! $ if "''P3'" .eqs "" then goto precompile $ if "''P3'" .eqs "P" then goto precompile $ if "''P3'" .eqs "p" then goto precompile $ if "''P3'" .eqs "PC" then goto precompile $ if "''P3'" .eqs "pc" then goto precompile $ if "''P3'" .eqs "PCL" then goto precompile $ if "''P3'" .eqs "pcl" then goto precompile $ if "''P3'" .eqs "PCLR" then goto precompile $ if "''P3'" .eqs "pclr" then goto precompile $! $ if "''P3'" .eqs "c" then goto compile $ if "''P3'" .eqs "C" then goto compile $ if "''P3'" .eqs "cl" then goto compile $ if "''P3'" .eqs "CL" then goto compile $ if "''P3'" .eqs "clr" then goto compile $ if "''P3'" .eqs "CLR" then goto compile $! $ if "''P3'" .eqs "l" then goto link $ if "''P3'" .eqs "L" then goto link $ if "''P3'" .eqs "lr" then goto link $ if "''P3'" .eqs "LR" then goto link $! $ if "''P3'" .eqs "r" then goto run $ if "''P3'" .eqs "R" then goto run $ goto USAGE $! Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. $! $! ************************************************************************* $! *************************** Precompile ****************************** $! ************************************************************************* $ precompile: $ proc iname='P2'.pc include=ora_pcc: include=clib: ireclen=132 $ $ if "''P3'" .eqs "p" then goto continue $ if "''P3'" .eqs "P" then goto continue $ $ $! ************************************************************************* $! ***************************** Compile ******************************* $! ************************************************************************* $ compile: $ write sys$output "Compiling ''P2'.C" $ cc/noopt/include_directory=clib:/define=VMS 'P2' $! $ if "''P3'" .eqs "pc" then goto continue $ if "''P3'" .eqs "PC" then goto continue $ if "''P3'" .eqs "c" then goto continue $ if "''P3'" .eqs "C" then goto continue $! $! $! ************************************************************************* $! ******************************* Link ********************************* $! ************************************************************************* $ link: $! Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. $ @ora_rdbms:loutl 'P2' 'P2''P4',clib:c'P1'.olb/lib,clib:ccom.olb/lib- ,ora_util:sqllib.olb/lib,ora_rdbms:oci/lib/include=(ocicee) 'P2' s $! $ endlink: $ if "''P3'" .eqs "PCL" then goto continue $ if "''P3'" .eqs "pcl" then goto continue $ if "''P3'" .eqs "cl" then goto continue $ if "''P3'" .eqs "CL" then goto continue $ if "''P3'" .eqs "l" then goto continue $ if "''P3'" .eqs "L" then goto continue $! $! $! ************************************************************************* $! ******************************** Run ********************************* $! ************************************************************************* $ run: $ P2 P1/P1 $! $! $! ************************************************************************* $! ************************* continue **************************** $! ************************************************************************* $ continue: $ goto exit $! $! ************************************************************************* $! *************************** USAGE ***************************** $! ************************************************************************* $ USAGE: Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. $ write sys$output " " $ write sys$output " " $ write sys$output "Usage: @PCL [SYSTEM] [PROGRAM NAME] [options] [d] [libinfo] $ write sys$output " " $ write sys$output "Where: APPLICATION - Application system: (TEST, etc) $ write sys$output " Used to link the system library (ie. LTEST.OLB/LIB) $ write sys$output " PROGRAM NAME - (TEST100, TEST200, etc) $ write sys$output " options - Options (PCLR): P = precompile $ write sys$output " C = compile $ write sys$output " L = link $ write sys$output " R = run $ write sys$output " PCLR = all the above (default) $ write sys$output " Options entered must appear in above order. $ write sys$output " valid: P PC C CL PCL not valid: CP LC PL $ write sys$output " d - Compile with #define DEBUG (default is nodebug) $ write sys$output " libinfo - Additional User link libraries: ,mydir: mylib.olb/lib $ write sys$output " " $ write sys$output "*Note: Upper case are REQUIRED, Lower case are optional $ write sys$output " " $ write sys$output "Example: @PCL TEST TEST100 PCL $ write sys$output " (compile TEST100.C, nodebug, links TEST200.OBJ including MYLIB.OLB) $ write sys$output " " $ goto exit $ $ $ exit: Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. [...]... your code The following Oracle statements are utilized when creating a conditional section Statement Meaning EXEC ORACLE DEFINE symbol Define a symbol EXEC ORACLE IFDEF symbol If symbol is defined EXEC ORACLE IFNDEF symbol If symbol is not defined EXEC ORACLE ELSE EXEC ORACLE ENDIF Otherwise End this control block Some symbols are port-specific and predefined for you when the Oracle precompilers are... formatting, editing SQL statements, and environment-setting commands Executable Statements Executable statements are used to connect to Oracle; query, manipulate and control access to Oracle data; and to process data These statements result in calls to and return codes from Oracle There are four types of executable embedded SQL statements: data definition, data control, data manipulation and data retrieval... chapter each of these statements will be discussed in further detail Declarative Statements Declarative statements are used to declare Oracle objects, communication areas, and SQL variables These statements do not result in Oracle calls or return codes and do not operate on Oracle data Now that you know there are two sections involved in writing an embedded SQL host program, we should look at exactly what... variables can consist of letters, digits, and underscores, but they must begin with an alpha character To store a datatype, Oracle must know the format and valid range of values Oracle recognizes only two kinds of datatypes: internal and external Internal datatypes indicate how Oracle will store the data, and external specifies how the data is stored in the host variable Table 50.4 shows the internal... all process resources and provides a clean exit from Oracle After the release, there is no further access to the Oracle database until another connect is issued An explicit COMMIT or ROLLBACK with RELEASE should always be done at the end of your program If the RELEASE option is not specified, any locks or resources obtained will not be released until Oracle recognizes that the process is no longer active... data, but what happens when someone else executes a program and it tries to manipulate the same data? Oracle has provided a mechanism that enables you to reserve the data just for your use Locking Oracle uses locks (sometimes called enqueues) to control access to the data When a row of data is being sought, Oracle will lock the row until the user has completed the current transaction A user can get hung... program and Oracle needs to be established to monitor successes and failures This communication is made by utilizing the SQL Include area SQL Include Area This section of the program enables the user to include copies of files into the host program Any file can be included if it contains embedded SQL statements The most common include file is the SQL Communication Area file (SQLCA) When MODE =ORACLE (the... must declare the status variable SQLCODE The SQLCA is a data structure that handles certain events and provides diagnostic checking between the Oracle RDMBS and the host program SQLCA variables maintain valuable runtime statistics such as: warning codes with text, Oracle error codes and number of rows processed are convenient for handling special conditions within the host program The following examples... more portable, and ANSI-compliant These statements are used to direct a program's execution whenever an error or warning condition occurs Some of the conditions that this statement can detect are Oracle errors, Oracle warnings, and no data found If a WHENEVER statement is omitted, the process will continue The following example shows the syntax of the WHENEVER statement EXEC SQL WHENEVER ... sections within the data declaration area: the DECLARE section, SQL Include section, and the SQL connect area Declare Section All host language variables referenced in a SQL statement must be declared to Oracle; otherwise, an error message will be issued at precompile time These variables are declared in the DECLARE section Most host languages will allow multiple DECLARE sections per precompiled unit, . following Oracle statements are utilized when creating a conditional section. Statement Meaning EXEC ORACLE DEFINE symbol Define a symbol EXEC ORACLE IFDEF. IFDEF symbol If symbol is defined EXEC ORACLE IFNDEF symbol If symbol is not defined EXEC ORACLE ELSE Otherwise EXEC ORACLE ENDIF End this control block Some

Ngày đăng: 15/12/2013, 05:15

Xem thêm: Tài liệu Oracle Unleashed- P18 ppt

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN