
IBM® DB2 Universal Database™ Application Development Guide: Programming Client Applications Ve r s i o n 8 SC09-4826-00 IBM® DB2 Universal Database™ Application Development Guide: Programming Client Applications Ve r s i o n 8 SC09-4826-00 Before using this information and the product it supports, be sure to read the general information under Notices. This document contains proprietary information of IBM. It is provided under a license agreement and is protected by copyright law. The information contained in this publication does not include any product warranties, and any statements provided in this manual should not be interpreted as such. You can order IBM publications online or through your local IBM representative. v To order publications online, go to the IBM Publications Center at www.ibm.com/shop/publications/order v To find your local IBM representative, go to the IBM Directory of Worldwide Contacts at www.ibm.com/planetwide To order DB2 publications from DB2 Marketing and Sales in the United States or Canada, call 1-800-IBM-4YOU (426-4968). When you send information to IBM, you grant IBM a nonexclusive right to use or distribute the information in any way it believes appropriate without incurring any obligation to you. © Copyright International Business Machines Corporation 1993-2002. All rights reserved. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents About This Book..........xiii Programming a Standalone Application . 30 Creating the Declaration Section of a Part 1. Introduction........1 Standalone Application .......31 Declaring Variables That Interact with the Database Manager .........32 Chapter 1. Overview of Supported Declaring Variables That Represent SQL Programming Interfaces ........3 Objects.............33 DB2 Developer’s Edition ........3 Declaring Host Variables with the DB2 Developer’s Edition Products ....3 db2dclgn Declaration Generator ....35 Instructions for Installing DB2 Developer’s Relating Host Variables to an SQL Edition Products ..........5 Statement............36 DB2 Universal Database Tools for Developing Declaring the SQLCA for Error Handling 37 Applications ............5 Error Handling Using the WHENEVER Supported Programming Interfaces.....6 Statement............38 DB2 Supported Programming Interfaces . 6 Adding Non-Executable Statements to an DB2 Application Programming Interfaces . 8 Application ...........40 Embedded SQL ..........9 Connecting an Application to a Database 40 DB2 Call Level Interface .......10 Coding Transactions ........41 DB2 CLI versus Embedded Dynamic SQL 12 Ending a Transaction with the COMMIT Java Database Connectivity (JDBC) . 14 Statement............42 Embedded SQL for Java (SQLj) ....15 Ending a Transaction with the ROLLBACK ActiveX Data Objects and Remote Data Statement............43 Objects.............16 Ending an Application Program ....44 PerlDBI............17 Implicit Ending of a Transaction in a ODBC End-User Tools .......17 Standalone Application .......45 Web Applications ..........17 Application Pseudocode Framework . 45 Tools for Building Web Applications . 17 Facilities for Prototyping SQL Statements 46 WebSphere Studio .........18 Administrative APIs in Embedded SQL or XMLExtender..........19 DB2CLIPrograms.........48 MQSeries Enablement........19 Definition of FIPS 127-2 and ISO/ANS Net.Data............20 SQL92 .............48 ProgrammingFeatures........20 Controlling Data Values and Relationships . 48 DB2ProgrammingFeatures......20 Data Value Control.........49 DB2StoredProcedures.......22 Data Value Control Using Data Types . 49 DB2 User-Defined Functions and Methods 22 Data Value Control Using Unique DevelopmentCenter........23 Constraints ...........49 User-Defined Types (UDTs) and Large Data Value Control Using Table Check Objects (LOBs) ..........24 Constraints ...........50 OLEAutomationRoutines......26 Data Value Control Using Referential OLEDBTableFunctions.......26 Integrity Constraints ........50 DB2Triggers...........27 Data Value Control Using Views with CheckOption..........51 Chapter 2. Coding a DB2 Application . 29 Data Value Control Using Application Prerequisites for Programming ......30 Logic and Program Variable Types . 51 DB2 Application Coding Overview ....30 Data Relationship Control ......51 © Copyright IBM Corp. 1993-2002 iii Data Relationship Control Using Compilation and Linkage of Source Files Referential Integrity Constraints ....52 Containing Embedded SQL ......81 Data Relationship Control Using Triggers 52 Package Creation Using the BIND Data Relationship Control Using Before Command...........83 Triggers............53 Package Versioning ........83 Data Relationship Control Using After Effect of Special Registers on Bound Triggers............53 Dynamic SQL ..........85 Data Relationship Control Using Resolution of Unqualified Table Names . 85 Application Logic .........54 Additional Considerations when Binding 86 Application Logic at the Server ....54 Advantages of Deferred Binding ....87 Authorization Considerations for SQL and BindFileContents.........87 APIs..............55 Application, Bind File, and Package Authorization Considerations for Relationships...........88 EmbeddedSQL..........55 Precompiler-Generated Timestamps . 88 Authorization Considerations for Dynamic Package Rebinding.........90 SQL..............57 Authorization Considerations for Static Chapter 4. Writing Static SQL Programs. 93 SQL..............58 Characteristics and Reasons for Using Static Authorization Considerations for APIs . 58 SQL...............93 Testing the Application ........59 Advantages of Static SQL .......94 Setting up the Test Environment for an Example Static SQL Program ......95 Application ...........59 Data Retrieval in Static SQL Programs . 97 Debugging and Optimizing an Application 63 Host Variables in Static SQL Programs . 97 IBM DB2 Universal Database Project Add-In HostVariablesinStaticSQL.....97 forMicrosoftVisualC++........64 Declaring Host Variables in Static SQL The IBM DB2 Universal Database Project Programs............99 Add-InforMicrosoftVisualC++....64 Referencing Host Variables in Static SQL IBM DB2 Universal Database Project Programs...........101 Add-In for Microsoft Visual C++ Indicator Variables in Static SQL Programs 101 Terminology...........66 Including Indicator Variables in Static Activating the IBM DB2 Universal SQLPrograms..........101 Database Project Add-In for Microsoft Data Types for Indicator Variables in VisualC++...........67 StaticSQLPrograms........104 Activating the IBM DB2 Universal Example of an Indicator Variable in a Database Tools Add-In for Microsoft Visual StaticSQLProgram........106 C++..............68 Selecting Multiple Rows Using a Cursor . 108 Selecting Multiple Rows Using a Cursor 108 Part 2. Embedded SQL......69 Declaring and Using Cursors in Static SQLPrograms..........109 Chapter 3. Embedded SQL Overview . 71 Cursor Types and Unit of Work Considerations..........110 Embedding SQL Statements in a Host Example of a Cursor in a Static SQL Language .............71 Program............112 Source File Creation and Preparation....73 Manipulating Retrieved Data ......113 Packages, Binding, and Embedded SQL . 76 Updating and Deleting Retrieved Data in Package Creation for Embedded SQL . 76 StaticSQLPrograms........114 Precompilation of Source Files Containing CursorTypes..........114 EmbeddedSQL..........78 Example of a Fetch in a Static SQL Source File Requirements for Embedded Program............115 SQL Applications .........80 iv Programming Client Applications Scrolling Through and Manipulating Processing the Cursor in a Dynamic SQL Retrieved Data ...........117 Program............145 Scrolling Through Previously Retrieved Allocating an SQLDA Structure for a Data.............117 Dynamic SQL Program .......145 Keeping a Copy of the Data .....117 Transferring Data in a Dynamic SQL Retrieving Data a Second Time ....118 Program Using an SQLDA Structure . 149 Row Order Differences Between the First Processing Interactive SQL Statements in andSecondResultTable......119 Dynamic SQL Programs ......150 Positioning a Cursor at the End of a Table 120 Determination of Statement Type in Updating Previously Retrieved Data . 121 Dynamic SQL Programs ......151 Example of an Insert, Update, and Delete Processing Variable-List SELECT inaStaticSQLProgram.......121 Statements in Dynamic SQL Programs . 151 Diagnostic Information ........123 Saving SQL Requests from End Users . 152 Return Codes ..........123 Parameter Markers in Dynamic SQL Error Information in the SQLCODE, Programs............153 SQLSTATE, and SQLWARN Fields . 123 Providing Variable Input to Dynamic SQL Token Truncation in the SQLCA Structure 124 Using Parameter Markers ......153 Exception, Signal, and Interrupt Handler Example of Parameter Markers in a Considerations..........125 Dynamic SQL Program .......154 ExitListRoutineConsiderations....125 DB2 Call Level Interface (CLI) Compared to Error Message Retrieval in an Application 126 Dynamic SQL ...........155 DB2 Call Level Interface (CLI) versus Chapter 5. Writing Dynamic SQL Embedded Dynamic SQL ......155 Programs ............127 Advantages of DB2 CLI over Embedded Characteristics and Reasons for Using SQL.............157 Dynamic SQL ...........127 When to Use DB2 CLI or Embedded SQL 159 Reasons for Using Dynamic SQL....127 Dynamic SQL Support Statements . 128 Chapter 6. Programming in C and C++ 161 Dynamic SQL Versus Static SQL ....129 Programming Considerations for C/C++ . 161 Cursors
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages568 Page
-
File Size-