IBM Informix User-Defined Routines and Data Types Developer.S Guide
Total Page:16
File Type:pdf, Size:1020Kb
DB2 ® IBM Informix Version 10.0 IBM Informix User-Defined Routines and Data Types Developer’s Guide G251-2301-00 DB2 ® IBM Informix Version 10.0 IBM Informix User-Defined Routines and Data Types Developer’s Guide G251-2301-00 Note! Before using this information and the product it supports, read the information in “Notices” on page B-1. First Edition (December 2004) 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. 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 1996, 2004. All rights reserved. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents Introduction . .ix About This Manual . .ix Types of Users . .x Software Dependencies . .x Assumptions About Your Locale . .x Demonstration Databases . .x New Features . .xi Version 10.0 Enhancements . .xi Version 9.4 Enhancements . xii Documentation Conventions . xii Typographical Conventions . xii Feature, Product, and Platform . xiii Syntax Diagrams . xiv Example Code Conventions . xvii Additional Documentation . xviii Installation Guides . xviii Online Notes . xviii Informix Error Messages . .xx Manuals . xxi Online Help . xxi Accessibility . xxi IBM Informix Dynamic Server Version 10.0 and CSDK Version 2.90 Documentation Set . xxi Compliance with Industry Standards . xxiv IBM Welcomes Your Comments . xxv Chapter 1. Extending the Database Server . 1-1 Creating User-Defined Routines . 1-1 Extending Built-In Data Types . 1-2 Extending Operators . 1-2 Building Opaque Data Types . 1-3 Extending Operator Classes . 1-4 Routine Management . 1-4 Chapter 2. Using a User-Defined Routine . 2-1 User-Defined Routines . 2-1 SPL Routines . 2-2 External-Language Routines . 2-2 Information About User-Defined Routines . 2-3 Tasks That You Can Perform with User-Defined Routines . 2-3 Extending Data Type Support . 2-3 Supporting User-Defined Data Types . 2-4 Creating an End-User Routine . 2-11 Invoking a User-Defined Routine . 2-13 Chapter 3. Running a User-Defined Routine . 3-1 © Copyright IBM Corp. 1996, 2004 iii Invoking a UDR in an SQL Statement . 3-2 Invoking a UDR with an EXECUTE Statement . 3-2 Invoking a User-Defined Function in an Expression . 3-3 Invoking a Function That Is Bound to an Operator . 3-3 Named Parameters and UDRs . 3-3 Invoking a UDR in an SPL Routine . 3-4 Executing a User-Defined Routine . 3-4 Parsing the SQL Statement . 3-5 Optimizing the SQL Statement . 3-5 Executing a UDR Across Databases of the Same Database Server Instance . 3-5 Executing the Routine . 3-6 Understanding Routine Resolution . 3-10 The Routine Signature . 3-10 Overloading Routines . 3-11 The Routine-Resolution Process . 3-14 Routine Resolution with User-Defined Data Types . 3-18 Null Arguments in Overloaded Routines . 3-22 Chapter 4. Developing a User-Defined Routine . 4-1 Planning the Routine . 4-2 Naming the Routine . 4-2 Defining Routine Parameters . 4-3 Returning Values . 4-5 Naming Return Parameters . 4-8 Using an Iterator Function . 4-9 Adhering to Coding Standards . 4-17 Writing the Routine . 4-18 Registering a User-Defined Routine . 4-19 Setting Privileges for a Routine . 4-20 Creating an SPL Routine . 4-22 Creating an External-Language Routine . 4-24 Reviewing Information about User-Defined Routines . 4-27 Using a UDR With HDR . 4-28 Chapter 5. Extending Data Types . 5-1 Understanding the Data Type System . 5-1 Understanding Data Types . 5-2 Built-In Data Types . 5-3 Extended Data Types . 5-5 Extending the Data Type System . 5-8 Operations . 5-9 Casts . 5-9 Operator Classes . 5-10 Optimizer Information . 5-11 Chapter 6. Extending Operators and Built-In Functions . 6-1 Operators and Operator Functions . 6-2 Arithmetic Operators . 6-2 Text Operators . 6-2 Relational Operators . 6-3 iv IBM Informix User-Defined Routines and Data Types Developer’s Guide Overloading an Operator Function . 6-4 Built-In Functions . 6-4 Built-In Functions That You Can Overload . 6-4 Built-In Functions That You Cannot Overload . 6-4 Overloading a Built-In Function . 6-5 Chapter 7. Creating User-Defined Casts . 7-1 Understanding Casts . 7-1 Built-In Casts . 7-1 User-Defined Casts . 7-2 Casts That You Cannot Create . 7-2 Creating a User-Defined Cast . 7-3 Choosing the Kind of User-Defined Cast . 7-3 Choosing the Cast Mechanism . 7-4 Defining the Direction of the Cast . 7-7 Dropping a Cast . 7-9 Chapter 8. Creating User-Defined Aggregates . 8-1 Extending Existing Aggregates . 8-2 Overloading Operators for Built-In Aggregates . 8-2 Extending an Aggregate . 8-3 Example of Extending a Built-In Aggregate . 8-3 Creating User-Defined Aggregates . 8-4 Support Functions . 8-4 Resolving the Support Functions . 8-8 Support-Function States . 8-8 Using C or Java Support Functions . 8-9 Example of a User-Defined Aggregate . 8-10 Managing Aggregates . 8-13 Parallel Execution of Aggregates . 8-13 Privileges for User-Defined Aggregates . 8-13 Aggregate Information in the System Catalog . 8-13 Aggregate Information from the Command Line . 8-14 Dropping an Aggregate . ..