Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
273167ab
提交
273167ab
authored
4月 23, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
New system property h2.analyzeAuto.
上级
6bb3ea33
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
60 行增加
和
15 行删除
+60
-15
Analyze.java
h2/src/main/org/h2/command/ddl/Analyze.java
+10
-4
User.java
h2/src/main/org/h2/engine/User.java
+25
-11
TestBase.java
h2/src/test/org/h2/test/TestBase.java
+5
-0
TestOptimizations.java
h2/src/test/org/h2/test/db/TestOptimizations.java
+20
-0
没有找到文件。
h2/src/main/org/h2/command/ddl/Analyze.java
浏览文件 @
273167ab
...
@@ -9,6 +9,7 @@ package org.h2.command.ddl;
...
@@ -9,6 +9,7 @@ package org.h2.command.ddl;
import
org.h2.command.Prepared
;
import
org.h2.command.Prepared
;
import
org.h2.constant.SysProperties
;
import
org.h2.constant.SysProperties
;
import
org.h2.engine.Database
;
import
org.h2.engine.Database
;
import
org.h2.engine.Right
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.result.ResultInterface
;
import
org.h2.result.ResultInterface
;
import
org.h2.table.Column
;
import
org.h2.table.Column
;
...
@@ -54,17 +55,22 @@ public class Analyze extends DefineCommand {
...
@@ -54,17 +55,22 @@ public class Analyze extends DefineCommand {
if
(!(
table
instanceof
RegularTable
)
||
table
.
isHidden
()
||
session
==
null
)
{
if
(!(
table
instanceof
RegularTable
)
||
table
.
isHidden
()
||
session
==
null
)
{
return
;
return
;
}
}
if
(
session
.
getDatabase
().
isSysTableLocked
())
{
if
(!
manual
)
{
return
;
if
(
session
.
getDatabase
().
isSysTableLocked
())
{
return
;
}
if
(
table
.
hasSelectTrigger
())
{
return
;
}
}
}
if
(
table
.
isTemporary
()
&&
!
table
.
isGlobalTemporary
()
if
(
table
.
isTemporary
()
&&
!
table
.
isGlobalTemporary
()
&&
session
.
findLocalTempTable
(
table
.
getName
())
==
null
)
{
&&
session
.
findLocalTempTable
(
table
.
getName
())
==
null
)
{
return
;
return
;
}
}
if
(
!
manual
&&
table
.
hasSelectTrigger
(
))
{
if
(
table
.
isLockedExclusively
()
&&
!
table
.
isLockedExclusivelyBy
(
session
))
{
return
;
return
;
}
}
if
(
table
.
isLockedExclusively
()
&&
!
table
.
isLockedExclusivelyBy
(
session
))
{
if
(
!
session
.
getUser
().
hasRight
(
table
,
Right
.
SELECT
))
{
return
;
return
;
}
}
Database
db
=
session
.
getDatabase
();
Database
db
=
session
.
getDatabase
();
...
...
h2/src/main/org/h2/engine/User.java
浏览文件 @
273167ab
...
@@ -91,19 +91,32 @@ public class User extends RightOwner {
...
@@ -91,19 +91,32 @@ public class User extends RightOwner {
* @throws SQLException if this user does not have the required rights
* @throws SQLException if this user does not have the required rights
*/
*/
public
void
checkRight
(
Table
table
,
int
rightMask
)
{
public
void
checkRight
(
Table
table
,
int
rightMask
)
{
if
(!
hasRight
(
table
,
rightMask
))
{
throw
DbException
.
get
(
ErrorCode
.
NOT_ENOUGH_RIGHTS_FOR_1
,
table
.
getSQL
());
}
}
/**
* See if this user has the given rights for this database object.
*
* @param table the database object
* @param rightMask the rights required
* @return true if the user has the rights
*/
public
boolean
hasRight
(
Table
table
,
int
rightMask
)
{
if
(
rightMask
!=
Right
.
SELECT
&&
!
systemUser
)
{
if
(
rightMask
!=
Right
.
SELECT
&&
!
systemUser
)
{
table
.
checkWritingAllowed
();
table
.
checkWritingAllowed
();
}
}
if
(
admin
)
{
if
(
admin
)
{
return
;
return
true
;
}
}
Role
publicRole
=
database
.
getPublicRole
();
Role
publicRole
=
database
.
getPublicRole
();
if
(
publicRole
.
isRightGrantedRecursive
(
table
,
rightMask
))
{
if
(
publicRole
.
isRightGrantedRecursive
(
table
,
rightMask
))
{
return
;
return
true
;
}
}
if
(
table
instanceof
MetaTable
||
table
instanceof
RangeTable
)
{
if
(
table
instanceof
MetaTable
||
table
instanceof
RangeTable
)
{
// everybody has access to the metadata information
// everybody has access to the metadata information
return
;
return
true
;
}
}
String
tableType
=
table
.
getTableType
();
String
tableType
=
table
.
getTableType
();
if
(
Table
.
VIEW
.
equals
(
tableType
))
{
if
(
Table
.
VIEW
.
equals
(
tableType
))
{
...
@@ -111,19 +124,20 @@ public class User extends RightOwner {
...
@@ -111,19 +124,20 @@ public class User extends RightOwner {
if
(
v
.
getOwner
()
==
this
)
{
if
(
v
.
getOwner
()
==
this
)
{
// the owner of a view has access:
// the owner of a view has access:
// SELECT * FROM (SELECT * FROM ...)
// SELECT * FROM (SELECT * FROM ...)
return
;
return
true
;
}
}
}
else
if
(
tableType
==
null
)
{
}
else
if
(
tableType
==
null
)
{
// function table
// function table
return
;
return
true
;
}
}
if
(
!
isRightGrantedRecursive
(
table
,
rightMask
))
{
if
(
table
.
isTemporary
()
&&
!
table
.
isGlobalTemporary
(
))
{
if
(
table
.
isTemporary
()
&&
!
table
.
isGlobalTemporary
())
{
// the owner has all rights on local temporary tables
// the owner has all rights on local temporary tables
return
true
;
return
;
}
}
if
(
isRightGrantedRecursive
(
table
,
rightMask
))
{
throw
DbException
.
get
(
ErrorCode
.
NOT_ENOUGH_RIGHTS_FOR_1
,
table
.
getSQL
())
;
return
true
;
}
}
return
false
;
}
}
/**
/**
...
...
h2/src/test/org/h2/test/TestBase.java
浏览文件 @
273167ab
...
@@ -22,6 +22,7 @@ import java.sql.Types;
...
@@ -22,6 +22,7 @@ import java.sql.Types;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.LinkedList
;
import
java.util.LinkedList
;
import
org.h2.constant.SysProperties
;
import
org.h2.jdbc.JdbcConnection
;
import
org.h2.jdbc.JdbcConnection
;
import
org.h2.message.TraceSystem
;
import
org.h2.message.TraceSystem
;
import
org.h2.store.FileLock
;
import
org.h2.store.FileLock
;
...
@@ -1080,6 +1081,10 @@ public abstract class TestBase {
...
@@ -1080,6 +1081,10 @@ public abstract class TestBase {
* @throws AssertionError if the databases don't match
* @throws AssertionError if the databases don't match
*/
*/
protected
void
assertEqualDatabases
(
Statement
stat1
,
Statement
stat2
)
throws
SQLException
{
protected
void
assertEqualDatabases
(
Statement
stat1
,
Statement
stat2
)
throws
SQLException
{
if
(
SysProperties
.
ANALYZE_AUTO
>
0
)
{
stat1
.
execute
(
"analyze"
);
stat2
.
execute
(
"analyze"
);
}
ResultSet
rs1
=
stat1
.
executeQuery
(
"SCRIPT NOPASSWORDS"
);
ResultSet
rs1
=
stat1
.
executeQuery
(
"SCRIPT NOPASSWORDS"
);
ResultSet
rs2
=
stat2
.
executeQuery
(
"SCRIPT NOPASSWORDS"
);
ResultSet
rs2
=
stat2
.
executeQuery
(
"SCRIPT NOPASSWORDS"
);
ArrayList
<
String
>
list1
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
list1
=
new
ArrayList
<
String
>();
...
...
h2/src/test/org/h2/test/db/TestOptimizations.java
浏览文件 @
273167ab
...
@@ -16,6 +16,7 @@ import java.util.ArrayList;
...
@@ -16,6 +16,7 @@ import java.util.ArrayList;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Random
;
import
java.util.Random
;
import
java.util.TreeSet
;
import
java.util.TreeSet
;
import
org.h2.constant.SysProperties
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.util.New
;
import
org.h2.util.New
;
...
@@ -36,6 +37,7 @@ public class TestOptimizations extends TestBase {
...
@@ -36,6 +37,7 @@ public class TestOptimizations extends TestBase {
}
}
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
testAutoAnalyze
();
testInAndBetween
();
testInAndBetween
();
testNestedIn
();
testNestedIn
();
testNestedInSelectAndLike
();
testNestedInSelectAndLike
();
...
@@ -59,6 +61,24 @@ public class TestOptimizations extends TestBase {
...
@@ -59,6 +61,24 @@ public class TestOptimizations extends TestBase {
deleteDb
(
"optimizations"
);
deleteDb
(
"optimizations"
);
}
}
private
void
testAutoAnalyze
()
throws
SQLException
{
int
auto
=
SysProperties
.
ANALYZE_AUTO
;
if
(
auto
==
0
)
{
return
;
}
deleteDb
(
"optimizations"
);
Connection
conn
=
getConnection
(
"optimizations"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int)"
);
stat
.
execute
(
"create user onlyInsert password ''"
);
stat
.
execute
(
"grant insert on test to onlyInsert"
);
Connection
conn2
=
getConnection
(
"optimizations"
,
"onlyInsert"
,
getPassword
(
""
));
Statement
stat2
=
conn2
.
createStatement
();
stat2
.
execute
(
"insert into test select x from system_range(1, "
+
(
auto
+
10
)
+
")"
);
conn
.
close
();
conn2
.
close
();
}
private
void
testInAndBetween
()
throws
SQLException
{
private
void
testInAndBetween
()
throws
SQLException
{
deleteDb
(
"optimizations"
);
deleteDb
(
"optimizations"
);
Connection
conn
=
getConnection
(
"optimizations"
);
Connection
conn
=
getConnection
(
"optimizations"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论