Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
41d238b1
提交
41d238b1
authored
1月 17, 2019
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add TypeInfo and use it in Column
上级
734f8029
显示空白字符变更
内嵌
并排
正在显示
27 个修改的文件
包含
230 行增加
和
140 行删除
+230
-140
Parser.java
h2/src/main/org/h2/command/Parser.java
+13
-10
Analyze.java
h2/src/main/org/h2/command/ddl/Analyze.java
+1
-1
CreateTable.java
h2/src/main/org/h2/command/ddl/CreateTable.java
+1
-1
ExpressionColumn.java
h2/src/main/org/h2/expression/ExpressionColumn.java
+6
-6
Parameter.java
h2/src/main/org/h2/expression/Parameter.java
+4
-4
AggregateDataEnvelope.java
...in/org/h2/expression/aggregate/AggregateDataEnvelope.java
+1
-1
CompareLike.java
h2/src/main/org/h2/expression/condition/CompareLike.java
+1
-1
Comparison.java
h2/src/main/org/h2/expression/condition/Comparison.java
+1
-1
ConditionInConstantSet.java
...n/org/h2/expression/condition/ConditionInConstantSet.java
+1
-1
Function.java
h2/src/main/org/h2/expression/function/Function.java
+7
-5
TableFunction.java
h2/src/main/org/h2/expression/function/TableFunction.java
+2
-2
BaseIndex.java
h2/src/main/org/h2/index/BaseIndex.java
+1
-1
HashIndex.java
h2/src/main/org/h2/index/HashIndex.java
+1
-1
LinkedCursor.java
h2/src/main/org/h2/index/LinkedCursor.java
+1
-1
LinkedIndex.java
h2/src/main/org/h2/index/LinkedIndex.java
+4
-2
NonUniqueHashIndex.java
h2/src/main/org/h2/index/NonUniqueHashIndex.java
+1
-1
SpatialTreeIndex.java
h2/src/main/org/h2/index/SpatialTreeIndex.java
+1
-1
MVSecondaryIndex.java
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
+3
-1
MVSpatialIndex.java
h2/src/main/org/h2/mvstore/db/MVSpatialIndex.java
+1
-1
MVTable.java
h2/src/main/org/h2/mvstore/db/MVTable.java
+1
-1
Column.java
h2/src/main/org/h2/table/Column.java
+33
-90
MetaTable.java
h2/src/main/org/h2/table/MetaTable.java
+2
-2
RegularTable.java
h2/src/main/org/h2/table/RegularTable.java
+1
-1
Table.java
h2/src/main/org/h2/table/Table.java
+1
-1
TableBase.java
h2/src/main/org/h2/table/TableBase.java
+1
-1
TableView.java
h2/src/main/org/h2/table/TableView.java
+2
-2
TypeInfo.java
h2/src/main/org/h2/value/TypeInfo.java
+138
-0
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
41d238b1
...
...
@@ -226,6 +226,7 @@ import org.h2.value.DataType;
import
org.h2.value.ExtTypeInfo
;
import
org.h2.value.ExtTypeInfoEnum
;
import
org.h2.value.ExtTypeInfoGeometry
;
import
org.h2.value.TypeInfo
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
import
org.h2.value.ValueBoolean
;
...
...
@@ -5355,13 +5356,14 @@ public class Parser {
Domain
domain
=
database
.
findDomain
(
original
);
if
(
domain
!=
null
)
{
templateColumn
=
domain
.
getColumn
();
dataType
=
DataType
.
getDataType
(
templateColumn
.
getType
());
TypeInfo
type
=
templateColumn
.
getType
();
dataType
=
DataType
.
getDataType
(
type
.
getValueType
());
comment
=
templateColumn
.
getComment
();
original
=
forTable
?
domain
.
getSQL
()
:
templateColumn
.
getOriginalSQL
();
precision
=
t
emplateColumn
.
getPrecision
();
displaySize
=
t
emplateColumn
.
getDisplaySize
();
scale
=
t
emplateColumn
.
getScale
();
extTypeInfo
=
t
emplateColumn
.
getExtTypeInfo
();
precision
=
t
ype
.
getPrecision
();
displaySize
=
t
ype
.
getDisplaySize
();
scale
=
t
ype
.
getScale
();
extTypeInfo
=
t
ype
.
getExtTypeInfo
();
}
else
{
Mode
mode
=
database
.
getMode
();
dataType
=
DataType
.
getTypeByName
(
original
,
mode
);
...
...
@@ -5863,10 +5865,11 @@ public class Parser {
.
get
(
ErrorCode
.
COLUMN_COUNT_DOES_NOT_MATCH
);
}
Column
c
=
columns
.
get
(
i
);
type
=
Value
.
getHigherOrder
(
c
.
getType
(),
type
);
prec
=
Math
.
max
(
c
.
getPrecision
(),
prec
);
scale
=
Math
.
max
(
c
.
getScale
(),
scale
);
displaySize
=
Math
.
max
(
c
.
getDisplaySize
(),
displaySize
);
TypeInfo
t
=
c
.
getType
();
type
=
Value
.
getHigherOrder
(
t
.
getValueType
(),
type
);
prec
=
Math
.
max
(
t
.
getPrecision
(),
prec
);
scale
=
Math
.
max
(
t
.
getScale
(),
scale
);
displaySize
=
Math
.
max
(
t
.
getDisplaySize
(),
displaySize
);
column
=
new
Column
(
columnName
,
type
,
prec
,
scale
,
displaySize
);
columns
.
set
(
i
,
column
);
row
.
add
(
expr
);
...
...
@@ -5883,7 +5886,7 @@ public class Parser {
}
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
Column
c
=
columns
.
get
(
i
);
if
(
c
.
getType
()
==
Value
.
UNKNOWN
)
{
if
(
c
.
getType
()
.
getValueType
()
==
Value
.
UNKNOWN
)
{
c
=
new
Column
(
c
.
getName
(),
Value
.
STRING
,
0
,
0
,
0
);
columns
.
set
(
i
,
c
);
}
...
...
h2/src/main/org/h2/command/ddl/Analyze.java
浏览文件 @
41d238b1
...
...
@@ -105,7 +105,7 @@ public class Analyze extends DefineCommand {
StatementBuilder
buff
=
new
StatementBuilder
(
"SELECT "
);
for
(
Column
col
:
columns
)
{
buff
.
appendExceptFirst
(
", "
);
if
(
DataType
.
isLargeObject
(
col
.
getType
()))
{
if
(
DataType
.
isLargeObject
(
col
.
getType
()
.
getValueType
()
))
{
// can not index LOB columns, so calculating
// the selectivity is not required
buff
.
append
(
"MAX(NULL)"
);
...
...
h2/src/main/org/h2/command/ddl/CreateTable.java
浏览文件 @
41d238b1
...
...
@@ -202,7 +202,7 @@ public class CreateTable extends CommandWithColumns {
int
t
=
dt
.
type
;
if
(
DataType
.
isExtInfoType
(
t
))
{
if
(
expr
instanceof
ExpressionColumn
)
{
extTypeInfo
=
((
ExpressionColumn
)
expr
).
getColumn
().
getExtTypeInfo
();
extTypeInfo
=
((
ExpressionColumn
)
expr
).
getColumn
().
get
Type
().
get
ExtTypeInfo
();
}
else
if
(
t
==
Value
.
ENUM
)
{
/*
* Only columns of tables may be enumerated.
...
...
h2/src/main/org/h2/expression/ExpressionColumn.java
浏览文件 @
41d238b1
...
...
@@ -216,7 +216,7 @@ public class ExpressionColumn extends Expression {
}
}
if
(
value
!=
ValueNull
.
INSTANCE
)
{
ExtTypeInfo
extTypeInfo
=
column
.
getExtTypeInfo
();
ExtTypeInfo
extTypeInfo
=
column
.
get
Type
().
get
ExtTypeInfo
();
if
(
extTypeInfo
!=
null
)
{
return
extTypeInfo
.
cast
(
value
);
}
...
...
@@ -226,7 +226,7 @@ public class ExpressionColumn extends Expression {
@Override
public
int
getType
()
{
return
column
==
null
?
Value
.
UNKNOWN
:
column
.
getType
();
return
column
==
null
?
Value
.
UNKNOWN
:
column
.
getType
()
.
getValueType
()
;
}
@Override
...
...
@@ -239,17 +239,17 @@ public class ExpressionColumn extends Expression {
@Override
public
int
getScale
()
{
return
column
.
getScale
();
return
column
.
get
Type
().
get
Scale
();
}
@Override
public
long
getPrecision
()
{
return
column
.
getPrecision
();
return
column
.
get
Type
().
get
Precision
();
}
@Override
public
int
getDisplaySize
()
{
return
column
.
getDisplaySize
();
return
column
.
get
Type
().
get
DisplaySize
();
}
public
String
getOriginalColumnName
()
{
...
...
@@ -360,7 +360,7 @@ public class ExpressionColumn extends Expression {
@Override
public
void
createIndexConditions
(
Session
session
,
TableFilter
filter
)
{
TableFilter
tf
=
getTableFilter
();
if
(
filter
==
tf
&&
column
.
getType
()
==
Value
.
BOOLEAN
)
{
if
(
filter
==
tf
&&
column
.
getType
()
.
getValueType
()
==
Value
.
BOOLEAN
)
{
IndexCondition
cond
=
IndexCondition
.
get
(
Comparison
.
EQUAL
,
this
,
ValueExpression
.
get
(
ValueBoolean
.
TRUE
));
...
...
h2/src/main/org/h2/expression/Parameter.java
浏览文件 @
41d238b1
...
...
@@ -66,7 +66,7 @@ public class Parameter extends Expression implements ParameterInterface {
return
value
.
getType
();
}
if
(
column
!=
null
)
{
return
column
.
getType
();
return
column
.
getType
()
.
getValueType
()
;
}
return
Value
.
UNKNOWN
;
}
...
...
@@ -114,7 +114,7 @@ public class Parameter extends Expression implements ParameterInterface {
return
value
.
getScale
();
}
if
(
column
!=
null
)
{
return
column
.
getScale
();
return
column
.
get
Type
().
get
Scale
();
}
return
0
;
}
...
...
@@ -125,7 +125,7 @@ public class Parameter extends Expression implements ParameterInterface {
return
value
.
getPrecision
();
}
if
(
column
!=
null
)
{
return
column
.
getPrecision
();
return
column
.
get
Type
().
get
Precision
();
}
return
0
;
}
...
...
@@ -136,7 +136,7 @@ public class Parameter extends Expression implements ParameterInterface {
return
value
.
getDisplaySize
();
}
if
(
column
!=
null
)
{
return
column
.
getDisplaySize
();
return
column
.
get
Type
().
get
DisplaySize
();
}
return
0
;
}
...
...
h2/src/main/org/h2/expression/aggregate/AggregateDataEnvelope.java
浏览文件 @
41d238b1
...
...
@@ -38,7 +38,7 @@ class AggregateDataEnvelope extends AggregateData {
if
(
on
instanceof
ExpressionColumn
)
{
ExpressionColumn
col
=
(
ExpressionColumn
)
on
;
Column
column
=
col
.
getColumn
();
if
(
column
.
getType
()
==
Value
.
GEOMETRY
)
{
if
(
column
.
getType
()
.
getValueType
()
==
Value
.
GEOMETRY
)
{
TableFilter
filter
=
col
.
getTableFilter
();
if
(
filter
!=
null
)
{
ArrayList
<
Index
>
indexes
=
filter
.
getTable
().
getIndexes
();
...
...
h2/src/main/org/h2/expression/condition/CompareLike.java
浏览文件 @
41d238b1
...
...
@@ -206,7 +206,7 @@ public class CompareLike extends Condition {
// can't use an index
return
;
}
if
(!
DataType
.
isStringType
(
l
.
getColumn
().
getType
()))
{
if
(!
DataType
.
isStringType
(
l
.
getColumn
().
getType
()
.
getValueType
()
))
{
// column is not a varchar - can't use the index
return
;
}
...
...
h2/src/main/org/h2/expression/condition/Comparison.java
浏览文件 @
41d238b1
...
...
@@ -235,7 +235,7 @@ public class Comparison extends Condition {
Column
column
=
((
ExpressionColumn
)
left
).
getColumn
();
right
=
ValueExpression
.
get
(
r
.
convertTo
(
resType
,
MathUtils
.
convertLongToInt
(
left
.
getPrecision
()),
session
.
getDatabase
().
getMode
(),
column
,
column
.
getExtTypeInfo
()));
session
.
getDatabase
().
getMode
(),
column
,
column
.
get
Type
().
get
ExtTypeInfo
()));
}
}
else
if
(
right
instanceof
Parameter
)
{
((
Parameter
)
right
).
setColumn
(
...
...
h2/src/main/org/h2/expression/condition/ConditionInConstantSet.java
浏览文件 @
41d238b1
...
...
@@ -57,7 +57,7 @@ public class ConditionInConstantSet extends Condition {
type
=
left
.
getType
();
Mode
mode
=
database
.
getMode
();
if
(
type
==
Value
.
ENUM
)
{
extTypeInfo
=
((
ExpressionColumn
)
left
).
getColumn
().
getExtTypeInfo
();
extTypeInfo
=
((
ExpressionColumn
)
left
).
getColumn
().
get
Type
().
get
ExtTypeInfo
();
for
(
Expression
expression
:
valueList
)
{
add
(
extTypeInfo
.
cast
(
expression
.
getValue
(
session
)));
}
...
...
h2/src/main/org/h2/expression/function/Function.java
浏览文件 @
41d238b1
...
...
@@ -62,6 +62,7 @@ import org.h2.util.StringUtils;
import
org.h2.util.Utils
;
import
org.h2.value.DataType
;
import
org.h2.value.ExtTypeInfo
;
import
org.h2.value.TypeInfo
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
import
org.h2.value.ValueBoolean
;
...
...
@@ -2293,11 +2294,12 @@ public class Function extends Expression implements FunctionCall {
}
public
void
setDataType
(
Column
col
)
{
dataType
=
col
.
getType
();
precision
=
col
.
getPrecision
();
displaySize
=
col
.
getDisplaySize
();
scale
=
col
.
getScale
();
extTypeInfo
=
col
.
getExtTypeInfo
();
TypeInfo
type
=
col
.
getType
();
dataType
=
type
.
getValueType
();
precision
=
type
.
getPrecision
();
displaySize
=
type
.
getDisplaySize
();
scale
=
type
.
getScale
();
extTypeInfo
=
type
.
getExtTypeInfo
();
}
@Override
...
...
h2/src/main/org/h2/expression/function/TableFunction.java
浏览文件 @
41d238b1
...
...
@@ -125,8 +125,8 @@ public class TableFunction extends Function {
Column
c
=
columns
[
j
];
v
=
l
[
row
];
if
(!
unnest
)
{
v
=
c
.
convert
(
v
).
convertPrecision
(
c
.
getPrecision
(),
false
)
.
convertScale
(
true
,
c
.
getScale
());
v
=
c
.
convert
(
v
).
convertPrecision
(
c
.
get
Type
().
get
Precision
(),
false
)
.
convertScale
(
true
,
c
.
get
Type
().
get
Scale
());
}
}
r
[
j
]
=
v
;
...
...
h2/src/main/org/h2/index/BaseIndex.java
浏览文件 @
41d238b1
...
...
@@ -73,7 +73,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
*/
protected
static
void
checkIndexColumnTypes
(
IndexColumn
[]
columns
)
{
for
(
IndexColumn
c
:
columns
)
{
if
(
DataType
.
isLargeObject
(
c
.
column
.
getType
()))
{
if
(
DataType
.
isLargeObject
(
c
.
column
.
getType
()
.
getValueType
()
))
{
throw
DbException
.
getUnsupportedException
(
"Index on BLOB or CLOB column: "
+
c
.
column
.
getCreateSQL
());
}
...
...
h2/src/main/org/h2/index/HashIndex.java
浏览文件 @
41d238b1
...
...
@@ -77,7 +77,7 @@ public class HashIndex extends BaseIndex {
* case we need to convert, otherwise the ValueHashMap will not find the
* result.
*/
v
=
v
.
convertTo
(
tableData
.
getColumn
(
indexColumn
).
getType
(),
database
.
getMode
());
v
=
v
.
convertTo
(
tableData
.
getColumn
(
indexColumn
).
getType
()
.
getValueType
()
,
database
.
getMode
());
Row
result
;
Long
pos
=
rows
.
get
(
v
);
if
(
pos
==
null
)
{
...
...
h2/src/main/org/h2/index/LinkedCursor.java
浏览文件 @
41d238b1
...
...
@@ -64,7 +64,7 @@ public class LinkedCursor implements Cursor {
current
=
tableLink
.
getTemplateRow
();
for
(
int
i
=
0
;
i
<
current
.
getColumnCount
();
i
++)
{
Column
col
=
tableLink
.
getColumn
(
i
);
Value
v
=
DataType
.
readValue
(
session
,
rs
,
i
+
1
,
col
.
getType
());
Value
v
=
DataType
.
readValue
(
session
,
rs
,
i
+
1
,
col
.
getType
()
.
getValueType
()
);
current
.
setValue
(
i
,
v
);
}
return
true
;
...
...
h2/src/main/org/h2/index/LinkedIndex.java
浏览文件 @
41d238b1
...
...
@@ -22,6 +22,7 @@ import org.h2.table.TableFilter;
import
org.h2.table.TableLink
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.Utils
;
import
org.h2.value.TypeInfo
;
import
org.h2.value.Value
;
import
org.h2.value.ValueNull
;
...
...
@@ -131,12 +132,13 @@ public class LinkedIndex extends BaseIndex {
}
private
void
addParameter
(
StatementBuilder
buff
,
Column
col
)
{
if
(
col
.
getType
()
==
Value
.
STRING_FIXED
&&
link
.
isOracle
())
{
TypeInfo
type
=
col
.
getType
();
if
(
type
.
getValueType
()
==
Value
.
STRING_FIXED
&&
link
.
isOracle
())
{
// workaround for Oracle
// create table test(id int primary key, name char(15));
// insert into test values(1, 'Hello')
// select * from test where name = ? -- where ? = "Hello" > no rows
buff
.
append
(
"CAST(? AS CHAR("
).
append
(
col
.
getPrecision
()).
append
(
"))"
);
buff
.
append
(
"CAST(? AS CHAR("
).
append
(
type
.
getPrecision
()).
append
(
"))"
);
}
else
{
buff
.
append
(
'?'
);
}
...
...
h2/src/main/org/h2/index/NonUniqueHashIndex.java
浏览文件 @
41d238b1
...
...
@@ -101,7 +101,7 @@ public class NonUniqueHashIndex extends BaseIndex {
* case we need to convert, otherwise the ValueHashMap will not find the
* result.
*/
v
=
v
.
convertTo
(
tableData
.
getColumn
(
indexColumn
).
getType
(),
database
.
getMode
());
v
=
v
.
convertTo
(
tableData
.
getColumn
(
indexColumn
).
getType
()
.
getValueType
()
,
database
.
getMode
());
ArrayList
<
Long
>
positions
=
rows
.
get
(
v
);
return
new
NonUniqueHashCursor
(
session
,
tableData
,
positions
);
}
...
...
h2/src/main/org/h2/index/SpatialTreeIndex.java
浏览文件 @
41d238b1
...
...
@@ -87,7 +87,7 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
}
this
.
needRebuild
=
create
;
if
(!
database
.
isStarting
())
{
if
(
columns
[
0
].
column
.
getType
()
!=
Value
.
GEOMETRY
)
{
if
(
columns
[
0
].
column
.
getType
()
.
getValueType
()
!=
Value
.
GEOMETRY
)
{
throw
DbException
.
getUnsupportedException
(
"spatial index on non-geometry column, "
+
columns
[
0
].
column
.
getCreateSQL
());
...
...
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
浏览文件 @
41d238b1
...
...
@@ -30,6 +30,7 @@ import org.h2.table.Column;
import
org.h2.table.IndexColumn
;
import
org.h2.table.TableFilter
;
import
org.h2.value.CompareMode
;
import
org.h2.value.TypeInfo
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
import
org.h2.value.ValueLong
;
...
...
@@ -288,7 +289,8 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
int
idx
=
c
.
getColumnId
();
Value
v
=
r
.
getValue
(
idx
);
if
(
v
!=
null
)
{
array
[
i
]
=
v
.
convertTo
(
c
.
getType
(),
-
1
,
database
.
getMode
(),
null
,
c
.
getExtTypeInfo
());
TypeInfo
type
=
c
.
getType
();
array
[
i
]
=
v
.
convertTo
(
type
.
getValueType
(),
-
1
,
database
.
getMode
(),
null
,
type
.
getExtTypeInfo
());
}
}
array
[
keyColumns
-
1
]
=
key
!=
null
?
key
:
ValueLong
.
get
(
r
.
getKey
());
...
...
h2/src/main/org/h2/mvstore/db/MVSpatialIndex.java
浏览文件 @
41d238b1
...
...
@@ -88,7 +88,7 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
throw
DbException
.
getUnsupportedException
(
"Nulls last is not supported"
);
}
if
(
col
.
column
.
getType
()
!=
Value
.
GEOMETRY
)
{
if
(
col
.
column
.
getType
()
.
getValueType
()
!=
Value
.
GEOMETRY
)
{
throw
DbException
.
getUnsupportedException
(
"Spatial index on non-geometry column, "
+
col
.
column
.
getCreateSQL
());
...
...
h2/src/main/org/h2/mvstore/db/MVTable.java
浏览文件 @
41d238b1
...
...
@@ -136,7 +136,7 @@ public class MVTable extends TableBase {
this
.
isHidden
=
data
.
isHidden
;
boolean
b
=
false
;
for
(
Column
col
:
getColumns
())
{
if
(
DataType
.
isLargeObject
(
col
.
getType
()))
{
if
(
DataType
.
isLargeObject
(
col
.
getType
()
.
getValueType
()
))
{
b
=
true
;
break
;
}
...
...
h2/src/main/org/h2/table/Column.java
浏览文件 @
41d238b1
...
...
@@ -28,6 +28,7 @@ import org.h2.util.MathUtils;
import
org.h2.util.StringUtils
;
import
org.h2.value.DataType
;
import
org.h2.value.ExtTypeInfo
;
import
org.h2.value.TypeInfo
;
import
org.h2.value.Value
;
import
org.h2.value.ValueInt
;
import
org.h2.value.ValueLong
;
...
...
@@ -64,11 +65,7 @@ public class Column {
public
static
final
int
NULLABLE_UNKNOWN
=
ResultSetMetaData
.
columnNullableUnknown
;
private
final
int
type
;
private
long
precision
;
private
int
scale
;
private
ExtTypeInfo
extTypeInfo
;
private
int
displaySize
;
private
final
TypeInfo
type
;
private
Table
table
;
private
String
name
;
private
int
columnId
;
...
...
@@ -90,28 +87,28 @@ public class Column {
private
boolean
visible
=
true
;
private
Domain
domain
;
public
Column
(
String
name
,
int
t
ype
)
{
this
(
name
,
t
ype
,
-
1
,
-
1
,
-
1
,
null
);
public
Column
(
String
name
,
int
valueT
ype
)
{
this
(
name
,
valueT
ype
,
-
1
,
-
1
,
-
1
,
null
);
}
public
Column
(
String
name
,
int
type
,
long
precision
,
int
scale
,
int
displaySize
)
{
this
(
name
,
type
,
precision
,
scale
,
displaySize
,
null
);
public
Column
(
String
name
,
int
valueType
,
long
precision
,
int
scale
,
int
displaySize
)
{
this
(
name
,
valueType
,
precision
,
scale
,
displaySize
,
null
);
}
public
Column
(
String
name
,
int
t
ype
,
long
precision
,
int
scale
,
int
displaySize
,
ExtTypeInfo
extTypeInfo
)
{
public
Column
(
String
name
,
int
valueT
ype
,
long
precision
,
int
scale
,
int
displaySize
,
ExtTypeInfo
extTypeInfo
)
{
this
.
name
=
name
;
this
.
type
=
type
;
if
(
precision
==
-
1
&&
scale
==
-
1
&&
displaySize
==
-
1
&&
type
!=
Value
.
UNKNOWN
)
{
DataType
dt
=
DataType
.
getDataType
(
type
);
if
(
precision
==
-
1
&&
scale
==
-
1
&&
displaySize
==
-
1
&&
valueType
!=
Value
.
UNKNOWN
)
{
DataType
dt
=
DataType
.
getDataType
(
valueType
);
precision
=
dt
.
defaultPrecision
;
scale
=
dt
.
defaultScale
;
displaySize
=
dt
.
defaultDisplaySize
;
}
this
.
precision
=
precision
;
this
.
scale
=
scale
;
this
.
displaySize
=
displaySize
;
this
.
extTypeInfo
=
extTypeInfo
;
this
.
type
=
new
TypeInfo
(
valueType
,
precision
,
scale
,
displaySize
,
extTypeInfo
);
}
public
Column
(
String
name
,
TypeInfo
type
)
{
this
.
name
=
name
;
this
.
type
=
type
;
}
@Override
...
...
@@ -141,7 +138,7 @@ public class Column {
}
public
Column
getClone
()
{
Column
newColumn
=
new
Column
(
name
,
type
,
precision
,
scale
,
displaySize
,
extTypeInfo
);
Column
newColumn
=
new
Column
(
name
,
type
);
newColumn
.
copy
(
this
);
return
newColumn
;
}
...
...
@@ -167,7 +164,8 @@ public class Column {
*/
public
Value
convert
(
Value
v
,
Mode
mode
)
{
try
{
return
v
.
convertTo
(
type
,
MathUtils
.
convertLongToInt
(
precision
),
mode
,
this
,
extTypeInfo
);
return
v
.
convertTo
(
type
.
getValueType
(),
MathUtils
.
convertLongToInt
(
type
.
getPrecision
()),
mode
,
this
,
type
.
getExtTypeInfo
());
}
catch
(
DbException
e
)
{
if
(
e
.
getErrorCode
()
==
ErrorCode
.
DATA_CONVERSION_ERROR_1
)
{
String
target
=
(
table
==
null
?
""
:
table
.
getName
()
+
": "
)
+
...
...
@@ -271,30 +269,14 @@ public class Column {
return
name
;
}
public
int
getType
()
{
public
TypeInfo
getType
()
{
return
type
;
}
public
long
getPrecision
()
{
return
precision
;
}
public
int
getDisplaySize
()
{
return
displaySize
;
}
public
int
getScale
()
{
return
scale
;
}
public
void
setNullable
(
boolean
b
)
{
nullable
=
b
;
}
public
ExtTypeInfo
getExtTypeInfo
()
{
return
extTypeInfo
;
}
public
boolean
getVisible
()
{
return
visible
;
}
...
...
@@ -350,9 +332,10 @@ public class Column {
}
if
(
value
==
ValueNull
.
INSTANCE
&&
!
nullable
)
{
if
(
mode
.
convertInsertNullToZero
)
{
DataType
dt
=
DataType
.
getDataType
(
type
);
int
t
=
type
.
getValueType
();
DataType
dt
=
DataType
.
getDataType
(
t
);
if
(
dt
.
decimal
)
{
value
=
ValueInt
.
get
(
0
).
convertTo
(
t
ype
);
value
=
ValueInt
.
get
(
0
).
convertTo
(
t
);
}
else
if
(
dt
.
type
==
Value
.
TIMESTAMP
)
{
value
=
session
.
getCurrentCommandStart
().
convertTo
(
Value
.
TIMESTAMP
);
}
else
if
(
dt
.
type
==
Value
.
TIMESTAMP_TZ
)
{
...
...
@@ -362,7 +345,7 @@ public class Column {
}
else
if
(
dt
.
type
==
Value
.
DATE
)
{
value
=
session
.
getCurrentCommandStart
().
convertTo
(
Value
.
DATE
);
}
else
{
value
=
ValueString
.
get
(
""
).
convertTo
(
t
ype
);
value
=
ValueString
.
get
(
""
).
convertTo
(
t
);
}
}
else
{
throw
DbException
.
get
(
ErrorCode
.
NULL_NOT_ALLOWED
,
name
);
...
...
@@ -382,7 +365,8 @@ public class Column {
checkConstraint
.
getSQL
());
}
}
value
=
value
.
convertScale
(
mode
.
convertOnlyToSmallerScale
,
scale
);
value
=
value
.
convertScale
(
mode
.
convertOnlyToSmallerScale
,
type
.
getScale
());
long
precision
=
type
.
getPrecision
();
if
(
precision
>
0
)
{
if
(!
value
.
checkPrecision
(
precision
))
{
String
s
=
value
.
getTraceSQL
();
...
...
@@ -393,8 +377,8 @@ public class Column {
getCreateSQL
(),
s
+
" ("
+
value
.
getPrecision
()
+
")"
);
}
}
if
(
value
!=
ValueNull
.
INSTANCE
&&
DataType
.
isExtInfoType
(
type
)
&&
extTypeInfo
!=
null
)
{
value
=
extTypeInfo
.
cast
(
value
);
if
(
value
!=
ValueNull
.
INSTANCE
&&
DataType
.
isExtInfoType
(
type
.
getValueType
())
&&
type
.
getExtTypeInfo
()
!=
null
)
{
value
=
type
.
getExtTypeInfo
()
.
cast
(
value
);
}
updateSequenceIfRequired
(
session
,
value
);
return
value
;
...
...
@@ -493,44 +477,7 @@ public class Column {
if
(
originalSQL
!=
null
)
{
buff
.
append
(
originalSQL
);
}
else
{
DataType
dataType
=
DataType
.
getDataType
(
type
);
if
(
type
==
Value
.
TIMESTAMP_TZ
)
{
buff
.
append
(
"TIMESTAMP"
);
}
else
{
buff
.
append
(
dataType
.
name
);
}
switch
(
type
)
{
case
Value
.
DECIMAL
:
buff
.
append
(
'('
).
append
(
precision
).
append
(
", "
).
append
(
scale
).
append
(
')'
);
break
;
case
Value
.
GEOMETRY
:
if
(
extTypeInfo
==
null
)
{
break
;
}
//$FALL-THROUGH$
case
Value
.
ENUM
:
buff
.
append
(
extTypeInfo
.
getCreateSQL
());
break
;
case
Value
.
BYTES
:
case
Value
.
STRING
:
case
Value
.
STRING_IGNORECASE
:
case
Value
.
STRING_FIXED
:
if
(
precision
<
Integer
.
MAX_VALUE
)
{
buff
.
append
(
'('
).
append
(
precision
).
append
(
')'
);
}
break
;
case
Value
.
TIME
:
case
Value
.
TIMESTAMP
:
case
Value
.
TIMESTAMP_TZ
:
if
(
scale
!=
dataType
.
defaultScale
)
{
buff
.
append
(
'('
).
append
(
scale
).
append
(
')'
);
}
if
(
type
==
Value
.
TIMESTAMP_TZ
)
{
buff
.
append
(
" WITH TIME ZONE"
);
}
break
;
default
:
}
type
.
getSQL
(
buff
);
}
if
(!
visible
)
{
...
...
@@ -729,11 +676,11 @@ public class Column {
}
int
getPrecisionAsInt
()
{
return
MathUtils
.
convertLongToInt
(
precision
);
return
MathUtils
.
convertLongToInt
(
type
.
getPrecision
()
);
}
DataType
getDataType
()
{
return
DataType
.
getDataType
(
type
);
return
DataType
.
getDataType
(
type
.
getValueType
()
);
}
/**
...
...
@@ -803,10 +750,10 @@ public class Column {
if
(
type
!=
newColumn
.
type
)
{
return
false
;
}
if
(
precision
>
newColumn
.
precision
)
{
if
(
type
.
getPrecision
()
>
newColumn
.
type
.
getPrecision
()
)
{
return
false
;
}
if
(
scale
!=
newColumn
.
scale
)
{
if
(
type
.
getScale
()
!=
newColumn
.
type
.
getScale
()
)
{
return
false
;
}
if
(
nullable
&&
!
newColumn
.
nullable
)
{
...
...
@@ -836,7 +783,7 @@ public class Column {
if
(
onUpdateExpression
!=
null
||
newColumn
.
onUpdateExpression
!=
null
)
{
return
false
;
}
if
(!
Objects
.
equals
(
extTypeInfo
,
newColumn
.
extTypeInfo
))
{
if
(!
Objects
.
equals
(
type
.
getExtTypeInfo
(),
newColumn
.
type
.
getExtTypeInfo
()
))
{
return
false
;
}
return
true
;
...
...
@@ -850,11 +797,7 @@ public class Column {
public
void
copy
(
Column
source
)
{
checkConstraint
=
source
.
checkConstraint
;
checkConstraintSQL
=
source
.
checkConstraintSQL
;
displaySize
=
source
.
displaySize
;
name
=
source
.
name
;
precision
=
source
.
precision
;
extTypeInfo
=
source
.
extTypeInfo
;
scale
=
source
.
scale
;
// table is not set
// columnId is not set
nullable
=
source
.
nullable
;
...
...
h2/src/main/org/h2/table/MetaTable.java
浏览文件 @
41d238b1
...
...
@@ -849,7 +849,7 @@ public class MetaTable extends Table {
Domain
domain
=
c
.
getDomain
();
DataType
dataType
=
c
.
getDataType
();
ValueInt
precision
=
ValueInt
.
get
(
c
.
getPrecisionAsInt
());
ValueInt
scale
=
ValueInt
.
get
(
c
.
getScale
());
ValueInt
scale
=
ValueInt
.
get
(
c
.
get
Type
().
get
Scale
());
Sequence
sequence
=
c
.
getSequence
();
boolean
hasDateTimePrecision
;
int
type
=
dataType
.
type
;
...
...
@@ -1792,7 +1792,7 @@ public class MetaTable extends Table {
// PRECISION
ValueInt
.
get
(
col
.
getPrecisionAsInt
()),
// SCALE
ValueInt
.
get
(
col
.
getScale
()),
ValueInt
.
get
(
col
.
get
Type
().
get
Scale
()),
// TYPE_NAME
col
.
getDataType
().
name
,
// SELECTIVITY INT
...
...
h2/src/main/org/h2/table/RegularTable.java
浏览文件 @
41d238b1
...
...
@@ -78,7 +78,7 @@ public class RegularTable extends TableBase {
this
.
isHidden
=
data
.
isHidden
;
boolean
b
=
false
;
for
(
Column
col
:
getColumns
())
{
if
(
DataType
.
isLargeObject
(
col
.
getType
()))
{
if
(
DataType
.
isLargeObject
(
col
.
getType
()
.
getValueType
()
))
{
b
=
true
;
break
;
}
...
...
h2/src/main/org/h2/table/Table.java
浏览文件 @
41d238b1
...
...
@@ -454,7 +454,7 @@ public abstract class Table extends SchemaObjectBase {
}
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
Column
col
=
columns
[
i
];
int
dataType
=
col
.
getType
();
int
dataType
=
col
.
getType
()
.
getValueType
()
;
if
(
dataType
==
Value
.
UNKNOWN
)
{
throw
DbException
.
get
(
ErrorCode
.
UNKNOWN_DATA_TYPE_1
,
col
.
getSQL
());
...
...
h2/src/main/org/h2/table/TableBase.java
浏览文件 @
41d238b1
...
...
@@ -51,7 +51,7 @@ public abstract class TableBase extends Table {
if
(
first
.
sortType
!=
SortOrder
.
ASCENDING
)
{
return
SearchRow
.
ROWID_INDEX
;
}
switch
(
first
.
column
.
getType
())
{
switch
(
first
.
column
.
getType
()
.
getValueType
()
)
{
case
Value
.
BYTE
:
case
Value
.
SHORT
:
case
Value
.
INT
:
...
...
h2/src/main/org/h2/table/TableView.java
浏览文件 @
41d238b1
...
...
@@ -184,7 +184,7 @@ public class TableView extends Table {
int
type
=
Value
.
UNKNOWN
;
if
(
columnTemplates
!=
null
&&
columnTemplates
.
length
>
i
)
{
name
=
columnTemplates
[
i
].
getName
();
type
=
columnTemplates
[
i
].
getType
();
type
=
columnTemplates
[
i
].
getType
()
.
getValueType
()
;
}
if
(
name
==
null
)
{
name
=
expr
.
getAlias
();
...
...
@@ -199,7 +199,7 @@ public class TableView extends Table {
ExtTypeInfo
extTypeInfo
=
null
;
if
(
DataType
.
isExtInfoType
(
type
))
{
if
(
expr
instanceof
ExpressionColumn
)
{
extTypeInfo
=
((
ExpressionColumn
)
expr
).
getColumn
().
getExtTypeInfo
();
extTypeInfo
=
((
ExpressionColumn
)
expr
).
getColumn
().
get
Type
().
get
ExtTypeInfo
();
}
}
Column
col
=
new
Column
(
name
,
type
,
precision
,
scale
,
displaySize
,
extTypeInfo
);
...
...
h2/src/main/org/h2/value/TypeInfo.java
0 → 100644
浏览文件 @
41d238b1
/*
* Copyright 2004-2019 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
value
;
/**
* Data type with parameters.
*/
public
class
TypeInfo
{
private
final
int
valueType
;
private
final
long
precision
;
private
final
int
scale
;
private
final
int
displaySize
;
private
final
ExtTypeInfo
extTypeInfo
;
/**
* Creates new instance of data type with parameters.
*
* @param valueType
* the value type
* @param precision
* the precision
* @param scale
* the scale
* @param displaySize
* the display size in characters
* @param extTypeInfo
* the extended type information, or null
*/
public
TypeInfo
(
int
valueType
,
long
precision
,
int
scale
,
int
displaySize
,
ExtTypeInfo
extTypeInfo
)
{
this
.
valueType
=
valueType
;
this
.
precision
=
precision
;
this
.
scale
=
scale
;
this
.
displaySize
=
displaySize
;
this
.
extTypeInfo
=
extTypeInfo
;
}
/**
* Returns the value type.
*
* @return the value type
*/
public
int
getValueType
()
{
return
valueType
;
}
/**
* Returns the precision.
*
* @return the precision
*/
public
long
getPrecision
()
{
return
precision
;
}
/**
* Returns the scale.
*
* @return the scale
*/
public
int
getScale
()
{
return
scale
;
}
/**
* Returns the display size in characters.
*
* @return the display size
*/
public
int
getDisplaySize
()
{
return
displaySize
;
}
/**
* Returns the extended type information, or null.
*
* @return the extended type information, or null
*/
public
ExtTypeInfo
getExtTypeInfo
()
{
return
extTypeInfo
;
}
/**
* Appends SQL representation of this object to the specified string
* builder.
*
* @param builder
* string builder
* @return the specified string builder
*/
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
DataType
dataType
=
DataType
.
getDataType
(
valueType
);
if
(
valueType
==
Value
.
TIMESTAMP_TZ
)
{
builder
.
append
(
"TIMESTAMP"
);
}
else
{
builder
.
append
(
dataType
.
name
);
}
switch
(
valueType
)
{
case
Value
.
DECIMAL
:
builder
.
append
(
'('
).
append
(
precision
).
append
(
", "
).
append
(
scale
).
append
(
')'
);
break
;
case
Value
.
GEOMETRY
:
if
(
extTypeInfo
==
null
)
{
break
;
}
//$FALL-THROUGH$
case
Value
.
ENUM
:
builder
.
append
(
extTypeInfo
.
getCreateSQL
());
break
;
case
Value
.
BYTES
:
case
Value
.
STRING
:
case
Value
.
STRING_IGNORECASE
:
case
Value
.
STRING_FIXED
:
if
(
precision
<
Integer
.
MAX_VALUE
)
{
builder
.
append
(
'('
).
append
(
precision
).
append
(
')'
);
}
break
;
case
Value
.
TIME
:
case
Value
.
TIMESTAMP
:
case
Value
.
TIMESTAMP_TZ
:
if
(
scale
!=
dataType
.
defaultScale
)
{
builder
.
append
(
'('
).
append
(
scale
).
append
(
')'
);
}
if
(
valueType
==
Value
.
TIMESTAMP_TZ
)
{
builder
.
append
(
" WITH TIME ZONE"
);
}
}
return
builder
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论