org.hsqldb
Class Library

java.lang.Object
  extended byorg.hsqldb.Library

public class Library
extends Object

Provides the HSQLDB implementation of standard Open Group SQL CLI Extended Scalar Functions and other public HSQLDB SQL functions.

Version:
1.7.2

Field Summary
static String[][] sNumeric
           
static String[][] sString
           
static String[][] sSystem
           
static String[][] sTimeDate
           
 
Constructor Summary
Library()
           
 
Method Summary
static double abs(double d)
          Returns the absolute value of the given double value.
static Integer ascii(String s)
          Returns the Unicode code value of the leftmost character of s as an int.
static int bitand(int i, int j)
          Returns the bit-wise logical and of the given integer values.
static Integer bitLength(String s)
           
static int bitor(int i, int j)
          Returns the bit-wise logical or of the given integer values.
static String character(int code)
          Returns the character string corresponding to the given ASCII (or Unicode) value.
static String concat(String s1, String s2)
          Returns a String object that is the result of an SQL-style concatenation of the given String objects.
static double cot(double d)
          Returns the cotangent of the given double value expressed in radians.
static Date curdate()
          Returns the current date as a date value.
static Time curtime()
          Returns the current local time as a time value.
static String database(Connection conn)
          Returns the name of the database corresponding to this connection.
static String dayname(Date d)
          Returns a character string containing the name of the day (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday ) for the day portion of the given java.sql.Date.
static int dayofmonth(Date d)
          Returns the day of the month from the given date value, as an integer value in the range of 1-31.
static int dayofweek(Date d)
          Returns the day of the week from the given date value, as an integer value in the range 1-7, where 1 represents Sunday.
static int dayofyear(Date d)
          Returns the day of the year from the given date value, as an integer value in the range 1-366.
static int difference(String s1, String s2)
          Returns a count of the characters that do not match when comparing the 4 digit numeric SOUNDEX character sequences for the given String objects.
static boolean getAutoCommit(Connection conn)
          Retrieves the autocommit status of this connection.
static int getDatabaseMajorVersion()
          Retrieves the major version number of this database.
static int getDatabaseMinorVersion()
          Retrieves the major version number of this database.
static String getDatabaseProductName()
          Retrieves the name of this database product.
static String getDatabaseProductVersion()
          Retrieves the version number of this database product.
static String hexToRaw(String s)
          Converts a String of hexidecimal digit characters to a raw binary value, represented as a String.
static int hour(Time t)
          Returns the hour from the given time value, as an integer value in the range of 0-23.
static int identity()
          Retrieves the last auto-generated integer indentity value used by this connection.
static String insert(String s1, int start, int length, String s2)
          Returns a character sequence which is the result of writing the first length number of characters from the second given String over the first string.
static boolean isReadOnlyConnection(Connection conn)
          Retrieves whether this connection is in read-only mode.
static boolean isReadOnlyDatabase(Connection c)
          Retrieves whether this database is in read-only mode.
static boolean isReadOnlyDatabaseFiles(Connection c)
          Retrieves whether the files of this database are in read-only mode.
static String lcase(String s)
          Returns a copy of the given String, with all upper case characters converted to lower case.
static String left(String s, int count)
          Returns the leftmost count characters from the given String.
static Integer length(String s)
          Returns the number of characters in the given String.
static int locate(String search, String s, Integer start)
          Returns the starting position of the first occurrence of the given search String object within the given String object, s.
static double log10(double x)
          Returns the base 10 logarithm of the given double value.
static String ltrim(String s)
          Returns the characters of the given String, with the leading spaces removed.
static int minute(Time t)
          Returns the minute from the given time value, as integer value in the range of 0-59.
static int mod(int i1, int i2)
          Returns the remainder (modulus) of the first given integer divided by the second.
static int month(Date d)
          Returns the month from the given date value, as an integer value in the range of 1-12.
static String monthname(Date d)
          Returns a character string containing the name of month (January, February, March, April, May, June, July, August, September, October, November, December) for the month portion of the given date value.
static Timestamp now()
          Returns the current date and time as a timestamp value.
static Integer octetLength(String s)
          Returns the number of bytes in the given String.
static double pi()
          Returns the constant value, pi.
static int position(String search, String s)
          As locate but from start positionl
static int quarter(Date d)
          Returns the quarter of the year in the given date value, as an integer value in the range of 1-4.
