21.10.2013 Views

Firebird 2.1 Language Reference Update

Firebird 2.1 Language Reference Update

Firebird 2.1 Language Reference Update

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

External functions (UDFs)<br />

DECLARE EXTERNAL FUNCTION i64Round<br />

NUMERIC(18,4) BY DESCRIPTOR, NUMERIC(18,4) BY DESCRIPTOR<br />

RETURNS PARAMETER 2<br />

ENTRY_POINT 'round' MODULE_NAME 'fbudf'<br />

In <strong>Firebird</strong> 1.5, the entry point has been renamed to fbround:<br />

DECLARE EXTERNAL FUNCTION Round<br />

INT BY DESCRIPTOR, INT BY DESCRIPTOR<br />

RETURNS PARAMETER 2<br />

ENTRY_POINT 'fbround' MODULE_NAME 'fbudf'<br />

DECLARE EXTERNAL FUNCTION i64Round<br />

NUMERIC(18,4) BY DESCRIPTOR, NUMERIC(18,4) BY DESCRIPTOR<br />

RETURNS PARAMETER 2<br />

ENTRY_POINT 'fbround' MODULE_NAME 'fbudf'<br />

If you move an existing database from <strong>Firebird</strong> 1.0.x to 1.5 or higher, drop any existing *round and<br />

*truncate declarations and declare them anew, using the updated entry point names. From <strong>Firebird</strong><br />

2.0 onward you can also perform this update with ALTER EXTERNAL FUNCTION.<br />

Library: ib_udf<br />

Added in: 1.5<br />

Changed in: 1.5.2, 2.0<br />

Better alternative: Internal function RPAD()<br />

rpad<br />

Description: Returns the input string right-padded with padchars until endlength is reached.<br />

Result type: VARCHAR(n)<br />

Syntax:<br />

rpad (str, endlength, padchar)<br />

Declaration:<br />

DECLARE EXTERNAL FUNCTION rpad<br />

CSTRING(255) NULL, INTEGER, CSTRING(1) NULL<br />

RETURNS CSTRING(255) FREE_IT<br />

ENTRY_POINT 'IB_UDF_rpad' MODULE_NAME 'ib_udf'<br />

The above declaration is from the file ib_udf2.sql. The NULLs after the CSTRING arguments<br />

are an optional addition that became available in <strong>Firebird</strong> 2. If an argument is declared with the NULL<br />

keyword, the engine will pass a NULL argument value unchanged to the function. This leads to a NULL<br />

result, which is correct. Without the NULL keyword (your only option in pre-2.0 versions), NULLs<br />

are passed to the function as empty strings and the result is a string with endlengh padchars (if str<br />

is NULL) or a copy of str itself (if padchar is NULL).<br />

186

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!