=== modified file 'build.gradle'
--- build.gradle	2023-01-28 04:45:51 +0000
+++ build.gradle	2023-02-08 15:41:34 +0000
@@ -848,6 +848,7 @@
 
 task mergeMariaDBUDFs(dependsOn: 'makeManifests') {
     inputs.files('udf/mariadb/udfs.sql', 
+                 'udf/mariadb/guarded.sql', 
                  'udf/mariadb/error_handler.sql', 
                  "${buildDir}/udf/mariadb/getFWDVersion.sql")
     outputs.file( "${buildDir}/udf/mariadb/udfs.sql" )

=== modified file 'src/com/goldencode/p2j/persist/FQLPreprocessor.java'
--- src/com/goldencode/p2j/persist/FQLPreprocessor.java	2023-02-10 09:39:25 +0000
+++ src/com/goldencode/p2j/persist/FQLPreprocessor.java	2023-02-12 14:08:04 +0000
@@ -3319,18 +3319,8 @@
             int idxPos = next.getIndexPos();
             parent = (HQLAst) next.getParent();
             
-            String checkErrorFn = "checkError";
-            String initErrorFn = "initError";
-            if (dialect instanceof P2JSQLServer2008Dialect)
-            {
-               checkErrorFn = "dbo.checkError_bb"; 
-               initErrorFn = "dbo.initError_b";
-            }
-            if (useSQLUdfs)
-            {
-               checkErrorFn = udfSchema + checkErrorFn;
-               initErrorFn = udfSchema + initErrorFn;
-            }
+            String checkErrorFn = (useSQLUdfs ? udfSchema : "") + dialect.checkErrorFn();
+            String initErrorFn = (useSQLUdfs ? udfSchema : "") + dialect.initErrorFn();
             
             HQLAst checkErrFunc = createAstNode(FUNCTION, checkErrorFn, null);
             HQLAst initErrFunc = createAstNode(FUNCTION, initErrorFn, checkErrFunc);
@@ -3365,7 +3355,7 @@
                // as operand of the logical operators:
                needSQLBooleanConversion.add(checkErrFunc);
             }
-            if (dialect instanceof P2JPostgreSQLDialect)
+            if (useSQLUdfs)
             {
                Iterator<Aast> it = next.iterator();
                while (it.hasNext())
@@ -6361,6 +6351,12 @@
       {
          fn = fn.substring(udfSchema.length());
       }
+      int pos = fn.lastIndexOf("_");
+      if (pos > 0)
+      {
+         fn = fn.substring(0, pos);
+      }
+               
       return UdfNamesHolder.UDF_NAMES.contains(fn); 
    }
    

=== modified file 'src/com/goldencode/p2j/persist/dialect/Dialect.java'
--- src/com/goldencode/p2j/persist/dialect/Dialect.java	2023-01-28 04:45:51 +0000
+++ src/com/goldencode/p2j/persist/dialect/Dialect.java	2023-02-12 15:00:42 +0000
@@ -95,6 +95,7 @@
 **     SVL 20230110          P2JIndex.components() provides direct access to the components array in order to
 **                           improve performance.
 **     ECF 20230127          Added resolveBooleanConstant method.
+**     IAS 20230208          Dialect-specific error handler support.
 */
 
 /*
@@ -168,6 +169,7 @@
 import com.goldencode.p2j.persist.sequence.SequenceHandler;
 import com.goldencode.p2j.util.*;
 import com.goldencode.p2j.util.ErrorManager.*;
+import com.mchange.v2.c3p0.*;
 
 /**
  * Extends the API defined by Hibernate's abstract <code>Dialect</code> class
@@ -403,6 +405,7 @@
     */
    public abstract boolean useWordTables();
    
+   
    /**
     * Check if native UDFs are supported for the dialect
     * 
@@ -420,6 +423,24 @@
       return "";
    }
    
+   /** 
+    * Get name of the checkError UDF. 
+    * @return the name of the checkError UDF.  
+    */ 
+   public String checkErrorFn()
+   {
+      return "checkError";
+   }
+
+   /** 
+    * Get name of the initError UDF. 
+    * @return the name of the initError UDF.  
+    */ 
+   public String initErrorFn()
+   {
+      return "initError";
+   }
+
    /**
     * Check if the exception was caused by an error in UDF. 
     * @param e
@@ -493,6 +514,44 @@
    }
 
    /**
+    * Get c3p0 ConnectionCustomizer class for the dialect.
+    * 
+    * @param cfg 
+    *        Database configuration.
+    * @return c3p0 ConnectionCustomizer class for the dialect.
+    */
+   public Class<? extends AbstractConnectionCustomizer> connectionCustomizer(DatabaseConfig cfg)
+   {
+      return null;
+   }
+   
+   /**
+    * Activate error handler at the database side.
+    * @param  conn 
+    *         Database connection
+    * @throws SQLException
+    *         on error.
+    */
+   public void activateErrorHandler(Connection conn)
+   throws SQLException
+   {
+      
+   }
+   
+   /**
+    * Reset error handler at the database side.
+    * @param  conn 
+    *         Database connection
+    * @throws SQLException
+    *         on error.
+    */
+   public void resetErrorHandler(Connection conn)
+   throws SQLException
+   {
+      
+   }
+
+   /**
     * Worker method for {@code generateTriggerDDLs()}. It generates the DDLs needed to create all
     * triggers in a database with a specific schema and using a certain dialect.
     *

=== added file 'src/com/goldencode/p2j/persist/dialect/FWDMariaDBConnectionCustomizer.java'
--- src/com/goldencode/p2j/persist/dialect/FWDMariaDBConnectionCustomizer.java	1970-01-01 00:00:00 +0000
+++ src/com/goldencode/p2j/persist/dialect/FWDMariaDBConnectionCustomizer.java	2023-02-12 14:57:59 +0000
@@ -0,0 +1,113 @@
+/*
+** Module   : FWDMariaDBConnectionCustomizer
+** Abstract : c3p0 connection customizer
+**
+** Copyright (c) 2023, Golden Code Development Corporation.
+**
+** -#- -I- --Date-- ---------------------------------------Description---------------------------------------
+** 001 IAS 20230208 Created initial version.
+*/
+
+/*
+** This program is free software: you can redistribute it and/or modify
+** it under the terms of the GNU Affero General Public License as
+** published by the Free Software Foundation, either version 3 of the
+** License, or (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU Affero General Public License for more details.
+**
+** You may find a copy of the GNU Affero GPL version 3 at the following
+** location: https://www.gnu.org/licenses/agpl-3.0.en.html
+**
+** Additional terms under GNU Affero GPL version 3 section 7:
+**
+**   Under Section 7 of the GNU Affero GPL version 3, the following additional
+**   terms apply to the works covered under the License.  These additional terms
+**   are non-permissive additional terms allowed under Section 7 of the GNU
+**   Affero GPL version 3 and may not be removed by you.
+**
+**   0. Attribution Requirement.
+**
+**     You must preserve all legal notices or author attributions in the covered
+**     work or Appropriate Legal Notices displayed by works containing the covered
+**     work.  You may not remove from the covered work any author or developer
+**     credit already included within the covered work.
+**
+**   1. No License To Use Trademarks.
+**
+**     This license does not grant any license or rights to use the trademarks
+**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
+**     of Golden Code Development Corporation. You are not authorized to use the
+**     name Golden Code, FWD, or the names of any author or contributor, for
+**     publicity purposes without written authorization.
+**
+**   2. No Misrepresentation of Affiliation.
+**
+**     You may not represent yourself as Golden Code Development Corporation or FWD.
+**
+**     You may not represent yourself for publicity purposes as associated with
+**     Golden Code Development Corporation, FWD, or any author or contributor to
+**     the covered work, without written authorization.
+**
+**   3. No Misrepresentation of Source or Origin.
+**
+**     You may not represent the covered work as solely your work.  All modified
+**     versions of the covered work must be marked in a reasonable way to make it
+**     clear that the modified work is not originating from Golden Code Development
+**     Corporation or FWD.  All modified versions must contain the notices of
+**     attribution required in this license.
+*/
+
+package com.goldencode.p2j.persist.dialect;
+
+import java.sql.*;
+import org.slf4j.*;
+import com.goldencode.p2j.*;
+import com.mchange.v2.c3p0.*;
+
+/**
+ * Customizes the connection to database by setting up the {@code use.java.udfs} and {@code fwd.version}
+ * SQL configuration variable. 
+ */
+public class FWDMariaDBConnectionCustomizer 
+extends AbstractConnectionCustomizer
+{
+   /** Logger */
+   private static final Logger LOG = LoggerFactory.getLogger(FWDPostgreSQLConnectionCustomizer.class);
+   
+   /**
+    * Called immediately after a {@code Connection} is acquired from the underlying database for 
+    * incorporation into the pool.
+    *
+    * @param   c
+    *          Connection to be customized.
+    * @param   parentDataSourceIdentityToken
+    *          The parent data source identity token.
+    */
+   @Override
+   public void onAcquire(Connection c, String parentDataSourceIdentityToken)
+   throws java.lang.Exception 
+   {
+      // The database session user should be able to create temporary tables
+      // This can be granted by GRANT CREATE TEMPORARY TABLES ON *.* TO 'fwd_user'@'%';
+      try
+      {
+         c.prepareStatement(
+            "create temporary table if not exists "
+            + "temp_error_stack("
+            + "id integer not null auto_increment, "
+            + "state boolean not null, "
+            + "fwd_error_ctx text default @fwd_error_ctx, "
+            + "PRIMARY KEY (id)"
+            + ")"
+         ).executeUpdate();
+      }
+      catch(SQLException e)
+      {
+         LOG.warn("Failed to customize connection", e);
+      }
+   }
+}

=== renamed file 'src/com/goldencode/p2j/persist/dialect/FWDConnectionCustomizer.java' => 'src/com/goldencode/p2j/persist/dialect/FWDPostgreSQLConnectionCustomizer.java'
--- src/com/goldencode/p2j/persist/dialect/FWDConnectionCustomizer.java	2022-07-20 23:46:17 +0000
+++ src/com/goldencode/p2j/persist/dialect/FWDPostgreSQLConnectionCustomizer.java	2023-02-08 16:19:49 +0000
@@ -1,12 +1,13 @@
 /*
-** Module   : FWDConnectionCustomizer.java
+** Module   : FWDPostgreSQLConnectionCustomizer.java
 ** Abstract : c3p0 connection customizer
 **
-** Copyright (c) 2021-2022, Golden Code Development Corporation.
+** Copyright (c) 2021-2023, Golden Code Development Corporation.
 **
 ** -#- -I- --Date-- ---------------------------------------Description---------------------------------------
 ** 001 IAS 20210803 Created initial version.
 **     OM  20220721 Added copyright statement, javadoc and updated formatting to GC standard.
+*      IAS 20230202 Renamed
 */
 
 /*
@@ -73,11 +74,11 @@
  * Customizes the connection to database by setting up the {@code use.java.udfs} and {@code fwd.version}
  * SQL configuration variable. 
  */