static double rand(Integer seed)
          Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from a single, system-wide random number generator's sequence, optionally re-seeding (and thus resetting) the generator sequence.
static String rawToHex(String s)
          Converts a raw binary value, as represented by the given String, to the equivalent String of hexidecimal digit characters.
static String repeat(String s, Integer count)
          Returns a String composed of the given String, repeated count times.
static String replace(String s, String replace, String with)
          Replaces all occurrences of replace in s with the String object: with
static String right(String s, int count)
          Returns the rightmost count characters of the given String, s.
static double round(double d, int p)
          Returns the given double value, rounded to the given int places right of the decimal point.
static double roundMagic(double d)
          Retrieves a magically rounded double value produced from the given double value.
static String rtrim(String s)
          Returns the characters of the given String, with trailing spaces removed.
static int second(Time d)
          Returns the second of the given time value, as an integer value in the range of 0-59.
static int sign(double d)
          Returns an indicator of the sign of the given double value.
static String soundex(String s)
          Returns a four character code representing the sound of the given String.
static String space(int count)
          Returns a String consisting of count spaces, or null if count is less than zero.
static String substring(String s, int start, Integer length)
          Returns the characters from the given String, starting at the indicated one-based start position and extending the (optional) indicated length.
static String trim(String s, String trimstr, boolean leading, boolean trailing)
           
static double truncate(double d, int p)
          Returns the given double value, truncated to the given int places right of the decimal point.
static String ucase(String s)
          Returns a copy of the given String, with all lower case characters converted to upper case using the default Java method.
static String user(Connection conn)
          Returns the user's authorization name (the user's name as known to this database).
static int week(Date d)
          Returns the week of the year from the given date value, as an integer value in the range of 1-53.
static int year(Date d)
          Returns the year from the given date value, as an integer value in the range of 1-9999.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sNumeric

public static final String[][] sNumeric

sString

public static final String[][] sString

sTimeDate

public static final String[][] sTimeDate

sSystem

public static final String[][] sSystem
Constructor Detail

Library

public Library()
Method Detail

rand

public static double rand(Integer seed)
Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from a single, system-wide random number generator's sequence, optionally re-seeding (and thus resetting) the generator sequence. If the seed value is null, then the underlying random number generator retrieves the next value in its current sequence, else the seed alters the state of the generator object so as to be in exactly the same state as if it had just been created with the seed value.

Parameters:
seed - an optional parameter with which to reseed the underlying pseudorandom number generator
Returns:
the next pseudorandom, uniformly distributed double value between 0.0 and 1.0

abs

public static double abs(double d)
Returns the absolute value of the given double value.

Parameters:
d - the number for which to determine the absolute value
Returns:
the absolute value of d, as a double

log10

public static double log10(double x)
Returns the base 10 logarithm of the given double value.

Parameters:
x - the value for which to calculate the base 10 logarithm
Returns:
the base 10 logarithm of x, as a double

roundMagic

public static double roundMagic(double d)
Retrieves a magically rounded double value produced from the given double value. This method provides special handling for numbers close to zero and performs rounding only for numbers within a specific range, returning precisely the given value if it does not lie in this range.

Special handling includes:

Parameters:
d - the double value for which to retrieve the magically rounded value
Returns:
the magically rounded value produced

cot

public static double cot(double d)
Returns the cotangent of the given double value expressed in radians.

Parameters:
d - the angle, expressed in radians
Returns:
the cotangent

mod

public static int mod(int i1,
                      int i2)
Returns the remainder (modulus) of the first given integer divided by the second.

Parameters:
i1 - the numerator
i2 - the divisor
Returns:
i1 % i2, as an int

pi

public static double pi()
Returns the constant value, pi.

Returns:
pi as a double value

round

public static double round(double d,
                           int p)
Returns the given double value, rounded to the given int places right of the decimal point. If the supplied rounding place value is negative, rounding is performed to the left of the decimal point, using its magnitude (absolute value).

Parameters:
d - the value to be rounded
p - the rounding place value
Returns:
d rounded

sign

public static int sign(double d)
Returns an indicator of the sign of the given double value. If the value is less than zero, -1 is returned. If the value equals zero, 0 is returned. If the value is greater than zero, 1 is returned.

Parameters:
d - the value
Returns:
the sign of d

truncate

public static double truncate(double d,
                              int p)
