org.h2.expression
Class Function

java.lang.Object
  extended by org.h2.expression.Expression
      extended by org.h2.expression.Function
All Implemented Interfaces:
FunctionCall
Direct Known Subclasses:
TableFunction

public class Function
extends Expression
implements FunctionCall

This class implements most built-in functions of this database.


Field Summary
static int ABS
           
static int ACOS
           
protected  Expression[] args
           
static int ARRAY_GET
           
static int ARRAY_LENGTH
           
static int ASCII
           
static int ASIN
           
static int ATAN
           
static int ATAN2
           
static int AUTOCOMMIT
           
static int BIT_LENGTH
           
static int BITAND
           
static int BITOR
           
static int BITXOR
           
static int CANCEL_SESSION
           
static int CASE
           
static int CASEWHEN
           
static int CAST
           
static int CEILING
           
static int CHAR
           
static int CHAR_LENGTH
           
static int COALESCE
           
static int COMPRESS
           
static int CONCAT
           
static int CONVERT
           
static int COS
           
static int COT
           
static int CSVREAD
           
static int CSVWRITE
           
static int CURDATE
           
static int CURRENT_DATE
           
static int CURRENT_TIME
           
static int CURRENT_TIMESTAMP
           
static int CURRENT_USER
           
static int CURRVAL
           
static int CURTIME
           
static int DATABASE
           
static int DATABASE_PATH
           
static int DATE_ADD
           
static int DATE_DIFF
           
static int DAY_NAME
           
static int DAY_OF_MONTH
           
static int DAY_OF_WEEK
           
static int DAY_OF_YEAR
           
static int DECRYPT
           
static int DEGREES
           
static int DIFFERENCE
           
static int ENCRYPT
           
static int EXP
           
static int EXPAND
           
static int EXTRACT
           
static int FILE_READ
           
static int FLOOR
           
static int FORMATDATETIME
           
static int GREATEST
           
static int HASH
           
static int HEXTORAW
           
static int HOUR
           
static int IDENTITY
           
static int IFNULL
           
static int INSERT
           
static int INSTR
           
static int ISO_DAY_OF_WEEK
           
static int ISO_WEEK
           
static int ISO_YEAR
           
static int LCASE
           
static int LEAST
           
static int LEFT
           
static int LENGTH
           
static int LINK_SCHEMA
           
static int LOCATE
           
static int LOCK_MODE
           
static int LOCK_TIMEOUT
           
static int LOG
           
static int LOG10
           
static int LOWER
           
static int LPAD
           
static int LTRIM
           
static int MEMORY_FREE
           
static int MEMORY_USED
           
static int MINUTE
           
static int MOD
           
static int MONTH
           
static int MONTH_NAME
           
static int NEXTVAL
           
static int NOW
           
static int NULLIF
           
static int OCTET_LENGTH
           
static int PARSEDATETIME
           
static int PI
           
static int POSITION
           
static int POWER
           
static int QUARTER
           
static int RADIANS
           
static int RAND
           
static int RANDOM_UUID
           
static int RAWTOHEX
           
static int READONLY
           
static int REGEXP_REPLACE
           
static int REPEAT
           
static int REPLACE
           
static int RIGHT
           
static int ROUND
           
static int ROUNDMAGIC
           
static int RPAD
           
static int RTRIM
           
static int SCHEMA
           
static int SCOPE_IDENTITY
           
static int SECOND
           
static int SECURE_RAND
           
static int SESSION_ID
           
static int SET
           
static int SIGN
           
static int SIN
           
static int SOUNDEX
           
static int SPACE
           
static int SQRT
           
static int STRINGDECODE
           
static int STRINGENCODE
           
static int STRINGTOUTF8
           
static int SUBSTR
           
static int SUBSTRING
           
static int TABLE
           
static int TABLE_DISTINCT
           
static int TAN
           
static int TRANSACTION_ID
           