-public class FWDConnectionCustomizer
+public class FWDPostgreSQLConnectionCustomizer
 extends AbstractConnectionCustomizer
 {
    /** Logger */
-   private static final Logger LOG = LoggerFactory.getLogger(FWDConnectionCustomizer.class);
+   private static final Logger LOG = LoggerFactory.getLogger(FWDPostgreSQLConnectionCustomizer.class);
    
    /**
     * Called immediately after a {@code Connection} is acquired from the underlying database for 

=== modified file 'src/com/goldencode/p2j/persist/dialect/MariaDbLenientDialect.java'
--- src/com/goldencode/p2j/persist/dialect/MariaDbLenientDialect.java	2023-01-31 20:57:34 +0000
+++ src/com/goldencode/p2j/persist/dialect/MariaDbLenientDialect.java	2023-02-12 15:00:42 +0000
@@ -14,6 +14,7 @@
 **     BS  20230126 Added support for SAVE CACHE.
 **     ECF 20230127 Data type adjustment for SAVE CACHE.
 **     OM  20230131 Code cleanup.
+**     IAS 20230208 Added error handler support.
 */
 
 /*
@@ -78,6 +79,8 @@
 import com.goldencode.p2j.persist.sequence.*;
 import com.goldencode.p2j.util.*;
 import com.goldencode.p2j.util.ErrorManager.*;
+import com.mchange.v2.c3p0.*;
+
 import java.io.*;
 import java.sql.*;
 import java.sql.Date;
@@ -479,6 +482,48 @@
    }
    
    /**
+    * Get c3p0 ConnectionCustomizer class for the dialect.
+    * @param <T>
+    *        Customizer class  
+    * @param cfg 
+    *        Database configuration.
+    * @return c3p0 ConnectionCustomizer class for the dialect.
+    */
+   @Override
+   public Class<? extends AbstractConnectionCustomizer> connectionCustomizer(DatabaseConfig cfg)
+   {
+      return FWDMariaDBConnectionCustomizer.class;
+   }
+   
+   /**
+    * Activate error handler at the database side.
+    * @param  conn 
+    *         Database connection
+    * @throws SQLException
+    *         on error.
+    */
+   @Override
+   public void activateErrorHandler(Connection conn)
+   throws SQLException
+   {
+      conn.prepareCall("{ call activateErrorHandler()}").executeUpdate();
+   }
+   
+   /**
+    * Reset error handler at the database side.
+    * @param  conn 
+    *         Database connection
+    * @throws SQLException
+    *         on error.
+    */
+   @Override
+   public void resetErrorHandler(Connection conn)
+   throws SQLException
+   {
+      conn.prepareCall("{ call resetErrorHandler()}").executeUpdate();
+   }
+
+   /**
     * Get a new instance of a splitter for DDL scripts. Reuses the splitter for PG dialect.
     * 
     * @return  A new instance of splitter for DDL scripts.
@@ -609,6 +654,26 @@
       return true;
    }
    
+   /** 
+    * Get name of the checkError UDF. 
+    * @return the name of the checkError UDF.  
+    */
+   @Override
+   public String checkErrorFn()
+   {
+      return "checkError_BB";
+   }
+
+   /** 
+    * Get name of the initError UDF. 
+    * @return the name of the initError UDF.  
+    */ 
+   @Override
+   public String initErrorFn()
+   {
+      return "initError_B";
+   }
+
    /**
     * Check if the exception was caused by an error in UDF.
     *

=== modified file 'src/com/goldencode/p2j/persist/dialect/P2JPostgreSQLDialect.java'
--- src/com/goldencode/p2j/persist/dialect/P2JPostgreSQLDialect.java	2023-02-04 14:43:34 +0000
+++ src/com/goldencode/p2j/persist/dialect/P2JPostgreSQLDialect.java	2023-02-12 15:00:56 +0000
@@ -123,6 +123,7 @@
 **     OM  20221026          Excluded table name from index name by default. It will be added as needed by
 **                           dialects.
 **     RAA 20230109          Overrided method getSequenceSetValString().
+**     IAS 20230208          Dialect-specific error handler support.
 */
 
 /*
@@ -196,6 +197,7 @@
 import com.goldencode.p2j.util.LogHelper;
 import com.goldencode.p2j.util.ErrorManager.*;
 import com.goldencode.util.*;
+import com.mchange.v2.c3p0.*;
 import com.goldencode.p2j.cfg.*;
 import com.goldencode.p2j.convert.*;
 import com.goldencode.p2j.directory.DirectoryService;
@@ -2032,6 +2034,19 @@
    }
    
    /**
+    * Get c3p0 ConnectionCustomizer class for the dialect.
+    * @param <T>
+    *        Customizer class  
+    * @param cfg 
+    *        Database configuration.
+    * @return c3p0 ConnectionCustomizer class for the dialect.
+    */
+   @Override
+   public Class<? extends AbstractConnectionCustomizer> connectionCustomizer(DatabaseConfig cfg)
+   {
+      return cfg.isUseJavaUDFs() ? null : FWDPostgreSQLConnectionCustomizer.class;
+   }
+   /**
     * Worker method for {@code generateTriggerDDLs()}. It generates the DDLs needed to create all
     * triggers in a database with a specific schema and using a certain dialect.
     *

=== modified file 'src/com/goldencode/p2j/persist/dialect/P2JSQLServer2008Dialect.java'
--- src/com/goldencode/p2j/persist/dialect/P2JSQLServer2008Dialect.java	2023-01-10 16:58:00 +0000
+++ src/com/goldencode/p2j/persist/dialect/P2JSQLServer2008Dialect.java	2023-02-12 15:01:53 +0000
@@ -43,6 +43,7 @@
 **     RAA 20230109 Overrided method getSequenceSetValString().
 **     SVL 20230110 P2JIndex.components() provides direct access to the components array in order to improve
 **                  performance.
+**     IAS 20230208 Dialect-specific error handler support.
 */
 
 /*
@@ -1363,6 +1364,26 @@
       return false;
    }
 
+   /** 
+    * Get name of the checkError UDF. 
+    * @return the name of the checkError UDF.  
+    */
+   @Override
+   public String checkErrorFn()
+   {
+      return "dbo.checkError_bb";
+   }
+
+   /** 
+    * Get name of the initError UDF. 
+    * @return the name of the initError UDF.  
+    */ 
+   @Override
+   public String initErrorFn()
+   {
+      return "dbo.initError_b";
+   }
+
    /**
     * Check if the exception was caused by error in UDF. 
     * @param e

=== modified file 'src/com/goldencode/p2j/persist/orm/FqlToSqlConverter.java'
--- src/com/goldencode/p2j/persist/orm/FqlToSqlConverter.java	2023-02-04 14:43:34 +0000
+++ src/com/goldencode/p2j/persist/orm/FqlToSqlConverter.java	2023-02-12 15:02:55 +0000
@@ -47,6 +47,7 @@
 **     SVL 20230108 Improved performance by replacing some "for-each" loops with indexed "for" loops.
 **         20221031 Collected fields of "select" query.
 **         20221101 Fixed possible NPE.
+**     IAS 20230208 Dialect-specific error handler support.
 */
 
 /*
@@ -271,6 +272,13 @@
     * Mutable session attributes' values used in the query 
     */
    private final List<SessionAttr> sessionAttrs = new ArrayList<>(); 
+
+   /** The name of the checkError UDF with prepended dot */
+   private final String _checkErrorFn;
+   
+   /** Flag indicating that the query contains error handling */
+   private boolean containsErrorHandling = false;
+
    
    /**
     * The constructor is private. To create an instance of this class, use the {@code getInstance}
@@ -296,6 +304,7 @@
       this.generateUniqueSqlColumnNames = true;
       this.useWordTables = !SchemaDictionary.TEMP_TABLE_DB.equals(schema) && 
                            !db.isDirty() && !db.isMeta() && dialect.useWordTables();
+      this._checkErrorFn = "." + dialect.checkErrorFn();
    }
    
    /**
@@ -347,6 +356,16 @@
    {
       return sessionAttrs;
    }
+
+   /**
+    * Checks if the query contains error handling.
+    * 
+    * @return  {@code true} if the query contains error handling.
+    */
+   public boolean containsErrorHandling()
+   {
+      return containsErrorHandling;
+   }
    /**
     * Check if the query reads _UserTableStat VST. 
     * 
@@ -2481,6 +2500,10 @@
                   }
                   else 
                   {
+                     if (text.equals(dialect.checkErrorFn()) || text.endsWith(_checkErrorFn))
+                     {
+                        containsErrorHandling = true;
+                     }
                      sb.append(text);
                      sb.append("(");
                      if (next.getNumImmediateChildren() == 0)

=== modified file 'src/com/goldencode/p2j/persist/orm/PooledDataSourceProvider.java'
--- src/com/goldencode/p2j/persist/orm/PooledDataSourceProvider.java	2022-10-24 10:38:22 +0000
+++ src/com/goldencode/p2j/persist/orm/PooledDataSourceProvider.java	2023-02-12 15:04:54 +0000
@@ -2,7 +2,7 @@
 ** Module   : PooledDataSourceProvider.java
 ** Abstract : Implementation of DataSourceProvider that offers a pooled DataSource.
 **
-** Copyright (c) 2019-2021, Golden Code Development Corporation.
+** Copyright (c) 2019-2023, Golden Code Development Corporation.
 **
 ** -#- -I- --Date-- --------------------------------------Description----------------------------------------
 ** 001 ECF 20191001 Created initial version with basic runtime support.
@@ -11,6 +11,7 @@
 **     ECF 20210910 Minor cleanup.
 **     IAS 20220816 Do not use ConnectionCustomizer for non-PostgreSQL databases.
 **     TW  20221024 Implement support for driver_properties.
+**     IAS 20230208 Dialect-specific error handler support.
 */
 
 /*
@@ -191,14 +192,15 @@
                }
             }
          }
-         if (!cfg.isUseJavaUDFs() && 
-                  (DatabaseManager.getDialect(database) instanceof P2JPostgreSQLDialect))
+         Class<? extends AbstractConnectionCustomizer> customizer = 
+                  DatabaseManager.getDialect(database).connectionCustomizer(cfg);
+         if (ds.getConnectionCustomizerClassName() == null && customizer != null)
+         {
+            ds.setConnectionCustomizerClassName(customizer.getName());
+         }
+         if (!cfg.isUseJavaUDFs() )
          {
             extensions.putIfAbsent("useJavaUdfs", "n");
-            if (ds.getConnectionCustomizerClassName() == null)
-            {
-               ds.setConnectionCustomizerClassName(FWDConnectionCustomizer.class.getName());
-            }
          }
          if (!extensions.isEmpty())
          {

=== modified file 'src/com/goldencode/p2j/persist/orm/Query.java'
--- src/com/goldencode/p2j/persist/orm/Query.java	2023-02-10 09:39:25 +0000
+++ src/com/goldencode/p2j/persist/orm/Query.java	2023-02-12 15:04:48 +0000
@@ -2,7 +2,7 @@
 ** Module   : Query.java
 ** Abstract : Wrapper for FQL statements.
 **
-** Copyright (c) 2019-2022, Golden Code Development Corporation.
+** Copyright (c) 2019-2023, Golden Code Development Corporation.
 **
 ** -#- -I- --Date-- ---------------------------------------Description---------------------------------------
 ** 001 ECF 20191001 Created initial version with stubbed methods.
@@ -26,6 +26,7 @@
 **     SBI 20221023 Added a usage of SQLQuery.uniqueResult(Session session, RowStructure rowStructure).
 **     CA  20221031 Javadoc fixes.
 **     IAS 20230209 Fixed ${TZ} placeholder value
+**     IAS 20230208 Dialect-specific error handler support.
 */
 
 /*
@@ -120,6 +121,9 @@
    /** Flag indicating that the query reads from _Lock VST */
    private boolean lockTableRead = false;
 
+   /** Flag indicating that the query contains error handling */
+   private boolean containsErrorHandling = false;
+   
    /**
     * The maximum number of results accepted by the (SELECT) query. Used with {@code firstResult}
     * to configure result pagination.
@@ -353,12 +357,15 @@
             paramCount = fql2sql.getLastConversionParamCount();
             wasRewritten = fql2sql.isQueryWasRewritten();
             userTableStatRead = fql2sql.isUserTableStatRead();
+            this.containsErrorHandling = fql2sql.containsErrorHandling();
             lockTableRead = fql2sql.isLockTableRead();
             if (!wasRewritten)
             {
                cache.accept(this);
             }
-            sqlQuery = Session.createSQLQuery(sql, fql2sql.sessionAttrs(), fql2sql.getParameterPermutation());
+            sqlQuery = Session.createSQLQuery(sql, fql2sql.sessionAttrs(), 
+                     fql2sql.getParameterPermutation()).
+                     containsErrorHandling(containsErrorHandling);
          };
          
          QUERY_PARSE.timer(op);

=== modified file 'src/com/goldencode/p2j/persist/orm/SQLQuery.java'
--- src/com/goldencode/p2j/persist/orm/SQLQuery.java	2023-02-10 09:39:25 +0000
+++ src/com/goldencode/p2j/persist/orm/SQLQuery.java	2023-02-12 15:04:05 +0000
@@ -51,6 +51,7 @@
 **     CA  20230104 If a cached record is incomplete, get the full record from the database when a hydrate is
 **                  is performed.
 **     IAS 20230209 Fixed ${TZ} placeholder value
+**     IAS 20230208 Dialect-specific error handler support.
 */
 
 /*
@@ -172,6 +173,9 @@
    /** Mutable session attributes' values used in the query. */
    private final List<SessionAttr> sessionAttrs; 
    
+   /** Flag indicating that the query contains error handling */
+   private boolean containsErrorHandling = false;
+
    /** The {@code PreparedStatement}. */
    private PreparedStatement stmt;
    
@@ -214,6 +218,18 @@
    }
    
    /**
+    * Set the value of the flag indicating that the query contains error handling.
+    * @param value
+    *        The new value of the flag;
+    * @return <code>this</code>
+    */
+   public SQLQuery containsErrorHandling(boolean value)
+   {
+      this.containsErrorHandling = value;
+      return this;
+   }
+   
+   /**
     * Checks if the query can raise {@code SQLWarning}.
     * 
     * @return  {@code true} if the query can raise {@code SQLWarning}.
@@ -237,6 +253,7 @@
       return this;
    }
    
+
    /**
     * Expand placeholder.
     * @param dialect 
@@ -319,6 +336,7 @@
       
       try
       {
+         activateErrorHandler(session);
          stmt = conn.prepareStatement(sql, scrollMode, readOnlyMode);
          setParameters(stmt, false);
          
@@ -332,7 +350,8 @@
          
          ResultSet resultSet = resultSetArray[0];
          reportSQLWarnings(session);
-         return new ScrollableResults<>(stmt, resultSet, rowStructure, session);
+         return new ScrollableResults<T>(stmt, resultSet, rowStructure, session).
+                    onClose(() -> {resetErrorHandler(session); return null;});
       }
       catch (SQLException exc)
       {
@@ -344,6 +363,10 @@
          }
          throw new PersistenceException("Error scrolling", exc);
       }
+//      finally
+//      {
+//         resetErrorHandler(session);
+//      }
    }
    
    /**
@@ -372,6 +395,7 @@
       
       try
       {
+         activateErrorHandler(session);
          stmt = conn.prepareStatement(sql);
          setParameters(stmt, false);
          
@@ -381,13 +405,18 @@
             log(session.getDatabase(), stmt, () -> resultSetArray[0] = stmt.executeQuery());
          
          ResultSet resultSet = resultSetArray[0];
-         return new ScrollableResults<>(stmt, resultSet, rowStructure, session);
+         return new ScrollableResults<T>(stmt, resultSet, rowStructure, session).
+                  onClose(() -> {resetErrorHandler(session); return null;});
       }
       catch (SQLException exc)
       {
          close();
          throw new PersistenceException("Error scrolling", exc);
       }
+//      finally 
+//      {
+//         resetErrorHandler(session);
+//      }
    }
    
    /**
@@ -439,6 +468,7 @@
       
       try
       {
+         activateErrorHandler(session);
          stmt = conn.prepareStatement(sql);
          setParameters(stmt, false);
          
@@ -489,6 +519,7 @@
       finally
       {
          close();
+         resetErrorHandler(session);
       }
    }
    
@@ -511,6 +542,7 @@
       
       try
       {
+         activateErrorHandler(session);
          stmt = conn.prepareStatement(sql);
          setParameters(stmt, true);
          
@@ -529,6 +561,7 @@
       finally
       {
          close();
+         resetErrorHandler(session);
       }
    }
    
@@ -562,6 +595,7 @@
       
       try
       {
+         activateErrorHandler(session);
          int rowSize = rowStructure.size();
          List<T> ret = new ArrayList<>();
          stmt = conn.prepareStatement(sql);
@@ -640,6 +674,7 @@
       }
       finally
       {
+         resetErrorHandler(session);
          close();
       }
    }
@@ -1022,6 +1057,50 @@
    }
    
    /**
+    * Activate error handler at the database side.
+    * @param  session 
+    *         Database session
+    * @throws SQLException
+    *         on error.
+    * @throws PersistenceException 
+    *         on error.
+    */
+   private void activateErrorHandler(Session session)
+   throws SQLException, PersistenceException
+   {
+      if (!containsErrorHandling)
+      {
+         return;
+      }
+      Query.getDialect(session).activateErrorHandler(session.getConnection());  
+   }
+   
+   /**
+    * Reset error handler at the database side.
+    * @param  session 
+    *         Database session
+    * @throws SQLException
+    *         on error.
+    * @throws PersistenceException 
+    *         on error.
+    */
+   public void resetErrorHandler(Session session)
+   throws PersistenceException
+   {
+      if (!containsErrorHandling)
+      {
+         return;
+      }
+      try
+      {
+         Query.getDialect(session).activateErrorHandler(session.getConnection());
+      }
+      catch (SQLException e)
+      {
+         throw new PersistenceException("Failed to reset error handler", e);
+      }  
+   }
+   /**
     * Sets the value for a parameter at a specified position in a statement. The process is done in recursive
     * manner for arrays and {@code List}s. The {@code pos} is incremented automatically for each scalar
     * parameter configured.

=== modified file 'src/com/goldencode/p2j/persist/orm/ScrollableResults.java'
--- src/com/goldencode/p2j/persist/orm/ScrollableResults.java	2022-10-27 21:27:12 +0000
+++ src/com/goldencode/p2j/persist/orm/ScrollableResults.java	2023-02-12 15:04:30 +0000
@@ -2,13 +2,14 @@
 ** Module   : ScrollableResults.java
 ** Abstract : Allows scrollable access to result set.
 **
-** Copyright (c) 2019-2022, Golden Code Development Corporation.
+** Copyright (c) 2019-2023, Golden Code Development Corporation.
 **
 ** -#- -I- --Date-- ---------------------------------Description---------------------------------
 ** 001 ECF 20191001 Created initial version, with stubbed methods.
 **     OM  20191111 Added method implementation.
 ** 002 SBI 20220811 Added new version of get method to retrieve selected columns from a row.
 **         20221023 Added a usage of SQLQuery.hydrateRecord(ResultSet, RowStructure, int, Session).
+**     IAS 20230208          Dialect-specific error handler support.
 */
 
 /*
@@ -96,6 +97,9 @@
    /** The {@code Session} to be used.*/
    private final Session session;
    
+   /** On close hook*/
+   private SandboxRun<Void> onClose = () -> null;
+   
    /**
     * Constructs a {@code ScrollableResults} object for further use.
     * 
@@ -129,6 +133,17 @@
    }
    
    /**
+    * Set on close hook
+    * @param hook
+    *        new hook;
+    * @return <code>this</code>
+    */
+   public ScrollableResults<T> onClose(SandboxRun<Void> hook)
+   {
+      this.onClose = hook;
+      return this;
+   }
+   /**
     * Go to result row.
     *
     * @return  {@code true} if there is a result under the cursor and {@code false} otherwise
@@ -339,11 +354,15 @@
 
    /**
     * Obtain the value of a {@code i}-th column of the current row.
+    * @param i 
+    *        column number
+    * @param tClass 
+    *        column 
     *
     * @return  The value on {@code i}-th column of the current row if {@code i} and current row
     *          are valid and {@code null} otherwise.
     */
-   public T get(int i, Class<T> tClass)
+   public T get(int i, Class<T>tClass)
    {
       return execute(() -> rs.getObject(i + 1, tClass), null);
    }
