Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f6798389
提交
f6798389
authored
6月 18, 2013
作者:
noelgrandin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Issue 473: PgServer missing -key option, patch from Andrew Franklin
上级
312d476d
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
53 行增加
和
1 行删除
+53
-1
changelog.html
h2/src/docsrc/html/changelog.html
+1
-0
PgServer.java
h2/src/main/org/h2/server/pg/PgServer.java
+24
-0
PgServerThread.java
h2/src/main/org/h2/server/pg/PgServerThread.java
+1
-1
TestPgServer.java
h2/src/test/org/h2/test/unit/TestPgServer.java
+27
-0
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
f6798389
...
@@ -36,6 +36,7 @@ Change Log
...
@@ -36,6 +36,7 @@ Change Log
</li><li>
Improve error message when we have a unique constraint violation, displays the offending key in the error message
</li><li>
Improve error message when we have a unique constraint violation, displays the offending key in the error message
</li><li>
Issue 478: Support for "SHOW TRANSACTION ISOLATION LEVEL", patch from Andrew Franklin
</li><li>
Issue 478: Support for "SHOW TRANSACTION ISOLATION LEVEL", patch from Andrew Franklin
</li><li>
Issue 475: PgServer: add support for CancelRequest, patch from Andrew Franklin
</li><li>
Issue 475: PgServer: add support for CancelRequest, patch from Andrew Franklin
</li><li>
Issue 473: PgServer missing -key option, patch from Andrew Franklin
</li></ul>
</li></ul>
<h2>
Version 1.3.172 (2013-05-25)
</h2>
<h2>
Version 1.3.172 (2013-05-25)
</h2>
...
...
h2/src/main/org/h2/server/pg/PgServer.java
浏览文件 @
f6798389
...
@@ -20,6 +20,7 @@ import java.util.Collections;
...
@@ -20,6 +20,7 @@ import java.util.Collections;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Constants
;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.server.Service
;
import
org.h2.server.Service
;
...
@@ -84,6 +85,7 @@ public class PgServer implements Service {
...
@@ -84,6 +85,7 @@ public class PgServer implements Service {
private
boolean
allowOthers
;
private
boolean
allowOthers
;
private
boolean
isDaemon
;
private
boolean
isDaemon
;
private
boolean
ifExists
;
private
boolean
ifExists
;
private
String
key
,
keyDatabase
;
@Override
@Override
public
void
init
(
String
...
args
)
{
public
void
init
(
String
...
args
)
{
...
@@ -103,6 +105,9 @@ public class PgServer implements Service {
...
@@ -103,6 +105,9 @@ public class PgServer implements Service {
isDaemon
=
true
;
isDaemon
=
true
;
}
else
if
(
Tool
.
isOption
(
a
,
"-ifExists"
))
{
}
else
if
(
Tool
.
isOption
(
a
,
"-ifExists"
))
{
ifExists
=
true
;
ifExists
=
true
;
}
else
if
(
Tool
.
isOption
(
a
,
"-key"
))
{
key
=
args
[++
i
];
keyDatabase
=
args
[++
i
];
}
}
}
}
org
.
h2
.
Driver
.
load
();
org
.
h2
.
Driver
.
load
();
...
@@ -517,6 +522,25 @@ public class PgServer implements Service {
...
@@ -517,6 +522,25 @@ public class PgServer implements Service {
}
}
}
}
/**
* If no key is set, return the original database name. If a key is set,
* check if the key matches. If yes, return the correct database name. If
* not, throw an exception.
*
* @param db the key to test (or database name if no key is used)
* @return the database name
* @throws DbException if a key is set but doesn't match
*/
public
String
checkKeyAndGetDatabaseName
(
String
db
)
{
if
(
key
==
null
)
{
return
db
;
}
if
(
key
.
equals
(
db
))
{
return
keyDatabase
;
}
throw
DbException
.
get
(
ErrorCode
.
WRONG_USER_OR_PASSWORD
);
}
@Override
@Override
public
boolean
isDaemon
()
{
public
boolean
isDaemon
()
{
return
isDaemon
;
return
isDaemon
;
...
...
h2/src/main/org/h2/server/pg/PgServerThread.java
浏览文件 @
f6798389
...
@@ -171,7 +171,7 @@ public class PgServerThread implements Runnable {
...
@@ -171,7 +171,7 @@ public class PgServerThread implements Runnable {
if
(
"user"
.
equals
(
param
))
{
if
(
"user"
.
equals
(
param
))
{
this
.
userName
=
value
;
this
.
userName
=
value
;
}
else
if
(
"database"
.
equals
(
param
))
{
}
else
if
(
"database"
.
equals
(
param
))
{
this
.
databaseName
=
value
;
this
.
databaseName
=
server
.
checkKeyAndGetDatabaseName
(
value
)
;
}
else
if
(
"client_encoding"
.
equals
(
param
))
{
}
else
if
(
"client_encoding"
.
equals
(
param
))
{
// UTF8
// UTF8
clientEncoding
=
value
;
clientEncoding
=
value
;
...
...
h2/src/test/org/h2/test/unit/TestPgServer.java
浏览文件 @
f6798389
...
@@ -37,6 +37,11 @@ public class TestPgServer extends TestBase {
...
@@ -37,6 +37,11 @@ public class TestPgServer extends TestBase {
@Override
@Override
public
void
test
()
throws
SQLException
{
public
void
test
()
throws
SQLException
{
testPGAdapter
();
testKeyAlias
();
}
private
void
testPGAdapter
()
throws
SQLException
{
deleteDb
(
"test"
);
deleteDb
(
"test"
);
Server
server
=
Server
.
createPgServer
(
"-baseDir"
,
getBaseDir
(),
"-pgPort"
,
"5535"
,
"-pgDaemon"
);
Server
server
=
Server
.
createPgServer
(
"-baseDir"
,
getBaseDir
(),
"-pgPort"
,
"5535"
,
"-pgDaemon"
);
assertEquals
(
5535
,
server
.
getPort
());
assertEquals
(
5535
,
server
.
getPort
());
...
@@ -259,4 +264,26 @@ public class TestPgServer extends TestBase {
...
@@ -259,4 +264,26 @@ public class TestPgServer extends TestBase {
conn
.
close
();
conn
.
close
();
}
}
private
void
testKeyAlias
()
throws
SQLException
{
Server
server
=
Server
.
createPgServer
(
"-pgPort"
,
"5535"
,
"-pgDaemon"
,
"-key"
,
"test"
,
"mem:test"
);
server
.
start
();
try
{
Class
.
forName
(
"org.postgresql.Driver"
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://localhost:5535/test"
,
"sa"
,
"sa"
);
Statement
stat
=
conn
.
createStatement
();
// confirm that we've got the in memory implementation by creating a table and checking flags
stat
.
execute
(
"create table test(id int primary key, name varchar)"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select storage_type from information_schema.tables where table_name = 'TEST'"
);
assertTrue
(
rs
.
next
());
assertEquals
(
"MEMORY"
,
rs
.
getString
(
1
));
conn
.
close
();
}
catch
(
ClassNotFoundException
e
)
{
println
(
"PostgreSQL JDBC driver not found - PgServer not tested"
);
}
finally
{
server
.
stop
();
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论