static int TRIM
           
static int TRUNCATE
           
static int UCASE
           
static int UPPER
           
static int USER
           
static int UTF8TOSTRING
           
static int WEEK
           
static int XMLATTR
           
static int XMLCDATA
           
static int XMLCOMMENT
           
static int XMLNODE
           
static int XMLSTARTDOC
           
static int XMLTEXT
           
static int YEAR
           
static int ZERO
           
 
Constructor Summary
protected Function(Database database, org.h2.expression.FunctionInfo info)
           
 
Method Summary
protected  void checkParameterCount(int len)
          Check if the parameter count is correct.
 void doneWithParameters()
          This method is called after all the parameters have been set.
 Expression[] getArgs()
          Get the function arguments.
 int getCost()
          Estimate the cost to process the expression.
 int getDisplaySize()
          Get the display size of this expression.
static Function getFunction(Database database, java.lang.String name)
          Get an instance of the given function for this database.
static org.h2.expression.FunctionInfo getFunctionInfo(java.lang.String name)
          Get the function info object for this function, or null if there is no such function.
 int getFunctionType()
           
 java.lang.String getName()
          Get the name of the function.
 int getParameterCount()
          Get the number of parameters.
 long getPrecision()
          Get the precision of this expression.
 int getScale()
          Get the scale of this expression.
 java.lang.String getSQL()
          Get the SQL statement of this expression.
 int getType()
          Return the data type.
 Value getValue(Session session)
          Return the resulting value for the current row.
 ValueResultSet getValueForColumnList(Session session, Expression[] argList)
          Get an empty result set with the column names set.
static boolean isDatePart(java.lang.String part)
          Check if a given string is a valid date part string.
 boolean isDeterministic()
          Whether the function always returns the same result for the same parameters.
 boolean isEverything(ExpressionVisitor visitor)
          Check if this expression and all sub-expressions can fulfill a criteria.
 void mapColumns(ColumnResolver resolver, int level)
          Map the columns of the resolver to expression columns.
 Expression optimize(Session session)
          Try to optimize the expression.
 void setDataType(Column col)
           
 void setDataType(int dataType, long precision, int scale, int displaySize)
          Set the result data type of this function.
 void setEvaluatable(TableFilter tableFilter, boolean b)
          Tell the expression columns whether the table filter can return values now.
 void setParameter(int index, Expression param)
          Set the parameter expression at the given index.
 void updateAggregate(Session session)
          Update an aggregate value.
 
Methods inherited from class org.h2.expression.Expression
addFilterConditions, createIndexConditions, getAlias, getBooleanValue, getColumnName, getNonAliasExpression, getNotIfPossible, getNullable, getSchemaName, getTableAlias, getTableName, isAutoIncrement, isConstant, isEverything, isValueSet, isWildcard, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ABS

public static final int ABS
See Also:
Constant Field Values

ACOS

public static final int ACOS
See Also:
Constant Field Values

ASIN

public static final int ASIN
See Also:
Constant Field Values

ATAN

public static final int ATAN
See Also:
Constant Field Values

ATAN2

public static final int ATAN2
See Also:
Constant Field Values

BITAND

public static final int BITAND
See Also:
Constant Field Values

BITOR

public static final int BITOR
See Also:
Constant Field Values

BITXOR

public static final int BITXOR
See Also:
Constant Field Values

CEILING

public static final int CEILING
See Also:
Constant Field Values

COS

public static final int COS
See Also:
Constant Field Values

COT

public static final int COT
See Also:
Constant Field Values

DEGREES

public static final int DEGREES
See Also:
Constant Field Values

EXP

public static final int EXP
See Also:
Constant Field Values

FLOOR

public static final int FLOOR
See Also:
Constant Field Values

LOG

public static final int LOG
See Also:
Constant Field Values

LOG10

public static final int LOG10
See Also:
Constant Field Values

MOD

public static final int MOD
See Also:
Constant Field Values

