Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
77f0beac
提交
77f0beac
authored
1月 21, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add partial support of DATE, TIME, and TIMESTAMP data types to PgServer
上级
11e20221
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
77 行增加
和
5 行删除
+77
-5
PgServerThread.java
h2/src/main/org/h2/server/pg/PgServerThread.java
+66
-3
TestPgServer.java
h2/src/test/org/h2/test/unit/TestPgServer.java
+11
-2
没有找到文件。
h2/src/main/org/h2/server/pg/PgServerThread.java
浏览文件 @
77f0beac
...
@@ -26,10 +26,14 @@ import java.sql.ResultSet;
...
@@ -26,10 +26,14 @@ import java.sql.ResultSet;
import
java.sql.ResultSetMetaData
;
import
java.sql.ResultSetMetaData
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.sql.Statement
;
import
java.sql.Time
;
import
java.sql.Timestamp
;
import
java.sql.Types
;
import
java.sql.Types
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Properties
;
import
java.util.Properties
;
import
java.util.TimeZone
;
import
org.h2.command.CommandInterface
;
import
org.h2.command.CommandInterface
;
import
org.h2.engine.ConnectionInfo
;
import
org.h2.engine.ConnectionInfo
;
import
org.h2.engine.SysProperties
;
import
org.h2.engine.SysProperties
;
...
@@ -520,6 +524,11 @@ public class PgServerThread implements Runnable {
...
@@ -520,6 +524,11 @@ public class PgServerThread implements Runnable {
sendMessage
();
sendMessage
();
}
}
private
static
long
toPostgreSeconds
(
long
millis
)
{
// TODO handle Julian/Gregorian transitions
return
millis
/
1000
-
946684800L
;
}
private
void
writeDataColumn
(
ResultSet
rs
,
int
column
,
int
pgType
,
boolean
text
)
private
void
writeDataColumn
(
ResultSet
rs
,
int
column
,
int
pgType
,
boolean
text
)
throws
Exception
{
throws
Exception
{
if
(
text
)
{
if
(
text
)
{
...
@@ -562,7 +571,7 @@ public class PgServerThread implements Runnable {
...
@@ -562,7 +571,7 @@ public class PgServerThread implements Runnable {
writeInt
(
8
);
writeInt
(
8
);
dataOut
.
writeDouble
(
rs
.
getDouble
(
column
));
dataOut
.
writeDouble
(
rs
.
getDouble
(
column
));
break
;
break
;
case
PgServer
.
PG_TYPE_BYTEA
:
case
PgServer
.
PG_TYPE_BYTEA
:
{
byte
[]
data
=
rs
.
getBytes
(
column
);
byte
[]
data
=
rs
.
getBytes
(
column
);
if
(
data
==
null
)
{
if
(
data
==
null
)
{
writeInt
(-
1
);
writeInt
(-
1
);
...
@@ -571,7 +580,40 @@ public class PgServerThread implements Runnable {
...
@@ -571,7 +580,40 @@ public class PgServerThread implements Runnable {
write
(
data
);
write
(
data
);
}
}
break
;
break
;
}
case
PgServer
.
PG_TYPE_DATE
:
{
writeInt
(
4
);
long
millis
=
rs
.
getDate
(
column
).
getTime
();
millis
+=
TimeZone
.
getDefault
().
getOffset
(
millis
);
writeInt
((
int
)
(
toPostgreSeconds
(
millis
)
/
86400
));
break
;
}
case
PgServer
.
PG_TYPE_TIME
:
{
writeInt
(
8
);
Time
t
=
rs
.
getTime
(
column
);
long
m
=
t
.
getTime
();
m
+=
TimeZone
.
getDefault
().
getOffset
(
m
);
// double format
m
/=
1000
;
m
=
Double
.
doubleToLongBits
(
m
);
// long format
// m *= 1000;
writeInt
((
int
)
(
m
>>>
32
));
writeInt
((
int
)
m
);
break
;
}
case
PgServer
.
PG_TYPE_TIMESTAMP_NO_TMZONE
:
{
writeInt
(
8
);
Timestamp
t
=
rs
.
getTimestamp
(
column
);
long
m
=
t
.
getTime
();
m
+=
TimeZone
.
getDefault
().
getOffset
(
m
);
// double format
m
=
toPostgreSeconds
(
m
);
m
=
Double
.
doubleToLongBits
(
m
+
t
.
getNanos
()
*
0.000000001
);
writeInt
((
int
)
(
m
>>>
32
));
writeInt
((
int
)
m
);
break
;
}
default
:
throw
new
IllegalStateException
(
"output binary format is undefined"
);
default
:
throw
new
IllegalStateException
(
"output binary format is undefined"
);
}
}
}
}
...
@@ -595,7 +637,28 @@ public class PgServerThread implements Runnable {
...
@@ -595,7 +637,28 @@ public class PgServerThread implements Runnable {
// plain text
// plain text
byte
[]
data
=
DataUtils
.
newBytes
(
paramLen
);
byte
[]
data
=
DataUtils
.
newBytes
(
paramLen
);
readFully
(
data
);
readFully
(
data
);
prep
.
setString
(
col
,
new
String
(
data
,
getEncoding
()));
String
str
=
new
String
(
data
,
getEncoding
());
switch
(
pgType
)
{
case
PgServer
.
PG_TYPE_DATE
:
{
// Strip timezone offset
int
idx
=
str
.
indexOf
(
' '
);
if
(
idx
>
0
)
{
str
=
str
.
substring
(
0
,
idx
);
}
break
;
}
case
PgServer
.
PG_TYPE_TIME
:
{
// Strip timezone offset
int
idx
=
str
.
indexOf
(
'+'
);
if
(
idx
<=
0
)
idx
=
str
.
indexOf
(
'-'
);
if
(
idx
>
0
)
{
str
=
str
.
substring
(
0
,
idx
);
}
break
;
}
}
prep
.
setString
(
col
,
str
);
}
else
{
}
else
{
// binary
// binary
switch
(
pgType
)
{
switch
(
pgType
)
{
...
...
h2/src/test/org/h2/test/unit/TestPgServer.java
浏览文件 @
77f0beac
...
@@ -7,6 +7,7 @@ package org.h2.test.unit;
...
@@ -7,6 +7,7 @@ package org.h2.test.unit;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.DatabaseMetaData
;
import
java.sql.DatabaseMetaData
;
import
java.sql.Date
;
import
java.sql.DriverManager
;
import
java.sql.DriverManager
;
import
java.sql.ParameterMetaData
;
import
java.sql.ParameterMetaData
;
import
java.sql.PreparedStatement
;
import
java.sql.PreparedStatement
;
...
@@ -14,6 +15,7 @@ import java.sql.ResultSet;
...
@@ -14,6 +15,7 @@ import java.sql.ResultSet;
import
java.sql.ResultSetMetaData
;
import
java.sql.ResultSetMetaData
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.sql.Statement
;
import
java.sql.Time
;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.sql.Types
;
import
java.sql.Types
;
import
java.util.Properties
;
import
java.util.Properties
;
...
@@ -406,10 +408,11 @@ public class TestPgServer extends TestBase {
...
@@ -406,10 +408,11 @@ public class TestPgServer extends TestBase {
stat
.
execute
(
stat
.
execute
(
"create table test(x1 varchar, x2 int, "
+
"create table test(x1 varchar, x2 int, "
+
"x3 smallint, x4 bigint, x5 double, x6 float, "
+
"x3 smallint, x4 bigint, x5 double, x6 float, "
+
"x7 real, x8 boolean, x9 char, x10 bytea)"
);
"x7 real, x8 boolean, x9 char, x10 bytea, "
+
"x11 date, x12 time, x13 timestamp)"
);
PreparedStatement
ps
=
conn
.
prepareStatement
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
"insert into test values (?,?,?,?,?,?,?,?,?,?)"
);
"insert into test values (?,?,?,?,?,?,?,?,?,?
,?,?,?
)"
);
ps
.
setString
(
1
,
"test"
);
ps
.
setString
(
1
,
"test"
);
ps
.
setInt
(
2
,
12345678
);
ps
.
setInt
(
2
,
12345678
);
ps
.
setShort
(
3
,
(
short
)
12345
);
ps
.
setShort
(
3
,
(
short
)
12345
);
...
@@ -420,6 +423,9 @@ public class TestPgServer extends TestBase {
...
@@ -420,6 +423,9 @@ public class TestPgServer extends TestBase {
ps
.
setBoolean
(
8
,
true
);
ps
.
setBoolean
(
8
,
true
);
ps
.
setByte
(
9
,
(
byte
)
0xfe
);
ps
.
setByte
(
9
,
(
byte
)
0xfe
);
ps
.
setBytes
(
10
,
new
byte
[]
{
'a'
,
(
byte
)
0xfe
,
'\
127
'
});
ps
.
setBytes
(
10
,
new
byte
[]
{
'a'
,
(
byte
)
0xfe
,
'\
127
'
});
ps
.
setDate
(
11
,
Date
.
valueOf
(
"2015-01-31"
));
ps
.
setTime
(
12
,
Time
.
valueOf
(
"20:11:15"
));
ps
.
setTimestamp
(
13
,
Timestamp
.
valueOf
(
"2001-10-30 14:16:10.111"
));
ps
.
execute
();
ps
.
execute
();
ResultSet
rs
=
stat
.
executeQuery
(
"select * from test"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from test"
);
...
@@ -435,6 +441,9 @@ public class TestPgServer extends TestBase {
...
@@ -435,6 +441,9 @@ public class TestPgServer extends TestBase {
assertEquals
((
byte
)
0xfe
,
rs
.
getByte
(
9
));
assertEquals
((
byte
)
0xfe
,
rs
.
getByte
(
9
));
assertEquals
(
new
byte
[]
{
'a'
,
(
byte
)
0xfe
,
'\
127
'
},
assertEquals
(
new
byte
[]
{
'a'
,
(
byte
)
0xfe
,
'\
127
'
},
rs
.
getBytes
(
10
));
rs
.
getBytes
(
10
));
assertEquals
(
Date
.
valueOf
(
"2015-01-31"
),
rs
.
getDate
(
11
));
assertEquals
(
Time
.
valueOf
(
"20:11:15"
),
rs
.
getTime
(
12
));
assertEquals
(
Timestamp
.
valueOf
(
"2001-10-30 14:16:10.111"
),
rs
.
getTimestamp
(
13
));
conn
.
close
();
conn
.
close
();
}
finally
{
}
finally
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论