Firebird Documentation IndexFirebird 2.1 Release NotesExternal Functions (UDFs) → UDFs Added and Changed
Firebird Home Firebird Home Prev: UDF library diagnostic messages improvedFirebird Documentation IndexUp: External Functions (UDFs)Next: General UDF Changes

UDFs Added and Changed

IB_UDF_rand() vs IB_UDF_srand()
IB_UDF_lower

UDFs added or enhanced in Firebird 2.0's supplied libraries are:

IB_UDF_rand() vs IB_UDF_srand()

F. Schlottmann-Goedde

In previous versions, the external function rand() sets the random number generator's starting point based on the current time and then generates the pseudo-random value.

   srand((unsigned) time(NULL));
   return ((float) rand() / (float) RAND_MAX);
      

The problem with this algorithm is that it will return the same value for two calls done within a second.

To work around this issue, rand() was changed in Firebird 2.0 so that the starting point is not set explicitly. This ensures that different values will always be returned.

In order to keep the legacy behaviour available in case somebody needs it, srand() has been introduced. It does exactly the same as the old rand() did.

IB_UDF_lower

The function IB_UDF_lower() in the IB_UDF library might conflict with the new internal function lower(), if you try to declare it in a database using the ib_udf.sql script from a previous Firebird version.

  /* ib_udf.sql declaration that now causes conflict */
  DECLARE EXTERNAL FUNCTION lower
      CSTRING(255)
      RETURNS CSTRING(255) FREE_IT
      ENTRY_POINT 'IB_UDF_lower' MODULE_NAME 'ib_udf';
      

The problem will be resolved in the latest version of the new ib_udf2.sql script, where the old UDF is declared using a quoted identifier.

  /* New declaration in ib_udf2.sql */
  DECLARE EXTERNAL FUNCTION "LOWER"
    CSTRING(255) NULL
    RETURNS CSTRING(255) FREE_IT
    ENTRY_POINT 'IB_UDF_lower' MODULE_NAME 'ib_udf';
      

Tip

It is preferable to use the internal function LOWER() than to call the UDF.

Prev: UDF library diagnostic messages improvedFirebird Documentation IndexUp: External Functions (UDFs)Next: General UDF Changes
Firebird Documentation IndexFirebird 2.1 Release NotesExternal Functions (UDFs) → UDFs Added and Changed