PI

public static final int PI
See Also:
Constant Field Values

POWER

public static final int POWER
See Also:
Constant Field Values

RADIANS

public static final int RADIANS
See Also:
Constant Field Values

RAND

public static final int RAND
See Also:
Constant Field Values

ROUND

public static final int ROUND
See Also:
Constant Field Values

ROUNDMAGIC

public static final int ROUNDMAGIC
See Also:
Constant Field Values

SIGN

public static final int SIGN
See Also:
Constant Field Values

SIN

public static final int SIN
See Also:
Constant Field Values

SQRT

public static final int SQRT
See Also:
Constant Field Values

TAN

public static final int TAN
See Also:
Constant Field Values

TRUNCATE

public static final int TRUNCATE
See Also:
Constant Field Values

SECURE_RAND

public static final int SECURE_RAND
See Also:
Constant Field Values

HASH

public static final int HASH
See Also:
Constant Field Values

ENCRYPT

public static final int ENCRYPT
See Also:
Constant Field Values

DECRYPT

public static final int DECRYPT
See Also:
Constant Field Values

COMPRESS

public static final int COMPRESS
See Also:
Constant Field Values

EXPAND

public static final int EXPAND
See Also:
Constant Field Values

ZERO

public static final int ZERO
See Also:
Constant Field Values

RANDOM_UUID

public static final int RANDOM_UUID
See Also:
Constant Field Values

ASCII

public static final int ASCII
See Also:
Constant Field Values

BIT_LENGTH

public static final int BIT_LENGTH
See Also:
Constant Field Values

CHAR

public static final int CHAR
See Also:
Constant Field Values

CHAR_LENGTH

public static final int CHAR_LENGTH
See Also:
Constant Field Values

CONCAT

public static final int CONCAT
See Also:
Constant Field Values

DIFFERENCE

public static final int DIFFERENCE
See Also:
Constant Field Values

HEXTORAW

public static final int HEXTORAW
See Also:
Constant Field Values

INSERT

public static final int INSERT
See Also:
Constant Field Values

INSTR

public static final int INSTR
See Also:
Constant Field Values

LCASE

public static final int LCASE
See Also:
Constant Field Values

LEFT

public static final int LEFT
See Also:
Constant Field Values

LENGTH

public static final int LENGTH
See Also:
Constant Field Values

LOCATE

public static final int LOCATE
See Also:
Constant Field Values

LTRIM

public static final int LTRIM
See Also:
Constant Field Values

OCTET_LENGTH

public static final int OCTET_LENGTH
See Also:
Constant Field Values

RAWTOHEX

public static final int RAWTOHEX
See Also:
Constant Field Values

REPEAT

public static final int REPEAT
See Also:
Constant Field Values

REPLACE

public static final int REPLACE
See Also:
Constant Field Values

RIGHT

public static final int RIGHT
See Also:
Constant Field Values

RTRIM

public static final int RTRIM
See Also:
Constant Field Values

SOUNDEX

public static final int SOUNDEX
See Also:
Constant Field Values

SPACE

public static final int SPACE
See Also:
Constant Field Values

SUBSTR

public static final int SUBSTR
See Also:
Constant Field Values

SUBSTRING

public static final int SUBSTRING
See Also:
Constant Field Values

UCASE

public static final int UCASE
See Also:
Constant Field Values

LOWER

public static final int LOWER
See Also:
Constant Field Values

UPPER

public static final int UPPER
See Also:
Constant Field Values

POSITION

public static final int POSITION
See Also:
Constant Field Values

TRIM

public static final int TRIM
See Also:
Constant Field Values

STRINGENCODE

public static final int STRINGENCODE
See Also:
Constant Field Values

STRINGDECODE

public static final int STRINGDECODE
See Also:
Constant Field Values

STRINGTOUTF8

public static final int STRINGTOUTF8
See Also:
Constant Field Values

