Sequence_value in Windows 4GL

>>bm656@cleveland.Freenet.Edu (Mark D. Gold) writes:
>
>I would like to use the sequence_value function, but it is not an included 
>function in windows4gl.
>
  This is true for release 6.3/03 and above, however in prior releases
  sequence_value was a database procedure and not a 4GL function at all.

>Is there any way to translate it from 4gl to w4gl.  Is there a text file
>around that contains the code?  How would it be used, as a procedure called
>by a rule in the db?

  You can utilize the old DB procedure code as if it was your *own* DB
  procedure. I would strongly suggest renaming the procedure and
  table names to something other than what they are below for later
  compatibility (ie. don't use the 'ii_' for user defined DB procedures
  and/or table names).

  Procedure and table definitions are listed below (note that the parameter
  'key' is usually the table name the sequence value is generated for):


 help procedure _ii_sequence_value
Procedure:            _ii_sequence_value
Owner:                supp60
Created:              21-jan-1992 13:14:00     

Procedure Definition:
create procedure  _ii_sequence_value (                                
                key = char(32) not null,                              
                inc = integer not null                                
        ) =                                                           
        declare                                                       
                value = integer not null;                             
        begin                                                         
                if inc <= 0 then                                      
                        return 0                                      
                endif;                                                
                update ii_sequence_values set sequence_value =        
sequence_value + :inc                                                 
                        where sequence_value > 0 and sequence_key =   
:key;                                                                 
                if iierrornumber != 0 then                            
                        return 0                                      
                endif;                                                
                if iirowcount = 0 then                                
                        select value = sequence_value from            
ii_sequence_values                                                    
                                where sequence_key = :key;            
                        if iierrornumber != 0 or iirowcount > 0 then  
                                return 0                              
                        endif;                                        
                        insert into ii_sequence_values values ( :key, 
:inc );                                                               
                        if iierrornumber != 0 or iirowcount = 0 then  
                                return 0                              
                        endif                                         
                endif;                                                
                select value = sequence_value from ii_sequence_values 
                        where sequence_key = :key;                    
                if iierrornumber != 0 or iirowcount = 0 then          
                        return 0                                      
                endif;                                                
                return :value                                         
        end                                                           

Permissions on procedure _ii_sequence_value are:


Permission 2:
grant execute on procedure _ii_sequence_value       to public         



continue
Executing . . .

help table ii_sequence_values
Name:                 ii_sequence_values
Owner:                $ingres
Created:              21-jan-1992 13:14:00     
Location:             ii_database
Type:                 system catalog
Version:              ING6.0  
Row width:            36
Number of rows:       0
Storage structure:    hash with unique keys
Duplicate Rows:       not allowed
Number of pages:      16
Overflow data pages:  0
Journaling:           disabled
Base table for view:  no
Permissions:          yes, including SELECT to ALL
Integrities:          none
Optimizer statistics: none

Column Information:
                                                                  Key
Column Name                      Type       Length Nulls Defaults Seq
sequence_key                     char           32   no      no     1 
sequence_value                   integer         4   no     yes       



  Hope this helps,

  Phil Bloemink				The opinions expressed in this
  INGRES Technical Support		posting are my own, damn it! 
  INGRES, An ASK Company		They're not yours, and you can't
  pab@ingres.com			have them!
Ingres Q & A
To William's Home Page

© William Yuan 2000

Email William