Returns the given double value, truncated to the given int places right of the decimal point. If the given place value is negative, the given double value is truncated to the left of the decimal point, using the magnitude (aboslute value) of the place value.

Parameters:
d - the value to truncate
p - the places left or right of the decimal point at which to truncate
Returns:
d, truncated

bitand

public static int bitand(int i,
                         int j)
Returns the bit-wise logical and of the given integer values.

Parameters:
i - the first value
j - the second value
Returns:
he bit-wise logical and of i and j

bitor

public static int bitor(int i,
                        int j)
Returns the bit-wise logical or of the given integer values.

Parameters:
i - the first value
j - the second value
Returns:
he bit-wise logical and of i and j

ascii

public static Integer ascii(String s)
Returns the Unicode code value of the leftmost character of s as an int. This is the same as the ASCII value if the string contains only ASCII characters.

Parameters:
s - the String to evaluate
Returns:
the integer Unicode value of the leftmost character

character

public static String character(int code)
Returns the character string corresponding to the given ASCII (or Unicode) value. Note:

In some SQL CLI implementations, a null is returned if the range is outside 0..255. In HSQLDB, the corresponding Unicode character is returned unchecked.

Parameters:
code - the character code for which to return a String representation
Returns:
the String representation of the character

concat

public static String concat(String s1,
                            String s2)
Returns a String object that is the result of an SQL-style concatenation of the given String objects.

Note: by SQL-style, it is meant:

Parameters:
s1 - the first String
s2 - the second String
Returns:
s1 concatentated with s2

difference

public static int difference(String s1,
                             String s2)
Returns a count of the characters that do not match when comparing the 4 digit numeric SOUNDEX character sequences for the given String objects. If either String object is null, zero is returned.

Parameters:
s1 - the first String
s2 - the second String
Returns:
the number of differences between the SOUNDEX of s1 and the SOUNDEX of s2

hexToRaw

public static String hexToRaw(String s)
Converts a String of hexidecimal digit characters to a raw binary value, represented as a String.

The given String object must consist of a sequence of 4 digit hexidecimal character substrings.

If its length is not evenly divisible by 4, null is returned. If any of its 4 character subsequences cannot be parsed as a 4 digit, base 16 value, then a NumberFormatException is thrown. This conversion has the effect of reducing the character count 4:1.

Parameters:
s - a String of hexidecimal digit characters
Returns:
an equivalent raw binary value, represented as a String

insert

public static String insert(String s1,
                            int start,
                            int length,
                            String s2)
Returns a character sequence which is the result of writing the first length number of characters from the second given String over the first string. The start position in the first string where the characters are overwritten is given by start.

Note: In order of precedence, boundry conditions are handled as follows:

Parameters:
s1 - the String into which to insert s2
start - the position, with origin one, at which to start the insertion
length - the number of characters in s1 to replace
s2 - the String to insert into s1
Returns:
s2 inserted into s1, as indicated by start and length and adjusted for boundry conditions

lcase

public static String lcase(String s)
Returns a copy of the given String, with all upper case characters converted to lower case. This uses the default Java String conversion.

Parameters:
s - the String from which to produce a lower case version
Returns:
a lower case version of s

left

public static String left(String s,
                          int count)
Returns the leftmost count characters from the given String.

Note: boundry conditions are handled in the following order of precedence:

Parameters:
s - the String from which to retrieve the leftmost characters
count - the count of leftmost characters to retrieve
Returns:
the leftmost count characters of s

length

public static Integer length(String s)
Returns the number of characters in the given String. This includes trailing blanks.

Parameters:
s - the String for which to determine length
Returns:
the length of s, including trailing blanks

octetLength

public static Integer octetLength(String s)
Returns the number of bytes in the given String. This includes trailing blanks.

Parameters:
s - the String for which to determine length
Returns:
the length of s, including trailing blanks

bitLength

public static Integer bitLength(String s)

locate

public static int locate(String search,
                         String s,
                         Integer start)
Returns the starting position of the first occurrence of the given search String object within the given String object, s. The search for the first occurrence of search begins with the first character position in s, unless the optional argument, start, is specified (non-null). If start is specified, the search begins with the character position indicated by the value of start, where the first character position in s is indicated by the value 1. If search is not found within s, the value 0 is returned.

Parameters:
search - the String occurence to find in s
s - the String within which to find the first occurence of search
start - the optional character position from which to start looking in s
Returns:
the one-based starting position of the first occurrence of search within s, or 0 if not found