UTF8TOSTRING

public static final int UTF8TOSTRING
See Also:
Constant Field Values

XMLATTR

public static final int XMLATTR
See Also:
Constant Field Values

XMLNODE

public static final int XMLNODE
See Also:
Constant Field Values

XMLCOMMENT

public static final int XMLCOMMENT
See Also:
Constant Field Values

XMLCDATA

public static final int XMLCDATA
See Also:
Constant Field Values

XMLSTARTDOC

public static final int XMLSTARTDOC
See Also:
Constant Field Values

XMLTEXT

public static final int XMLTEXT
See Also:
Constant Field Values

REGEXP_REPLACE

public static final int REGEXP_REPLACE
See Also:
Constant Field Values

RPAD

public static final int RPAD
See Also:
Constant Field Values

LPAD

public static final int LPAD
See Also:
Constant Field Values

CURDATE

public static final int CURDATE
See Also:
Constant Field Values

CURTIME

public static final int CURTIME
See Also:
Constant Field Values

DATE_ADD

public static final int DATE_ADD
See Also:
Constant Field Values

DATE_DIFF

public static final int DATE_DIFF
See Also:
Constant Field Values

DAY_NAME

public static final int DAY_NAME
See Also:
Constant Field Values

DAY_OF_MONTH

public static final int DAY_OF_MONTH
See Also:
Constant Field Values

DAY_OF_WEEK

public static final int DAY_OF_WEEK
See Also:
Constant Field Values

DAY_OF_YEAR

public static final int DAY_OF_YEAR
See Also:
Constant Field Values

HOUR

public static final int HOUR
See Also:
Constant Field Values

MINUTE

public static final int MINUTE
See Also:
Constant Field Values

MONTH

public static final int MONTH
See Also:
Constant Field Values

MONTH_NAME

public static final int MONTH_NAME
See Also:
Constant Field Values

NOW

public static final int NOW
See Also:
Constant Field Values

QUARTER

public static final int QUARTER
See Also:
Constant Field Values

SECOND

public static final int SECOND
See Also:
Constant Field Values

WEEK

public static final int WEEK
See Also:
Constant Field Values

YEAR

public static final int YEAR
See Also:
Constant Field Values

CURRENT_DATE

public static final int CURRENT_DATE
See Also:
Constant Field Values

CURRENT_TIME

public static final int CURRENT_TIME
See Also:
Constant Field Values

CURRENT_TIMESTAMP

public static final int CURRENT_TIMESTAMP
See Also:
Constant Field Values

EXTRACT

public static final int EXTRACT
See Also:
Constant Field Values

FORMATDATETIME

public static final int FORMATDATETIME
See Also:
Constant Field Values

PARSEDATETIME

public static final int PARSEDATETIME
See Also:
Constant Field Values

ISO_YEAR

public static final int ISO_YEAR
See Also:
Constant Field Values

ISO_WEEK

public static final int ISO_WEEK
See Also:
Constant Field Values

ISO_DAY_OF_WEEK

public static final int ISO_DAY_OF_WEEK
See Also:
Constant Field Values

DATABASE

public static final int DATABASE
See Also:
Constant Field Values

USER

public static final int USER
See Also:
Constant Field Values

CURRENT_USER

public static final int CURRENT_USER
See Also:
Constant Field Values

IDENTITY

public static final int IDENTITY
See Also:
Constant Field Values

SCOPE_IDENTITY

public static final int SCOPE_IDENTITY
See Also:
Constant Field Values

AUTOCOMMIT

public static final int AUTOCOMMIT
See Also:
Constant Field Values

READONLY

public static final int READONLY
See Also:
Constant Field Values

DATABASE_PATH

public static final int DATABASE_PATH
See Also:
Constant Field Values

LOCK_TIMEOUT

public static final int LOCK_TIMEOUT
See Also:
Constant Field Values

IFNULL

public static final int IFNULL
See Also:
Constant Field Values

