| java.lang.Object org.hsqldb.Column
Column | public class Column (Code) | | Implementation of SQL table columns as defined in DDL statements with
static methods to process their values.
Enhanced type checking and conversion by fredt@users
author: Thomas Mueller (Hypersonic SQL Group) author: fredt@users version: 1.8.0 since: Hypersonic SQL |
Constructor Summary | |
| Column(HsqlName name, boolean nullable, int type, int size, int scale, boolean primarykey, Expression defexpression) Creates a column defined in DDL statement. |
Method Summary | |
static Object | add(Object a, Object b, int type) | static String | checkChar(String s, int len, boolean check) | static String | checkVarchar(String s, int len, boolean check) Checks the length of a VARCHAR string. | static int | compare(Collation collation, Object a, Object b, int type) Compare a with b and return int value as result. | static int | compareTo(byte[] o1, byte[] o2) Compares a byte[] with another specified
byte[] for order. | static int | compareToTypeRange(Object o, int targettype) | static Object | concat(Object a, Object b) Concat two objects by turning them into strings first. | public static Object | convertObject(Object o, int type) Convert an object into a Java object that represents its SQL type.
All internal type conversion operations start with
this method. | public static Object | convertObject(Session session, Object o, int type, int precision, int scale) Explicit casts are handled here. | static Double | convertToDouble(Object o) Converter from a numeric object to Double. | static Integer | convertToInt(Object o) Converter from a numeric object to Integer. | static Long | convertToLong(Object o) Converter from a numeric object to Long. | static String | createSQLString(Object o, int type) Return an SQL representation of an object. | public static String | createSQLString(double x) | public static String | createSQLString(String s) | static Object | divide(Object a, Object b, int type) Divide numeric object a by object b. | Column | duplicate(boolean withIdentity) Used for primary key changes. | static Object | enforceSize(Object obj, int type, int size, int scale, boolean check) | static int | getCombinedNumberType(int type1, int type2, int expType) Arithmetic expression terms are promoted to a type that can
represent the resulting values and avoid incorrect results.
When the result or the expression is converted to the
type of the target column for storage, an exception is thrown if the
resulting value cannot be stored in the column
Returns a SQL type "wide" enough to represent the result of the
expression.
A type is "wider" than the other if it can represent all its
numeric values.
Types narrower than INTEGER (int) are promoted to
INTEGER. | int | getDIType() | int | getDITypeSub() | String | getDefaultDDL() Returns DDL for default value. | Expression | getDefaultExpression() Returns default expression for the column. | Object | getDefaultValue(Session session) Returns default value in the session context. | static int | getNumTypeWidth(int type) | int | getScale() Scale of the column in DDL (0 if not defined). | int | getSize() Size of the column in DDL (0 if not defined). | int | getType() Type of the column. | public static byte[] | hexToByteArray(String hexString) Converts the specified hexadecimal digit String
to an equivalent array of bytes.
Parameters: hexString - a String of hexadecimal digits throws: HsqlException - if the specified string contains non-hexadecimal digits. | boolean | isIdentity() Is this the identity column in the table. | boolean | isNullable() Is column nullable. | public boolean | isPrimaryKey() Is this single column primary key of the table. | static Object | multiply(Object a, Object b, int type) Multiply two numeric objects. | static Object | negate(Object a, int type) Negate a numeric object. | void | setDefaultExpression(Expression expr) | void | setIdentity(boolean identity, long startvalue, long increment) | void | setNullable(boolean value) Set nullable. | void | setPrimaryKey(boolean value) Set primary key. | void | setType(Column other) | static Object | subtract(Object a, Object b, int type) Subtract numeric object b from object a. |
columnName | public HsqlName columnName(Code) | | |
identityIncrement | long identityIncrement(Code) | | |
identityStart | long identityStart(Code) | | |
tenPower | static int[] tenPower(Code) | | |
Column | Column(HsqlName name, boolean nullable, int type, int size, int scale, boolean primarykey, Expression defexpression) throws HsqlException(Code) | | Creates a column defined in DDL statement.
Parameters: name - Parameters: nullable - Parameters: type - Parameters: size - Parameters: scale - Parameters: identity - Parameters: startvalue - Parameters: increment - Parameters: primarykey - Parameters: defstring - |
checkChar | static String checkChar(String s, int len, boolean check) throws HsqlException(Code) | | Checks and pads a CHARACTER string to len size
Parameters: s - the string to pad to truncate Parameters: len - the len to make the string Parameters: check - if true, throw an exception if truncation takes place the string of size len |
checkVarchar | static String checkVarchar(String s, int len, boolean check) throws HsqlException(Code) | | Checks the length of a VARCHAR string.
Parameters: s - the string to pad to truncate Parameters: len - the len to make the string Parameters: check - if true, throw an exception if truncation takes place the string of size len |
compare | static int compare(Collation collation, Object a, Object b, int type)(Code) | | Compare a with b and return int value as result.
Parameters: a - instance of Java wrapper, depending on type, but always same for a & b (can be null) Parameters: b - instance of Java wrapper, depending on type, but always same for a & b (can be null) Parameters: type - one of the java.sql.Types result 1 if a>b, 0 if a=b, -1 if b>a throws: HsqlException - |
compareTo | static int compareTo(byte[] o1, byte[] o2)(Code) | | Compares a byte[] with another specified
byte[] for order. Returns a negative integer, zero,
or a positive integer as the first object is less than, equal to, or
greater than the specified second byte[] .
Parameters: o1 - the first byte[] to be compared Parameters: o2 - the second byte[] to be compared a negative integer, zero, or a positive integer as this objectis less than, equal to, or greater than the specified object. |
compareToTypeRange | static int compareToTypeRange(Object o, int targettype)(Code) | | returns -1, 0 , +1
|
convertObject | public static Object convertObject(Object o, int type) throws HsqlException(Code) | | Convert an object into a Java object that represents its SQL type.
All internal type conversion operations start with
this method. If a direct conversion doesn't take place, the object
is converted into a string first and an attempt is made to convert
the string into the target type.
One objective of this mehod is to ensure the Object can be converted
to the given SQL type. For example, a very large BIGINT
value cannot be narrowed down to an INTEGER or SMALLINT.
Type conversion performed by this method has gradually evolved in 1.7.2
to allow narrowing of numeric types in all cases according to the SQL
standard.
Another new objective is to normalize DATETIME values.
Objects set via JDBC PreparedStatement use this method to convert
the data to the Java type that is required for custom serialization
by the engine.
Parameters: o - Parameters: type - result throws: HsqlException - |
convertObject | public static Object convertObject(Session session, Object o, int type, int precision, int scale) throws HsqlException(Code) | | Explicit casts are handled here. This is separate from the implicit
casts carried out when inserting/updating rows.
SQL standard 6.12 rules for enforcement of size, precision and scale
are implemented here are as follows:
For no size, precision or scale, default to convertObject(Object)
Right truncation is allowed only for CHAR to CHAR casts
(CHAR is generic for all string types).
For other casts to CHAR, right truncation is not allowed.
For numeric conversions, scale is always converted to target first,
then precision is imposed. No truncation is allowed. (fredt)
|
convertToDouble | static Double convertToDouble(Object o) throws HsqlException(Code) | | Converter from a numeric object to Double. Input is checked to be
within range represented by Double
|
convertToInt | static Integer convertToInt(Object o) throws HsqlException(Code) | | Converter from a numeric object to Integer. Input is checked to be
within range represented by Integer.
|
convertToLong | static Long convertToLong(Object o) throws HsqlException(Code) | | Converter from a numeric object to Long. Input is checked to be
within range represented by Long.
|
createSQLString | static String createSQLString(Object o, int type) throws HsqlException(Code) | | Return an SQL representation of an object. Strings will be quoted
with single quotes, other objects will represented as in a SQL
statement.
Parameters: o - Parameters: type - result throws: HsqlException - |
createSQLString | public static String createSQLString(double x)(Code) | | |
createSQLString | public static String createSQLString(String s)(Code) | | Turns a java string into a quoted SQL string
Parameters: s - java string quoted SQL string |
enforceSize | static Object enforceSize(Object obj, int type, int size, int scale, boolean check) throws HsqlException(Code) | | Check an object for type CHAR and VARCHAR and truncate/pad based on
the size
Parameters: obj - object to check Parameters: type - the object type Parameters: size - size to enforce Parameters: check - throw if too long the altered object if the right type, else the objectpassed in unaltered throws: HsqlException - if data too long |
getCombinedNumberType | static int getCombinedNumberType(int type1, int type2, int expType)(Code) | | Arithmetic expression terms are promoted to a type that can
represent the resulting values and avoid incorrect results.
When the result or the expression is converted to the
type of the target column for storage, an exception is thrown if the
resulting value cannot be stored in the column
Returns a SQL type "wide" enough to represent the result of the
expression.
A type is "wider" than the other if it can represent all its
numeric values.
Types narrower than INTEGER (int) are promoted to
INTEGER. The order is as follows
INTEGER, BIGINT, DOUBLE, DECIMAL
TINYINT and SMALLINT in any combination return INTEGER
INTEGER and INTEGER return BIGINT
BIGINT and INTEGER return NUMERIC/DECIMAL
BIGINT and BIGINT return NUMERIC/DECIMAL
DOUBLE and INTEGER return DOUBLE
DOUBLE and BIGINT return DOUBLE
NUMERIC/DECIMAL and any type returns NUMERIC/DECIMAL
author: fredt@users Parameters: type1 - java.sql.Types value for the first numeric type Parameters: type2 - java.sql.Types value for the second numeric type either type1 or type2 on the basis of the above order |
getDIType | int getDIType()(Code) | | |
getDITypeSub | int getDITypeSub()(Code) | | |
getDefaultDDL | String getDefaultDDL()(Code) | | Returns DDL for default value.
|
getDefaultExpression | Expression getDefaultExpression()(Code) | | Returns default expression for the column.
|
getNumTypeWidth | static int getNumTypeWidth(int type)(Code) | | Parameters: type - java.sql.Types int for a numeric type relative width |
getScale | int getScale()(Code) | | Scale of the column in DDL (0 if not defined).
DDL scale of column |
getSize | int getSize()(Code) | | Size of the column in DDL (0 if not defined).
DDL size of column |
getType | int getType()(Code) | | Type of the column.
java.sql.Types int value for the column |
hexToByteArray | public static byte[] hexToByteArray(String hexString) throws HsqlException(Code) | | Converts the specified hexadecimal digit String
to an equivalent array of bytes.
Parameters: hexString - a String of hexadecimal digits throws: HsqlException - if the specified string contains non-hexadecimal digits. a byte array equivalent to the specified string of hexadecimal digits |
isIdentity | boolean isIdentity()(Code) | | Is this the identity column in the table.
boolean |
isNullable | boolean isNullable()(Code) | | Is column nullable.
boolean |
isPrimaryKey | public boolean isPrimaryKey()(Code) | | Is this single column primary key of the table.
boolean |
setIdentity | void setIdentity(boolean identity, long startvalue, long increment) throws HsqlException(Code) | | |
setNullable | void setNullable(boolean value)(Code) | | Set nullable.
|
setPrimaryKey | void setPrimaryKey(boolean value)(Code) | | Set primary key.
|
|
|