position

public static int position(String search,
                           String s)
As locate but from start positionl

Parameters:
search - the String occurence to find in s
s - the String within which to find the first occurence of search
Returns:
the one-based starting position of the first occurrence of search within s, or 0 if not found

ltrim

public static String ltrim(String s)
Returns the characters of the given String, with the leading spaces removed. Characters such as TAB are not removed.

Parameters:
s - the String from which to remove the leading blanks
Returns:
the characters of the given String, with the leading spaces removed

rawToHex

public static String rawToHex(String s)
Converts a raw binary value, as represented by the given String, to the equivalent String of hexidecimal digit characters.

This conversion has the effect of expanding the character count 1:4.

Parameters:
s - the raw binary value, as a String
Returns:
an equivalent String of hexidecimal digit characters

repeat

public static String repeat(String s,
                            Integer count)
Returns a String composed of the given String, repeated count times.

Parameters:
s - the String to repeat
count - the number of repetitions
Returns:
the given String, repeated count times

replace

public static String replace(String s,
                             String replace,
                             String with)
Replaces all occurrences of replace in s with the String object: with

Parameters:
s - the target for replacement
replace - the substring(s), if any, in s to replace
with - the value to substitute for replace
Returns:
s, with all occurences of replace replaced by with

right

public static String right(String s,
                           int count)
Returns the rightmost count characters of the given String, s. Note: boundry conditions are handled in the following order of precedence:

Parameters:
s - the String from which to retrieve the rightmost count characters
count - the number of rightmost characters to retrieve
Returns:
the rightmost count characters of s

rtrim

public static String rtrim(String s)
Returns the characters of the given String, with trailing spaces removed.

Parameters:
s - the String from which to remove the trailing blanks
Returns:
the characters of the given String, with the trailing spaces removed

trim

public static String trim(String s,
                          String trimstr,
                          boolean leading,
                          boolean trailing)

soundex

public static String soundex(String s)
Returns a four character code representing the sound of the given String. Non-ASCCI characters in the input String are ignored.

This method was rewritten for HSQLDB by fredt@users to comply with the description at http://www.nara.gov/genealogy/coding.html.

Parameters:
s - the String for which to calculate the 4 character SOUNDEX value
Returns:
the 4 character SOUNDEX value for the given String

space

public static String space(int count)
Returns a String consisting of count spaces, or null if count is less than zero.

Parameters:
count - the number of spaces to produce
Returns:
a String of count spaces

substring

public static String substring(String s,
                               int start,
                               Integer length)
Returns the characters from the given String, starting at the indicated one-based start position and extending the (optional) indicated length. If length is not specified (is null), the remainder of s is implied.

Parameters:
s - the String from which to produce the indicated substring
start - the starting position of the desired substring
length - the length of the desired substring
Returns:
the indicted substring of s.

ucase

public static String ucase(String s)
Returns a copy of the given String, with all lower case characters converted to upper case using the default Java method.

Parameters:
s - the String from which to produce an upper case version
Returns:
an upper case version of s

curdate

public static Date curdate()
Returns the current date as a date value.

Returns:
a date value representing the current date

curtime

public static Time curtime()
Returns the current local time as a time value.

Returns:
a time value representing the current local time

dayname

public static String dayname(Date d)
Returns a character string containing the name of the day (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday ) for the day portion of the given java.sql.Date.

Parameters:
d - the date value from which to extract the day name
Returns:
the name of the day corresponding to the given java.sql.Date

dayofmonth

public static int dayofmonth(Date d)
Returns the day of the month from the given date value, as an integer value in the range of 1-31.

Parameters:
d - the date value from which to extract the day of month
Returns:
the day of the month from the given date value

dayofweek

public static int dayofweek(Date d)
Returns the day of the week from the given date value, as an integer value in the range 1-7, where 1 represents Sunday.

Parameters:
d - the date value from which to extract the day of week
Returns:
the day of the week from the given date value

dayofyear

public static int dayofyear(Date d)
Returns the day of the year from the given date value, as an integer value in the range 1-366.

Parameters:
d - the date value from which to extract the day of year
Returns:
the day of the year from the given date value

hour

public static int hour(Time t)
Returns the hour from the given time value, as an integer value in the range of 0-23.

Parameters:
t - the time value from which to extract the hour of day
Returns:
the hour of day from the given time value

minute