CASEWHEN

public static final int CASEWHEN
See Also:
Constant Field Values

CONVERT

public static final int CONVERT
See Also:
Constant Field Values

CAST

public static final int CAST
See Also:
Constant Field Values

COALESCE

public static final int COALESCE
See Also:
Constant Field Values

NULLIF

public static final int NULLIF
See Also:
Constant Field Values

CASE

public static final int CASE
See Also:
Constant Field Values

NEXTVAL

public static final int NEXTVAL
See Also:
Constant Field Values

CURRVAL

public static final int CURRVAL
See Also:
Constant Field Values

ARRAY_GET

public static final int ARRAY_GET
See Also:
Constant Field Values

CSVREAD

public static final int CSVREAD
See Also:
Constant Field Values

CSVWRITE

public static final int CSVWRITE
See Also:
Constant Field Values

MEMORY_FREE

public static final int MEMORY_FREE
See Also:
Constant Field Values

MEMORY_USED

public static final int MEMORY_USED
See Also:
Constant Field Values

LOCK_MODE

public static final int LOCK_MODE
See Also:
Constant Field Values

SCHEMA

public static final int SCHEMA
See Also:
Constant Field Values

SESSION_ID

public static final int SESSION_ID
See Also:
Constant Field Values

ARRAY_LENGTH

public static final int ARRAY_LENGTH
See Also:
Constant Field Values

LINK_SCHEMA

public static final int LINK_SCHEMA
See Also:
Constant Field Values

GREATEST

public static final int GREATEST
See Also:
Constant Field Values

LEAST

public static final int LEAST
See Also:
Constant Field Values

CANCEL_SESSION

public static final int CANCEL_SESSION
See Also:
Constant Field Values

SET

public static final int SET
See Also:
Constant Field Values

TABLE

public static final int TABLE
See Also:
Constant Field Values

TABLE_DISTINCT

public static final int TABLE_DISTINCT
See Also:
Constant Field Values

FILE_READ

public static final int FILE_READ
See Also:
Constant Field Values

TRANSACTION_ID

public static final int TRANSACTION_ID
See Also:
Constant Field Values

args

protected Expression[] args
Constructor Detail

Function

protected Function(Database database,
                   org.h2.expression.FunctionInfo info)
Method Detail

getFunctionInfo

public static org.h2.expression.FunctionInfo getFunctionInfo(java.lang.String name)
Get the function info object for this function, or null if there is no such function.

Parameters:
name - the function name
Returns:
the function info

getFunction

public static Function getFunction(Database database,
                                   java.lang.String name)
Get an instance of the given function for this database. If no function with this name is found, null is returned.

Parameters:
database - the database
name - the function name
Returns:
the function object or null

setParameter

public void setParameter(int index,
                         Expression param)
Set the parameter expression at the given index.

Parameters:
index - the index (0, 1,...)
param - the expression

getValue

public Value getValue(Session session)
Description copied from class: Expression
Return the resulting value for the current row.

Specified by:
getValue in interface FunctionCall
Specified by:
getValue in class Expression
Parameters:
session - the session
Returns:
the result

isDatePart

public static boolean isDatePart(java.lang.String part)
Check if a given string is a valid date part string.

Parameters:
part - the string
Returns:
true if it is

getType

public int getType()
Description copied from class: Expression
Return the data type. The data type may not be known before the optimization phase.

Specified by:
getType in interface FunctionCall
Specified by:
getType in class Expression
Returns:
the type

mapColumns

public void mapColumns(ColumnResolver resolver,
                       int level)
Description copied from class: Expression
Map the columns of the resolver to expression columns.

Specified by:
mapColumns in class Expression
Parameters:
resolver - the column resolver
level - the subquery nesting level

checkParameterCount

protected void checkParameterCount(int len)
Check if the parameter count is correct.

Parameters:
len - the number of parameters set
Throws:
java.sql.SQLException - if the parameter count is incorrect