@@ -409,7 +428,7 @@
    public void close()
    throws PersistenceException
    {
-      execute(() -> { stmt.close(); return null; }, null);
+      execute(() -> { stmt.close(); onClose.run(); return null; }, null);
    }
    
    /**

=== modified file 'udf/mariadb/error_handler.sql'
--- udf/mariadb/error_handler.sql	2022-08-17 06:40:50 +0000
+++ udf/mariadb/error_handler.sql	2023-02-12 14:29:52 +0000
@@ -1,11 +1,11 @@
 /*
 ** Module   : error-handlers.sql
-** Abstract : 'Native' versions of the ErrorHandler-based Java UDFs
+** Abstract : 'Native' versions of the ErrorHandler-based Java UDFs (MariaDB version)
 **
-** Copyright (c) 2021, Golden Code Development Corporation.
+** Copyright (c) 2023, Golden Code Development Corporation.
 **
 ** -#- -I- --Date-- --------------------------------Description----------------------------------
-** 001 IAS 20210803 Created initial version.
+** 001 IAS 20230208 Created initial version.
 */
 /*
 ** This program is free software: you can redistribute it and/or modify
@@ -62,24 +62,14 @@
 /**
  * Check if the error stack is active
  */
-##CREATE OR REPLACE FUNCTION udf.error_handler_active()
-CREATE OR REPLACE FUNCTION error_handler_active() ##!! TODO
-##RETURNS boolean 
+CREATE OR REPLACE FUNCTION error_handler_active()
 RETURNS BOOLEAN
 DETERMINISTIC
 BEGIN
-  RETURN null;
+  RETURN true; -- exists(select * from temp_error_stack where fwd_error_ctx = @fwd_error_ctx);
 END;
 $$
 
-##AS $function$
-##select exists (
-##   select 1
-##   from   information_schema.tables 
-##   where  table_schema like 'pg_temp_%'
-##   and table_name='temp_error_stack'
-##)
-##$function$
 
 /**
  * A special wrapper function for a UDF called
@@ -118,25 +108,21 @@
  * @return  false if an error occurred in this scope;
  *          otherwise, the result of the boolean sub-expression.
  */
-##CREATE OR REPLACE FUNCTION udf.initerror(state boolean) 
-CREATE OR REPLACE FUNCTION initerror_B(state BOOLEAN) ##!! TODO
-##RETURNS boolean 
+CREATE OR REPLACE FUNCTION initError_B(state BOOLEAN)
 RETURNS BOOLEAN
 DETERMINISTIC
 BEGIN
-  RETURN null;
+  call initError_P(state);
+  return true;
 END;
 $$
 
-##AS $function$
-##begin
-##   if not udf.error_handler_active() then  
-##      create temporary table if not exists temp_error_stack(id serial, state boolean not null) on commit drop;
-##   end if;
-##   insert into temp_error_stack(state) values (state);
-##   return true;
-##end;
-##$function$
+CREATE OR REPLACE PROCEDURE initError_P(state BOOLEAN)
+DETERMINISTIC
+BEGIN
+  insert into temp_error_stack(state,fwd_error_ctx) values (state, @fwd_error_ctx);
+END;
+$$
 
 /**
  * Initialize the error flag stack for the current function scope by
@@ -147,31 +133,41 @@
  * 
  * @return  Boolean.TRUE.
  */
-##CREATE OR REPLACE FUNCTION udf.checkerror(init boolean, result boolean)
-CREATE OR REPLACE FUNCTION checkerror_BB(init BOOLEAN, result BOOLEAN) ##!! TODO
-##RETURNS boolean 
+CREATE OR REPLACE FUNCTION checkError_BB(init BOOLEAN, result BOOLEAN)
 RETURNS BOOLEAN
 DETERMINISTIC
 BEGIN
-  RETURN null;
-END;
-$$
-
-##AS $function$
-##declare top bigint;
-##declare val boolean;
-##begin
-##   if not udf.error_handler_active() then  
-##      create temporary table if not exists temp_error_stack(id serial, state boolean not null) on commit drop;
-##   end if;
-##   top := (select max(id) from temp_error_stack);
-##   if top is null then
-##      return null;
-##--    raise exception 'Error stack is empty';
-##   end if;
-##   val := (select state from temp_error_stack where id = top);
-##   delete from temp_error_stack where id = top;
-##   return case when val then false else result end;
-##end;
-##$function$
+   declare top integer;
+   declare val boolean;
+   set top = (select max(id) from temp_error_stack);
+   if top is null then
+      return null;
+   end if;
+   set val = (select state from temp_error_stack where id = top);
+   delete from temp_error_stack where id = top;
+   return if(val, false, result);
+END;
+$$
+
+/**
+ * Activate error handler
+ */
+CREATE OR REPLACE PROCEDURE activateErrorHandler()
+DETERMINISTIC
+begin
+   truncate table temp_error_stack;
+   set @fwd_error_ctx = uuid();  
+END;
+$$
+
+/**
+ * Reset error handler
+ */
+CREATE OR REPLACE PROCEDURE resetErrorHandler()
+DETERMINISTIC
+begin
+   truncate table temp_error_stack;
+   set @fwd_error_ctx = null;  
+END;
+$$
 

=== added file 'udf/mariadb/guard.awk'
--- udf/mariadb/guard.awk	1970-01-01 00:00:00 +0000
+++ udf/mariadb/guard.awk	2023-02-12 13:38:24 +0000
@@ -0,0 +1,104 @@
+# Module   : guard.awk
+# Abstract : awk script for generating 'guarded' versions of the MariaDB UDFs
+#
+# Copyright (c) 2023, Golden Code Development Corporation.
+#
+# -#- -I- --Date-- --------------------------------Description----------------------------------
+# 001 IAS 20230308 Created initial version.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You may find a copy of the GNU Affero GPL version 3 at the following
+# location: https://www.gnu.org/licenses/agpl-3.0.en.html
+#
+# Additional terms under GNU Affero GPL version 3 section 7:
+#
+#   Under Section 7 of the GNU Affero GPL version 3, the following additional
+#   terms apply to the works covered under the License.  These additional terms
+#   are non-permissive additional terms allowed under Section 7 of the GNU
+#   Affero GPL version 3 and may not be removed by you.
+#
+#   0. Attribution Requirement.
+#
+#     You must preserve all legal notices or author attributions in the covered
+#     work or Appropriate Legal Notices displayed by works containing the covered
+#     work.  You may not remove from the covered work any author or developer
+#     credit already included within the covered work.
+#
+#   1. No License To Use Trademarks.
+#
+#     This license does not grant any license or rights to use the trademarks
+#     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
+#     of Golden Code Development Corporation. You are not authorized to use the
+#     name Golden Code, FWD, or the names of any author or contributor, for
+#     publicity purposes without written authorization.
+#
+#   2. No Misrepresentation of Affiliation.
+#
+#     You may not represent yourself as Golden Code Development Corporation or FWD.
+#
+#     You may not represent yourself for publicity purposes as associated with
+#     Golden Code Development Corporation, FWD, or any author or contributor to
+#     the covered work, without written authorization.
+#
+#   3. No Misrepresentation of Source or Origin.
+#
+#     You may not represent the covered work as solely your work.  All modified
+#     versions of the covered work must be marked in a reasonable way to make it
+#     clear that the modified work is not originating from Golden Code Development
+#     Corporation or FWD.  All modified versions must contain the notices of
+#     attribution required in this license.
+
+# Generates 'guarded' versions of the UDFs
+# Usage: awk -f guard.awk <udfs.sql >guarded.sql
+
+BEGIN {
+print "-- The 'guarded' versions of SQL UDFs";
+print "-- Generated automatically from udfs.sql with guard.awk script.";
+print "-- DO NOT MODIFY!";
+}
+
+/\/\*/, /\*\// {
+   print $0;
+}
+
+match($0, "^CREATE *OR *REPLACE *FUNCTION *(.*)$", m) {
+   f = m[1];
+   print "create or replace function guarded_" f; 
+}
+/^RETURNS/ {
+   print tolower($0);
+   s = f; 
+   gsub(/\(50, 10\)/, "", s); 
+   gsub(/\(3\)/, "", s); 
+   gsub(/ JSON/, "", s);
+   gsub(/ [a-zA-Z]*\)/, ")", s);
+   gsub(/ [^,]*, */, ", ", s); 
+   gsub(/##!! TODO/, "", s);
+   print "deterministic";
+   print "begin";
+   print "declare tmp text;"
+   print "declare exit handler for SQLEXCEPTION";
+   print "  begin";
+   print "    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;";
+   print "    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);";
+   print "    if error_handler_active() then";
+   print "      call initError_P(true);";
+   print "      signal sqlstate '01FWD' set message_text = tmp;";
+   print "      return null;";
+   print "    else";
+   print "      signal sqlstate 'FWD00' set message_text = tmp;";
+   print "    end if;";
+   print "  end;";
+   print "  return " s ";";
+   print "end;";
+   print "$$";
+}

