/*====================================================================
      File rfunc4.sql

      rFunc InterBase UDF library.
      Install SQL-script for IB 4.2.

      Copyright 1998-2001 Polaris Software
      http://polesoft.da.ru
      mailto: rFunc@mail.ru

      Version 2.0.1.2
====================================================================== */

/* Define valid path and password for your database */
/*CONNECT "d:\progra~1\borland\intrbase\examples\employee.gdb" USER "SYSDBA" PASSWORD "masterkey";*/

/* Date&Time functions */

DECLARE EXTERNAL FUNCTION YEAR
   DATE
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_year'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION MONTH
   DATE
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_month'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION DAY
   DATE
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_day'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION YEARDAY
   DATE
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_yearday'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION WEEKDAY
   DATE
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_weekday'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION HOUR
   DATE
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_hour'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION MINUTE
   DATE
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_minute'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION SECOND
   DATE
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_second'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION ISLEAPYEAR
   INTEGER
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_isleapyear'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION QUARTER
   DATE
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_quarter'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION DATETOSTR
   DATE, CSTRING(256)
   RETURNS CSTRING(256)
  ENTRY_POINT 'fn_datetostr'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION ENCODEDATE
   INTEGER, INTEGER, INTEGER
   RETURNS DATE
  ENTRY_POINT 'fn_encodedate'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION ENCODEDATETIME
   INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER
   RETURNS DATE
  ENTRY_POINT 'fn_encodedatetime'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION EXTRACTDATE
   DATE
   RETURNS DATE
  ENTRY_POINT 'fn_extractdate'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION EXTRACTTIME
   DATE
   RETURNS DATE
  ENTRY_POINT 'fn_extracttime'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION DOW
   DATE
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_dow'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION DAYPERMONTH
   INTEGER, INTEGER
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_daypermonth'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION FIRSTDAYMONTH
   DATE
   RETURNS DATE
  ENTRY_POINT 'fn_firstdaymonth'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION LASTDAYMONTH
   DATE
   RETURNS DATE
  ENTRY_POINT 'fn_lastdaymonth'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION DAYSBETWEEN
   DATE, DATE
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_daysbetween'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION INCDATE
   DATE, INTEGER, INTEGER, INTEGER
   RETURNS DATE
  ENTRY_POINT 'fn_incdate'  MODULE_NAME 'rfunc';

/* Math functions */
DECLARE EXTERNAL FUNCTION ABS
   DOUBLE PRECISION
   RETURNS DOUBLE PRECISION BY VALUE
  ENTRY_POINT 'fn_abs'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION MAXNUM
   DOUBLE PRECISION, DOUBLE PRECISION
   RETURNS DOUBLE PRECISION BY VALUE
  ENTRY_POINT 'fn_maxnum'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION MINNUM
   DOUBLE PRECISION, DOUBLE PRECISION
   RETURNS DOUBLE PRECISION BY VALUE
  ENTRY_POINT 'fn_minnum'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION CEIL
   DOUBLE PRECISION
   RETURNS DOUBLE PRECISION BY VALUE
  ENTRY_POINT 'fn_ceil'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION FLOOR
   DOUBLE PRECISION
   RETURNS DOUBLE PRECISION BY VALUE
  ENTRY_POINT 'fn_floor'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION POWER
   DOUBLE PRECISION, DOUBLE PRECISION
   RETURNS DOUBLE PRECISION BY VALUE
  ENTRY_POINT 'fn_power'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION ROUND
   DOUBLE PRECISION, INTEGER
   RETURNS DOUBLE PRECISION BY VALUE
  ENTRY_POINT 'fn_round'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION SOFTROUND
   DOUBLE PRECISION, INTEGER
   RETURNS DOUBLE PRECISION BY VALUE
  ENTRY_POINT 'fn_softround'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION DIV
   INTEGER, INTEGER
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_div'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION MOD
   INTEGER, INTEGER
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_mod'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION Z
   DOUBLE PRECISION
   RETURNS DOUBLE PRECISION BY VALUE
  ENTRY_POINT 'fn_z'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION DZERO
   DOUBLE PRECISION, DOUBLE PRECISION, DOUBLE PRECISION
   RETURNS DOUBLE PRECISION BY VALUE
  ENTRY_POINT 'fn_dividezero'  MODULE_NAME 'rfunc';


