Advance Features In Procedues And Triggers

2,262 views

Published on

describes IDS v11 features for stored procedures and triggers.

Published in: Technology, Business
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,262
On SlideShare
0
From Embeds
0
Number of Embeds
17
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide
  • Advance Features In Procedues And Triggers

    1. 1. Advance features in stored procedures and triggers. Keshava Murthy, Architect, Informix Software Session Number TIX-2258
    2. 2. Disclaimer <ul><ul><li>© Copyright IBM Corporation [current year]. All rights reserved. </li></ul></ul><ul><ul><li>U.S. Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. </li></ul></ul><ul><ul><li>THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY.  WHILE EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION CONTAINED IN THIS PRESENTATION, IT IS PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. IN ADDITION, THIS INFORMATION IS BASED ON IBM’S CURRENT PRODUCT PLANS AND STRATEGY, WHICH ARE SUBJECT TO CHANGE BY IBM WITHOUT NOTICE.  IBM SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE RELATED TO, THIS PRESENTATION OR ANY OTHER DOCUMENTATION. NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, NOR SHALL HAVE THE EFFECT OF, CREATING ANY WARRANTIES OR REPRESENTATIONS FROM IBM (OR ITS SUPPLIERS OR LICENSORS), OR ALTERING THE TERMS AND CONDITIONS OF ANY AGREEMENT OR LICENSE GOVERNING THE USE OF IBM PRODUCTS AND/OR SOFTWARE. </li></ul></ul><ul><li>IBM, the IBM logo, ibm.com, and informix software are trademarks or registered trademarks of International Business Machines Corporation in the United States, other countries, or both. If these and other IBM trademarked terms are marked on their first occurrence in this information with a trademark symbol (® or ™), these symbols indicate U.S. registered or common law trademarks owned by IBM at the time this information was published. Such trademarks may also be registered or common law trademarks in other countries. A current list of IBM trademarks is available on the Web at “Copyright and trademark information” at www.ibm.com/legal/copytrade.shtml </li></ul><ul><li>Other company, product, or service names may be trademarks or service marks of others. </li></ul>
    3. 3. Trigger Enhancements employee_tab Insert trigger Delete trigger Select triggers employee_tab Pre 11 server 11 server Single insert and delete triggers, and multiple update and select triggers on mutually exclusive columns Multiple insert, update, delete and select triggers without exclusivity rule. The multiple insert and delete triggers feature is new in Cheetah. Update triggers Insert triggers Delete triggers Update triggers Select triggers New Feature: Multiple Triggers New feature: No Exclusivity rule
    4. 4. Insert Trigger <ul><li>Create trigger emptab_instrig INSERT on emptab </li></ul><ul><li>Referencing new as n </li></ul><ul><li>Before ( insert into log_tab(CURRENT, “start of emptab insert”) ) </li></ul><ul><li>For each row </li></ul><ul><li>( execute procedure update_sal (n.empsalary) into empsalary, </li></ul><ul><li>execute procedure insert_payroll (n.empid, n.emplname, n.empfname, n.empaddr, n.empaddrress, n.empsalary) ) </li></ul><ul><li>After ( insert into log_tab(CURRENT, “end of emptab insert”) ); </li></ul>
    5. 5. Insert Trigger -- add a new trigger <ul><li>Create trigger emptab_instrig2 INSERT on emptab </li></ul><ul><li>Referencing new as n </li></ul><ul><li>Before ( insert into log_tab(CURRENT, “start emptab insert”) ); </li></ul><ul><li>For each row </li></ul><ul><li>(execute procedure update_401k(n.empid, n.emplname, n.empfname, n.empaddr, n.addrress,n.empsalary)) </li></ul><ul><li>After ( insert into log_tab(CURRENT, “end of emptab insert”) ); </li></ul>
    6. 6. Delete Trigger <ul><li>Create trigger emptab_deltrig DELETE on emptab </li></ul><ul><li>Referencing old as o </li></ul><ul><li>For each row </li></ul><ul><li>( execute procedure delete_payroll (o.empid ); </li></ul><ul><li>-- new trigger for DELETE </li></ul><ul><li>Create trigger emptab_instrig2 DELETE on emptab </li></ul><ul><li>Referencing old as o </li></ul><ul><li>For each row </li></ul><ul><li>(execute procedure delete_401k(n.empid)); </li></ul>
    7. 7. Update Trigger <ul><li>multiple update triggers on the complete table. </li></ul><ul><li>Multiple update triggers on each column or set of columns </li></ul><ul><li>In summary, multiple update triggers on any combination. </li></ul>
    8. 8. Writing trigger code, easily. <ul><li>Passing row values into procedures </li></ul><ul><li>Accessing and modifying row values easily within triggers. </li></ul><ul><li>Use the power of stored procedure to enforce the business rules. </li></ul>
    9. 9. <ul><li>create trigger ins_trig_tab1 INSERT on tab1 referencing new as post </li></ul><ul><li>for each row(execute procedure proc1() with trigger references); </li></ul><ul><li>create trigger ins_trig_tab2 INSERT on tab2 referencing new as n </li></ul><ul><li>for each row (execute procedure proc2() with trigger references); </li></ul>
    10. 10. <ul><li>create table tab1 (col1 int,col2 int); </li></ul><ul><li>create table tab2 (col1 int); </li></ul><ul><li>create table temptab1 (old_col1 int, new_col1 int, old_col2 int, new_col2 int); </li></ul><ul><li>create procedure proc1() </li></ul><ul><li>referencing OLD as o NEW as n for tab1; </li></ul><ul><li>if ( INSERTING ) then -- INSERTING new boolean function </li></ul><ul><li>n.col1 = n.col1 + 1; </li></ul><ul><li>insert into temptab1 values(0,n.col1,1,n.col2); </li></ul><ul><li>end if </li></ul><ul><li>if ( UPDATING ) then -- UPDATING new boolean function </li></ul><ul><li>insert into temptab1 values(o.col1,n.col1,o.col2,n.col2); </li></ul><ul><li>end if </li></ul><ul><li>if ( SELECTING ) then -- SELECTING new boolean function </li></ul><ul><li>-- you can access relevant old and new values. </li></ul><ul><li>insert into temptab1 values (o.col1,0,o.col2,0); </li></ul><ul><li>end if </li></ul><ul><li>if ( DELETING ) then -- DELETING new boolean function </li></ul><ul><li>delete from temptab1 where temptab1.col1 = o.col1; </li></ul><ul><li>end if </li></ul><ul><li>end procedure; </li></ul><ul><li>create procedure proc2() </li></ul><ul><li>referencing OLD as o NEW as n for tab2 </li></ul><ul><li>returning int; </li></ul><ul><li>LET n.col1 = n.col1 * 1.1 ; -- increment the inserted value 10% </li></ul><ul><li>end procedure; </li></ul>-- new syntax. New boolean functions: INSERTING SELECTING DELETING UPDATING -- You can modify the new row values.
    11. 11. Explain Enhancements <ul><li>Explain enhancements </li></ul><ul><ul><li>Query Optimization Time </li></ul></ul><ul><ul><li>Distributed query support </li></ul></ul><ul><ul><li>Estimated and Actual cardinalities </li></ul></ul><ul><ul><ul><li>Controlled by EXPLAIN_STAT </li></ul></ul></ul><ul><ul><li>Dynamic explain enhancements </li></ul></ul><ul><ul><ul><li>Prints the location the explain file in online.log </li></ul></ul></ul><ul><ul><ul><li>Provides any errors while trying to create the file </li></ul></ul></ul><ul><ul><ul><li>onmode –Y <sid> 0|1|2 [filename] </li></ul></ul></ul><ul><ul><ul><ul><li>Specify the location of the dynamic explain </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Specify whether you need query stats </li></ul></ul></ul></ul>
    12. 12. New Functions and Expressions ASCII(character_expression) The ASCII function returns the decimal representation of the first character in a character string. ASCII(‘a’) returns: 97 ASCII(‘Hello World!’) returns: 72 ASCII ADD_MONTHS(date/datetime expression , integer ) Adds months to a date or datetime value or expression. The first argument is date or datetime expression and second is an integer. Return type is same as first argument. ADD_MONTHS('4/16/2004', 20) returns: 12/16/2005 ADD_MONTHS(CURRENT, 3) returns: 2007-09-19 10:04:11.00000 ADD_MONTHS()
    13. 13. New Functions and Expressions CEIL (numerical_expession) returns the DECIMAL(32) representation of the smallest integer that is greater than or equal to its single argument. FLOOR(numerical_expression) returns the DECIMAL(32) representation of the largest integer that is smaller than or equal to its single argument. CEIL(-54.232) returns -54 FLOOR(-54.232) returns -55 CEIL(54.232) returns 55 FLOOR(54.232) returns 54 CEIL FLOOR BITAND(num1, num2) – returns the bitwise ANDed value. BITOR(num1, num2) – returns the bitwise ORed value. BITXOR(num1, num2) – returns the bitwise XORed value. BITNOT(num1) – returns the bitwise ANDed value. BITANDNOT(num1, num2) – is a short form for BITAND(arg1, BITNOT(arg2)) Bitwise functions
    14. 14. New Functions and Expressions LAST_DAY(date or datetime expression) Returns last day of the month in the argument. SELECT TODAY AS today, CURRENT AS current, LAST_DAY(TODAY) AS last_from_today, LAST_DAY(CURRENT) AS last_from_current FROM systables WHERE tabid = 1; today 06/19/2007 current 2007-06-19 10:23:01.000 last_from_today 06/30/2007 last_from_current 2007-06-30 10:23:01.00000 LAST_DAY FORMAT_UNITS(number, precision, units) Helps formatting of numbers in kilobytes to peta bytes. Detailed explanation with examples is in IDS SQL Syntax guide. SELECT FORMAT_UNITS( SUM(chksize), 'P') size, FORMAT_UNITS( SUM(nfree), 'p') free FROM syschunks; size 117 MB free 8.05 MB FORMAT_UNITS
    15. 15. New Functions and Expressions MONTHS_BETWEEN(date/datetime expr, date/datetime expr) Returns the difference between two date or datetime expressions in decimal, based on 31day months. SELECT CURRENT, MONTHS_BETWEEN(TODAY, LAST_DAY(CURRENT)) FROM systables WHERE tabid = 1; (expression) (expression) 2007-06-19 10:51:57.000 -0.3694433243728 MONTHS_BETWEEN LTRIM(source_string, pad_string) Returns the source_string after removing specified leading pad characters from a string. LTRIM will remove leading blanks when you simply pass the source string. LTRIM(‘Hello Cheetah!’, ‘Hello ‘) returns: Cheetah! LTRIM
    16. 16. New Functions and Expressions TO_NUMBER(character or numeric expression) converts a number or a character expression representing a number value to a DECIMAL. TO_NUMBER NULLIF(arg1, arg2) Returns NULL if arg1 and arg2 are equal, else returns arg1. If both are NULL – they won’t be equal – but still returns NULL because arg1 is NULL. NULLIF Next_day(date or datetime expr, abbreviated day of the week) Returns the date or datetime for next day matching the second argument. EXECUTE FUNCTION NEXT_DAY(TODAY, 'Mon') returns: 06/25/2007 EXECUTE FUNCTION NEXT_DAY(CURRENT, 'Mon') returns: 2007-06-25 6:57:52.00000 NEXT_DAY
    17. 17. Enhancements to Functions Works same as POW() function. POWER Returns the same value as CURRENT DATETIME year to fraction(5) SYSDATE These two functions can now take date and datetime expressions. IDS Syntax guide explains this in detail. TRUNC ROUND TO_CHAR(numeric expression) In addition to exisiting functionality, in IDS v11.10, this function will convert a number into a charater string. TO_CHAR
    18. 18. SYSDBOPEN() and SYSDBCLOSE() <ul><li>CREATE PROCEDURE public.sysdbopen (); </li></ul><ul><li>SET pdqpriority 1; </li></ul><ul><li>SET ENVIRONMENT OPTCOMPIND '1'; </li></ul><ul><li>SET ISOLATION COMMITTED READ; </li></ul><ul><li>SET ENVIRONMENT USELASTCOMMITTED 'ALL'; </li></ul><ul><li>SYSTEM &quot;echo Logged IN: &quot; || USER || &quot; &quot; || </li></ul><ul><li>CURRENT || &quot; >> /tmp/mylog&quot;; </li></ul><ul><li>END PROCEDURE; </li></ul><ul><li>-- log the entry. </li></ul><ul><li>CREATE PROCEDURE public.sysdbclose (); </li></ul><ul><li>SYSTEM &quot;echo Logged OUT: &quot; || USER || &quot; &quot; || </li></ul><ul><li>CURRENT || &quot; >> /tmp/mylog&quot;; </li></ul><ul><li>END PROCEDURE; </li></ul>
    19. 19. Named Parameters Support for JDBC <ul><li>This is an example of implicit positional binding: </li></ul><ul><li>CallableStatement cstmt = con.prepareCall(&quot;call order_item(?, ?, ?, ?, ?,?, ?)&quot;); </li></ul><ul><li>// Set parameters (positional notation) </li></ul><ul><li>cstmt.setInt( 1 , 5739 ); </li></ul><ul><li>cstmt.setInt( 2 , 8294); </li></ul><ul><li>cstmt.setString( 6 , &quot;345, University ave.&quot;); </li></ul><ul><li>cstmt.setInt( 7 , 94303); </li></ul><ul><li>cstmt.setString( 4 ,&quot;4100 Bohannon Dr.&quot;); </li></ul><ul><li>cstmt.setInt( 5 , 94025); </li></ul><ul><li>cstmt.setInt( 3 ,5); </li></ul><ul><li>// Execute </li></ul><ul><li>cstmt.execute(); </li></ul>
    20. 20. Named Parameters Support for JDBC Here is the same code rewritten using named parameter notation: // Set parameters (named notation) cstmt.setInt(&quot; cust_id &quot;, 5739 ); Chapter 9. SQL Language 275 cstmt.setInt(&quot; item_id &quot;, 8294); cstmt.setString(&quot; shipping_addr &quot;, &quot;345, University ave.&quot;); cstmt.setInt(&quot; shipping_zip &quot;, 94303); cstmt.setString(&quot; billing_addr &quot;,&quot;4100 Bohannon Dr.&quot;); cstmt.setInt(&quot; billing_zip &quot;, 94025); cstmt.setInt(&quot; count &quot;, 5); // Execute cstmt.execute();
    21. 21. Stored Procedure Enhancements <ul><li>GO TO Statement </li></ul><ul><li>LOOP Statement </li></ul><ul><li>Stored procedure recompilation </li></ul>
    22. 22. GO TO Statement <ul><li>CREATE PROCEDURE simple_goto(a int) </li></ul><ul><li>RETURNS int; </li></ul><ul><li>IF a < 50 THEN </li></ul><ul><li>GOTO lessval; -- jump to lessval. </li></ul><ul><li>END IF; </li></ul><ul><li>RETURN a * a; -- return something </li></ul><ul><li><<lessval>> -- define the label lessval </li></ul><ul><li>RETURN a * -1; </li></ul><ul><li>END PROCEDURE; </li></ul>
    23. 23. LOOP Statement <ul><li>CREATE PROCEDURE plusnum(a int) </li></ul><ul><li>RETURNS int; </li></ul><ul><li>DEFINE x int; </li></ul><ul><li>LET x = a; </li></ul><ul><li>LOOP -- start the loop </li></ul><ul><li>LET x = x + 1; </li></ul><ul><li>IF x < 0 THEN </li></ul><ul><li>CONTINUE; -- increment until +ve number. </li></ul><ul><li>ELIF x < 1000 THEN </li></ul><ul><li>RETURN x WITH RESUME; -- return and come back. </li></ul><ul><li>END IF; </li></ul><ul><li>EXIT LOOP WHEN x = 1000; -- exit loop at 1000. </li></ul><ul><li>END LOOP; </li></ul><ul><li>END PROCEDURE; </li></ul>
    24. 24. LOOP Statement <ul><li>CREATE PROCEDURE sumto_a(a int) </li></ul><ul><li>RETURNS int; </li></ul><ul><li>DEFINE x int; </li></ul><ul><li>DEFINE total int; </li></ul><ul><li>LET total = 0; </li></ul><ul><li>FOR x IN (1 TO a) LOOP -- start the loop </li></ul><ul><li>LET total = total + x; </li></ul><ul><li>END LOOP; </li></ul><ul><li>RETURN total; </li></ul><ul><li>END PROCEDURE; </li></ul>
    25. 25. LOOP Statement <ul><li>CREATE PROCEDURE facto(a int) </li></ul><ul><li>RETURNS int AS x, int AS factx; </li></ul><ul><li>DEFINE x,y, factx int; </li></ul><ul><li>DEFING total int; </li></ul><ul><li>LET total = 0; </li></ul><ul><li>LET x = 1; </li></ul><ul><li><<main_loop>> </li></ul><ul><li>WHILE (x <= a) LOOP -- start the loop </li></ul><ul><li>LET factx = 1; </li></ul><ul><li><<facto_loop>> </li></ul><ul><li>FOR y IN (1 TO x) LOOP </li></ul><ul><li>-- Abruptly stop at 10 </li></ul><ul><li>EXIT main_loop WHEN x = 10; </li></ul><ul><li>LET factx = factx * y; </li></ul><ul><li>END LOOP facto_loop; </li></ul><ul><li>RETURN x, factx WITH RESUME; </li></ul><ul><li>LET X = x+1; </li></ul><ul><li>END LOOP main_loop; </li></ul><ul><li>END PROCEDURE; </li></ul>
    26. 26. Stored Procedure language(SPL) routines IDS Client IDS Client Informix routine manager Informix Dynamic Server Query processing and Optimizer C Language routines Java language routines
    27. 27. <ul><li>SQL inside stored procedure </li></ul><ul><li>create procedure foo_static </li></ul><ul><li>(vpkid int,vname varchar(32)) returns int; </li></ul><ul><li>update mytab set myname = vname </li></ul><ul><li>where pkid = vpkid; </li></ul><ul><li>End procedure; </li></ul>
    28. 28. <ul><li>Dynamic Statement </li></ul><ul><li>create procedure foo_dynamic(vpkid int, </li></ul><ul><li>vname varchar(32), tabname varchar(128)) returns int; </li></ul><ul><li>define query lvarchar(512); </li></ul><ul><li>let query = &quot;update &quot; || tabname || &quot;set myname = '&quot; || vname || &quot;' where pkid = &quot; || vpkid; </li></ul><ul><li>execute immediate query; </li></ul><ul><li>return sqlcode ; </li></ul><ul><li>end procedure; </li></ul><ul><li>execute procedure foo_dynamic </li></ul><ul><li>(123, &quot;John Doe&quot;, &quot;customer&quot;); </li></ul>
    29. 29. <ul><li>Dynamic SQL Statement in SPL </li></ul><ul><ul><li>Non cursory statements </li></ul></ul><ul><ul><ul><li>EXECUTE IMMEDIATE </li></ul></ul></ul><ul><ul><li>Cursory statements </li></ul></ul><ul><ul><ul><li>PREPARE, DECLARE, OPEN, FETCH, CLOSE, FREE </li></ul></ul></ul><ul><ul><li>SQLCODE function </li></ul></ul>
    30. 30. <ul><li>EXECUTE IMMEDIATE { SQL_quoted_string | Str_variable } ; </li></ul><ul><ul><ul><li>SQL_quoted_string: A string containing a single SQL statement </li></ul></ul></ul><ul><ul><ul><li>Str_variable: A character variable containing the SQL statement </li></ul></ul></ul><ul><li>Only string values or variables are allowed. Statement length is limited to 32K. </li></ul><ul><li>Allows only ONE SQL statement allowed. </li></ul>
    31. 31. <ul><li>create procedure update_this( owner varchar(32), tabname varchar(32), cid int, val decimal(10,2), operation varchar(24)) r eturns int as operation_code; </li></ul><ul><li>define oper varchar(4); </li></ul><ul><li>define update_query lvarchar; </li></ul><ul><li>let oper = &quot;None&quot;; </li></ul><ul><li>if (operation = &quot;add&quot;) then </li></ul><ul><li>let oper = &quot; + &quot;; </li></ul><ul><li>elif (operation = &quot;subtract&quot;) then </li></ul><ul><li>let oper = &quot; - &quot;; </li></ul><ul><li>else </li></ul><ul><li>return -11111; </li></ul><ul><li>end if; </li></ul><ul><li>let update_query = &quot;update &quot; || owner || &quot;.&quot; || tabname || &quot; set balance = balance &quot; || oper || val || &quot; &quot;; </li></ul><ul><li>if (tabname = &quot;noordinary_joe&quot;) then </li></ul><ul><li>let update_query = update_query || &quot;, last_priv_usage = CURRENT &quot;; </li></ul><ul><li>end if; </li></ul><ul><li>let update_query = update_query || &quot;where customer = &quot; || cid; </li></ul><ul><li>insert into log(b) values(update_query); </li></ul><ul><li>EXECUTE IMMEDIATE update_query; </li></ul><ul><li>return sqlcode ; </li></ul><ul><li>end procedure; </li></ul>
    32. 32. SQL Injection http://xkcd.com/327/ http://imgs.xkcd.com/comics/exploits_of_a_mom.png This work is licensed under a Creative Commons Attribution- NonCommercial 2.5 License . This means you're free to copy and share these comics (but not to sell them).
    33. 33. <ul><li>Need to use EXECUTE FUNCTION or EXECUTE PROCEDURE </li></ul><ul><ul><li>From JDBC, use Callable statements </li></ul></ul><ul><li>Using procedures with dynamic statements within other DML statements is disallowed </li></ul><ul><ul><li>SELECT MYPROC() from systables where tabid = 1; </li></ul></ul><ul><ul><li>Use the new SQLCODE function to check for any error </li></ul></ul><ul><ul><li>It should return zero when the statement is successful </li></ul></ul>
    34. 34. <ul><li>Cursor support in dynamic SQL </li></ul><ul><ul><li>PREPARE <statementname> from query </li></ul></ul><ul><ul><li>DECLARE <cursorname> cursor for <statementname> </li></ul></ul><ul><ul><li>OPEN <cursor> </li></ul></ul><ul><ul><li>FETCH <cursor>, CLOSE <cursor> </li></ul></ul><ul><ul><li>FREE <cursor>, FREE <statement-id> </li></ul></ul><ul><ul><li>sqlcode for error check on each operation </li></ul></ul>
    35. 35. <ul><li>create procedure getlist (skipm int, firstn int, maxid int) </li></ul><ul><li>returns int, varchar(128) </li></ul><ul><li>define tabname varchar(128); </li></ul><ul><li>define tabid integer; </li></ul><ul><li>define query varchar(128); </li></ul><ul><li>let query = &quot;select skip &quot; || skipm || &quot;first &quot; || firstn </li></ul><ul><li>|| &quot; tabid, tabname from systables where tabid < ? and tabname = ? order by 1&quot;; </li></ul><ul><li>prepare stmt_id from query; </li></ul><ul><li>declare myCur cursor for stmt_id; </li></ul><ul><li>open myCur using maxid, myname; </li></ul><ul><li>while (1=1) </li></ul><ul><li>fetch myCur into tabid, tabname; </li></ul><ul><li>if ( sqlcode != 0) then </li></ul><ul><li>exit; </li></ul><ul><li>end if; </li></ul><ul><li>return tabid, tabname with resume; </li></ul><ul><li>end while; </li></ul><ul><li>close myCur; </li></ul><ul><li>free myCur; </li></ul><ul><li>free stmt_id; </li></ul><ul><li>end procedure; </li></ul><ul><li>execute procedure getlist(maxid=100, skipm=10, firstn=5); </li></ul>
    36. 36. <ul><li>Summary </li></ul><ul><ul><li>IDS 11.5 supports dynamic statements in its stored procedure language </li></ul></ul><ul><ul><li>EXECUTE IMMEDIATE </li></ul></ul><ul><ul><li>PREPARE, DELCARE, OPEN, FETCH, CLOSE, FREE </li></ul></ul><ul><ul><li>SQLCODE </li></ul></ul><ul><li>IDS 11.5 Infocenter </li></ul><ul><ul><li>http://publib.boulder.ibm.com/infocenter/idshelp/v115/index.jsp </li></ul></ul>
    37. 37. Stored Procedure Recompilation <ul><li>This will be in 10.00.xC7 and 11.10.xC2 </li></ul><ul><li>-211 error: Cannot read system catalog sysprocplan </li></ul><ul><ul><li>Happens after altering the table or creating/dropping indices. </li></ul></ul><ul><ul><li>Also happens if you lock procedure plans when you UPDATE STATISTICS for procedures within BEGIN– COMMIT. </li></ul></ul><ul><li>Automatic Recompilation </li></ul><ul><ul><li>Automatically recognize and recompile the required statements </li></ul></ul><ul><ul><li>Write back the plan in a separate transaction so the locks are release. </li></ul></ul><ul><li>Automatically available. Nothing for applications to do. </li></ul>
    38. 39. Savepoints. <ul><li>Savepoints are markers within a transaction. </li></ul><ul><li>Enables you to take corrective action within the transaction by partially rolling back the transaction. </li></ul><ul><li>Even after the partial rollback, the transaction is still open. </li></ul><ul><li>E.g. Customer order transaction. </li></ul><ul><ul><li>Basic order entry goes thru. </li></ul></ul><ul><ul><li>Couldn’t update the info at CRM database </li></ul></ul><ul><ul><ul><ul><li>System down, new user is still unknown/etc </li></ul></ul></ul></ul><ul><ul><li>Rollback the status for order entry </li></ul></ul><ul><ul><li>Save the non-critical activity for batch processing later </li></ul></ul><ul><ul><li>But, continue with order entry transaction successfully. </li></ul></ul>
    39. 40. Savepoints. <ul><li>Begin work; </li></ul><ul><li>Insert into mytab values(00, “step 00 completed”); </li></ul><ul><li>Savepoint step1; </li></ul><ul><li>Insert into mytab values(10, “step 10 completed”); </li></ul><ul><li>Savepoint step2; </li></ul><ul><li>Insert into mytab values(20, “step 20 completed”); </li></ul><ul><li>Savepoint step3; </li></ul><ul><li>Insert into mytab values(30, “step 30 completed”); </li></ul><ul><li>-- something happens </li></ul><ul><li>Rollback work to savepoint step2; </li></ul><ul><li>-- continue the transaction; </li></ul><ul><li>Savepoint stepfixup; </li></ul><ul><li>Insert into mytab values(55, “All steps done”); </li></ul><ul><li>Commit work; </li></ul>
    40. 41. Savepoints <ul><li>Enabled for All Informix APIs </li></ul><ul><ul><li>ESQL/C </li></ul></ul><ul><ul><li>JDBC, ODBC, etc </li></ul></ul><ul><ul><li>JCC will have the functionality in their next fixpack. </li></ul></ul><ul><li>Standard compliant. </li></ul><ul><li>Scope of the savepoint names in procedures is limited to that instance of the stored procedure. </li></ul><ul><li>Distributed queries are supported. </li></ul><ul><li>You can enforce the uniqueness of savepoint names. </li></ul>
    41. 42. <ul><li>Thank You </li></ul><ul><li>[email_address] </li></ul><ul><li>Session 2258 </li></ul>

    ×