doneWithParameters

public void doneWithParameters()
This method is called after all the parameters have been set. It checks if the parameter count is correct.

Throws:
java.sql.SQLException - if the parameter count is incorrect.

setDataType

public void setDataType(int dataType,
                        long precision,
                        int scale,
                        int displaySize)
Set the result data type of this function.

Parameters:
dataType - the data type
precision - the precision
scale - the scale
displaySize - the display size

setDataType

public void setDataType(Column col)

optimize

public Expression optimize(Session session)
Description copied from class: Expression
Try to optimize the expression.

Specified by:
optimize in interface FunctionCall
Specified by:
optimize in class Expression
Parameters:
session - the session
Returns:
the optimized expression

setEvaluatable

public void setEvaluatable(TableFilter tableFilter,
                           boolean b)
Description copied from class: Expression
Tell the expression columns whether the table filter can return values now. This is used when optimizing the query.

Specified by:
setEvaluatable in class Expression
Parameters:
tableFilter - the table filter
b - true if the table filter can return value

getScale

public int getScale()
Description copied from class: Expression
Get the scale of this expression.

Specified by:
getScale in class Expression
Returns:
the scale

getPrecision

public long getPrecision()
Description copied from class: Expression
Get the precision of this expression.

Specified by:
getPrecision in class Expression
Returns:
the precision

getDisplaySize

public int getDisplaySize()
Description copied from class: Expression
Get the display size of this expression.

Specified by:
getDisplaySize in class Expression
Returns:
the display size

getSQL

public java.lang.String getSQL()
Description copied from class: Expression
Get the SQL statement of this expression. This may not always be the original SQL statement, specially after optimization.

Specified by:
getSQL in interface FunctionCall
Specified by:
getSQL in class Expression
Returns:
the SQL statement

updateAggregate

public void updateAggregate(Session session)
Description copied from class: Expression
Update an aggregate value. This method is called at statement execution time. It is usually called once for each row, but if the expression is used multiple times (for example in the column list, and as part of the HAVING expression) it is called multiple times - the row counter needs to be used to make sure the internal state is only updated once.

Specified by:
updateAggregate in class Expression
Parameters:
session - the session

getFunctionType

public int getFunctionType()

getName

public java.lang.String getName()
Description copied from interface: FunctionCall
Get the name of the function.

Specified by:
getName in interface FunctionCall
Returns:
the name

getParameterCount

public int getParameterCount()
Description copied from interface: FunctionCall
Get the number of parameters.

Specified by:
getParameterCount in interface FunctionCall
Returns:
the number of parameters

getValueForColumnList

public ValueResultSet getValueForColumnList(Session session,
                                            Expression[] argList)
Description copied from interface: FunctionCall
Get an empty result set with the column names set.

Specified by:
getValueForColumnList in interface FunctionCall
Parameters:
session - the session
argList - the argument list (some arguments may be null)
Returns:
the empty result set

getArgs

public Expression[] getArgs()
Description copied from interface: FunctionCall
Get the function arguments.

Specified by:
getArgs in interface FunctionCall
Returns:
argument list

isEverything

public boolean isEverything(ExpressionVisitor visitor)
Description copied from class: Expression
Check if this expression and all sub-expressions can fulfill a criteria. If any part returns false, the result is false.

Specified by:
isEverything in class Expression
Parameters:
visitor - the visitor
Returns:
if the criteria can be fulfilled

getCost

public int getCost()
Description copied from class: Expression
Estimate the cost to process the expression. Used when optimizing the query, to calculate the query plan with the lowest estimated cost.

Specified by:
getCost in class Expression
Returns:
the estimated cost

isDeterministic

public boolean isDeterministic()
Description copied from interface: FunctionCall
Whether the function always returns the same result for the same parameters.

Specified by:
isDeterministic in interface FunctionCall
Returns:
true if it does