DECLARE EXTERNAL FUNCTION INITRANDOM
   INTEGER
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_initRandom'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION GETRANDOM
   INTEGER
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_getRandom'  MODULE_NAME 'rfunc';


DECLARE EXTERNAL FUNCTION GETBIT
   INTEGER, INTEGER
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_getBit'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION SETBIT
   INTEGER, INTEGER, INTEGER
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_setBit'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION BITAND
   INTEGER, INTEGER
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_bitAnd'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION BITOR
   INTEGER, INTEGER
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_bitOr'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION BITXOR
   INTEGER, INTEGER
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_bitXor'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION BITNOT
   INTEGER
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_bitNot'  MODULE_NAME 'rfunc';

/* String functions */
DECLARE EXTERNAL FUNCTION CHR
   SMALLINT
   RETURNS CSTRING(2)
  ENTRY_POINT 'fn_chr'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION ORD
   CSTRING(2)
   RETURNS SMALLINT BY VALUE
  ENTRY_POINT 'fn_ord'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION LTRIM
   CSTRING(256)
   RETURNS CSTRING(256)
  ENTRY_POINT 'fn_ltrim'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION LONGLTRIM
   CSTRING(16384)
   RETURNS CSTRING(16384)
  ENTRY_POINT 'fn_ltrim'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION RTRIM
   CSTRING(256)
   RETURNS CSTRING(256)
  ENTRY_POINT 'fn_rtrim'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION LONGRTRIM
   CSTRING(16384)
   RETURNS CSTRING(16384)
  ENTRY_POINT 'fn_rtrim'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION TRIM
   CSTRING(256)
   RETURNS CSTRING(256)
  ENTRY_POINT 'fn_trim'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION LONGTRIM
   CSTRING(16384)
   RETURNS CSTRING(16384)
  ENTRY_POINT 'fn_trim'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION RUPPER
   CSTRING(256)
   RETURNS CSTRING(256)
  ENTRY_POINT 'fn_rupper'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION LONGRUPPER
   CSTRING(16384)
   RETURNS CSTRING(16384)
  ENTRY_POINT 'fn_rupper'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION RLOWER
   CSTRING(256)
   RETURNS CSTRING(256)
  ENTRY_POINT 'fn_rlower'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION LONGRLOWER
   CSTRING(16384)
   RETURNS CSTRING(16384)
  ENTRY_POINT 'fn_rlower'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION RLATIN
   CSTRING(256)
   RETURNS CSTRING(256)
  ENTRY_POINT 'fn_rlatin'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION LONGRLATIN
   CSTRING(16384)
   RETURNS CSTRING(16384)
  ENTRY_POINT 'fn_rlatin'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION RTRANSLIT
   CSTRING(256)
   RETURNS CSTRING(256)
  ENTRY_POINT 'fn_rtranslit'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION LONGRTRANSLIT
   CSTRING(16384)
   RETURNS CSTRING(16384)
  ENTRY_POINT 'fn_longrtranslit'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION SUBSTR
   CSTRING(256), INTEGER, INTEGER
   RETURNS CSTRING(256)
  ENTRY_POINT 'fn_substr'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION LONGSUBSTR
   CSTRING(16384), INTEGER, INTEGER
   RETURNS CSTRING(16384)
  ENTRY_POINT 'fn_substr'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION STRREPEAT
   CSTRING(256), INTEGER
   RETURNS CSTRING(256)
  ENTRY_POINT 'fn_strrepeat'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION LONGSTRREPEAT
   CSTRING(16384), INTEGER
   RETURNS CSTRING(16384)
  ENTRY_POINT 'fn_longstrrepeat'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION STRSTUFF
   CSTRING(256), INTEGER, INTEGER, CSTRING(256)
   RETURNS CSTRING(256)
  ENTRY_POINT 'fn_strstuff'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION LONGSTRSTUFF
   CSTRING(16384), INTEGER, INTEGER, CSTRING(16384)
   RETURNS CSTRING(16384)
  ENTRY_POINT 'fn_longstrstuff'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION STRREPLACE
   CSTRING(256), CSTRING(256), CSTRING(256)
   RETURNS CSTRING(256)
  ENTRY_POINT 'fn_strreplace'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION LONGSTRREPLACE
   CSTRING(16384), CSTRING(8128), CSTRING(8128)
   RETURNS CSTRING(16384)
  ENTRY_POINT 'fn_longstrreplace'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION STRPOS
   CSTRING(16384), CSTRING(16384)
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_strpos'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION STRLEN
   CSTRING(16384)
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_strlen'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION STRCOUNT
   CSTRING(256), CSTRING(16384)
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_strcount'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION WORDCOUNT
   CSTRING(16384),
   CSTRING(32),
   SMALLINT
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_wordcount'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION WORDNUM
   CSTRING(16384),
   INTEGER,
   CSTRING(32),
   SMALLINT
   RETURNS CSTRING(256)
  ENTRY_POINT 'fn_wordnum'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION LONGWORDNUM
   CSTRING(16384),
   INTEGER,
   CSTRING(32),
   SMALLINT
   RETURNS CSTRING(16384)
  ENTRY_POINT 'fn_wordnum'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION PADRIGHT
   CSTRING(256), SMALLINT, CSTRING(2)
   RETURNS CSTRING(256)
  ENTRY_POINT 'fn_padright'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION LONGPADRIGHT
   CSTRING(16384), SMALLINT, CSTRING(2)
   RETURNS CSTRING(16384)
  ENTRY_POINT 'fn_longpadright'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION PADLEFT
   CSTRING(256), SMALLINT, CSTRING(2)
   RETURNS CSTRING(256)
  ENTRY_POINT 'fn_padleft'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION LONGPADLEFT
   CSTRING(16384), SMALLINT, CSTRING(2)
   RETURNS CSTRING(16384)
  ENTRY_POINT 'fn_longpadleft'  MODULE_NAME 'rfunc';

