Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
a0b5e544
提交
a0b5e544
authored
7月 09, 2009
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
PG Server: improved compatibility by using the type ids of the PostgreSQL driver.
上级
16380c5b
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
77 行增加
和
6 行删除
+77
-6
PgServer.java
h2/src/main/org/h2/server/pg/PgServer.java
+67
-0
PgServerThread.java
h2/src/main/org/h2/server/pg/PgServerThread.java
+1
-1
pg_catalog.sql
h2/src/main/org/h2/server/pg/pg_catalog.sql
+9
-5
没有找到文件。
h2/src/main/org/h2/server/pg/PgServer.java
浏览文件 @
a0b5e544
...
...
@@ -15,6 +15,7 @@ import java.sql.PreparedStatement;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Timestamp
;
import
java.sql.Types
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.Set
;
...
...
@@ -32,6 +33,9 @@ import org.h2.util.Tool;
* http://developer.postgresql.org/pgdocs/postgres/protocol.html
* The PostgreSQL catalog is described here:
* http://www.postgresql.org/docs/7.4/static/catalogs.html
*
* @author Thomas Mueller
* @author Sergi Vladykin 2009-07-03 (convertType)
*/
public
class
PgServer
implements
Service
{
...
...
@@ -41,6 +45,24 @@ public class PgServer implements Service {
*/
public
static
final
int
DEFAULT_PORT
=
5435
;
private
static
final
int
PG_TYPE_BOOL
=
16
;
private
static
final
int
PG_TYPE_BYTEA
=
17
;
private
static
final
int
PG_TYPE_CHAR
=
18
;
private
static
final
int
PG_TYPE_INT8
=
20
;
private
static
final
int
PG_TYPE_INT2
=
21
;
private
static
final
int
PG_TYPE_INT4
=
23
;
private
static
final
int
PG_TYPE_TEXT
=
25
;
private
static
final
int
PG_TYPE_OID
=
26
;
private
static
final
int
PG_TYPE_FLOAT4
=
700
;
private
static
final
int
PG_TYPE_FLOAT8
=
701
;
private
static
final
int
PG_TYPE_UNKNOWN
=
705
;
private
static
final
int
PG_TYPE_TEXTARRAY
=
1009
;
private
static
final
int
PG_TYPE_VARCHAR
=
1043
;
private
static
final
int
PG_TYPE_DATE
=
1082
;
private
static
final
int
PG_TYPE_TIME
=
1083
;
private
static
final
int
PG_TYPE_TIMESTAMP_NO_TMZONE
=
1114
;
private
static
final
int
PG_TYPE_NUMERIC
=
1700
;
private
int
port
=
PgServer
.
DEFAULT_PORT
;
private
boolean
stop
;
private
boolean
trace
;
...
...
@@ -373,4 +395,49 @@ public class PgServer implements Service {
return
1
;
}
/**
* Convert the SQL type to a PostgreSQL type
*
* @param type the SQL type
* @return the PostgreSQL type
*/
public
static
int
convertType
(
final
int
type
)
{
switch
(
type
)
{
case
Types
.
BOOLEAN
:
return
PG_TYPE_BOOL
;
case
Types
.
VARCHAR
:
return
PG_TYPE_VARCHAR
;
case
Types
.
CLOB
:
return
PG_TYPE_TEXT
;
case
Types
.
CHAR
:
return
PG_TYPE_CHAR
;
case
Types
.
SMALLINT
:
return
PG_TYPE_INT2
;
case
Types
.
INTEGER
:
return
PG_TYPE_INT4
;
case
Types
.
BIGINT
:
return
PG_TYPE_INT8
;
case
Types
.
DECIMAL
:
return
PG_TYPE_NUMERIC
;
case
Types
.
REAL
:
return
PG_TYPE_FLOAT4
;
case
Types
.
DOUBLE
:
return
PG_TYPE_FLOAT8
;
case
Types
.
TIME
:
return
PG_TYPE_TIME
;
case
Types
.
DATE
:
return
PG_TYPE_DATE
;
case
Types
.
TIMESTAMP
:
return
PG_TYPE_TIMESTAMP_NO_TMZONE
;
case
Types
.
VARBINARY
:
return
PG_TYPE_BYTEA
;
case
Types
.
BLOB
:
return
PG_TYPE_OID
;
case
Types
.
ARRAY
:
return
PG_TYPE_TEXTARRAY
;
default
:
return
PG_TYPE_UNKNOWN
;
}
}
}
h2/src/main/org/h2/server/pg/PgServerThread.java
浏览文件 @
a0b5e544
...
...
@@ -61,7 +61,7 @@ public class PgServerThread implements Runnable {
private
String
userName
;
private
String
databaseName
;
private
int
processId
;
private
String
clientEncoding
=
"UTF-8"
;
private
String
clientEncoding
=
SysProperties
.
PG_DEFAULT_CLIENT_ENCODING
;
private
String
dateStyle
=
"ISO"
;
private
HashMap
<
String
,
Prepared
>
prepared
=
New
.
hashMap
();
private
HashMap
<
String
,
Portal
>
portals
=
New
.
hashMap
();
...
...
h2/src/main/org/h2/server/pg/pg_catalog.sql
浏览文件 @
a0b5e544
...
...
@@ -8,6 +8,9 @@
drop
schema
if
exists
pg_catalog
;
create
schema
pg_catalog
;
drop
alias
if
exists
pg_convertType
;
create
alias
pg_convertType
deterministic
for
"org.h2.server.pg.PgServer.convertType"
;
create
table
pg_catalog
.
pg_version
as
select
1
as
version
;
create
view
pg_catalog
.
pg_roles
-- (oid, rolname, rolcreaterole, rolcreatedb)
...
...
@@ -36,17 +39,18 @@ create table pg_catalog.pg_type(
insert
into
pg_catalog
.
pg_type
select
data_type
oid
,
pg_convertType
(
data_type
)
oid
,
cast
(
type_name
as
varchar_ignorecase
)
typname
,
(
select
oid
from
pg_catalog
.
pg_namespace
where
nspname
=
'pg_catalog'
)
typnamespace
,
-
1
typlen
,
'c'
typtype
,
0
typbasetype
from
information_schema
.
type_info
where
pos
=
0
;
where
pos
=
0
and
pg_convertType
(
data_type
)
<>
705
;
-- not unknown
merge
into
pg_catalog
.
pg_type
values
(
1
111
,
1
9
,
'name'
,
(
select
oid
from
pg_catalog
.
pg_namespace
where
nspname
=
'pg_catalog'
),
-
1
,
...
...
@@ -122,7 +126,7 @@ select
t
.
id
*
10000
+
c
.
ordinal_position
oid
,
t
.
id
attrelid
,
c
.
column_name
attname
,
data_type
atttypid
,
pg_convertType
(
data_type
)
atttypid
,
-
1
attlen
,
c
.
ordinal_position
attnum
,
-
1
atttypmod
,
...
...
@@ -137,7 +141,7 @@ select
1000000
+
t
.
id
*
10000
+
c
.
ordinal_position
oid
,
i
.
id
attrelid
,
c
.
column_name
attname
,
data_type
atttypid
,
pg_convertType
(
data_type
)
atttypid
,
-
1
attlen
,
c
.
ordinal_position
attnum
,
-
1
atttypmod
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论