=== added file 'udf/mariadb/guarded.sql'
--- udf/mariadb/guarded.sql	1970-01-01 00:00:00 +0000
+++ udf/mariadb/guarded.sql	2023-02-12 13:42:03 +0000
@@ -0,0 +1,7893 @@
+-- The 'guarded' versions of SQL UDFs
+-- Generated automatically from udfs.sql with guard.awk script.
+-- DO NOT MODIFY!
+/*
+** Module   : udfs.sql
+** Abstract : 'native' versions of the Java UDFs for MariaDB
+**
+** Copyright (c) 2022, Golden Code Development Corporation.
+**
+** -#- -I- --Date-- --------------------------------Description----------------------------------
+** 001 IAS 20220810 Created UDFs' templates.
+*/
+/*
+** This program is free software: you can redistribute it and/or modify
+** it under the terms of the GNU Affero General Public License as
+** published by the Free Software Foundation, either version 3 of the
+** License, or (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU Affero General Public License for more details.
+**
+** You may find a copy of the GNU Affero GPL version 3 at the following
+** location: https://www.gnu.org/licenses/agpl-3.0.en.html
+**
+** Additional terms under GNU Affero GPL version 3 section 7:
+**
+**   Under Section 7 of the GNU Affero GPL version 3, the following additional
+**   terms apply to the works covered under the License.  These additional terms
+**   are non-permissive additional terms allowed under Section 7 of the GNU
+**   Affero GPL version 3 and may not be removed by you.
+**
+**   0. Attribution Requirement.
+**
+**     You must preserve all legal notices or author attributions in the covered
+**     work or Appropriate Legal Notices displayed by works containing the covered
+**     work.  You may not remove from the covered work any author or developer
+**     credit already included within the covered work.
+**
+**   1. No License To Use Trademarks.
+**
+**     This license does not grant any license or rights to use the trademarks
+**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
+**     of Golden Code Development Corporation. You are not authorized to use the
+**     name Golden Code, FWD, or the names of any author or contributor, for
+**     publicity purposes without written authorization.
+**
+**   2. No Misrepresentation of Affiliation.
+**
+**     You may not represent yourself as Golden Code Development Corporation or FWD.
+**
+**     You may not represent yourself for publicity purposes as associated with
+**     Golden Code Development Corporation, FWD, or any author or contributor to
+**     the covered work, without written authorization.
+**
+**   3. No Misrepresentation of Source or Origin.
+**
+**     You may not represent the covered work as solely your work.  All modified
+**     versions of the covered work must be marked in a reasonable way to make it
+**     clear that the modified work is not originating from Golden Code Development
+**     Corporation or FWD.  All modified versions must contain the notices of
+**     attribution required in this license.
+*/
+/**
+ * For debugging.
+ * See the commented table definition above 
+ */
+/**
+ * Convert 4GL 'matches' pattern to regex
+ */
+create or replace function guarded_regex_tb(s TEXT, windows BOOLEAN)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return regex_tb(s, windows);
+end;
+$$
+/**
+ * Convert 4GL 'CAN-DO' function pattern to regex
+ */
+create or replace function guarded_regex_t(s TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return regex_t(s);
+end;
+$$
+/**
+ * Transform the given integer into a string as the time value 
+ */
+create or replace function guarded_totimestring_lti(v BIGINT, fmt TEXT, tz INTEGER)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return totimestring_lti(v, fmt, tz);
+end;
+$$
+/**
+ * Computes a new date by adding respective number of time units.
+ * Corresponds to the 4GL ADD-INTERVAL function.
+ * 
+ * @param   initial
+ *          The first date.
+ * @param   amount
+ *          The count of units to be added.
+ * @param   unit
+ *          The unit to measure the interval.
+ *          
+ * @return  The date that is amount units further in time. 
+ */
+create or replace function guarded_addinterval_dit(initial DATE, amount INTEGER, unit TEXT)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return addinterval_dit(initial, amount, unit);
+end;
+$$
+/**
+ * Computes a new date by adding respective number of time units.
+ * Corresponds to the 4GL ADD-INTERVAL function.
+ * 
+ * @param   initial
+ *          The first date.
+ * @param   amount
+ *          The count of units to be added.
+ * @param   unit
+ *          The unit to measure the interval.
+ *          
+ * @return  The date that is amount units further in time. 
+ */
+create or replace function guarded_addinterval_dlt(initial DATE, amount BIGINT, unit TEXT)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return addinterval_dlt(initial, amount, unit);
+end;
+$$
+/**
+ * Computes a new date by adding respective number of time units.
+ * Corresponds to the 4GL ADD-INTERVAL function.
+ * 
+ * @param   initial
+ *          The first date.
+ * @param   amount
+ *          The count of units to be added.
+ * @param   unit
+ *          The unit to measure the interval.
+ *          
+ * @return  The date that is amount units further in time. 
+ */
+create or replace function guarded_addinterval_sit(initial TIMESTAMP(3), amount INTEGER, unit TEXT)
+returns timestamp(3)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return addinterval_sit(initial, amount, unit);
+end;
+$$
+/**
+ * Computes a new date by adding respective number of time units.
+ * Corresponds to the 4GL ADD-INTERVAL function.
+ * 
+ * @param   initial
+ *          The first date.
+ * @param   amount
+ *          The count of units to be added.
+ * @param   unit
+ *          The unit to measure the interval.
+ *          
+ * @return  The date that is amount units further in time. 
+ */
+create or replace function guarded_addinterval_slt(initial TIMESTAMP(3), amount BIGINT, unit TEXT)
+returns timestamp(3)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return addinterval_slt(initial, amount, unit);
+end;
+$$
+/**
+ * Test whether one string begins with another case insensitively.
+ * Corresponds to the 4GL BEGINS operator
+ */
+create or replace function guarded_begins_tt(a TEXT, b TEXT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return begins_tt(a, b);
+end;
+$$
+/**
+ * Test whether one string begins with another, optionally taking case into account.
+ * Corresponds to the 4GL BEGINS operator
+ */
+create or replace function guarded_begins_ttb(a TEXT, b TEXT, cs BOOLEAN)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return begins_ttb(a, b, cs);
+end;
+$$
+/**
+ * Returns the uppercase representation of the string.
+ * Corresponds to the 4GL CAPS function
+ */
+create or replace function guarded_caps_t(t TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return caps_t(t);
+end;
+$$
+/**
+ * Returns the lowercase representation of the string.
+ * Corresponds to the 4GL CAPS function
+ */
+create or replace function guarded_lc_t(t TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lc_t(t);
+end;
+$$
+/**
+ * Concatenate two strings.
+ * Corresponds to the 4GL CONCAT function
+ */
+create or replace function guarded_concat_tt(a TEXT, b TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return concat_tt(a, b);
+end;
+$$
+/**
+ * Calculate the quotient of two numbers.
+ * Corresponds to the 4GL Division operator
+ */
+create or replace function guarded_divide_nn(x DECIMAL(50, 10), y DECIMAL(50, 10))
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return divide_nn(x, y);
+end;
+$$
+/**
+ * Calculate the quotient of two numbers.
+ * Corresponds to the 4GL Division operator
+ */
+create or replace function guarded_divide_ni(x DECIMAL(50, 10), y INTEGER)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return divide_ni(x, y);
+end;
+$$
+/**
+ * Calculate the quotient of two numbers.
+ * Corresponds to the 4GL Division operator
+ */
+create or replace function guarded_divide_nl(x DECIMAL(50, 10), y BIGINT)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return divide_nl(x, y);
+end;
+$$
+/**
+ * Calculate the quotient of two numbers.
+ * Corresponds to the 4GL Division operator
+ */
+create or replace function guarded_divide_ll(x BIGINT, y BIGINT)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return divide_ll(x, y);
+end;
+$$
+/**
+ * Calculate the quotient of two numbers.
+ * Corresponds to the 4GL Division operator
+ */
+create or replace function guarded_divide_li(x BIGINT, y INTEGER)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return divide_li(x, y);
+end;
+$$
+/**
+ * Calculate the quotient of two numbers.
+ * Corresponds to the 4GL Division operator
+ */
+create or replace function guarded_divide_ln(x BIGINT, y DECIMAL(50, 10))
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return divide_ln(x, y);
+end;
+$$
+/**
+ * Calculate the quotient of two numbers.
+ * Corresponds to the 4GL Division operator
+ */
+create or replace function guarded_divide_ii(x INTEGER, y INTEGER)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return divide_ii(x, y);
+end;
+$$
+/**
+ * Calculate the quotient of two numbers.
+ * Corresponds to the 4GL Division operator
+ */
+create or replace function guarded_divide_il(x INTEGER, y BIGINT)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return divide_il(x, y);
+end;
+$$
+/**
+ * Calculate the quotient of two numbers.
+ * Corresponds to the 4GL Division operator
+ */
+create or replace function guarded_divide_in(x INTEGER, y DECIMAL(50, 10))
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return divide_in(x, y);
+end;
+$$
+/**
+ * Extract a string from a delimited list represented by another string,
+ * given its index within the list and the delimiter.
+ * Corresponds to the 4GL ENTRY function
+ */
+create or replace function guarded_entryin_ltt(idx BIGINT, list TEXT, delim TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return entryin_ltt(idx, list, delim);
+end;
+$$
+/**
+ * Extract a string from a delimited list represented by another string,
+ * given its index within the list and the delimiter.
+ * Corresponds to the 4GL ENTRY function
+ */
+create or replace function guarded_entryin_itt(idx INTEGER, list TEXT, delim TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return entryin_itt(idx, list, delim);
+end;
+$$
+/**
+ * Extract a string from a delimited list represented by another string,
+ * given its index within the list.
+ * Corresponds to the 4GL ENTRY function
+ */
+create or replace function guarded_entryin_lt(idx BIGINT, list TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return entryin_lt(idx, list);
+end;
+$$
+/**
+ * Extract a string from a delimited list represented by another string,
+ * given its index within the list.
+ * Corresponds to the 4GL ENTRY function
+ */
+create or replace function guarded_entryin_it(idx INTEGER, list TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return entryin_it(idx, list);
+end;
+$$
+/**
+ * Test two value for equality 
+ * Corresponds to the 4GL EQ (=) operator
+ */
+create or replace function guarded_eq_ll(x BIGINT, y BIGINT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return eq_ll(x, y);
+end;
+$$
+/**
+ * Test two value for equality 
+ * Corresponds to the 4GL EQ (=) operator
+ */
+create or replace function guarded_eq_li(x BIGINT, y INTEGER)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return eq_li(x, y);
+end;
+$$
+/**
+ * Test two value for equality 
+ * Corresponds to the 4GL EQ (=) operator
+ */
+create or replace function guarded_eq_ln(x BIGINT, y DECIMAL(50, 10))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return eq_ln(x, y);
+end;
+$$
+/**
+ * Test two value for equality 
+ * Corresponds to the 4GL EQ (=) operator
+ */
+create or replace function guarded_eq_ss(x DATETIME(3), y DATETIME(3))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return eq_ss(x, y);
+end;
+$$
+/**
+ * Test two value for equality 
+ * Corresponds to the 4GL EQ (=) operator
+ */
+create or replace function guarded_eq_bb(x BOOLEAN, y BOOLEAN)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return eq_bb(x, y);
+end;
+$$
+/**
+ * Test two value for equality 
+ * Corresponds to the 4GL EQ (=) operator
+ */
+create or replace function guarded_eq_tt(x TEXT, y TEXT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return eq_tt(x, y);
+end;
+$$
+/**
+ * Test two value for equality 
+ * Corresponds to the 4GL EQ (=) operator
+ */
+create or replace function guarded_eq_ii(x INTEGER, y INTEGER)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return eq_ii(x, y);
+end;
+$$
+/**
+ * Test two value for equality 
+ * Corresponds to the 4GL EQ (=) operator
+ */
+create or replace function guarded_eq_il(x INTEGER, y BIGINT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return eq_il(x, y);
+end;
+$$
+/**
+ * Test two value for equality 
+ * Corresponds to the 4GL EQ (=) operator
+ */
+create or replace function guarded_eq_in(x INTEGER, y DECIMAL(50, 10))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return eq_in(x, y);
+end;
+$$
+/**
+ * Test two value for equality 
+ * Corresponds to the 4GL EQ (=) operator
+ */
+create or replace function guarded_eq_nn(x DECIMAL(50, 10), y DECIMAL(50, 10))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return eq_nn(x, y);
+end;
+$$
+/**
+ * Test two value for equality 
+ * Corresponds to the 4GL EQ (=) operator
+ */
+create or replace function guarded_eq_ni(x DECIMAL(50, 10), y INTEGER)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return eq_ni(x, y);
+end;
+$$
+/**
+ * Test two value for equality 
+ * Corresponds to the 4GL EQ (=) operator
+ */
+create or replace function guarded_eq_nl(x DECIMAL(50, 10), y BIGINT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return eq_nl(x, y);
+end;
+$$
+/**
+ * Test two value for equality 
+ * Corresponds to the 4GL EQ (=) operator
+ */
+create or replace function guarded_eq_dd(x DATE, y DATE)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return eq_dd(x, y);
+end;
+$$
+/**
+ * Return a character instance that is comprised of num concatenated copies of a given string
+ * Corresponds to the 4GL FILL function
+ */
+create or replace function guarded_fill_ti(str TEXT, num INTEGER) 
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return fill_ti(str, num) ;
+end;
+$$
+/**
+ * Return a character instance that is comprised of num concatenated copies of a given string
+ * Corresponds to the 4GL FILL function
+ */
+create or replace function guarded_fill_tl(str TEXT, num BIGINT) 
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return fill_tl(str, num) ;
+end;
+$$
+/**
+ * Retrieve the day of the month (1-based) from a date.
+ * Corresponds to the 4GL DAY function
+ */
+create or replace function guarded_getday_s(ts TIMESTAMP(3))
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return getday_s(ts);
+end;
+$$
+/**
+ * Retrieve the day of the month (1-based) from a date.
+ * Corresponds to the 4GL DAY function
+ */
+create or replace function guarded_getday_d(dt DATE)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return getday_d(dt);
+end;
+$$
+/**
+ * Computes the interval between two dates. The value is expressed in unit units.
+ * Corresponds to the 4GL INTERVAL function
+ */
+create or replace function guarded_getinterval_sst(ts1 TIMESTAMP(3), ts2 TIMESTAMP(3), unit TEXT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return getinterval_sst(ts1, ts2, unit);
+end;
+$$
+/**
+ * Computes the interval between two dates. The value is expressed in unit units.
+ * Corresponds to the 4GL INTERVAL function
+ */
+create or replace function guarded_getinterval_dst(dt1 DATE, ts2 TIMESTAMP(3), unit TEXT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return getinterval_dst(dt1, ts2, unit);
+end;
+$$
+/**
+ * Computes the interval between two dates. The value is expressed in unit units.
+ * Corresponds to the 4GL INTERVAL function
+ */
+create or replace function guarded_getinterval_ddt(dt1 DATE, dt2 DATE, unit TEXT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return getinterval_ddt(dt1, dt2, unit);
+end;
+$$
+/**
+ * Computes the interval between two dates. The value is expressed in unit units.
+ * Corresponds to the 4GL INTERVAL function
+ */
+create or replace function guarded_getinterval_sdt(ts1 TIMESTAMP(3), dt2 DATE, unit TEXT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return getinterval_sdt(ts1, dt2, unit);
+end;
+$$
+/**
+ * Determine the number of days between two dates.
+ * Corresponds to the 4GL Date subtraction operator
+ */
+create or replace function guarded_datespan_dd(d1 DATE, d2 DATE)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return datespan_dd(d1, d2);
+end;
+$$
+/**
+ * Retrieve the month number (1-based) from a date.
+ * Corresponds to the 4GL MONTH function
+ */
+create or replace function guarded_getmonth_s(ts TIMESTAMP(3))
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return getmonth_s(ts);
+end;
+$$
+/**
+ * Retrieve the month number (1-based) from a date.
+ * Corresponds to the 4GL MONTH function
+ */
+create or replace function guarded_getmonth_d(dt DATE)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return getmonth_d(dt);
+end;
+$$
+/**
+ * Retrieve the time  in milliseconds from the timestamp
+ * Corresponds to the 4GL MTIME(datetime-expression) function
+ */
+create or replace function guarded_getmtime_s(ts TIMESTAMP(3))
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return getmtime_s(ts);
+end;
+$$
+/**
+ * Retrieve the time since midnight in milliseconds
+ * Corresponds to the 4GL MTIME() function
+ */
+create or replace function guarded_getmtime()
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return getmtime();
+end;
+$$
+/**
+ * Returns the current timezone.
+ * Corresponds to the 4GL TIMEZONE() function
+ * 
+ * TODO: rework to consider SESSION:TIMEZONE and SESSION:DATE-SOURCE values
+ */
+create or replace function guarded_gettimezone()
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gettimezone();
+end;
+$$
+/**
+ * Retrieve the week day number from a date.
+ * Corresponds to the 4GL WEEKDAY function
+ */
+create or replace function guarded_getweekday_d(dt DATE)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return getweekday_d(dt);
+end;
+$$
+/**
+ * Retrieve the week day number from a date.
+ * Corresponds to the 4GL WEEKDAY function
+ */
+create or replace function guarded_getweekday_s(ts TIMESTAMP(3))
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return getweekday_s(ts);
+end;
+$$
+/**
+ * Retrieve the year number from a date.
+ * Corresponds to the 4GL YEAR function
+*/
+create or replace function guarded_getyear_s(ts TIMESTAMP(3))
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return getyear_s(ts);
+end;
+$$
+/**
+ * Retrieve the year number from a date.
+ * Corresponds to the 4GL YEAR function
+ */
+create or replace function guarded_getyear_d(dt DATE)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return getyear_d(dt);
+end;
+$$
+/**
+ * Test whether x > y. 
+ * Corresponds to the 4GL GT (>) operator
+ */
+create or replace function guarded_gt_bb(x BOOLEAN, y BOOLEAN)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gt_bb(x, y);
+end;
+$$
+/**
+ * Test whether x > y. 
+ * Corresponds to the 4GL GT (>) operator
+ */
+create or replace function guarded_gt_nn(x DECIMAL(50, 10), y DECIMAL(50, 10))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gt_nn(x, y);
+end;
+$$
+/**
+ * Test whether x > y. 
+ * Corresponds to the 4GL GT (>) operator
+ */
+create or replace function guarded_gt_ni(x DECIMAL(50, 10), y INTEGER)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gt_ni(x, y);
+end;
+$$
+/**
+ * Test whether x > y. 
+ * Corresponds to the 4GL GT (>) operator
+ */
+create or replace function guarded_gt_nl(x DECIMAL(50, 10), y BIGINT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gt_nl(x, y);
+end;
+$$
+/**
+ * Test whether x > y. 
+ * Corresponds to the 4GL GT (>) operator
+ */
+create or replace function guarded_gt_ss(x DATETIME(3), y DATETIME(3))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gt_ss(x, y);
+end;
+$$
+/**
+ * Test whether x > y. 
+ * Corresponds to the 4GL GT (>) operator
+ */
+create or replace function guarded_gt_tt(x TEXT, y TEXT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gt_tt(x, y);
+end;
+$$
+/**
+ * Test whether x > y. 
+ * Corresponds to the 4GL GT (>) operator
+ */
+create or replace function guarded_gt_ll(x BIGINT, y BIGINT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gt_ll(x, y);
+end;
+$$
+/**
+ * Test whether x > y. 
+ * Corresponds to the 4GL GT (>) operator
+ */
+create or replace function guarded_gt_li(x BIGINT, y INTEGER)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gt_li(x, y);
+end;
+$$
+/**
+ * Test whether x > y. 
+ * Corresponds to the 4GL GT (>) operator
+ */
+create or replace function guarded_gt_ln(x BIGINT, y DECIMAL(50, 10))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gt_ln(x, y);
+end;
+$$
+/**
+ * Test whether x > y. 
+ * Corresponds to the 4GL GT (>) operator
+ */
+create or replace function guarded_gt_dd(x DATE, y DATE)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gt_dd(x, y);
+end;
+$$
+/**
+ * Test whether x > y. 
+ * Corresponds to the 4GL GT (>) operator
+ */
+create or replace function guarded_gt_ii(x INTEGER, y INTEGER)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gt_ii(x, y);
+end;
+$$
+/**
+ * Test whether x > y. 
+ * Corresponds to the 4GL GT (>) operator
+ */
+create or replace function guarded_gt_il(x INTEGER, y BIGINT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gt_il(x, y);
+end;
+$$
+/**
+ * Test whether x > y. 
+ * Corresponds to the 4GL GT (>) operator
+ */
+create or replace function guarded_gt_in(x INTEGER, y DECIMAL(50, 10))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gt_in(x, y);
+end;
+$$
+/**
+ * Test whether x >= y. 
+ * Corresponds to the 4GL GE (>=) operator
+ */
+create or replace function guarded_gte_bb(x BOOLEAN, y BOOLEAN)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gte_bb(x, y);
+end;
+$$
+/**
+ * Test whether x >= y. 
+ * Corresponds to the 4GL GE (>=) operator
+ */
+create or replace function guarded_gte_dd(x DATE, y DATE)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gte_dd(x, y);
+end;
+$$
+/**
+ * Test whether x >= y. 
+ * Corresponds to the 4GL GE (>=) operator
+ */
+create or replace function guarded_gte_tt(x TEXT, y TEXT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gte_tt(x, y);
+end;
+$$
+/**
+ * Test whether x >= y. 
+ * Corresponds to the 4GL GE (>=) operator
+ */
+create or replace function guarded_gte_ii(x INTEGER, y INTEGER)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gte_ii(x, y);
+end;
+$$
+/**
+ * Test whether x >= y. 
+ * Corresponds to the 4GL GE (>=) operator
+ */
+create or replace function guarded_gte_il(x INTEGER, y BIGINT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gte_il(x, y);
+end;
+$$
+/**
+ * Test whether x >= y. 
+ * Corresponds to the 4GL GE (>=) operator
+ */
+create or replace function guarded_gte_in(x INTEGER, y DECIMAL(50, 10))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gte_in(x, y);
+end;
+$$
+/**
+ * Test whether x >= y. 
+ * Corresponds to the 4GL GE (>=) operator
+ */
+create or replace function guarded_gte_ss(x DATETIME(3), y DATETIME(3))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gte_ss(x, y);
+end;
+$$
+/**
+ * Test whether x >= y. 
+ * Corresponds to the 4GL GE (>=) operator
+ */
+create or replace function guarded_gte_ll(x BIGINT, y BIGINT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gte_ll(x, y);
+end;
+$$
+/**
+ * Test whether x >= y. 
+ * Corresponds to the 4GL GE (>=) operator
+ */
+create or replace function guarded_gte_li(x BIGINT, y INTEGER)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gte_li(x, y);
+end;
+$$
+/**
+ * Test whether x >= y. 
+ * Corresponds to the 4GL GE (>=) operator
+ */
+create or replace function guarded_gte_ln(x BIGINT, y DECIMAL(50, 10))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gte_ln(x, y);
+end;
+$$
+/**
+ * Test whether x >= y. 
+ * Corresponds to the 4GL GE (>=) operator
+ */
+create or replace function guarded_gte_nn(x DECIMAL(50, 10), y DECIMAL(50, 10))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gte_nn(x, y);
+end;
+$$
+/**
+ * Test whether x >= y. 
+ * Corresponds to the 4GL GE (>=) operator
+ */
+create or replace function guarded_gte_ni(x DECIMAL(50, 10), y INTEGER)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gte_ni(x, y);
+end;
+$$
+/**
+ * Test whether x >= y. 
+ * Corresponds to the 4GL GE (>=) operator
+ */
+create or replace function guarded_gte_nl(x DECIMAL(50, 10), y BIGINT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return gte_nl(x, y);
+end;
+$$
+/**
+ * Retrieve the 1-based index at which one string is found within another,
+ * or 0 if the string is not found, starting at a particular index,
+ * optionally taking case into account.
+ * Corresponds to the 4GL INDEX function
+ */
+create or replace function guarded_indexof_ttib(src TEXT, target TEXT, startp INTEGER, cs BOOLEAN)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return indexof_ttib(src, target, startp, cs);
+end;
+$$
+/**
+ * Retrieve the 1-based index at which one string is found within another,
+ * or 0 if the string is not found, starting at a particular index,
+ * optionally taking case into account.
+ * Corresponds to the 4GL INDEX function
+ */
+create or replace function guarded_indexof_ttnb(src TEXT, target TEXT, startp DECIMAL(50, 10), cs BOOLEAN)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return indexof_ttnb(src, target, startp, cs);
+end;
+$$
+/**
+ * Retrieve the 1-based index at which one string is found within another,
+ * or 0 if the string is not found, starting at a particular index.
+ * Corresponds to the 4GL INDEX function
+ */
+create or replace function guarded_indexof_ttn(src TEXT, target TEXT, startp DECIMAL(50, 10))
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return indexof_ttn(src, target, startp);
+end;
+$$
+/**
+ * Retrieve the 1-based index at which one string is found within another,
+ * or 0 if the string is not found, starting at a particular index.
+ * Corresponds to the 4GL INDEX function
+ */
+create or replace function guarded_indexof_tti(src TEXT, target TEXT, startp INTEGER)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return indexof_tti(src, target, startp);
+end;
+$$
+/**
+ * Retrieve the 1-based index at which one string is found within another,
+ * or 0 if the string is not found, starting at a particular index,
+ * optionally taking case into account.
+ * Corresponds to the 4GL INDEX function
+ */
+create or replace function guarded_indexof_ttlb(src TEXT, target TEXT, startp BIGINT, cs BOOLEAN)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return indexof_ttlb(src, target, startp, cs);
+end;
+$$
+/**
+ * Retrieve the 1-based index at which one string is found within another,
+ * or 0 if the string is not found, starting at a particular index.
+ * Corresponds to the 4GL INDEX function
+ */
+create or replace function guarded_indexof_ttl(src TEXT, target TEXT, startp BIGINT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return indexof_ttl(src, target, startp);
+end;
+$$
+/**
+ * Retrieve the 1-based index at which one string is found within another,
+ * or 0 if the string is not found.
+ * Corresponds to the 4GL INDEX function
+ */
+create or replace function guarded_indexof_ttb(src TEXT, target TEXT, cs BOOLEAN)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return indexof_ttb(src, target, cs);
+end;
+$$
+/**
+ * Retrieve the 1-based index at which one string is found within another,
+ * or 0 if the string is not found.
+ * Corresponds to the 4GL INDEX function
+ */
+create or replace function guarded_indexof_tt(src TEXT, target TEXT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return indexof_tt(src, target);
+end;
+$$
+/**
+ * Retrieve the 1-based last index at which one string is found within another,
+ * or 0 if the string is not found, starting at a particular index,
+ * optionally taking case into account.
+ * Corresponds to the 4GL R-INDEX function
+ */
+create or replace function guarded_rindexof_ttib(src TEXT, target TEXT, startp INTEGER, cs BOOLEAN)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return rindexof_ttib(src, target, startp, cs);
+end;
+$$
+/**
+ * Retrieve the 1-based last index at which one string is found within another,
+ * or 0 if the string is not found, starting at a particular index,
+ * optionally taking case into account.
+ * Corresponds to the 4GL R-INDEX function
+ */
+create or replace function guarded_rindexof_ttnb(src TEXT, target TEXT, startp DECIMAL(50, 10), cs BOOLEAN)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return rindexof_ttnb(src, target, startp, cs);
+end;
+$$
+/**
+ * Retrieve the 1-based last index at which one string is found within another,
+ * or 0 if the string is not found, starting at a particular index,
+ * optionally taking case into account.
+ * Corresponds to the 4GL R-INDEX function
+ */
+create or replace function guarded_rindexof_ttn(src TEXT, target TEXT, startp DECIMAL(50, 10))
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return rindexof_ttn(src, target, startp);
+end;
+$$
+/**
+ * Retrieve the 1-based last index at which one string is found within another,
+ * or 0 if the string is not found, starting at a particular index,
+ * optionally taking case into account.
+ * Corresponds to the 4GL R-INDEX function
+ */
+create or replace function guarded_rindexof_tti(src TEXT, target TEXT, startp INTEGER)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return rindexof_tti(src, target, startp);
+end;
+$$
+/**
+ * Retrieve the 1-based last index at which one string is found within another,
+ * or 0 if the string is not found, starting at a particular index,
+ * optionally taking case into account.
+ * Corresponds to the 4GL R-INDEX function
+ */
+create or replace function guarded_rindexof_ttlb(src TEXT, target TEXT, startp BIGINT, cs BOOLEAN)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return rindexof_ttlb(src, target, startp, cs);
+end;
+$$
+/**
+ * Retrieve the 1-based last index at which one string is found within another,
+ * or 0 if the string is not found, starting at a particular index,
+ * optionally taking case into account.
+ * Corresponds to the 4GL R-INDEX function
+ */
+create or replace function guarded_rindexof_ttl(src TEXT, target TEXT, startp BIGINT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return rindexof_ttl(src, target, startp);
+end;
+$$
+/**
+ * Retrieve the 1-based last index at which one string is found within another,
+ * or 0 if the string is not found, starting at a particular index,
+ * optionally taking case into account.
+ * Corresponds to the 4GL R-INDEX function
+ */
+create or replace function guarded_rindexof_ttb(src TEXT, target TEXT, cs BOOLEAN)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return rindexof_ttb(src, target, cs);
+end;
+$$
+/**
+ * Retrieve the 1-based last index at which one string is found within another,
+ * or 0 if the string is not found, starting at a particular index,
+ * optionally taking case into account.
+ * Corresponds to the 4GL R-INDEX function
+ */
+create or replace function guarded_rindexof_tt(src TEXT, target TEXT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return rindexof_tt(src, target);
+end;
+$$
+/**
+ * Get the length of a string, using the type parameter
+ * to determine the measurement.
+ * Corresponds to the 4GL LENTGH function
+ */
+create or replace function guarded_lengthof_tt(str TEXT, stype TEXT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lengthof_tt(str, stype);
+end;
+$$
+/**
+ * Get the length of a string.
+ * Corresponds to the 4GL LENTGH function
+ */
+create or replace function guarded_lengthof_t(str TEXT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lengthof_t(str);
+end;
+$$
+/**
+ * Look up the index of a string which represents an element in a
+ * comma-delimited list represented by another string, using a specific
+ * delimiter, and optionally taking case into account.
+ * Corresponds to the 4GL LOOKUP function
+ */
+create or replace function guarded_lookup_tttb(entry TEXT, list TEXT, delim TEXT, cs BOOLEAN)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lookup_tttb(entry, list, delim, cs);
+end;
+$$
+/**
+ * Look up the index of a string which represents an element in a
+ * comma-delimited list represented by another string, using a specific
+ * delimiter.
+ * Corresponds to the 4GL LOOKUP function
+ */
+create or replace function guarded_lookup_ttt(entry TEXT, list TEXT, delim TEXT) 
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lookup_ttt(entry, list, delim) ;
+end;
+$$
+/**
+ * Look up the index of a string which represents an element in a
+ * comma-delimited list represented by another string.
+ * Corresponds to the 4GL LOOKUP function
+ */
+create or replace function guarded_lookup_tt(entry TEXT, list TEXT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lookup_tt(entry, list);
+end;
+$$
+/**
+ * Look up the index of a string which represents an element in a
+ * comma-delimited list represented by another string.
+ * Corresponds to the 4GL LOOKUP function
+ */
+create or replace function guarded_lookup_ttb(entry TEXT, list TEXT, cs BOOLEAN)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lookup_ttb(entry, list, cs);
+end;
+$$
+/**
+ * Test whether x < y. 
+ * Corresponds to the 4GL LT (<) operator
+ */
+create or replace function guarded_lt_ss(x DATETIME(3), y DATETIME(3))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lt_ss(x, y);
+end;
+$$
+/**
+ * Test whether x < y. 
+ * Corresponds to the 4GL LT (<) operator
+ */
+create or replace function guarded_lt_bb(x BOOLEAN, y BOOLEAN)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lt_bb(x, y);
+end;
+$$
+/**
+ * Test whether x < y. 
+ * Corresponds to the 4GL LT (<) operator
+ */
+create or replace function guarded_lt_ll(x BIGINT, y BIGINT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lt_ll(x, y);
+end;
+$$
+/**
+ * Test whether x < y. 
+ * Corresponds to the 4GL LT (<) operator
+ */
+create or replace function guarded_lt_li(x BIGINT, y INTEGER)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lt_li(x, y);
+end;
+$$
+/**
+ * Test whether x < y. 
+ * Corresponds to the 4GL LT (<) operator
+ */
+create or replace function guarded_lt_ln(x BIGINT, y DECIMAL(50, 10))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lt_ln(x, y);
+end;
+$$
+/**
+ * Test whether x < y. 
+ * Corresponds to the 4GL LT (<) operator
+ */
+create or replace function guarded_lt_dd(x DATE, y DATE)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lt_dd(x, y);
+end;
+$$
+/**
+ * Test whether x < y. 
+ * Corresponds to the 4GL LT (<) operator
+ */
+create or replace function guarded_lt_nn(x DECIMAL(50, 10), y DECIMAL(50, 10))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lt_nn(x, y);
+end;
+$$
+/**
+ * Test whether x < y. 
+ * Corresponds to the 4GL LT (<) operator
+ */
+create or replace function guarded_lt_ni(x DECIMAL(50, 10), y INTEGER)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lt_ni(x, y);
+end;
+$$
+/**
+ * Test whether x < y. 
+ * Corresponds to the 4GL LT (<) operator
+ */
+create or replace function guarded_lt_nl(x DECIMAL(50, 10), y BIGINT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lt_nl(x, y);
+end;
+$$
+/**
+ * Test whether x < y. 
+ * Corresponds to the 4GL LT (<) operator
+ */
+create or replace function guarded_lt_tt(x TEXT, y TEXT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lt_tt(x, y);
+end;
+$$
+/**
+ * Test whether x < y. 
+ * Corresponds to the 4GL LT (<) operator
+ */
+create or replace function guarded_lt_ii(x INTEGER, y INTEGER)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lt_ii(x, y);
+end;
+$$
+/**
+ * Test whether x < y. 
+ * Corresponds to the 4GL LT (<) operator
+ */
+create or replace function guarded_lt_il(x INTEGER, y BIGINT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lt_il(x, y);
+end;
+$$
+/**
+ * Test whether x < y. 
+ * Corresponds to the 4GL LT (<) operator
+ */
+create or replace function guarded_lt_in(x INTEGER, y DECIMAL(50, 10))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lt_in(x, y);
+end;
+$$
+/**
+ * Test whether x <= y. 
+ * Corresponds to the 4GL LE (<=) operator
+ */
+create or replace function guarded_lte_ss(x DATETIME(3), y DATETIME(3))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lte_ss(x, y);
+end;
+$$
+/**
+ * Test whether x <= y. 
+ * Corresponds to the 4GL LE (<=) operator
+ */
+create or replace function guarded_lte_ii(x INTEGER, y INTEGER)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lte_ii(x, y);
+end;
+$$
+/**
+ * Test whether x <= y. 
+ * Corresponds to the 4GL LE (<=) operator
+ */
+create or replace function guarded_lte_il(x INTEGER, y BIGINT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lte_il(x, y);
+end;
+$$
+/**
+ * Test whether x <= y. 
+ * Corresponds to the 4GL LE (<=) operator
+ */
+create or replace function guarded_lte_in(x INTEGER, y DECIMAL(50, 10))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lte_in(x, y);
+end;
+$$
+/**
+ * Test whether x <= y. 
+ * Corresponds to the 4GL LE (<=) operator
+ */
+create or replace function guarded_lte_tt(x TEXT, y TEXT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lte_tt(x, y);
+end;
+$$
+/**
+ * Test whether x <= y. 
+ * Corresponds to the 4GL LE (<=) operator
+ */
+create or replace function guarded_lte_nn(x DECIMAL(50, 10), y DECIMAL(50, 10))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lte_nn(x, y);
+end;
+$$
+/**
+ * Test whether x <= y. 
+ * Corresponds to the 4GL LE (<=) operator
+ */
+create or replace function guarded_lte_nl(x DECIMAL(50, 10), y BIGINT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lte_nl(x, y);
+end;
+$$
+/**
+ * Test whether x <= y. 
+ * Corresponds to the 4GL LE (<=) operator
+ */
+create or replace function guarded_lte_ni(x DECIMAL(50, 10), y INTEGER)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lte_ni(x, y);
+end;
+$$
+/**
+ * Test whether x <= y. 
+ * Corresponds to the 4GL LE (<=) operator
+ */
+create or replace function guarded_lte_bb(x BOOLEAN, y BOOLEAN)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lte_bb(x, y);
+end;
+$$
+/**
+ * Test whether x <= y. 
+ * Corresponds to the 4GL LE (<=) operator
+ */
+create or replace function guarded_lte_ll(x BIGINT, y BIGINT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lte_ll(x, y);
+end;
+$$
+/**
+ * Test whether x <= y. 
+ * Corresponds to the 4GL LE (<=) operator
+ */
+create or replace function guarded_lte_li(x BIGINT, y INTEGER)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lte_li(x, y);
+end;
+$$
+/**
+ * Test whether x <= y. 
+ * Corresponds to the 4GL LE (<=) operator
+ */
+create or replace function guarded_lte_ln(x BIGINT, y DECIMAL(50, 10))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lte_ln(x, y);
+end;
+$$
+/**
+ * Test whether x <= y. 
+ * Corresponds to the 4GL LE (<=) operator
+ */
+create or replace function guarded_lte_dd(x DATE, y DATE)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return lte_dd(x, y);
+end;
+$$
+/**
+ * Trim white space from the left side of text.
+ * Corresponds to the 4GL LEFT-TRIM function
+ */
+create or replace function guarded_ltrimws_t(s TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return ltrimws_t(s);
+end;
+$$
+/**
+ * Trim the specified characters from the left side of text.
+ * Corresponds to the 4GL LEFT-TRIM function
+ */
+create or replace function guarded_ltrimws_tt(s TEXT, list TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return ltrimws_tt(s, list);
+end;
+$$
+/**
+ * Trim white space from the right side of text.
+ * Corresponds to the 4GL RIGHT-TRIM function
+ */
+create or replace function guarded_rtrimws_t(s TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return rtrimws_t(s);
+end;
+$$
+/**
+ * Trim white space from the right side of text.
+ * Corresponds to the 4GL RIGHT-TRIM function
+ */
+create or replace function guarded_rtrimws_tt(s TEXT, list TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return rtrimws_tt(s, list);
+end;
+$$
+/**
+ * Tests if the first operand matches a regular expression that is provided by the caller,
+ * honoring the case sensitivity preference of the caller.
+ * Corresponds to the 4GL MATCHES operator
+ * 
+ * @param   op
+ *          String to check for a match.
+ * @param   pattern
+ *          Progress style matching pattern.
+ * @param   caseSens
+ *          true if a case-sensitive comparison should be used.
+ * @param   windows
+ *          true if the backslash does not have special meaning. On Unix, P4GL
+ *          the backslash (\)is an escape character, like tilde (~).
+ */
+create or replace function guarded_matches__ttbb(op TEXT, pattern TEXT, casesens BOOLEAN, windows BOOLEAN)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return matches__ttbb(op, pattern, casesens, windows);
+end;
+$$
+create or replace function guarded_matches_ttbb(op TEXT, pattern TEXT, casesens BOOLEAN, windows BOOLEAN)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return matches_ttbb(op, pattern, casesens, windows);
+end;
+$$
+/**
+ * Tests if the first operand matches a regular expression that is provided by the caller,
+ * honoring the case sensitivity preference of the caller.
+ * Corresponds to the 4GL MATCHES operator
+ * 
+ * @param   op
+ *          String to check for a match.
+ * @param   pattern
+ *          Progress style matching pattern.
+ * @param   windows
+ *          true if the backslash does not have special meaning. On Unix, P4GL
+ *          the backslash (\)is an escape character, like tilde (\).
+ */
+create or replace function guarded_matches_ttb(op TEXT, pattern TEXT, windows BOOLEAN)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return matches_ttb(op, pattern, windows);
+end;
+$$
+/**
+ * Tests if the first operand matches a regular expression that is provided by the caller,
+ * honoring the case sensitivity preference of the caller.
+ * Corresponds to the 4GL MATCHES operator
+ * 
+ * @param   op
+ *          String to check for a match.
+ * @param   pattern
+ *          Progress style matching pattern.
+ */
+create or replace function guarded_matches_tt(op TEXT, pattern TEXT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return matches_tt(op, pattern);
+end;
+$$
+/**
+ * Determine whether a comma-separated list contains a specific item.
+ * Corresponds to the 4GL CAN-DO function
+ */
+create or replace function guarded_matcheslist_tt(list TEXT, item TEXT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return matcheslist_tt(list, item);
+end;
+$$
+/**
+ * Returns the maximum from a list of values.
+ * Corresponds to the 4GL MAXIMUM function
+ */
+create or replace function guarded_maximum_ss(v1 TIMESTAMP(3), v2 TIMESTAMP(3))
+returns timestamp(3)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return maximum_ss(v1, v2);
+end;
+$$
+/**
+ * Returns the maximum from a list of values.
+ * Corresponds to the 4GL MAXIMUM function
+ */
+create or replace function guarded_maximum_dd(v1 DATE, v2 DATE)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return maximum_dd(v1, v2);
+end;
+$$
+/**
+ * Returns the maximum from a list of values.
+ * Corresponds to the 4GL MAXIMUM function
+ */
+create or replace function guarded_maximum_nn(v1 DECIMAL(50, 10), v2 DECIMAL(50, 10))
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return maximum_nn(v1, v2);
+end;
+$$
+/**
+ * Returns the maximum from a list of values.
+ * Corresponds to the 4GL MAXIMUM function
+ */
+create or replace function guarded_maximum_ii(v1 INTEGER, v2 INTEGER)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return maximum_ii(v1, v2);
+end;
+$$
+/**
+ * Returns the maximum from a list of values.
+ * Corresponds to the 4GL MAXIMUM function
+ */
+create or replace function guarded_maximum_ll(v1 BIGINT, v2 BIGINT)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return maximum_ll(v1, v2);
+end;
+$$
+/**
+ * Returns the maximum from a list of values.
+ * Corresponds to the 4GL MAXIMUM function
+ */
+create or replace function guarded_maximum_ni(v1 DECIMAL(50, 10), v2 INTEGER)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return maximum_ni(v1, v2);
+end;
+$$
+/**
+ * Returns the maximum from a list of values.
+ * Corresponds to the 4GL MAXIMUM function
+ */
+create or replace function guarded_maximum_in(v1 INTEGER, v2 DECIMAL(50, 10))
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return maximum_in(v1, v2);
+end;
+$$
+/**
+ * Returns the maximum from a list of values.
+ * Corresponds to the 4GL MAXIMUM function
+ */
+create or replace function guarded_maximum_nl(v1 DECIMAL(50, 10), v2 BIGINT)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return maximum_nl(v1, v2);
+end;
+$$
+/**
+ * Returns the maximum from a list of values.
+ * Corresponds to the 4GL MAXIMUM function
+ */
+create or replace function guarded_maximum_ln(v1 BIGINT, v2 DECIMAL(50, 10))
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return maximum_ln(v1, v2);
+end;
+$$
+/**
+ * Returns the maximum from a list of values.
+ * Corresponds to the 4GL MAXIMUM function
+ */
+create or replace function guarded_maximum_il(v1 INTEGER, v2 BIGINT)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return maximum_il(v1, v2);
+end;
+$$
+/**
+ * Returns the maximum from a list of values.
+ * Corresponds to the 4GL MAXIMUM function
+ */
+create or replace function guarded_maximum_li(v1 BIGINT, v2 INTEGER)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return maximum_li(v1, v2);
+end;
+$$
+/**
+ * Returns the maximum from a list of values.
+ * Corresponds to the 4GL MAXIMUM function
+ */
+create or replace function guarded_maximum_tt(v1 TEXT, v2 TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return maximum_tt(v1, v2);
+end;
+$$
+/**
+ * Returns the minimum from a list of values.
+ * Corresponds to the 4GL MINIMUM function
+ */
+create or replace function guarded_minimum_ss(v1 TIMESTAMP(3), v2 TIMESTAMP(3))
+returns timestamp(3)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minimum_ss(v1, v2);
+end;
+$$
+/**
+ * Returns the minimum from a list of values.
+ * Corresponds to the 4GL MINIMUM function
+ */
+create or replace function guarded_minimum_dd(v1 DATE, v2 DATE)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minimum_dd(v1, v2);
+end;
+$$
+/**
+ * Returns the minimum from a list of values.
+ * Corresponds to the 4GL MINIMUM function
+ */
+create or replace function guarded_minimum_nn(v1 DECIMAL(50, 10), v2 DECIMAL(50, 10))
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minimum_nn(v1, v2);
+end;
+$$
+/**
+ * Returns the minimum from a list of values.
+ * Corresponds to the 4GL MAXIMUM function
+ */
+create or replace function guarded_minimum_ii(v1 INTEGER, v2 INTEGER)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minimum_ii(v1, v2);
+end;
+$$
+/**
+ * Returns the minimum from a list of values.
+ * Corresponds to the 4GL MAXIMUM function
+ */
+create or replace function guarded_minimum_ll(v1 BIGINT, v2 BIGINT)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minimum_ll(v1, v2);
+end;
+$$
+/**
+ * Returns the minimum from a list of values.
+ * Corresponds to the 4GL MAXIMUM function
+ */
+create or replace function guarded_minimum_ni(v1 DECIMAL(50, 10), v2 INTEGER)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minimum_ni(v1, v2);
+end;
+$$
+/**
+ * Returns the minimum from a list of values.
+ * Corresponds to the 4GL MAXIMUM function
+ */
+create or replace function guarded_minimum_in(v1 INTEGER, v2 DECIMAL(50, 10))
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minimum_in(v1, v2);
+end;
+$$
+/**
+ * Returns the minimum from a list of values.
+ * Corresponds to the 4GL MAXIMUM function
+ */
+create or replace function guarded_minimum_nl(v1 DECIMAL(50, 10), v2 BIGINT)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minimum_nl(v1, v2);
+end;
+$$
+/**
+ * Returns the minimum from a list of values.
+ * Corresponds to the 4GL MAXIMUM function
+ */
+create or replace function guarded_minimum_ln(v1 BIGINT, v2 DECIMAL(50, 10))
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minimum_ln(v1, v2);
+end;
+$$
+/**
+ * Returns the minimum from a list of values.
+ * Corresponds to the 4GL MAXIMUM function
+ */
+create or replace function guarded_minimum_il(v1 INTEGER, v2 BIGINT)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minimum_il(v1, v2);
+end;
+$$
+/**
+ * Returns the minimum from a list of values.
+ * Corresponds to the 4GL MAXIMUM function
+ */
+create or replace function guarded_minimum_li(v1 BIGINT, v2 INTEGER)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minimum_li(v1, v2);
+end;
+$$
+/**
+ * Returns the minimum from a list of values.
+ * Corresponds to the 4GL MINIMUM function
+ */
+create or replace function guarded_minimum_tt(v1 TEXT, v2 TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minimum_tt(v1, v2);
+end;
+$$
+/**
+ * Calculate a date by subtracting a number of days from a date.
+ * Corresponds to the 4GL Date subtraction operator
+ */
+create or replace function guarded_minus_dn(d DATE, x DECIMAL(50, 10))
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minus_dn(d, x);
+end;
+$$
+/**
+ * Calculate a date by subtracting a number of days from a date.
+ * Corresponds to the 4GL Date subtraction operator
+ */
+create or replace function guarded_minus_di(d DATE, x INTEGER)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minus_di(d, x);
+end;
+$$
+/**
+ * Calculate a date by subtracting a number of days from a date.
+ * Corresponds to the 4GL Date subtraction operator
+ */
+create or replace function guarded_minus_dl(d DATE, x BIGINT)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minus_dl(d, x);
+end;
+$$
+/**
+ * Subtract one number from another.
+ * Corresponds to the 4GL subtraction operator
+ */
+create or replace function guarded_minus_ll(x BIGINT, y BIGINT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minus_ll(x, y);
+end;
+$$
+/**
+ * Subtract one number from another.
+ * Corresponds to the 4GL subtraction operator
+ */
+create or replace function guarded_minus_li(x BIGINT, y INTEGER)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minus_li(x, y);
+end;
+$$
+/**
+ * Subtract one number from another.
+ * Corresponds to the 4GL subtraction operator
+ */
+create or replace function guarded_minus_ln(x BIGINT, y DECIMAL(50, 10))
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minus_ln(x, y);
+end;
+$$
+/**
+ * Subtract one number from another.
+ * Corresponds to the 4GL subtraction operator
+ */
+create or replace function guarded_minus_ii(x INTEGER, y INTEGER)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minus_ii(x, y);
+end;
+$$
+/**
+ * Subtract one number from another.
+ * Corresponds to the 4GL subtraction operator
+ */
+create or replace function guarded_minus_il(x INTEGER, y BIGINT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minus_il(x, y);
+end;
+$$
+/**
+ * Subtract one number from another.
+ * Corresponds to the 4GL subtraction operator
+ */
+create or replace function guarded_minus_in(x INTEGER, y DECIMAL(50, 10))
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minus_in(x, y);
+end;
+$$
+/**
+ * Subtract one number from another.
+ * Corresponds to the 4GL subtraction operator
+ */
+create or replace function guarded_minus_nn(x DECIMAL(50, 10), y DECIMAL(50, 10))
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minus_nn(x, y);
+end;
+$$
+/**
+ * Subtract one number from another.
+ * Corresponds to the 4GL subtraction operator
+ */
+create or replace function guarded_minus_ni(x DECIMAL(50, 10), y INTEGER)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minus_ni(x, y);
+end;
+$$
+/**
+ * Subtract one number from another.
+ * Corresponds to the 4GL subtraction operator
+ */
+create or replace function guarded_minus_nl(x DECIMAL(50, 10), y BIGINT)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minus_nl(x, y);
+end;
+$$
+/**
+ * Calculate a timestamp by substracting a number of milliseconds from a datetime.
+ */
+create or replace function guarded_minusmillis_sn(t TIMESTAMP(3), x DECIMAL(50, 10))
+returns timestamp(3)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minusmillis_sn(t, x);
+end;
+$$
+/**
+ * Calculate a timestamp by substracting a number of milliseconds from a datetime.
+ */
+create or replace function guarded_minusmillis_si(t TIMESTAMP(3), x INTEGER) 
+returns timestamp(3)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minusmillis_si(t, x) ;
+end;
+$$
+/**
+ * Calculate a timestamp by substracting a number of milliseconds from a datetime.
+ */
+create or replace function guarded_minusmillis_sl(t TIMESTAMP(3), x BIGINT)
+returns timestamp(3)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return minusmillis_sl(t, x);
+end;
+$$
+/**
+ * Calculate the remainder resulting from the integer division of two numbers.
+ */
+create or replace function guarded_modulo_ii(x INTEGER, y INTEGER)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return modulo_ii(x, y);
+end;
+$$
+/**
+ * Calculate the remainder resulting from the integer division of two numbers.
+ */
+create or replace function guarded_modulo_il(x INTEGER, y BIGINT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return modulo_il(x, y);
+end;
+$$
+/**
+ * Calculate the remainder resulting from the integer division of two numbers.
+ */
+create or replace function guarded_modulo_in(x INTEGER, y DECIMAL(50, 10))
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return modulo_in(x, y);
+end;
+$$
+/**
+ * Calculate the remainder resulting from the integer division of two numbers.
+ */
+create or replace function guarded_modulo_nn(x DECIMAL(50, 10), y DECIMAL(50, 10))
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return modulo_nn(x, y);
+end;
+$$
+/**
+ * Calculate the remainder resulting from the integer division of two numbers.
+ */
+create or replace function guarded_modulo_ni(x DECIMAL(50, 10), y INTEGER)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return modulo_ni(x, y);
+end;
+$$
+/**
+ * Calculate the remainder resulting from the integer division of two numbers.
+ */
+create or replace function guarded_modulo_nl(x DECIMAL(50, 10), y BIGINT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return modulo_nl(x, y);
+end;
+$$
+/**
+ * Calculate the remainder resulting from the integer division of two numbers.
+ */
+create or replace function guarded_modulo_ll(x BIGINT, y BIGINT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return modulo_ll(x, y);
+end;
+$$
+/**
+ * Calculate the remainder resulting from the integer division of two numbers.
+ */
+create or replace function guarded_modulo_li(x BIGINT, y INTEGER)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return modulo_li(x, y);
+end;
+$$
+/**
+ * Calculate the remainder resulting from the integer division of two numbers.
+ */
+create or replace function guarded_modulo_ln(x BIGINT, y DECIMAL(50, 10))
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return modulo_ln(x, y);
+end;
+$$
+/**
+ * Calculate the product of two numbers.
+ */
+create or replace function guarded_multiply_nn(x DECIMAL(50, 10), y DECIMAL(50, 10))
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return multiply_nn(x, y);
+end;
+$$
+/**
+ * Calculate the product of two numbers.
+ */
+create or replace function guarded_multiply_ni(x DECIMAL(50, 10), y INTEGER)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return multiply_ni(x, y);
+end;
+$$
+/**
+ * Calculate the product of two numbers.
+ */
+create or replace function guarded_multiply_nl(x DECIMAL(50, 10), y BIGINT)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return multiply_nl(x, y);
+end;
+$$
+/**
+ * Calculate the product of two numbers.
+ */
+create or replace function guarded_multiply_ll(x BIGINT, y BIGINT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return multiply_ll(x, y);
+end;
+$$
+/**
+ * Calculate the product of two numbers.
+ */
+create or replace function guarded_multiply_li(x BIGINT, y INTEGER)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return multiply_li(x, y);
+end;
+$$
+/**
+ * Calculate the product of two numbers.
+ */
+create or replace function guarded_multiply_ln(x BIGINT, y DECIMAL(50, 10))
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return multiply_ln(x, y);
+end;
+$$
+/**
+ * Calculate the product of two numbers.
+ */
+create or replace function guarded_multiply_ii(x INTEGER, y INTEGER)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return multiply_ii(x, y);
+end;
+$$
+/**
+ * Calculate the product of two numbers.
+ */
+create or replace function guarded_multiply_il(x INTEGER, y BIGINT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return multiply_il(x, y);
+end;
+$$
+/**
+ * Calculate the product of two numbers.
+ */
+create or replace function guarded_multiply_in(x INTEGER, y DECIMAL(50, 10))
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return multiply_in(x, y);
+end;
+$$
+/**
+ * Test two values for inequality.. 
+ */
+create or replace function guarded_ne_ll(x BIGINT, y BIGINT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return ne_ll(x, y);
+end;
+$$
+/**
+ * Test two values for inequality.. 
+ */
+create or replace function guarded_ne_li(x BIGINT, y INTEGER)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return ne_li(x, y);
+end;
+$$
+/**
+ * Test two values for inequality.. 
+ */
+create or replace function guarded_ne_ln(x BIGINT, y DECIMAL(50, 10))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return ne_ln(x, y);
+end;
+$$
+/**
+ * Test two values for inequality.. 
+ * Corresponds to the 4GL NE (<>) operator
+ */
+create or replace function guarded_ne_ss(x DATETIME(3), y DATETIME(3))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return ne_ss(x, y);
+end;
+$$
+/**
+ * Test two values for inequality.. 
+ * Corresponds to the 4GL NE (<>) operator
+ */
+create or replace function guarded_ne_dd(x DATE, y DATE)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return ne_dd(x, y);
+end;
+$$
+/**
+ * Test two values for inequality.. 
+ * Corresponds to the 4GL NE (<>) operator
+ */
+create or replace function guarded_ne_bb(x BOOLEAN, y BOOLEAN)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return ne_bb(x, y);
+end;
+$$
+/**
+ * Test two values for inequality.. 
+ * Corresponds to the 4GL NE (<>) operator
+ */
+create or replace function guarded_ne_ii(x INTEGER, y INTEGER)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return ne_ii(x, y);
+end;
+$$
+/**
+ * Test two values for inequality.. 
+ * Corresponds to the 4GL NE (<>) operator
+ */
+create or replace function guarded_ne_il(x INTEGER, y BIGINT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return ne_il(x, y);
+end;
+$$
+/**
+ * Test two values for inequality.. 
+ * Corresponds to the 4GL NE (<>) operator
+ */
+create or replace function guarded_ne_in(x INTEGER, y DECIMAL(50, 10))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return ne_in(x, y);
+end;
+$$
+/**
+ * Test two values for inequality.. 
+ * Corresponds to the 4GL NE (<>) operator
+ */
+create or replace function guarded_ne_nn(x DECIMAL(50, 10), y DECIMAL(50, 10))
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return ne_nn(x, y);
+end;
+$$
+/**
+ * Test two values for inequality.. 
+ * Corresponds to the 4GL NE (<>) operator
+ */
+create or replace function guarded_ne_ni(x DECIMAL(50, 10), y INTEGER)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return ne_ni(x, y);
+end;
+$$
+/**
+ * Test two values for inequality.. 
+ * Corresponds to the 4GL NE (<>) operator
+ */
+create or replace function guarded_ne_nl(x DECIMAL(50, 10), y BIGINT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return ne_nl(x, y);
+end;
+$$
+/**
+ * Test two values for inequality.. 
+ * Corresponds to the 4GL NE (<>) operator
+ */
+create or replace function guarded_ne_tt(x TEXT, y TEXT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return ne_tt(x, y);
+end;
+$$
+/**
+ * Returns the number of comma-delimited entries in the passed list.
+ * Corresponds to 4GL NUM-ENTRIES function.
+ */
+create or replace function guarded_numentries_t(list TEXT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return numentries_t(list);
+end;
+$$
+/**
+ * Returns the number of entries in the passed list using specied delimiter.
+ * Corresponds to 4GL NUM-ENTRIES function.
+ */
+create or replace function guarded_numentries_tt(list TEXT, delim TEXT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return numentries_tt(list, delim);
+end;
+$$
+/** Parse the time format used in the tostring(timestamp, text) */
+/**
+ * Add two numbers
+ */
+create or replace function guarded_plus_nn(x DECIMAL(50, 10), y DECIMAL(50, 10))
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return plus_nn(x, y);
+end;
+$$
+/**
+ * Add two numbers
+ */
+create or replace function guarded_plus_ni(x DECIMAL(50, 10), y INTEGER)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return plus_ni(x, y);
+end;
+$$
+/**
+ * Add two numbers
+ */
+create or replace function guarded_plus_nl(x DECIMAL(50, 10), y BIGINT)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return plus_nl(x, y);
+end;
+$$
+/**
+ * Add a number of days to a date.
+ */
+create or replace function guarded_plus_nd(x DECIMAL(50, 10), d DATE)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return plus_nd(x, d);
+end;
+$$
+/**
+ * Add a number of days to a date.
+ */
+create or replace function guarded_plus_id(x INTEGER, d DATE)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return plus_id(x, d);
+end;
+$$
+/**
+ * Add a number of days to a date.
+ */
+create or replace function guarded_plus_ld(x BIGINT, d DATE)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return plus_ld(x, d);
+end;
+$$
+/**
+ * Add two numbers
+ */
+create or replace function guarded_plus_ii(x INTEGER, y INTEGER)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return plus_ii(x, y);
+end;
+$$
+/**
+ * Add two numbers
+ */
+create or replace function guarded_plus_il(x INTEGER, y BIGINT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return plus_il(x, y);
+end;
+$$
+/**
+ * Add two numbers
+ */
+create or replace function guarded_plus_in(x INTEGER, y DECIMAL(50, 10))
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return plus_in(x, y);
+end;
+$$
+/**
+ * Add a number of days to a date.
+ */
+create or replace function guarded_plus_dn(d DATE, x DECIMAL(50, 10))
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return plus_dn(d, x);
+end;
+$$
+/**
+ * Add a number of days to a date.
+ */
+create or replace function guarded_plus_di(d DATE, x INTEGER)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return plus_di(d, x);
+end;
+$$
+/**
+ * Add a number of days to a date.
+ */
+create or replace function guarded_plus_dl(d DATE, x BIGINT)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return plus_dl(d, x);
+end;
+$$
+/**
+ * Add two numbers
+ */
+create or replace function guarded_plus_ll(x BIGINT, y BIGINT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return plus_ll(x, y);
+end;
+$$
+/**
+ * Add two numbers
+ */
+create or replace function guarded_plus_li(x BIGINT, y INTEGER)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return plus_li(x, y);
+end;
+$$
+/**
+ * Add two numbers
+ */
+create or replace function guarded_plus_ln(x BIGINT, y DECIMAL(50, 10))
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return plus_ln(x, y);
+end;
+$$
+/**
+ * Add a number of milliseconds to a datetime
+ */
+create or replace function guarded_plusmillis_ns(d DECIMAL(50, 10), t TIMESTAMP(3))
+returns timestamp(3)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return plusmillis_ns(d, t);
+end;
+$$
+/**
+ * Add a number of milliseconds to a datetime
+ */
+create or replace function guarded_plusmillis_sn(t TIMESTAMP(3), d DECIMAL(50, 10))
+returns timestamp(3)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return plusmillis_sn(t, d);
+end;
+$$
+/**
+ * Add a number of milliseconds to a datetime
+ */
+create or replace function guarded_plusmillis_si(t TIMESTAMP(3), d INTEGER)
+returns timestamp(3)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return plusmillis_si(t, d);
+end;
+$$
+/**
+ * Add a number of milliseconds to a datetime
+ */
+create or replace function guarded_plusmillis_sl(t TIMESTAMP(3), d BIGINT)
+returns timestamp(3)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return plusmillis_sl(t, d);
+end;
+$$
+/**
+ * Replaces the given values into the destination.
+ * Corresponds to 4GL REPLACE function.
+*/
+create or replace function guarded_replacetext_ttt(src TEXT, repl TEXT, replto TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return replacetext_ttt(src, repl, replto);
+end;
+$$
+/**
+ * Helper function to report the precision and scale of a numeric value.
+ */
+create or replace function guarded_reportprecisionscale_n(x DECIMAL(50, 10))
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return reportprecisionscale_n(x);
+end;
+$$
+/**
+ * Round a floating point number to a particular precision.
+ * Corresponds to 4GL ROUND function.
+ */
+create or replace function guarded_rounddec_ni(x DECIMAL(50, 10), s INTEGER)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return rounddec_ni(x, s);
+end;
+$$
+/**
+ * Round a floating point number to 10 decimal places.
+ * Corresponds to 4GL ROUND function.
+ */
+create or replace function guarded_rounddec_n(x DECIMAL(50, 10))
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return rounddec_n(x);
+end;
+$$
+/**
+ * Round a floating point number to a particular precision.
+ * Corresponds to 4GL ROUND function.
+ */
+create or replace function guarded_rounddec_nl(x DECIMAL(50, 10), s BIGINT)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return rounddec_nl(x, s);
+end;
+$$
+/**
+ * Extract a substring from a string, starting at a specific index.
+ * Corresponds to 4GL SUBSTRING function.
+ */
+create or replace function guarded_substringof_ti(s TEXT, pos INTEGER)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return substringof_ti(s, pos);
+end;
+$$
+/**
+ * Extract a substring of a specific length from a string, starting at a
+ * specific index.
+ * Corresponds to 4GL SUBSTRING function.
+ */
+create or replace function guarded_substringof_tii(s TEXT, pos INTEGER, len INTEGER)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return substringof_tii(s, pos, len);
+end;
+$$
+/**
+ * Extract a substring from a string, starting at a specific index.
+ * Corresponds to 4GL SUBSTRING function.
+ */
+create or replace function guarded_substringof_tl(s TEXT, pos BIGINT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return substringof_tl(s, pos);
+end;
+$$
+/**
+ * Extract a substring of a specific length from a string, starting at a
+ * specific index.
+ * Corresponds to 4GL SUBSTRING function.
+ */
+create or replace function guarded_substringof_til(s TEXT, pos INTEGER, len BIGINT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return substringof_til(s, pos, len);
+end;
+$$
+/**
+ * Extract a substring of a specific length from a string, starting at a
+ * specific index.
+ * Corresponds to 4GL SUBSTRING function.
+ */
+create or replace function guarded_substringof_tli(s TEXT, pos BIGINT, len INTEGER)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return substringof_tli(s, pos, len);
+end;
+$$
+/**
+ * Extract a substring of a specific length from a string, starting at a
+ * specific index.
+ * Corresponds to 4GL SUBSTRING function.
+ */
+create or replace function guarded_substringof_tll(s TEXT, pos BIGINT, len BIGINT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return substringof_tll(s, pos, len);
+end;
+$$
+/**
+ * Extract a substring of a specific length from a string, starting at a
+ * specific index.
+ * Corresponds to 4GL SUBSTRING function.
+ */
+create or replace function guarded_substringof_tiit(s TEXT, pos INTEGER, len INTEGER, stype TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return substringof_tiit(s, pos, len, stype);
+end;
+$$
+/**
+ * Extract a substring of a specific length from a string, starting at a
+ * specific index.
+ * Corresponds to 4GL SUBSTRING function.
+ */
+create or replace function guarded_substringof_tilt(s TEXT, pos INTEGER, len BIGINT, stype TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return substringof_tilt(s, pos, len, stype);
+end;
+$$
+/**
+ * Extract a substring of a specific length from a string, starting at a
+ * specific index.
+ * Corresponds to 4GL SUBSTRING function.
+ */
+create or replace function guarded_substringof_tlit(s TEXT, pos BIGINT, len INTEGER, stype TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return substringof_tlit(s, pos, len, stype);
+end;
+$$
+/**
+ * Extract a substring of a specific length from a string, starting at a
+ * specific index.
+ * Corresponds to 4GL SUBSTRING function.
+ */
+create or replace function guarded_substringof_tllt(s TEXT, pos BIGINT, len BIGINT, stype TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return substringof_tllt(s, pos, len, stype);
+end;
+$$
+/**
+ * Determine the number of milliseconds between two timestamps.
+ */
+create or replace function guarded_timespan_ss(t1 TIMESTAMP(3), t2 TIMESTAMP(3))
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return timespan_ss(t1, t2);
+end;
+$$
+/** Convert the time to an array [time, am/pm, tz] using  format used in the tostrint(timestamp, text) */
+/**
+ * Returns the character value of a numeric expression which must be
+ * between 1 and 65534 (inclusive).
+ * Corresponds to 4GL TO_CHAR function.
+ */
+create or replace function guarded_tochr_i(v INTEGER)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tochr_i(v);
+end;
+$$
+/**
+ * Returns the character value of a numeric expression which must be
+ * between 1 and 65534 (inclusive).
+ * Corresponds to 4GL TO_CHAR function.
+ */
+create or replace function guarded_tochr_l(v BIGINT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tochr_l(v);
+end;
+$$
+/**
+ * Creates an instance that represents the number of days (positive or
+ * negative) from the Progress 4GL base date of 12/31/-4714.
+ * Corresponds to 4GL DATE function.
+*/
+create or replace function guarded_todate_l(d BIGINT)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todate_l(d);
+end;
+$$
+/**
+ * Retrieve the date from a string variable. The date format and windowing year must be
+ * provided by the query. 
+ * Corresponds to 4GL TO_DATE function.
+ */
+create or replace function guarded_todate_tti(s TEXT, fmt TEXT, wyear INTEGER)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todate_tti(s, fmt, wyear);
+end;
+$$
+/**
+ *  Retrieve the date from a string variable.
+ *  Corresponds to 4GL DATE function.
+ */
+create or replace function guarded_todate_t(s TEXT)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todate_t(s);
+end;
+$$
+/**
+ * Extract the date from a timestamp variable.
+ * Corresponds to 4GL DATE function.
+ */
+create or replace function guarded_todate_s(ts TIMESTAMP(3))
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todate_s(ts);
+end;
+$$
+/**
+ * Retrieve the date from a month/day/year combination .
+ * Corresponds to 4GL DATE function.
+ */
+create or replace function guarded_todate_iil(m INTEGER, d INTEGER, y BIGINT)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todate_iil(m, d, y);
+end;
+$$
+/**
+ * Retrieve the date from a month/day/year combination .
+ * Corresponds to 4GL DATE function.
+ */
+create or replace function guarded_todate_lil(m BIGINT, d INTEGER, y BIGINT)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todate_lil(m, d, y);
+end;
+$$
+/**
+ * Retrieve the date from a month/day/year combination .
+ * Corresponds to 4GL DATE function.
+ */
+create or replace function guarded_todate_iii(m INTEGER, d INTEGER, y INTEGER)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todate_iii(m, d, y);
+end;
+$$
+/**
+ * Retrieve the date from a month/day/year combination .
+ * Corresponds to 4GL DATE function.
+ */
+create or replace function guarded_todate_ill(m INTEGER, d BIGINT, y BIGINT)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todate_ill(m, d, y);
+end;
+$$
+/**
+ * Retrieve the date from a month/day/year combination .
+ * Corresponds to 4GL DATE function.
+ */
+create or replace function guarded_todate_lii(m BIGINT, d INTEGER, y INTEGER)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todate_lii(m, d, y);
+end;
+$$
+/**
+ * Creates an instance that represents the number of days (positive or
+ * negative) from the Progress 4GL base date of 12/31/-4714.
+ * Corresponds to 4GL DATE function.
+ */
+create or replace function guarded_todate_i(d INTEGER)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todate_i(d);
+end;
+$$
+/**
+ * Retrieve the date from a month/day/year combination .
+ * Corresponds to 4GL DATE function.
+ */
+create or replace function guarded_todate_lli(m BIGINT, d BIGINT, y INTEGER)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todate_lli(m, d, y);
+end;
+$$
+/**
+ * Retrieve the date from a month/day/year combination .
+ * Corresponds to 4GL DATE function.
+ */
+create or replace function guarded_todate_lll(m BIGINT, d BIGINT, y BIGINT)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todate_lll(m, d, y);
+end;
+$$
+/**
+ * Retrieve the date from a month/day/year combination .
+ * Corresponds to 4GL DATE function.
+ */
+create or replace function guarded_todate_ili(m INTEGER, d BIGINT, y INTEGER)
+returns date
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todate_ili(m, d, y);
+end;
+$$
+/**
+ * Retrieve the timestamp from a month/day/year/hour/minutes/seconds combination .
+ * Corresponds to 4GL DATETIME function.
+ */
+create or replace function guarded_todatetime_llllll(m BIGINT, d BIGINT, y BIGINT, h BIGINT, minutes BIGINT, s BIGINT)
+returns timestamp(3)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todatetime_llllll(m, d, y, h, minutes, s);
+end;
+$$
+/**
+ * Retrieve the timestamp from a string variable. The date format and windowing year must be
+ * provided by the query. 
+ * Corresponds to 4GL DATETIME function.
+ */
+create or replace function guarded_todatetime_tti(s_ TEXT, fmt_ TEXT, wyear_ INTEGER)
+returns datetime(3)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todatetime_tti(s_, fmt_, wyear_);
+end;
+$$
+/**
+ * Retrieve the timestamp from a string variable.
+ * Corresponds to 4GL DATETIME function.
+ */
+create or replace function guarded_todatetime_t(s TEXT)
+returns timestamp(3)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todatetime_t(s);
+end;
+$$
+/**
+ * Retrieve the timestamp from a month/day/year/hour/minutes/seconds combination .
+ * Corresponds to 4GL DATETIME function.
+ */
+create or replace function guarded_todatetime_iiiiii(m INTEGER, d INTEGER, y INTEGER, h INTEGER, minutes INTEGER, s INTEGER)
+returns timestamp(3)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todatetime_iiiiii(m, d, y, h, minutes, s);
+end;
+$$
+/**
+ * Retrieve the timestamp from a month/day/year/hour/minutes/seconds combination .
+ * Corresponds to 4GL DATETIME function.
+ */
+create or replace function guarded_todatetime_lllllll(m BIGINT, d BIGINT, y BIGINT, h BIGINT, minutes BIGINT, s BIGINT, ms BIGINT)
+returns timestamp(3)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todatetime_lllllll(m, d, y, h, minutes, s, ms);
+end;
+$$
+/**
+ * Retrieve the timestamp from a month/day/year/hour/minutes/seconds/millisecons combination .
+ * Corresponds to 4GL DATETIME function.
+ */
+create or replace function guarded_todatetime_iiiiiii(m INTEGER, d INTEGER, y INTEGER, h INTEGER, minutes INTEGER, s INTEGER, ms INTEGER)
+returns timestamp(3)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todatetime_iiiiiii(m, d, y, h, minutes, s, ms);
+end;
+$$
+/**
+ * Construct a timestamp from a date variable.
+ * Corresponds to 4GL DATETIME function.
+ */
+create or replace function guarded_todatetime_d(dt DATE)
+returns timestamp(3)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todatetime_d(dt);
+end;
+$$
+/**
+ * Retrieve the timestamp from a date/time combination.
+ * Corresponds to 4GL DATETIME function.
+ */
+create or replace function guarded_todatetime_di(dt DATE, ms INTEGER)
+returns timestamp(3)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todatetime_di(dt, ms);
+end;
+$$
+/**
+ * Retrieve the timestamp from a month/day/year/hour/minutes combination .
+ * Corresponds to 4GL DATETIME function.
+ */
+create or replace function guarded_todatetime_lllll(m BIGINT, d BIGINT, y BIGINT, h BIGINT, minutes BIGINT)
+returns timestamp(3)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todatetime_lllll(m, d, y, h, minutes);
+end;
+$$
+/**
+ * Retrieve the timestamp from a month/day/year/hour/minutes combination .
+ * Corresponds to 4GL DATETIME function.
+ */
+create or replace function guarded_todatetime_iiiii(m INTEGER, d INTEGER, y INTEGER, h INTEGER, minutes INTEGER)
+returns timestamp(3)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todatetime_iiiii(m, d, y, h, minutes);
+end;
+$$
+/**
+ * Retrieve the timestamp from a date/time combination.
+ * Corresponds to 4GL DATETIME function.
+ */
+create or replace function guarded_todatetime_dl(dt DATE, ms BIGINT)
+returns timestamp(3)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todatetime_dl(dt, ms);
+end;
+$$
+/**
+ * Transform the given value into a decimal
+ */
+create or replace function guarded_todec_n(v DECIMAL(50, 10))
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todec_n(v);
+end;
+$$
+/**
+ * Return the given value after applying the given precision. 
+ */
+create or replace function guarded_todec_nl(v DECIMAL(50, 10), prec BIGINT)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todec_nl(v, prec);
+end;
+$$
+/**
+ * Transform the given value into a decimal
+ */
+create or replace function guarded_todec_l(v BIGINT)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todec_l(v);
+end;
+$$
+/**
+ * Return the given value after applying the given precision. 
+ */
+create or replace function guarded_todec_t(v TEXT)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todec_t(v);
+end;
+$$
+/**
+ * Return the given value after applying the given precision. 
+ */
+create or replace function guarded_todec_ni(v DECIMAL(50, 10), prec INTEGER)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todec_ni(v, prec);
+end;
+$$
+/**
+ * Transform the given value into a decimal
+ */
+create or replace function guarded_todec_i(v INTEGER)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todec_i(v);
+end;
+$$
+/**
+ * Transform the given value into a decimal
+ */
+create or replace function guarded_todec_b(v BOOLEAN)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todec_b(v);
+end;
+$$
+/**
+ * Transform the given value into a decimal
+ */
+create or replace function guarded_todec_d(dt DATE)
+returns decimal(50, 10)
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return todec_d(dt);
+end;
+$$
+/**
+ * Transform the given value into an int
+ */
+create or replace function guarded_toint_l(v BIGINT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return toint_l(v);
+end;
+$$
+/**
+ * Transform the given value into an int
+ */
+create or replace function guarded_toint_i(v INTEGER)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return toint_i(v);
+end;
+$$
+/**
+ * Transform the given value into an int
+ */
+create or replace function guarded_toint_n(v DECIMAL(50, 10))
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return toint_n(v);
+end;
+$$
+/**
+ * Transform the given value into an int
+ */
+create or replace function guarded_toint_t(v TEXT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return toint_t(v);
+end;
+$$
+/**
+ * Transform the given value into an int
+ */
+create or replace function guarded_toint_d(dt DATE)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return toint_d(dt);
+end;
+$$
+/**
+ * Transform the given value into an int
+ */
+create or replace function guarded_toint_b(v BOOLEAN)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return toint_b(v);
+end;
+$$
+create or replace function guarded_toint64_n(v DECIMAL(50, 10))
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return toint64_n(v);
+end;
+$$
+/**
+ * Transform the given value into an int64
+ */
+create or replace function guarded_toint64_d(dt DATE)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return toint64_d(dt);
+end;
+$$
+/**
+ * Transform the given value into an int64
+ */
+create or replace function guarded_toint64_l(v BIGINT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return toint64_l(v);
+end;
+$$
+/**
+ * Transform the given value into an int64
+ */
+create or replace function guarded_toint64_b(v BOOLEAN)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return toint64_b(v);
+end;
+$$
+/**
+ * Transform the given value into an int64
+ */
+create or replace function guarded_toint64_t(v TEXT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return toint64_t(v);
+end;
+$$
+/**
+ * Transform the given value into an int64
+ */
+create or replace function guarded_toint64_i(v INTEGER)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return toint64_i(v);
+end;
+$$
+/**
+ * Returns logical representation of a char variable using a format
+ */
+create or replace function guarded_tological_tt(v TEXT, fmt TEXT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tological_tt(v, fmt);
+end;
+$$
+create or replace function guarded_tological_t(v TEXT)
+returns boolean
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tological_t(v);
+end;
+$$
+/**
+ * Returns logical representation of a char variable
+ */
+create or replace function guarded_torowid_t(v TEXT)
+returns bigint
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return torowid_t(v);
+end;
+$$
+/**
+ * Transform the given value into a string
+ * Corresponds to th 4GL STRING function
+ */
+create or replace function guarded_tostring_n(v DECIMAL(50, 10))
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tostring_n(v);
+end;
+$$
+/**
+ * Transform the given value into a string using format
+ * Corresponds to th 4GL STRING function
+ */
+create or replace function guarded_tostring_bt(v BOOLEAN, fmt TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tostring_bt(v, fmt);
+end;
+$$
+/**
+ * Transform the given value into a string using format
+ * Corresponds to th 4GL STRING function
+ */
+create or replace function guarded_tostring_mti(t TIME(3), fmt TEXT, tz INTEGER) 
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tostring_mti(t, fmt, tz) ;
+end;
+$$
+/**
+ * Transform the given value into a string using format
+ * Corresponds to th 4GL STRING function
+ */
+create or replace function guarded_tostring_mt(t TIME, fmt TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tostring_mt(t, fmt);
+end;
+$$
+/**
+ * Transform the given value into a string
+ * Corresponds to th 4GL STRING function
+ */
+create or replace function guarded_tostring_i(v INTEGER)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tostring_i(v);
+end;
+$$
+/**
+ * Transform the given value into a string
+ * Corresponds to th 4GL STRING function
+ */
+create or replace function guarded_tostring_b(v BOOLEAN)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tostring_b(v);
+end;
+$$
+/**
+ * Transform the given value into a string using format
+ * Corresponds to th 4GL STRING function
+ */
+create or replace function guarded_tostring_tt(v TEXT, fmt TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tostring_tt(v, fmt);
+end;
+$$
+/**
+ * Transform the given date value into a string using format and observing the session:date-format value
+ * Corresponds to th 4GL STRING function
+ */
+create or replace function guarded_tostring_dtt(dt DATE, fmt TEXT, sfmt TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tostring_dtt(dt, fmt, sfmt);
+end;
+$$
+/**
+ * Transform the given datetime value into a string using format and observing the session:date-format value
+ * Corresponds to th 4GL STRING function
+ */
+create or replace function guarded_tostring_stti(ts TIMESTAMP(3), fmt TEXT, sfmt TEXT, tz INTEGER)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tostring_stti(ts, fmt, sfmt, tz);
+end;
+$$
+/**
+ * Transform the given datetime value into a string using format and observing the session:date-format value
+ * Corresponds to th 4GL STRING function
+ */
+create or replace function guarded_tostring_stt(ts TIMESTAMP(3), fmt TEXT, sfmt TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tostring_stt(ts, fmt, sfmt);
+end;
+$$
+/**
+ * Transform the given date value into a string using default format
+ * Corresponds to th 4GL STRING function
+ */
+create or replace function guarded_tostring_d(dt DATE)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tostring_d(dt);
+end;
+$$
+/**
+ * Transform the given date value into a string using format.
+ * Corresponds to th 4GL STRING function
+ */
+create or replace function guarded_tostring_dt(dt DATE, fmt TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tostring_dt(dt, fmt);
+end;
+$$
+/**
+ * Transform the given datetime value into a string using format.
+ * Corresponds to th 4GL STRING function
+ */
+create or replace function guarded_tostring_st(ts TIMESTAMP(3), fmt TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tostring_st(ts, fmt);
+end;
+$$
+/**
+ * Transform the given datetime value into a string using default format.
+ * Corresponds to th 4GL STRING function
+ */
+create or replace function guarded_tostring_s(ts TIMESTAMP(3))
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tostring_s(ts);
+end;
+$$
+/** 
+ * Convert bigint to string using format.
+ * A simplified version of PostgreSQL 'to_char' built-in function
+ */
+create or replace function guarded_l2s(v bigint, fmt TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return l2s(v, fmt);
+end;
+$$
+/**
+ * Transform the given value into a string using format
+ * Corresponds to th 4GL STRING function
+ */
+create or replace function guarded_tostring_nt(v DECIMAL(50, 10), fmt TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tostring_nt(v, fmt);
+end;
+$$
+/**
+ * Transform the given value into a string
+ * Corresponds to th 4GL STRING function
+ */
+create or replace function guarded_tostring_l(v BIGINT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tostring_l(v);
+end;
+$$
+/**
+ * Transform the given value into a string
+ * Corresponds to th 4GL STRING function
+ */
+create or replace function guarded_tostring_t(v TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tostring_t(v);
+end;
+$$
+/**
+ * Transform the given time value into a string
+ * @param sep - special separator between time part and tail (am/pm and timezone). 
+ *              Normally it is '', used only when parsing time part for datetime where date part of the format is '99999'  
+ * Corresponds to th 4GL STRING function
+ */
+create or replace function guarded_tostring_mtt(t TIME(3), fmt TEXT, sep TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tostring_mtt(t, fmt, sep);
+end;
+$$
+/**
+ * Transform the given date value into a string using format
+ * Corresponds to th 4GL STRING function
+ */
+create or replace function guarded_tostring_lti(v BIGINT, fmt TEXT, tz INTEGER)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tostring_lti(v, fmt, tz);
+end;
+$$
+/**
+ * Transform the given date value into a string using format
+ * Corresponds to th 4GL STRING function
+ */
+create or replace function guarded_tostring_lt(v BIGINT, fmt TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tostring_lt(v, fmt);
+end;
+$$
+/**
+ * Transform the given date value into a string using format
+ * Corresponds to th 4GL STRING function
+ */
+create or replace function guarded_tostring_it(v INTEGER, fmt TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tostring_it(v, fmt);
+end;
+$$
+/**
+ * Transform the given date value into a string using format
+ * Corresponds to th 4GL STRING function
+ */
+create or replace function guarded_tostring_ltt(v BIGINT, fmt TEXT, sfmt TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return tostring_ltt(v, fmt, sfmt);
+end;
+$$
+/**
+ * Trim white space from the left and right side of text.
+ * Corresponds to 4GL TRIM function.
+ */
+create or replace function guarded_trimws_t(s TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return trimws_t(s);
+end;
+$$
+/**
+ * Trim special characters listed in from the left and right side of text
+ * Corresponds to 4GL TRIM function.
+ */
+create or replace function guarded_trimws_tt(s TEXT, trimchars TEXT)
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return trimws_tt(s, trimchars);
+end;
+$$
+/**
+ * Returns a character string that is made up of a base string plus the substitution of arguments in the string.
+ * Corresponds to 4GL SUBSTITUTE function.
+ */
+create or replace function guarded_substitute_tf(base TEXT, args JSON )
+returns text
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return substitute_tf(base, args);
+end;
+$$
+/**
+ * Split a string to an array of words
+ * Used in the 4GL CONTAINS operator support
+ * @param s
+ *        string to be parsed
+ * @param toupper
+ *        convert words to uppercase
+ */
+create or replace function guarded_words_tb(s TEXT, toupper BOOLEAN) ##!! TODO
+returns json
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return words_tb(s, toupper) ;
+end;
+$$
+/**
+ * Split a string to an array of words
+ * Used in the 4GL CONTAINS operator support
+ */
+create or replace function guarded_words_t(s TEXT) ##!! TODO
+returns json
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return words_t(s) ;
+end;
+$$
+/**
+ * Split a string to an array of words
+ * Used in the 4GL CONTAINS operator support
+ * @param s
+ *        string to be parsed
+ * @param toupper
+ *        convert words to uppercase
+ * @param forCaseInsensitive
+ *        return words which are unique in case-insensitive sense 
+ */
+create or replace function guarded_words_tbb(s TEXT, toupper BOOLEAN, forcaseinsensitive BOOLEAN) ##!! TODO
+returns json
+deterministic
+begin
+declare tmp text;
+declare exit handler for SQLEXCEPTION
+  begin
+    GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,  @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+    set tmp = sformat('ERROR {} ({}): {}', @sqlstate, @errno, @text);
+    if error_handler_active() then
+      call initError_P(true);
+      signal sqlstate '01FWD' set message_text = tmp;
+      return null;
+    else
+      signal sqlstate 'FWD00' set message_text = tmp;
+    end if;
+  end;
+  return words_tbb(s, toupper, forcaseinsensitive) ;
+end;
+$$

=== modified file 'udf/mariadb/udfs.sql'
--- udf/mariadb/udfs.sql	2022-09-26 18:56:49 +0000
+++ udf/mariadb/udfs.sql	2023-02-12 13:50:42 +0000
@@ -6411,7 +6411,7 @@
    if upper(left(fmt, 5)) = 'HH:MM' then 
       return totimestring_lti(v, fmt, tz);
    else
-      return tostring_lt(v, fmt);
+      return tostring_nt(cast(v as DECIMAL(50, 10)), fmt);
    end if;
 END;
 $$