/* Miscellaneous functions */
DECLARE EXTERNAL FUNCTION IIF
   INTEGER, INTEGER, INTEGER
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_iif'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION DIF
   INTEGER, DOUBLE PRECISION, DOUBLE PRECISION
   RETURNS DOUBLE PRECISION BY VALUE
  ENTRY_POINT 'fn_dif'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION CIF
   INTEGER, CSTRING(256), CSTRING(256)
   RETURNS CSTRING(256)
  ENTRY_POINT 'fn_cif'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION LONGCIF
   INTEGER, CSTRING(16384), CSTRING(16384)
   RETURNS CSTRING(16384)
  ENTRY_POINT 'fn_cif'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION DTIF
   INTEGER, DATE, DATE
   RETURNS DATE
  ENTRY_POINT 'fn_dtif'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION MSGBOX
   CSTRING(16384),
   CSTRING(256),
   INTEGER
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_msgbox'  MODULE_NAME 'rfunc';

/* Simple parser */
DECLARE EXTERNAL FUNCTION CALCEXPR
   CSTRING(16384),
   CSTRING(16384)
   RETURNS DOUBLE PRECISION BY VALUE
  ENTRY_POINT 'fn_CalcExpr'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION EXPRISVALID
   CSTRING(16384),
   CSTRING(16384)
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_ExprIsValid'  MODULE_NAME 'rfunc';

/* Blob functions */
DECLARE EXTERNAL FUNCTION B_NUMBER_SEGMENTS
   BLOB
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_b_number_segments'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION B_MAX_SEGMENT
   BLOB
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_b_max_segment'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION B_TOTAL_LENGTH
   BLOB
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_b_total_length'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION B_LINE_COUNT
   BLOB
   RETURNS INTEGER BY VALUE
  ENTRY_POINT 'fn_b_line_count'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION B_SUBSTR
   BLOB, INTEGER, INTEGER
   RETURNS CSTRING(256)
  ENTRY_POINT 'fn_b_substr'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION B_LONGSUBSTR
   BLOB, INTEGER, INTEGER
   RETURNS CSTRING(16384)
  ENTRY_POINT 'fn_b_longsubstr'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION B_LINE
   BLOB, INTEGER
   RETURNS CSTRING(256)
  ENTRY_POINT 'fn_b_line'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION B_LONGLINE
   BLOB, INTEGER
   RETURNS CSTRING(16384)
  ENTRY_POINT 'fn_b_longline'  MODULE_NAME 'rfunc';

DECLARE EXTERNAL FUNCTION B_PUT_SEGMENT
   CSTRING(16384),
   BLOB
   RETURNS PARAMETER 2
  ENTRY_POINT 'fn_b_put_segment'  MODULE_NAME 'rfunc';

COMMIT;
