Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
43214cca
提交
43214cca
authored
7月 28, 2007
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
--no commit message
上级
2531186c
全部展开
显示空白字符变更
内嵌
并排
正在显示
23 个修改的文件
包含
144 行增加
和
1376 行删除
+144
-1376
build.xml
h2/build.xml
+1
-5
advanced.html
h2/src/docsrc/html/advanced.html
+68
-30
history.html
h2/src/docsrc/html/history.html
+3
-1
odbcDataSource.png
h2/src/docsrc/html/odbcDataSource.png
+0
-0
h2.nsi
h2/src/installer/h2.nsi
+0
-2
Constants.java
h2/src/main/org/h2/engine/Constants.java
+0
-1
Function.java
h2/src/main/org/h2/expression/Function.java
+0
-1
LinearHashEntry.java
h2/src/main/org/h2/index/LinearHashEntry.java
+8
-0
OdbcServer.java
h2/src/main/org/h2/server/OdbcServer.java
+0
-181
OdbcServerThread.java
h2/src/main/org/h2/server/OdbcServerThread.java
+0
-749
OdbcTransfer.java
h2/src/main/org/h2/server/OdbcTransfer.java
+0
-247
PgServer.java
h2/src/main/org/h2/server/pg/PgServer.java
+21
-30
PgServerThread.java
h2/src/main/org/h2/server/pg/PgServerThread.java
+17
-70
pg_catalog.sql
h2/src/main/org/h2/server/pg/pg_catalog.sql
+5
-1
Console.java
h2/src/main/org/h2/tools/Console.java
+1
-1
Server.java
h2/src/main/org/h2/tools/Server.java
+2
-34
Cache2Q.java
h2/src/main/org/h2/util/Cache2Q.java
+7
-3
CacheLRU.java
h2/src/main/org/h2/util/CacheLRU.java
+1
-7
DataType.java
h2/src/main/org/h2/value/DataType.java
+0
-1
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+1
-1
test.properties
h2/src/test/org/h2/test/bench/test.properties
+7
-8
TestBackup.java
h2/src/test/org/h2/test/db/TestBackup.java
+0
-1
testSimple.in.txt
h2/src/test/org/h2/test/testSimple.in.txt
+2
-2
没有找到文件。
h2/build.xml
浏览文件 @
43214cca
...
...
@@ -37,13 +37,10 @@
<target
name=
"clean"
depends=
"init"
>
<mkdir
dir=
"bin"
/>
<mkdir
dir=
"odbc"
/>
<mkdir
dir=
"docs"
/>
<delete
includeemptydirs=
"true"
>
<fileset
dir=
"."
includes=
"*.sql,*.txt,*.lock,**/*.db,node*"
/>
<fileset
dir=
"bin"
includes=
"**/*"
excludes=
"**/*.bat,**/*.sh"
/>
<fileset
dir=
"odbc"
includes=
"*.a,*.def,"
/>
<fileset
dir=
"odbc"
includes=
"*.def,h2odbcTest.exe"
/>
<fileset
dir=
"docs"
includes=
"**/*"
/>
</delete>
<delete
file=
"src/tools/org/h2/tools/code/CodeSwitch.class"
/>
...
...
@@ -251,7 +248,7 @@
<fileset
dir=
"src/main"
/>
</copy>
<java
classname=
"org.h2.test.coverage.Coverage"
classpath=
"bin"
dir=
"bin"
fork=
"true"
>
<arg
line=
"-e org/h2/web -e org/h2/
server/Odbc -e org/h2/
jdbcx -e org/h2/bnf -r org/h2"
/>
<arg
line=
"-e org/h2/web -e org/h2/jdbcx -e org/h2/bnf -r org/h2"
/>
</java>
<javac
target=
"${jdk}"
source=
"${jdk}"
executable=
"${javac}"
srcdir=
"bin"
destdir=
"bin"
debug=
"true"
includes=
"org/h2/**"
/>
<java
classname=
"org.h2.test.TestAll"
fork=
"true"
classpath=
"bin"
dir=
"bin"
>
...
...
@@ -279,7 +276,6 @@
<fileset
dir=
".."
includes=
"h2/ant-build.properties"
/>
<fileset
dir=
".."
includes=
"h2/bin/**/*"
/>
<fileset
dir=
".."
includes=
"h2/docs/**/*"
/>
<fileset
dir=
".."
includes=
"h2/odbc/**/*"
/>
<fileset
dir=
".."
includes=
"h2/service/**/*"
/>
<fileset
dir=
".."
includes=
"h2/src/**/*"
/>
</zip>
...
...
h2/src/docsrc/html/advanced.html
浏览文件 @
43214cca
...
...
@@ -311,48 +311,86 @@ If successful, a command prompt window will pop up and disappear immediately. If
<br
/><a
name=
"odbc_driver"
></a>
<h2>
ODBC Driver
</h2>
The ODBC driver of this database is currently not very stable and only tested superficially
with a few applications (OpenOffice 2.0, Microsoft Excel and Microsoft Access) and
data types (INT and VARCHAR), and should not be used for production applications.
Only a Windows version of the driver is available at this time.
This database does not come with its own ODBC driver at this time,
but it supports the PostgreSQL network protocol.
Therefore, the PostgreSQL ODBC driver can be used.
Support for the PostgreSQL network protocol is quite new and should be viewed
as experimental. It should not be used for production applications.
<h3>
ODBC Installation
</h3>
<p>
Before the ODBC driver can be used, it needs to be installed. To do this,
double click on h2odbcSetup.exe. If you do this the first time, it will ask you to locate the
driver dll (h2odbc.dll). If you already installed it, the ODBC administration dialog will open
where you can create new or modify existing data sources.
When you create a new H2 ODBC data source, a dialog window will appear
and ask for the database settings:
First, the ODBC driver must be installed.
Any recent PostgreSQL ODBC driver should work, however version 8.2.4 or newer is recommended.
The Windows version of the PostgreSQL ODBC driver is available at
<a
href=
"http://www.postgresql.org/ftp/odbc/versions/msi"
>
http://www.postgresql.org/ftp/odbc/versions/msi
</a>
.
</p>
<img
src=
"odbcDataSource.png"
alt=
"ODBC Configuration"
/>
<h3>
Log Option
</h3>
The driver is able to log operations to a file.
To enable logging, the log file name must be set in the registry under the key
CURRENT_USER/Software/H2/ODBC/LogFile. This key will only be read when the
driver starts, so you need to make sure all applications that may use the driver
are closed before changing this setting.
If this registry entry is not found when the driver starts, logging is disabled.
A sample registry key file may look like this:
<pre>
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\H2\ODBC]
"LogFile"="C:\\temp\\h2odbc.txt"
<h3>
Starting the Server
</h3>
<p>
After installing the ODBC driver, start the H2 Server using the command line:
<pre>
java -cp h2.jar org.h2.tools.Server
</pre>
The PG Server (PG for PostgreSQL protocol) is started as well.
By default, databases are stored in the current working directory where the server is started.
Use -baseDir to save databases in another directory, for example the user home directory:
<pre>
java -cp h2.jar org.h2.tools.Server -baseDir ~
</pre>
The PG server can be started and stopped from within a Java application as follows:
<pre>
Server server = Server.createPgServer(new String[]{"-baseDir", "~"});
server.start();
...
server.stop();
</pre>
By default, only connections from localhost are allowed. To allow remote connections, use
<code>
-pgAllowOthers true
</code>
when starting the server.
</p>
<h3>
ODBC Configuration
</h3>
<p>
After installing the driver, a new Data Source must be added. In Windows,
run
<code>
odbcad32.exe
</code>
to open the Data Source Administrator. Then click on 'Add...'
and select the PostgreSQL Unicode driver. Then click 'Finish'.
You will be able to change the connection properties:
</p>
<table>
<tr><th>
Property
</th><th>
Example
</th><th>
Remarks
</th></th>
<tr><td>
Data Source
</td><td>
H2 Test
</td><td>
The name of the ODBC Data Source
</td></tr>
<tr><td>
Database
</td><td>
test
</td>
<td>
The database name. Only simple names are supported at this time;
<br
/>
relative or absolute path are not supported in the database name.
<br
/>
By default, the database is stored in the current working directory
<br
/>
where the Server is started except when the -baseDir setting is used.
<br
/>
The name must be at least 3 characters.
</td></tr>
<tr><td>
Server
</td><td>
localhost
</td><td>
The server name or IP address.
<br
/>
By default, only remote connections are allowed
</td></tr>
<tr><td>
User Name
</td><td>
sa
</td><td>
The database user name.
</td></tr>
<tr><td>
SSL Mode
</td><td>
disabled
</td><td>
At this time, SSL is not supported.
</td></tr>
<tr><td>
Port
</td><td>
5435
</td><td>
The port where the PG Server is listening.
</td></tr>
<tr><td>
Password
</td><td>
sa
</td><td>
The database password.
</td></tr>
</table>
<p>
Afterwards, you may use this data source.
</p>
<h3>
PG Protocol Support Limitations
</h3>
<p>
At this time, only a subset of the PostgreSQL network protocol is implemented.
Also, there may be compatibility problems on the SQL level, with the catalog, or with text encoding.
Problems are fixed as they are found.
Currently, statements can not be cancelled when using the PG protocol.
</p>
<h3>
Security Considerations
</h3>
Currently, the
ODBC does not encrypt the password before sending it over TCP/IP to the server
.
This may be a problem if an attacker can listen to the data transferred between the ODBC
client
Currently, the
PG Server does not support challenge response or encrypt passwords
.
This may be a problem if an attacker can listen to the data transferred between the ODBC
driver
and the server, because the password is readable to the attacker.
Also, it is currently not possible to use encrypted SSL connections.
The password for a data source is stored unencrypted in the registry.
Therefore the ODBC driver should not be used where security is important.
<h3>
Uninstalling
</h3>
To uninstall the ODBC driver, double click on h2odbcUninstall.exe. This will uninstall the driver.
<br
/><a
name=
"acid"
></a>
<h2>
ACID
</h2>
In the database world, ACID stands for:
...
...
h2/src/docsrc/html/history.html
浏览文件 @
43214cca
...
...
@@ -39,7 +39,9 @@ Hypersonic SQL or HSQLDB. H2 is built from scratch.
<h3>
Version 1.0 (Current)
</h3>
<h3>
Version 1.0 / 2007-TODO
</h3><ul>
<li>
The default value for h2.defaultMaxMemoryUndo is now 50000.
<li>
</li><li>
The experimental H2 ODBC driver has been removed.
</li><li>
The default value for h2.defaultMaxMemoryUndo is now 50000.
This avoids out of memory problems when using very large transactions,
however large transactions are slower because they are buffered to disk.
To disable, use -Dh2.defaultMaxMemoryUndo=2000000000.
...
...
h2/src/docsrc/html/odbcDataSource.png
deleted
100644 → 0
浏览文件 @
2531186c
8.0 KB
h2/src/installer/h2.nsi
浏览文件 @
43214cca
...
...
@@ -119,8 +119,6 @@ Section "All"
File /r /x CVS /x .cvsignore ..\..\bin\*.*
SetOutPath "$INSTDIR\docs"
File /r /x CVS /x .cvsignore ..\..\docs\*.*
SetOutPath "$INSTDIR\odbc"
File /r /x CVS /x .cvsignore ..\..\odbc\*.*
SetOutPath "$INSTDIR\service"
File /r /x CVS /x .cvsignore /x .svn ..\..\service\*.*
SetOutPath "$INSTDIR"
...
...
h2/src/main/org/h2/engine/Constants.java
浏览文件 @
43214cca
...
...
@@ -50,7 +50,6 @@ import org.h2.message.TraceSystem;
* - table of contents
* - Switch off auto-build
* - ant all
* - Make sure odbc files are the
* - Copy the pdf file to h2/docs
* - Make sure the build files are removed
* - ant zip
...
...
h2/src/main/org/h2/expression/Function.java
浏览文件 @
43214cca
...
...
@@ -58,7 +58,6 @@ import org.h2.value.ValueUuid;
*/
public
class
Function
extends
Expression
implements
FunctionCall
{
// TODO functions: ODBC TIMESTAMPDIFF
// TODO functions: add function hashcode(value)
public
static
final
int
ABS
=
0
,
ACOS
=
1
,
ASIN
=
2
,
ATAN
=
3
,
ATAN2
=
4
,
...
...
h2/src/main/org/h2/index/LinearHashEntry.java
浏览文件 @
43214cca
...
...
@@ -10,6 +10,14 @@ import org.h2.value.Value;
* @author Thomas
*/
public
class
LinearHashEntry
{
// private LinearHashEntry(int home, int hash, Value key, int value) {
// this.home = home;
// this.hash = hash;
// this.key = key;
// this.value = value;
// }
public
int
home
;
public
int
hash
;
public
Value
key
;
...
...
h2/src/main/org/h2/server/OdbcServer.java
deleted
100644 → 0
浏览文件 @
2531186c
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
server
;
import
java.io.IOException
;
import
java.net.InetAddress
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
org.h2.message.TraceSystem
;
import
org.h2.util.MathUtils
;
import
org.h2.util.NetUtils
;
/**
* @author Thomas
*/
public
class
OdbcServer
implements
Service
{
public
static
final
int
DEFAULT_PORT
=
9083
;
// also in the docs
private
int
port
=
OdbcServer
.
DEFAULT_PORT
;
private
boolean
stop
;
private
boolean
log
;
private
ServerSocket
serverSocket
;
private
HashSet
running
=
new
HashSet
();
private
String
baseDir
;
private
String
url
;
private
boolean
allowOthers
;
private
boolean
ifExists
;
private
Thread
listenerThread
;
boolean
getLog
()
{
return
log
;
}
void
log
(
String
s
)
{
if
(
log
)
{
System
.
out
.
println
(
s
);
}
}
synchronized
void
remove
(
OdbcServerThread
t
)
{
running
.
remove
(
t
);
}
void
logError
(
Exception
e
)
{
if
(
log
)
{
e
.
printStackTrace
();
}
}
public
void
init
(
String
[]
args
)
throws
Exception
{
port
=
DEFAULT_PORT
;
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
String
a
=
args
[
i
];
if
(
a
.
equals
(
"-log"
))
{
log
=
Boolean
.
valueOf
(
args
[++
i
]).
booleanValue
();
}
else
if
(
a
.
equals
(
"-odbcPort"
))
{
port
=
MathUtils
.
decodeInt
(
args
[++
i
]);
}
else
if
(
a
.
equals
(
"-baseDir"
))
{
baseDir
=
args
[++
i
];
}
else
if
(
a
.
equals
(
"-odbcAllowOthers"
))
{
allowOthers
=
Boolean
.
valueOf
(
args
[++
i
]).
booleanValue
();
}
else
if
(
a
.
equals
(
"-ifExists"
))
{
ifExists
=
Boolean
.
valueOf
(
args
[++
i
]).
booleanValue
();
}
}
org
.
h2
.
Driver
.
load
();
url
=
"odbc://localhost:"
+
port
;
}
public
String
getURL
()
{
return
url
;
}
boolean
allow
(
Socket
socket
)
{
if
(
allowOthers
)
{
return
true
;
}
return
NetUtils
.
isLoopbackAddress
(
socket
);
}
public
void
start
()
throws
SQLException
{
serverSocket
=
NetUtils
.
createServerSocket
(
port
,
false
);
}
public
void
listen
()
{
listenerThread
=
Thread
.
currentThread
();
String
threadName
=
listenerThread
.
getName
();
try
{
while
(!
stop
)
{
Socket
s
=
serverSocket
.
accept
();
if
(!
allow
(
s
))
{
log
(
"Connection not allowed"
);
s
.
close
();
}
else
{
OdbcServerThread
c
=
new
OdbcServerThread
(
s
,
this
);
running
.
add
(
c
);
Thread
thread
=
new
Thread
(
c
);
thread
.
setName
(
threadName
+
" thread"
);
c
.
setThread
(
thread
);
thread
.
start
();
}
}
}
catch
(
Exception
e
)
{
if
(!
stop
)
{
e
.
printStackTrace
();
}
}
}
public
void
stop
()
{
// TODO server: share code between web and tcp servers
if
(!
stop
)
{
stop
=
true
;
if
(
serverSocket
!=
null
)
{
try
{
serverSocket
.
close
();
}
catch
(
IOException
e
)
{
// TODO log exception
e
.
printStackTrace
();
}
serverSocket
=
null
;
}
if
(
listenerThread
!=
null
)
{
try
{
listenerThread
.
join
(
1000
);
}
catch
(
InterruptedException
e
)
{
TraceSystem
.
traceThrowable
(
e
);
}
}
}
// TODO server: using a boolean 'now' argument? a timeout?
ArrayList
list
=
new
ArrayList
(
running
);
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
OdbcServerThread
c
=
(
OdbcServerThread
)
list
.
get
(
i
);
c
.
close
();
try
{
c
.
getThread
().
join
(
100
);
}
catch
(
Exception
e
)
{
// TODO log exception
e
.
printStackTrace
();
}
}
}
public
boolean
isRunning
()
{
if
(
serverSocket
==
null
)
{
return
false
;
}
try
{
Socket
s
=
NetUtils
.
createSocket
(
InetAddress
.
getLocalHost
(),
serverSocket
.
getLocalPort
(),
false
);
s
.
close
();
return
true
;
}
catch
(
Exception
e
)
{
return
false
;
}
}
public
String
getBaseDir
()
{
return
baseDir
;
}
public
boolean
getAllowOthers
()
{
return
allowOthers
;
}
public
String
getType
()
{
return
"ODBC"
;
}
public
boolean
getIfExists
()
{
return
ifExists
;
}
}
h2/src/main/org/h2/server/OdbcServerThread.java
deleted
100644 → 0
浏览文件 @
2531186c
差异被折叠。
点击展开。
h2/src/main/org/h2/server/OdbcTransfer.java
deleted
100644 → 0
浏览文件 @
2531186c
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
server
;
import
java.io.DataInputStream
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
/**
* @author Thomas
*/
public
class
OdbcTransfer
{
static
final
int
BUFFER_SIZE
=
1024
;
private
DataInputStream
in
;
private
DataOutputStream
out
;
OdbcTransfer
(
DataInputStream
in
,
DataOutputStream
out
)
{
this
.
in
=
in
;
this
.
out
=
out
;
}
OdbcTransfer
writeBoolean
(
boolean
x
)
throws
IOException
{
writeInt
(
x
?
1
:
0
);
return
this
;
}
OdbcTransfer
writeOk
()
throws
IOException
{
writeBoolean
(
true
);
return
this
;
}
boolean
readBoolean
()
throws
IOException
{
return
readInt
()
==
1
;
}
OdbcTransfer
writeByte
(
byte
x
)
throws
IOException
{
out
.
write
(
x
);
return
this
;
}
int
readByte
()
throws
IOException
{
return
in
.
read
();
}
OdbcTransfer
writeShort
(
short
x
)
throws
IOException
{
return
writeInt
(
x
);
}
short
readShort
()
throws
IOException
{
return
(
short
)
readInt
();
}
OdbcTransfer
writeInt
(
int
i
)
throws
IOException
{
out
.
writeInt
(
i
);
return
this
;
}
int
readInt
()
throws
IOException
{
return
in
.
readInt
();
}
OdbcTransfer
writeLong
(
long
i
)
throws
IOException
{
out
.
writeLong
(
i
);
return
this
;
}
long
readLong
()
throws
IOException
{
return
in
.
readLong
();
}
OdbcTransfer
writeFloat
(
float
i
)
throws
IOException
{
out
.
writeFloat
(
i
);
return
this
;
}
float
readFloat
()
throws
IOException
{
return
in
.
readFloat
();
}
OdbcTransfer
writeDouble
(
double
i
)
throws
IOException
{
out
.
writeDouble
(
i
);
return
this
;
}
double
readDouble
()
throws
IOException
{
return
in
.
readDouble
();
}
OdbcTransfer
writeString
(
String
s
)
throws
IOException
{
if
(
s
==
null
)
{
out
.
writeInt
(-
1
);
}
else
{
out
.
writeInt
(
s
.
length
());
for
(
int
i
=
0
;
i
<
s
.
length
();
i
++)
{
out
.
write
(
s
.
charAt
(
i
));
}
}
return
this
;
}
String
readString
()
throws
IOException
{
int
len
=
in
.
readInt
();
if
(
len
==
-
1
)
{
return
null
;
}
char
[]
chars
=
new
char
[
len
];
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
chars
[
i
]
=
(
char
)
in
.
readByte
();
}
return
new
String
(
chars
);
}
OdbcTransfer
writeDate
(
java
.
sql
.
Date
x
)
throws
IOException
{
if
(
x
==
null
)
{
writeString
(
null
);
}
else
{
writeString
(
x
.
toString
());
}
return
this
;
}
OdbcTransfer
writeTime
(
java
.
sql
.
Time
x
)
throws
IOException
{
if
(
x
==
null
)
{
writeString
(
null
);
}
else
{
writeString
(
x
.
toString
());
}
return
this
;
}
OdbcTransfer
writeTimestamp
(
java
.
sql
.
Timestamp
x
)
throws
IOException
{
if
(
x
==
null
)
{
writeString
(
null
);
}
else
{
writeString
(
x
.
toString
());
}
return
this
;
}
java
.
sql
.
Date
readDate
()
throws
IOException
{
String
s
=
readString
();
if
(
s
==
null
)
{
return
null
;
}
return
java
.
sql
.
Date
.
valueOf
(
s
);
}
java
.
sql
.
Time
readTime
()
throws
IOException
{
String
s
=
readString
();
if
(
s
==
null
)
{
return
null
;
}
return
java
.
sql
.
Time
.
valueOf
(
s
);
}
java
.
sql
.
Timestamp
readTimestamp
()
throws
IOException
{
String
s
=
readString
();
if
(
s
==
null
)
{
return
null
;
}
return
java
.
sql
.
Timestamp
.
valueOf
(
s
);
}
OdbcTransfer
writeByteArray
(
byte
[]
data
)
throws
IOException
{
if
(
data
==
null
)
{
writeInt
(-
1
);
}
else
{
writeInt
(
data
.
length
);
}
out
.
write
(
data
);
return
this
;
}
byte
[]
readByteArray
()
throws
IOException
{
int
len
=
readInt
();
if
(
len
==
-
1
)
{
return
null
;
}
byte
[]
b
=
new
byte
[
len
];
in
.
readFully
(
b
);
return
b
;
}
OdbcTransfer
writeIntArray
(
int
[]
s
)
throws
IOException
{
if
(
s
==
null
)
{
writeInt
(-
1
);
}
else
{
writeInt
(
s
.
length
);
for
(
int
i
=
0
;
i
<
s
.
length
;
i
++)
{
writeInt
(
s
[
i
]);
}
}
return
this
;
}
int
[]
readIntArray
()
throws
IOException
{
int
len
=
readInt
();
if
(
len
==
-
1
)
{
return
null
;
}
int
[]
s
=
new
int
[
len
];
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
s
[
i
]
=
readInt
();
}
return
s
;
}
OdbcTransfer
writeStringArray
(
String
[]
s
)
throws
IOException
{
if
(
s
==
null
)
{
writeInt
(-
1
);
}
else
{
writeInt
(
s
.
length
);
for
(
int
i
=
0
;
i
<
s
.
length
;
i
++)
{
writeString
(
s
[
i
]);
}
}
return
this
;
}
String
[]
readStringArray
()
throws
IOException
{
int
len
=
readInt
();
if
(
len
==
-
1
)
{
return
null
;
}
String
[]
s
=
new
String
[
len
];
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
s
[
i
]
=
readString
();
}
return
s
;
}
// buffer - cannot be null
OdbcTransfer
writeBuffer
(
byte
[]
buffer
)
throws
IOException
{
out
.
write
(
buffer
);
return
this
;
}
}
h2/src/main/org/h2/server/pg/PgServer.java
浏览文件 @
43214cca
...
...
@@ -38,11 +38,25 @@ public class PgServer implements Service {
private
boolean
allowOthers
;
private
boolean
ifExists
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
PgServer
app
=
new
PgServer
();
app
.
init
(
args
);
app
.
start
();
app
.
listen
();
public
void
init
(
String
[]
args
)
throws
Exception
{
port
=
DEFAULT_PORT
;
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
String
a
=
args
[
i
];
if
(
a
.
equals
(
"-log"
))
{
log
=
Boolean
.
valueOf
(
args
[++
i
]).
booleanValue
();
}
else
if
(
a
.
equals
(
"-pgPort"
))
{
port
=
MathUtils
.
decodeInt
(
args
[++
i
]);
}
else
if
(
a
.
equals
(
"-baseDir"
))
{
baseDir
=
args
[++
i
];
}
else
if
(
a
.
equals
(
"-pgAllowOthers"
))
{
allowOthers
=
Boolean
.
valueOf
(
args
[++
i
]).
booleanValue
();
}
else
if
(
a
.
equals
(
"-ifExists"
))
{
ifExists
=
Boolean
.
valueOf
(
args
[++
i
]).
booleanValue
();
}
}
org
.
h2
.
Driver
.
load
();
url
=
"pg://localhost:"
+
port
;
// log = true;
}
boolean
getLog
()
{
...
...
@@ -65,29 +79,6 @@ public class PgServer implements Service {
}
}
public
void
init
(
String
[]
args
)
throws
Exception
{
port
=
DEFAULT_PORT
;
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
String
a
=
args
[
i
];
if
(
a
.
equals
(
"-log"
))
{
log
=
Boolean
.
valueOf
(
args
[++
i
]).
booleanValue
();
}
else
if
(
a
.
equals
(
"-pgPort"
))
{
port
=
MathUtils
.
decodeInt
(
args
[++
i
]);
}
else
if
(
a
.
equals
(
"-baseDir"
))
{
baseDir
=
args
[++
i
];
}
else
if
(
a
.
equals
(
"-pgAllowOthers"
))
{
allowOthers
=
Boolean
.
valueOf
(
args
[++
i
]).
booleanValue
();
}
else
if
(
a
.
equals
(
"-ifExists"
))
{
ifExists
=
Boolean
.
valueOf
(
args
[++
i
]).
booleanValue
();
}
}
org
.
h2
.
Driver
.
load
();
url
=
"pg://localhost:"
+
port
;
int
testing
;
log
=
true
;
}
public
String
getURL
()
{
return
url
;
}
...
...
@@ -129,7 +120,7 @@ public class PgServer implements Service {
}
public
void
stop
()
{
// TODO server:
share code between web and tcp servers
// TODO server:
combine with tcp server
if
(!
stop
)
{
stop
=
true
;
if
(
serverSocket
!=
null
)
{
...
...
@@ -243,7 +234,7 @@ public class PgServer implements Service {
}
public
static
boolean
hasDatabasePrivilege
(
int
id
,
String
privilege
)
{
return
fals
e
;
return
tru
e
;
}
public
static
boolean
hasTablePrivilege
(
String
table
,
String
privilege
)
{
...
...
h2/src/main/org/h2/server/pg/PgServerThread.java
浏览文件 @
43214cca
...
...
@@ -26,7 +26,6 @@ import java.sql.Statement;
import
java.sql.Types
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Hashtable
;
import
java.util.Properties
;
import
org.h2.Driver
;
...
...
@@ -37,7 +36,7 @@ import org.h2.util.ScriptReader;
* This class implements a subset of the PostgreSQL protocol as described here:
* http://developer.postgresql.org/pgdocs/postgres/protocol.html
* The PostgreSQL catalog is described here:
* http://www.postgresql.org/docs/7.4/static/
view-pg-user.html
* http://www.postgresql.org/docs/7.4/static/
catalogs.html
* @author Thomas
*/
...
...
@@ -117,17 +116,6 @@ public class PgServerThread implements Runnable {
}
private
void
error
(
String
message
,
Exception
e
)
{
int
todoDocumentLimitations
;
/*
Limitations:
- The database name can not contains the path (~ or directory).
Workaround: use -baseDir when starting the server.
- SSL is not supported.
- Statements can not be cancelled.
- Metadata is static.
*/
if
(
e
!=
null
)
{
server
.
logError
(
e
);
}
...
...
@@ -154,8 +142,7 @@ Limitations:
server
.
log
(
"Init"
);
int
version
=
readInt
();
if
(
version
==
80877102
)
{
int
todoSupport
;
server
.
log
(
"CancelRequest"
);
server
.
log
(
"CancelRequest (not supported)"
);
server
.
log
(
" pid: "
+
readInt
());
server
.
log
(
" key: "
+
readInt
());
error
(
"CancelRequest"
,
null
);
...
...
@@ -382,7 +369,6 @@ Limitations:
private
String
getSQL
(
String
s
)
{
String
lower
=
s
.
toLowerCase
();
int
todo
;
if
(
lower
.
startsWith
(
"show max_identifier_length"
))
{
s
=
"CALL 63"
;
}
else
if
(
lower
.
startsWith
(
"set client_encoding to"
))
{
...
...
@@ -458,8 +444,7 @@ Limitations:
if
(
text
)
{
s
=
new
String
(
d2
,
getEncoding
());
}
else
{
int
testing
;
System
.
out
.
println
(
"binary format!"
);
server
.
logError
(
new
SQLException
(
"Binary format not supported"
));
s
=
new
String
(
d2
,
getEncoding
());
}
}
catch
(
Exception
e
)
{
...
...
@@ -483,6 +468,7 @@ Limitations:
writeString
(
e
.
getMessage
());
write
(
'D'
);
writeString
(
e
.
toString
());
write
(
0
);
sendMessage
();
}
...
...
@@ -534,7 +520,7 @@ Limitations:
writeString
(
names
[
i
].
toLowerCase
());
writeInt
(
0
);
// object ID
writeShort
(
0
);
// attribute number of the column
writeInt
(
getType
(
types
[
i
])
);
// data type
writeInt
(
types
[
i
]
);
// data type
writeShort
(
getTypeSize
(
types
[
i
]));
// pg_type.typlen
writeInt
(
getModifier
(
types
[
i
]));
// pg_attribute.atttypmod
writeShort
(
0
);
// text
...
...
@@ -546,15 +532,6 @@ Limitations:
}
}
private
int
getType
(
int
type
)
{
int
testing
;
// switch(type) {
// case Types.VARCHAR:
// return 19;
// }
return
type
;
}
private
int
getTypeSize
(
int
type
)
{
switch
(
type
)
{
case
Types
.
VARCHAR
:
...
...
@@ -590,8 +567,18 @@ Limitations:
}
private
void
initDb
()
throws
SQLException
{
int
todoUseVersionOnlyInitWhenRequired
;
ResultSet
rs
=
conn
.
getMetaData
().
getTables
(
null
,
"PG_CATALOG"
,
"PG_VERSION"
,
null
);
boolean
tableFound
=
rs
.
next
();
Statement
stat
=
conn
.
createStatement
();
if
(
tableFound
)
{
rs
=
stat
.
executeQuery
(
"SELECT VERION FROM PG_CATALOG.PG_VERSION"
);
if
(
rs
.
next
())
{
if
(
rs
.
getInt
(
1
)
==
1
)
{
// already installed
return
;
}
}
}
Reader
r
=
new
InputStreamReader
(
getClass
().
getResourceAsStream
(
"pg_catalog.sql"
));
r
=
new
BufferedReader
(
r
);
ScriptReader
reader
=
new
ScriptReader
(
r
);
...
...
@@ -604,52 +591,12 @@ Limitations:
}
reader
.
close
();
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT OID FROM PG_CATALOG.PG_TYPE"
);
rs
=
stat
.
executeQuery
(
"SELECT OID FROM PG_CATALOG.PG_TYPE"
);
while
(
rs
.
next
())
{
types
.
add
(
new
Integer
(
rs
.
getInt
(
1
)));
}
}
// private void sendResultSet(ResultSet rs) throws SQLException, IOException {
// ResultSetMetaData meta = rs.getMetaData();
// int columnCount = meta.getColumnCount();
// //
// startMessage('T');
// writeShort(columnCount);
// for(int i=0; i<columnCount; i++) {
// writeString(meta.getColumnName(i + 1));
// writeInt(0); // table id
// writeShort(0); // column id
// writeInt(0); // data type id
// writeShort(26); // data type size (see pg_type.typlen)
// writeInt(4); // type modifier (see pg_attribute.atttypmod)
// writeShort(0); // format code 0=text, 1=binary
// }
// sendMessage();
// while(rs.next()) {
// // DataRow
// startMessage('D');
// writeShort(columnCount);
// for(int i=0; i<columnCount; i++) {
// String v = rs.getString(i + 1);
// if(v == null) {
// writeInt(-1);
// } else {
// byte[] data = v.getBytes();
// writeInt(data.length);
// write(data);
// }
// }
// sendMessage();
// }
//
// // CommandComplete
// startMessage('C');
// writeString("SELECT");
// sendMessage();
// sendReadyForQuery('I');
// }
public
void
close
()
{
try
{
stop
=
true
;
...
...
h2/src/main/org/h2/server/pg/pg_catalog.sql
浏览文件 @
43214cca
...
...
@@ -6,6 +6,8 @@
drop
schema
if
exists
pg_catalog
;
create
schema
pg_catalog
;
create
table
pg_version
as
select
1
as
version
;
set
search_path
=
PUBLIC
,
pg_catalog
;
create
view
pg_catalog
.
pg_roles
-- (oid, rolname, rolcreaterole, rolcreatedb)
...
...
@@ -87,7 +89,9 @@ from information_schema.indexes;
create
table
pg_catalog
.
pg_proc
(
oid
int
,
proname
varchar_ignorecase
proname
varchar_ignorecase
,
prorettype
int
,
pronamespace
int
);
create
table
pg_catalog
.
pg_trigger
(
...
...
h2/src/main/org/h2/tools/Console.java
浏览文件 @
43214cca
...
...
@@ -31,7 +31,7 @@ import org.h2.util.IOUtils;
import
org.h2.util.StartBrowser
;
/**
* This tool starts the H2 Console (web-) server, as well as the TCP and
ODBC
server.
* This tool starts the H2 Console (web-) server, as well as the TCP and
PG
server.
* For JDK 1.6, a system tray icon is created, for platforms that support it.
* Otherwise, a small window opens.
*
...
...
h2/src/main/org/h2/tools/Server.java
浏览文件 @
43214cca
...
...
@@ -12,7 +12,6 @@ import java.sql.SQLException;
import
org.h2.engine.Constants
;
import
org.h2.message.Message
;
import
org.h2.message.TraceSystem
;
import
org.h2.server.OdbcServer
;
import
org.h2.server.Service
;
import
org.h2.server.TcpServer
;
import
org.h2.server.ftp.FtpServer
;
...
...
@@ -52,10 +51,6 @@ public class Server implements Runnable {
System
.
out
.
println
(
"-pgPort <port> (default: "
+
PgServer
.
DEFAULT_PORT
+
")"
);
System
.
out
.
println
(
"-pgAllowOthers [true|false]"
);
System
.
out
.
println
(
"-odbc (start the ODBC Server)"
);
System
.
out
.
println
(
"-odbcPort <port> (default: "
+
OdbcServer
.
DEFAULT_PORT
+
")"
);
System
.
out
.
println
(
"-odbcAllowOthers [true|false]"
);
System
.
out
.
println
(
"-ftp (start the FTP Server)"
);
System
.
out
.
println
(
"-ftpPort <port> (default: "
+
Constants
.
DEFAULT_FTP_PORT
+
")"
);
System
.
out
.
println
(
"-ftpDir <directory> (default: "
+
FtpServer
.
DEFAULT_ROOT
+
", use jdbc:... to access a database)"
);
...
...
@@ -74,7 +69,7 @@ public class Server implements Runnable {
/**
* The command line interface for this tool.
* The options must be split into strings like this: "-baseDir", "/temp/data",...
* By default, -tcp, -web, -browser and -
odbc
are started.
* By default, -tcp, -web, -browser and -
pg
are started.
* If there is a problem starting a service, the program terminates with an exit code of 1.
* The following options are supported:
* <ul>
...
...
@@ -83,7 +78,6 @@ public class Server implements Runnable {
* </li><li>-tcp (start the TCP Server)
* </li><li>-tcpShutdown {url} (shutdown the running TCP Server, URL example: tcp://localhost:9094)
* </li><li>-pg (start the PG Server)
* </li><li>-odbc (start the ODBC Server)
* </li><li>-browser (start a browser and open a page to connect to the Web Server)
* </li><li>-log [true|false] (enable or disable logging)
* </li><li>-baseDir {directory} (sets the base directory for database files; not for H2 Console)
...
...
@@ -102,8 +96,6 @@ public class Server implements Runnable {
* </li><li>-tcpShutdownForce [true|false] (don't wait for other connections to close)
* </li><li>-pgPort {port} (the port of PG Server, default: 5435)
* </li><li>-pgAllowOthers [true|false] (enable/disable remote connections)
* </li><li>-odbcPort {port} (the port of ODBC Server, default: 9083)
* </li><li>-odbcAllowOthers [true|false] (enable/disable remote connections)
* </li><li>-ftpPort {port}
* </li><li>-ftpDir {directory}
* </li><li>-ftpRead {readUserName}
...
...
@@ -122,7 +114,7 @@ public class Server implements Runnable {
}
private
int
run
(
String
[]
args
)
throws
SQLException
{
boolean
tcpStart
=
false
,
odbcStart
=
false
,
pgStart
=
false
,
webStart
=
false
,
ftpStart
=
false
;
boolean
tcpStart
=
false
,
pgStart
=
false
,
webStart
=
false
,
ftpStart
=
false
;
boolean
browserStart
=
false
;
boolean
tcpShutdown
=
false
,
tcpShutdownForce
=
false
;
String
tcpPassword
=
""
;
...
...
@@ -136,9 +128,6 @@ public class Server implements Runnable {
}
else
if
(
a
.
equals
(
"-web"
))
{
startDefaultServers
=
false
;
webStart
=
true
;
}
else
if
(
a
.
equals
(
"-odbc"
))
{
startDefaultServers
=
false
;
odbcStart
=
true
;
}
else
if
(
a
.
equals
(
"-tcp"
))
{
startDefaultServers
=
false
;
tcpStart
=
true
;
...
...
@@ -165,7 +154,6 @@ public class Server implements Runnable {
if
(
startDefaultServers
)
{
tcpStart
=
true
;
pgStart
=
true
;
odbcStart
=
false
;
webStart
=
true
;
browserStart
=
true
;
}
...
...
@@ -196,17 +184,6 @@ public class Server implements Runnable {
}
System
.
out
.
println
(
pg
.
getStatus
());
}
if
(
odbcStart
)
{
Server
odbc
=
createOdbcServer
(
args
);
try
{
odbc
.
start
();
}
catch
(
SQLException
e
)
{
// ignore (status is displayed)
e
.
printStackTrace
();
exitCode
=
EXIT_ERROR
;
}
System
.
out
.
println
(
odbc
.
getStatus
());
}
if
(
webStart
)
{
Server
web
=
createWebServer
(
args
);
try
{
...
...
@@ -341,15 +318,6 @@ public class Server implements Runnable {
return
new
Server
(
"H2 TCP Server"
,
new
TcpServer
(),
args
);
}
/**
* Create a new ODBC server, but does not start it yet.
* @param args
* @return the server
*/
public
static
Server
createOdbcServer
(
String
[]
args
)
throws
SQLException
{
return
new
Server
(
"H2 ODBC Server"
,
new
OdbcServer
(),
args
);
}
/**
* Create a new PG server, but does not start it yet.
* @param args
...
...
h2/src/main/org/h2/util/Cache2Q.java
浏览文件 @
43214cca
...
...
@@ -17,7 +17,7 @@ public class Cache2Q implements Cache {
public
static
final
String
TYPE_NAME
=
"TQ"
;
private
static
final
int
MAIN
=
1
,
IN
=
2
,
OUT
=
3
;
private
final
static
int
PERCENT_IN
=
20
,
PERCENT_OUT
=
50
;
private
static
final
int
PERCENT_IN
=
20
,
PERCENT_OUT
=
50
;
private
final
CacheWriter
writer
;
private
int
maxSize
;
...
...
@@ -160,7 +160,11 @@ public class Cache2Q implements Cache {
int
i
=
0
;
ObjectArray
changed
=
new
ObjectArray
();
while
(((
sizeIn
*
4
>
maxIn
*
3
)
||
(
sizeOut
*
4
>
maxOut
*
3
)
||
(
sizeMain
*
4
>
maxMain
*
3
))
&&
recordCount
>
Constants
.
CACHE_MIN_RECORDS
)
{
if
(
i
++
>=
recordCount
)
{
i
++;
if
(
i
==
recordCount
)
{
writer
.
flushLog
();
}
if
(
i
>=
recordCount
*
2
)
{
// can't remove any record, because the log is not written yet
// hopefully this does not happen too much, but it could happen theoretically
// TODO log this
...
...
h2/src/main/org/h2/util/CacheLRU.java
浏览文件 @
43214cca
...
...
@@ -90,23 +90,17 @@ public class CacheLRU implements Cache {
int
i
=
0
;
ObjectArray
changed
=
new
ObjectArray
();
while
(
sizeMemory
*
4
>
maxSize
*
3
&&
recordCount
>
Constants
.
CACHE_MIN_RECORDS
)
{
CacheObject
last
=
head
.
next
;
i
++;
if
(
i
==
recordCount
)
{
int
testing
;
int
todoCopyTo2Q
;
System
.
out
.
println
(
"flush log"
);
writer
.
flushLog
();
}
if
(
i
>=
recordCount
*
2
)
{
// can't remove any record, because the log is not written yet
// hopefully this does not happen too much, but it could happen theoretically
// TODO log this
System
.
out
.
println
(
"can not shrink cache"
);
break
;
}
CacheObject
last
=
head
.
next
;
if
(
Constants
.
CHECK
&&
last
==
head
)
{
throw
Message
.
getInternalError
(
"try to remove head"
);
}
...
...
h2/src/main/org/h2/value/DataType.java
浏览文件 @
43214cca
...
...
@@ -230,7 +230,6 @@ public class DataType {
}
Value
.
getOrder
(
i
);
}
// TODO data types: try to support other types as well (longvarchar for odbc/access,...) - maybe map them to regular types?
}
private
static
void
add
(
int
type
,
int
sqlType
,
String
jdbc
,
DataType
dataType
,
String
[]
names
,
int
memory
)
{
...
...
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
43214cca
...
...
@@ -201,7 +201,7 @@ CREATE TABLE TEST( ID BIGINT PRIMARY KEY, CREATED TIMESTAMP);
INSERT INTO TEST VALUES(1, '2007-01-01 00:00:00');
SELECT * FROM TEST;
Server: use one listener (detect if the request comes from an
ODBC
or TCP client).
Server: use one listener (detect if the request comes from an
PG
or TCP client).
PMD
...
...
h2/src/test/org/h2/test/bench/test.properties
浏览文件 @
43214cca
db2
=
H2, org.h2.Driver, jdbc:h2:data/test;LOCK_TIMEOUT=10000;LOCK_MODE=3, sa, sa
xdb2
=
H2 (XTEA), org.h2.Driver, jdbc:h2:data/test_xtea;LOCK_TIMEOUT=10000;LOCK_MODE=3;CIPHER=XTEA, sa, sa 123
xdb3
=
H2 (AES), org.h2.Driver, jdbc:h2:data/test_aes;LOCK_TIMEOUT=10000;LOCK_MODE=3;CIPHER=AES, sa, sa 123
xdb4
=
H2, org.h2.Driver, jdbc:h2:data/test;LOCK_TIMEOUT=10000;LOCK_MODE=3;write_mode_log=rws;write_delay=0, sa, sa
db1
=
H2, org.h2.Driver, jdbc:h2:data/test;LOCK_TIMEOUT=10000;LOCK_MODE=3, sa, sa
db1
=
H2_PG, org.postgresql.Driver, jdbc:postgresql://localhost:5435/h2test, sa, sa
xdb2
=
HSQLDB, org.hsqldb.jdbcDriver, jdbc:hsqldb:data/test;hsqldb.default_table_type=cached;sql.enforce_size=true, sa
#xdb2 = H2 (XTEA), org.h2.Driver, jdbc:h2:data/test_xtea;LOCK_TIMEOUT=10000;LOCK_MODE=3;CIPHER=XTEA, sa, sa 123
#xdb3 = H2 (AES), org.h2.Driver, jdbc:h2:data/test_aes;LOCK_TIMEOUT=10000;LOCK_MODE=3;CIPHER=AES, sa, sa 123
#xdb4 = H2, org.h2.Driver, jdbc:h2:data/test;LOCK_TIMEOUT=10000;LOCK_MODE=3;write_mode_log=rws;write_delay=0, sa, sa
#xdb5 = H2_PG, org.postgresql.Driver, jdbc:postgresql://localhost:5435/h2test, sa, sa
db2
=
HSQLDB, org.hsqldb.jdbcDriver, jdbc:hsqldb:data/test;hsqldb.default_table_type=cached;sql.enforce_size=true, sa
db3
=
Derby, org.apache.derby.jdbc.EmbeddedDriver, jdbc:derby:data/test;create=true, sa, sa
db4
=
H2, org.h2.Driver, jdbc:h2:tcp://localhost/data/testServer;LOCK_TIMEOUT=10000;LOCK_MODE=3, sa, sa
...
...
@@ -30,5 +30,4 @@ oracle.datetime = TIMESTAMP
#test3 = org.h2.test.bench.BenchB
test1
=
org.h2.test.bench.BenchC
#size = 400
size
=
10
\ No newline at end of file
size
=
400
h2/src/test/org/h2/test/db/TestBackup.java
浏览文件 @
43214cca
...
...
@@ -7,7 +7,6 @@ package org.h2.test.db;
import
java.sql.Connection
;
import
java.sql.Statement
;
import
org.h2.engine.Constants
;
import
org.h2.test.TestBase
;
import
org.h2.tools.Restore
;
...
...
h2/src/test/org/h2/test/testSimple.in.txt
浏览文件 @
43214cca
call
timestamp '2007-07-26 18:44:26.109000 +02:00';
>
1
;
select
timestamp '2007-07-26 18:44:26.109000 +02:00';
>
2007-07-26 18:44:26.109
;
create table test(id int primary key);
begin;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论