提交 aa66166c authored 作者: Thomas Mueller's avatar Thomas Mueller

PostgreSQL compatibility: the PgServer was not working properly when the setting…

PostgreSQL compatibility: the PgServer was not working properly when the setting database_to_upper was set to false.
上级 1b8ca254
...@@ -18,7 +18,9 @@ Change Log ...@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>JdbcDataSource: the methods setUrl and getUrl where added as aliases for setURL and getURL. <ul><li>PostgreSQL compatibility: the PgServer was not working properly when the setting
database_to_upper was set to false.
</li><li>JdbcDataSource: the methods setUrl and getUrl where added as aliases for setURL and getURL.
This should solve problems with the HikariCP (Hikari connection pool). This should solve problems with the HikariCP (Hikari connection pool).
</li><li>Issue 537: H2 Console: when loading the schema, incorrect JDBC calls where issued, which caused </li><li>Issue 537: H2 Console: when loading the schema, incorrect JDBC calls where issued, which caused
the exception "Column PRECISION not found". the exception "Column PRECISION not found".
......
...@@ -772,7 +772,7 @@ public class PgServerThread implements Runnable { ...@@ -772,7 +772,7 @@ public class PgServerThread implements Runnable {
if (!tableFound) { if (!tableFound) {
installPgCatalog(stat); installPgCatalog(stat);
} }
rs = stat.executeQuery("SELECT * FROM PG_CATALOG.PG_VERSION"); rs = stat.executeQuery("select * from pg_catalog.pg_version");
if (!rs.next() || rs.getInt(1) < 2) { if (!rs.next() || rs.getInt(1) < 2) {
// installation incomplete, or old version // installation incomplete, or old version
installPgCatalog(stat); installPgCatalog(stat);
...@@ -787,7 +787,7 @@ public class PgServerThread implements Runnable { ...@@ -787,7 +787,7 @@ public class PgServerThread implements Runnable {
stat.execute("set search_path = PUBLIC, pg_catalog"); stat.execute("set search_path = PUBLIC, pg_catalog");
HashSet<Integer> typeSet = server.getTypeSet(); HashSet<Integer> typeSet = server.getTypeSet();
if (typeSet.size() == 0) { if (typeSet.size() == 0) {
rs = stat.executeQuery("SELECT OID FROM PG_CATALOG.PG_TYPE"); rs = stat.executeQuery("select oid from pg_catalog.pg_type");
while (rs.next()) { while (rs.next()) {
typeSet.add(rs.getInt(1)); typeSet.add(rs.getInt(1));
} }
......
...@@ -15,7 +15,7 @@ drop alias if exists pg_get_oid; ...@@ -15,7 +15,7 @@ drop alias if exists pg_get_oid;
create alias pg_get_oid deterministic for "org.h2.server.pg.PgServer.getOid"; create alias pg_get_oid deterministic for "org.h2.server.pg.PgServer.getOid";
create table pg_catalog.pg_version as select 2 as version, 2 as version_read; create table pg_catalog.pg_version as select 2 as version, 2 as version_read;
grant select on pg_catalog.pg_version to public; grant select on pg_catalog.pg_version to PUBLIC;
create view pg_catalog.pg_roles -- (oid, rolname, rolcreaterole, rolcreatedb) create view pg_catalog.pg_roles -- (oid, rolname, rolcreaterole, rolcreatedb)
as as
...@@ -24,16 +24,16 @@ select ...@@ -24,16 +24,16 @@ select
cast(name as varchar_ignorecase) rolname, cast(name as varchar_ignorecase) rolname,
case when admin then 't' else 'f' end as rolcreaterole, case when admin then 't' else 'f' end as rolcreaterole,
case when admin then 't' else 'f' end as rolcreatedb case when admin then 't' else 'f' end as rolcreatedb
from information_schema.users; from INFORMATION_SCHEMA.users;
grant select on pg_catalog.pg_roles to public; grant select on pg_catalog.pg_roles to PUBLIC;
create view pg_catalog.pg_namespace -- (oid, nspname) create view pg_catalog.pg_namespace -- (oid, nspname)
as as
select select
id oid, id oid,
cast(schema_name as varchar_ignorecase) nspname cast(schema_name as varchar_ignorecase) nspname
from information_schema.schemata; from INFORMATION_SCHEMA.schemata;
grant select on pg_catalog.pg_namespace to public; grant select on pg_catalog.pg_namespace to PUBLIC;
create table pg_catalog.pg_type( create table pg_catalog.pg_type(
oid int primary key, oid int primary key,
...@@ -46,7 +46,7 @@ create table pg_catalog.pg_type( ...@@ -46,7 +46,7 @@ create table pg_catalog.pg_type(
typnotnull boolean, typnotnull boolean,
typinput varchar typinput varchar
); );
grant select on pg_catalog.pg_type to public; grant select on pg_catalog.pg_type to PUBLIC;
insert into pg_catalog.pg_type insert into pg_catalog.pg_type
select select
...@@ -59,7 +59,7 @@ select ...@@ -59,7 +59,7 @@ select
-1 typtypmod, -1 typtypmod,
false typnotnull, false typnotnull,
null typinput null typinput
from information_schema.type_info from INFORMATION_SCHEMA.type_info
where pos = 0 where pos = 0
and pg_convertType(data_type) <> 705; -- not unknown and pg_convertType(data_type) <> 705; -- not unknown
...@@ -115,7 +115,7 @@ as ...@@ -115,7 +115,7 @@ as
select select
id oid, id oid,
cast(table_name as varchar_ignorecase) relname, cast(table_name as varchar_ignorecase) relname,
(select id from information_schema.schemata where schema_name = table_schema) relnamespace, (select id from INFORMATION_SCHEMA.schemata where schema_name = table_schema) relnamespace,
case table_type when 'TABLE' then 'r' else 'v' end relkind, case table_type when 'TABLE' then 'r' else 'v' end relkind,
0 relam, 0 relam,
cast(0 as float) reltuples, cast(0 as float) reltuples,
...@@ -125,13 +125,13 @@ select ...@@ -125,13 +125,13 @@ select
false relhasrules, false relhasrules,
false relhasoids, false relhasoids,
cast(0 as smallint) relchecks, cast(0 as smallint) relchecks,
(select count(*) from information_schema.triggers t where t.table_schema = table_schema and t.table_name = table_name) reltriggers (select count(*) from INFORMATION_SCHEMA.triggers t where t.table_schema = table_schema and t.table_name = table_name) reltriggers
from information_schema.tables from INFORMATION_SCHEMA.tables
union all union all
select select
id oid, id oid,
cast(index_name as varchar_ignorecase) relname, cast(index_name as varchar_ignorecase) relname,
(select id from information_schema.schemata where schema_name = table_schema) relnamespace, (select id from INFORMATION_SCHEMA.schemata where schema_name = table_schema) relnamespace,
'i' relkind, 'i' relkind,
0 relam, 0 relam,
cast(0 as float) reltuples, cast(0 as float) reltuples,
...@@ -142,8 +142,8 @@ select ...@@ -142,8 +142,8 @@ select
false relhasoids, false relhasoids,
cast(0 as smallint) relchecks, cast(0 as smallint) relchecks,
0 reltriggers 0 reltriggers
from information_schema.indexes; from INFORMATION_SCHEMA.indexes;
grant select on pg_catalog.pg_class to public; grant select on pg_catalog.pg_class to PUBLIC;
create table pg_catalog.pg_proc( create table pg_catalog.pg_proc(
oid int, oid int,
...@@ -151,7 +151,7 @@ create table pg_catalog.pg_proc( ...@@ -151,7 +151,7 @@ create table pg_catalog.pg_proc(
prorettype int, prorettype int,
pronamespace int pronamespace int
); );
grant select on pg_catalog.pg_proc to public; grant select on pg_catalog.pg_proc to PUBLIC;
create table pg_catalog.pg_trigger( create table pg_catalog.pg_trigger(
oid int, oid int,
...@@ -164,7 +164,7 @@ create table pg_catalog.pg_trigger( ...@@ -164,7 +164,7 @@ create table pg_catalog.pg_trigger(
tgconstrname varchar_ignorecase, tgconstrname varchar_ignorecase,
tgrelid int tgrelid int
); );
grant select on pg_catalog.pg_trigger to public; grant select on pg_catalog.pg_trigger to PUBLIC;
create view pg_catalog.pg_attrdef -- (oid, adsrc, adrelid, adnum) create view pg_catalog.pg_attrdef -- (oid, adsrc, adrelid, adnum)
as as
...@@ -174,8 +174,8 @@ select ...@@ -174,8 +174,8 @@ select
0 adrelid, 0 adrelid,
0 adnum, 0 adnum,
null adbin null adbin
from information_schema.tables where 1=0; from INFORMATION_SCHEMA.tables where 1=0;
grant select on pg_catalog.pg_attrdef to public; grant select on pg_catalog.pg_attrdef to PUBLIC;
create view pg_catalog.pg_attribute -- (oid, attrelid, attname, atttypid, attlen, attnum, atttypmod, attnotnull, attisdropped, atthasdef) create view pg_catalog.pg_attribute -- (oid, attrelid, attname, atttypid, attlen, attnum, atttypmod, attnotnull, attisdropped, atthasdef)
as as
...@@ -190,7 +190,7 @@ select ...@@ -190,7 +190,7 @@ select
case c.is_nullable when 'YES' then false else true end attnotnull, case c.is_nullable when 'YES' then false else true end attnotnull,
false attisdropped, false attisdropped,
false atthasdef false atthasdef
from information_schema.tables t, information_schema.columns c from INFORMATION_SCHEMA.tables t, INFORMATION_SCHEMA.columns c
where t.table_name = c.table_name where t.table_name = c.table_name
and t.table_schema = c.table_schema and t.table_schema = c.table_schema
union all union all
...@@ -205,12 +205,12 @@ select ...@@ -205,12 +205,12 @@ select
case c.is_nullable when 'YES' then false else true end attnotnull, case c.is_nullable when 'YES' then false else true end attnotnull,
false attisdropped, false attisdropped,
false atthasdef false atthasdef
from information_schema.tables t, information_schema.indexes i, information_schema.columns c from INFORMATION_SCHEMA.tables t, INFORMATION_SCHEMA.indexes i, INFORMATION_SCHEMA.columns c
where t.table_name = i.table_name where t.table_name = i.table_name
and t.table_schema = i.table_schema and t.table_schema = i.table_schema
and t.table_name = c.table_name and t.table_name = c.table_name
and t.table_schema = c.table_schema; and t.table_schema = c.table_schema;
grant select on pg_catalog.pg_attribute to public; grant select on pg_catalog.pg_attribute to PUBLIC;
create view pg_catalog.pg_index -- (oid, indexrelid, indrelid, indisclustered, indisunique, indisprimary, indexprs, indkey, indpred) create view pg_catalog.pg_index -- (oid, indexrelid, indrelid, indisclustered, indisunique, indisprimary, indexprs, indkey, indpred)
as as
...@@ -224,13 +224,13 @@ select ...@@ -224,13 +224,13 @@ select
cast('' as varchar_ignorecase) indexprs, cast('' as varchar_ignorecase) indexprs,
cast(1 as array) indkey, cast(1 as array) indkey,
null indpred null indpred
from information_schema.indexes i, information_schema.tables t from INFORMATION_SCHEMA.indexes i, INFORMATION_SCHEMA.tables t
where i.table_schema = t.table_schema where i.table_schema = t.table_schema
and i.table_name = t.table_name and i.table_name = t.table_name
and i.ordinal_position = 1 and i.ordinal_position = 1
-- workaround for MS Access problem opening tables with primary key -- workaround for MS Access problem opening tables with primary key
and 1=0; and 1=0;
grant select on pg_catalog.pg_index to public; grant select on pg_catalog.pg_index to PUBLIC;
drop alias if exists pg_get_indexdef; drop alias if exists pg_get_indexdef;
create alias pg_get_indexdef for "org.h2.server.pg.PgServer.getIndexColumn"; create alias pg_get_indexdef for "org.h2.server.pg.PgServer.getIndexColumn";
...@@ -279,7 +279,7 @@ create table pg_catalog.pg_database( ...@@ -279,7 +279,7 @@ create table pg_catalog.pg_database(
datdba int, datdba int,
dattablespace int dattablespace int
); );
grant select on pg_catalog.pg_database to public; grant select on pg_catalog.pg_database to PUBLIC;
insert into pg_catalog.pg_database values( insert into pg_catalog.pg_database values(
0, -- oid 0, -- oid
...@@ -289,7 +289,7 @@ insert into pg_catalog.pg_database values( ...@@ -289,7 +289,7 @@ insert into pg_catalog.pg_database values(
true, -- datallowconn true, -- datallowconn
null, -- datconfig null, -- datconfig
null, -- datacl null, -- datacl
select min(id) from information_schema.users where admin=true, -- datdba select min(id) from INFORMATION_SCHEMA.users where admin=true, -- datdba
0 -- dattablespace 0 -- dattablespace
); );
...@@ -300,7 +300,7 @@ create table pg_catalog.pg_tablespace( ...@@ -300,7 +300,7 @@ create table pg_catalog.pg_tablespace(
spcowner int, spcowner int,
spcacl array -- aclitem[] spcacl array -- aclitem[]
); );
grant select on pg_catalog.pg_tablespace to public; grant select on pg_catalog.pg_tablespace to PUBLIC;
insert into pg_catalog.pg_tablespace values( insert into pg_catalog.pg_tablespace values(
0, 0,
...@@ -315,7 +315,7 @@ create table pg_catalog.pg_settings( ...@@ -315,7 +315,7 @@ create table pg_catalog.pg_settings(
name varchar_ignorecase, name varchar_ignorecase,
setting varchar_ignorecase setting varchar_ignorecase
); );
grant select on pg_catalog.pg_settings to public; grant select on pg_catalog.pg_settings to PUBLIC;
insert into pg_catalog.pg_settings values insert into pg_catalog.pg_settings values
(0, 'autovacuum', 'on'), (0, 'autovacuum', 'on'),
...@@ -329,8 +329,8 @@ select ...@@ -329,8 +329,8 @@ select
cast(name as varchar_ignorecase) usename, cast(name as varchar_ignorecase) usename,
true usecreatedb, true usecreatedb,
true usesuper true usesuper
from information_schema.users; from INFORMATION_SCHEMA.users;
grant select on pg_catalog.pg_user to public; grant select on pg_catalog.pg_user to PUBLIC;
create table pg_catalog.pg_authid( create table pg_catalog.pg_authid(
oid int, oid int,
...@@ -346,10 +346,10 @@ create table pg_catalog.pg_authid( ...@@ -346,10 +346,10 @@ create table pg_catalog.pg_authid(
rolvaliduntil timestamp, -- timestamptz rolvaliduntil timestamp, -- timestamptz
rolconfig array -- text[] rolconfig array -- text[]
); );
grant select on pg_catalog.pg_authid to public; grant select on pg_catalog.pg_authid to PUBLIC;
create table pg_catalog.pg_am(oid int, amname varchar_ignorecase); create table pg_catalog.pg_am(oid int, amname varchar_ignorecase);
grant select on pg_catalog.pg_am to public; grant select on pg_catalog.pg_am to PUBLIC;
insert into pg_catalog.pg_am values(0, 'btree'); insert into pg_catalog.pg_am values(0, 'btree');
insert into pg_catalog.pg_am values(1, 'hash'); insert into pg_catalog.pg_am values(1, 'hash');
...@@ -361,7 +361,7 @@ select ...@@ -361,7 +361,7 @@ select
-1 classoid, -1 classoid,
cast(datname as varchar_ignorecase) description cast(datname as varchar_ignorecase) description
from pg_catalog.pg_database; from pg_catalog.pg_database;
grant select on pg_catalog.pg_description to public; grant select on pg_catalog.pg_description to PUBLIC;
create table pg_catalog.pg_group -- oid, groname create table pg_catalog.pg_group -- oid, groname
as as
...@@ -369,11 +369,11 @@ select ...@@ -369,11 +369,11 @@ select
0 oid, 0 oid,
cast('' as varchar_ignorecase) groname cast('' as varchar_ignorecase) groname
from pg_catalog.pg_database where 1=0; from pg_catalog.pg_database where 1=0;
grant select on pg_catalog.pg_group to public; grant select on pg_catalog.pg_group to PUBLIC;
create table pg_catalog.pg_inherits( create table pg_catalog.pg_inherits(
inhrelid int, inhrelid int,
inhparent int, inhparent int,
inhseqno int inhseqno int
); );
grant select on pg_catalog.pg_inherits to public; grant select on pg_catalog.pg_inherits to PUBLIC;
...@@ -41,11 +41,36 @@ public class TestPgServer extends TestBase { ...@@ -41,11 +41,36 @@ public class TestPgServer extends TestBase {
@Override @Override
public void test() throws Exception { public void test() throws Exception {
testLowerCaseIdentifiers();
testPgAdapter(); testPgAdapter();
testKeyAlias(); testKeyAlias();
testKeyAlias();
testCancelQuery(); testCancelQuery();
testBinaryTypes(); testBinaryTypes();
} }
private void testLowerCaseIdentifiers() throws SQLException {
if (!getPgJdbcDriver()) {
return;
}
deleteDb("test");
Connection conn = getConnection("test;DATABASE_TO_UPPER=false", "sa", "sa");
Statement stat = conn.createStatement();
stat.execute("create table test(id int, name varchar(255))");
Server server = Server.createPgServer("-baseDir", getBaseDir(), "-pgPort", "5535", "-pgDaemon");
server.start();
try {
Connection conn2;
conn2 = DriverManager.getConnection("jdbc:postgresql://localhost:5535/test", "sa", "sa");
stat = conn2.createStatement();
stat.execute("select * from test");
conn2.close();
} finally {
server.stop();
}
conn.close();
deleteDb("test");
}
private boolean getPgJdbcDriver() { private boolean getPgJdbcDriver() {
try { try {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论