Using UDFlib
Using UDFlib is easy. Just treat the functions of UDFlib as if they were built
in.
Selects, Inserts, Updates and UDFlib
If you wanted to convert a name so that the first letters each word were in
capitals then you would use the UDFlib function proper. For example
Select proper(name), address, city, state, zip from customers
This SQL command would return all of the customers with the first letter of
each work of their names converted to uppercase. It would also return their
address, city, state and zip.
In an update command you could force all of the names to proper case before
posting so that you don't have to do it when you retrieve them:
update customer set name = proper("robert schieck") where cust_no = 102;
In an insert command you could again force all of the names to proper case
before posting:
insert into customer (cust_no, name) values (103, proper("robert schieck"));
If all of the names in the database are have been inserted with "proper" then
you can search for a customer by:
select * from customers where name = proper("rob schieck");
While this approach doesn't give you a case insensitive search, it comes
close. So long as all of the names are put into the database with proper then you
can retrieve them with proper as well.
Triggers, Stored Procedures
In a stored procedure you use UDFlib's functions just like a built in function
taking care not to not to mix up VarChars with Cstrings with Char variables.
Some examples of using UDFlib's functions in stored procedures are:
Using UDFlib Math Functions - mortgage payment stored procedure
Using UDFlib Character Functions - creating alphanumeric numbers base on dates in a stored procedure
External Applications
You can use UDFlib's functions in SQL statements no matter where the
statements are produced. So you can use "proper" from Delphi, Paradox, Visual dBASE or
even microsoft access. Here is an example of how to get quarterly results when
you only have daily information.
Using UDFlib Date Functions in external applications like ReportSmith
Variables
InterBase and UDFlib uses several types of variables. They are:
cstring: "C" style null terminated string
char(nnn) nnn specifies its length
varchar variable length string
Integer 4 byte signed integer
smallint 2 byte signed integer
float 4 byte floating point number
double precision 8 byte floating point number
All of the floating math functions are done with double precision variables.
While strings are done with cstrings and varchar types. Cstrings functions
would usually be used with dynamic SQL statements and C programs with embedded SQL.
The varchar functions would be used from stored procedures and triggers where
the data type of the field is VarChar.
InterBase is very good at coercing one type of data to another. When you type
an SQL command into WISQL that uses a function from UDFlib that requires a
VarChar variable, InterBase automatically converts your input to a VarChar. The
same thing happens when you type in a number. It is converted to an integer,
smallint, float or double precision as required. It automatically converts date
strings in SQL statements typed into WISQL into date variables. You must
exercise some care here as it can't and doesn't convert everything. It will not
convert one functions output to another s inputs. That is to say you cannot use a
function that returns a VarChar type as an input to a function that requires a
Cstring type. You will have to manually convert it using the vchar_to_cstr
function.
If you have a field or variable that is of type char and you want to use it
with UDFlib functions, just use the cast function in InterBase to convert it to a
VarChar first. See page 28 of the InterBase Language reference manual for
more information.
Limits and Errors
UDFlib strings are limited to 254 on input and output, with a couple of
exceptions on the output (cstradd). If you exceed them you will get an error message
returned in your string. If you exceed the bounds in the floating point math
functions it will return -999999 as a bad value. If you look at the examples in
the function reference, we tried to pick values that were average, at the
boundary and past the boundary so that you can see what to expect.
Built In
InterBase also supports a few laterals and functions (aggregates have not been
listed):
upper( s) - converts s to upper case
"now" - returns the current date and time
"today" - returns the current date with the time set to zero
"yesterday" -returns yesterdays date with the time set to zero
"tomorrow" -returns tomorrows date with the time set to zero
user -returns the attached users name
The "s are required.