public static int minute(Time t)
Returns the minute from the given time value, as integer value in the range of 0-59.

Parameters:
t - the time value from which to extract the minute value
Returns:
the minute value from the given time value

month

public static int month(Date d)
Returns the month from the given date value, as an integer value in the range of 1-12.

The sql_month database property is now obsolete. The function always returns the SQL (1-12) value for month.

Parameters:
d - the date value from which to extract the month value
Returns:
the month value from the given date value

monthname

public static String monthname(Date d)
Returns a character string containing the name of month (January, February, March, April, May, June, July, August, September, October, November, December) for the month portion of the given date value.

Parameters:
d - the date value from which to extract the month name
Returns:
a String representing the month name from the given date value

now

public static Timestamp now()
Returns the current date and time as a timestamp value.

Returns:
a timestamp value representing the current date and time

quarter

public static int quarter(Date d)
Returns the quarter of the year in the given date value, as an integer value in the range of 1-4.

Parameters:
d - the date value from which to extract the quarter of the year
Returns:
an integer representing the quater of the year from the given date value

second

public static int second(Time d)
Returns the second of the given time value, as an integer value in the range of 0-59.

Parameters:
d - the date value from which to extract the second of the hour
Returns:
an integer representing the second of the hour from the given time value

week

public static int week(Date d)
Returns the week of the year from the given date value, as an integer value in the range of 1-53.

Parameters:
d - the date value from which to extract the week of the year
Returns:
an integer representing the week of the year from the given date value

year

public static int year(Date d)
Returns the year from the given date value, as an integer value in the range of 1-9999.

Parameters:
d - the date value from which to extract the year
Returns:
an integer value representing the year from the given date value

database

public static String database(Connection conn)
                       throws HsqlException
Returns the name of the database corresponding to this connection.

Parameters:
conn - the connection for which to retrieve the database name
Returns:
the name of the database for the given connection
Throws:
HsqlException - if a database access error occurs

user

public static String user(Connection conn)
                   throws HsqlException
Returns the user's authorization name (the user's name as known to this database).

Parameters:
conn - the connection for which to retrieve the user name
Returns:
the user's name as known to the database
Throws:
HsqlException - if a database access error occurs

identity

public static int identity()
                    throws HsqlException
Retrieves the last auto-generated integer indentity value used by this connection.

Returns:
the connection's the last generated integer identity value
Throws:
HsqlException - if a database access error occurs

getAutoCommit

public static boolean getAutoCommit(Connection conn)
Retrieves the autocommit status of this connection.

Parameters:
conn - the Connection object for which to retrieve the current autocommit status
Returns:
a boolean value representing the connection's autocommit status
Since:
HSQLDB 1.7.0

getDatabaseProductName

public static String getDatabaseProductName()
Retrieves the name of this database product.

Returns:
database product name as a String object
Since:
HSQLDB 1.7.2

getDatabaseProductVersion

public static String getDatabaseProductVersion()
Retrieves the version number of this database product.

Returns:
database version number as a String object
Since:
HSQLDB 1.7.2

getDatabaseMajorVersion

public static int getDatabaseMajorVersion()
Retrieves the major version number of this database.

Returns:
the database's major version as an int value
Since:
HSQLDB 1.7.2

getDatabaseMinorVersion

public static int getDatabaseMinorVersion()
Retrieves the major version number of this database.

Returns:
the database's major version as an int value
Since:
HSQLDB 1.7.2

isReadOnlyConnection

public static boolean isReadOnlyConnection(Connection conn)
Retrieves whether this connection is in read-only mode.

Parameters:
conn - the Connection object for which to retrieve the current read-only status
Returns:
true if connection is read-only and false otherwise
Since:
HSQLDB 1.7.2

isReadOnlyDatabase

public static boolean isReadOnlyDatabase(Connection c)
Retrieves whether this database is in read-only mode.

Parameters:
c - the Connection object for which to retrieve the current database read-only status
Returns:
true if so; false otherwise
Since:
HSQLDB 1.7.2

isReadOnlyDatabaseFiles

public static boolean isReadOnlyDatabaseFiles(Connection c)
Retrieves whether the files of this database are in read-only mode.

Parameters:
c - the Connection object for which to retrieve the current database files read-only status
Returns:
true if so; false otherwise
Since:
HSQLDB 1.7.2


Copyright © 2001 - 2004 HSQL Development Group. All Rights Reserved.