提交 18cfcf6c authored 作者: noelgrandin's avatar noelgrandin

Issue 481: Further extensions to PgServer to support better support PG JDBC,…

Issue 481: Further extensions to PgServer to support better support PG JDBC, patch from Andrew Franklin.
上级 e948c80e
...@@ -44,6 +44,7 @@ Change Log ...@@ -44,6 +44,7 @@ Change Log
</li><li>Add syntax for passing additional parameters into custom TableEngine implementations. </li><li>Add syntax for passing additional parameters into custom TableEngine implementations.
</li><li>Add support for spatial datatype GEOMETRY. </li><li>Add support for spatial datatype GEOMETRY.
</li><li>Issue 480: Bugfix post issue #475, #477, patch from Andrew Franklin. </li><li>Issue 480: Bugfix post issue #475, #477, patch from Andrew Franklin.
</li><li>Issue 481: Further extensions to PgServer to support better support PG JDBC, 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>
......
...@@ -2676,6 +2676,10 @@ public class Parser { ...@@ -2676,6 +2676,10 @@ public class Parser {
} }
if (readIf("::")) { if (readIf("::")) {
// PostgreSQL compatibility // PostgreSQL compatibility
if (isToken("PG_CATALOG")) {
read("PG_CATALOG");
read(".");
}
if (readIf("REGCLASS")) { if (readIf("REGCLASS")) {
FunctionAlias f = findFunctionAlias(Constants.SCHEMA_MAIN, "PG_GET_OID"); FunctionAlias f = findFunctionAlias(Constants.SCHEMA_MAIN, "PG_GET_OID");
if (f == null) { if (f == null) {
......
...@@ -471,6 +471,25 @@ public class PgServer implements Service { ...@@ -471,6 +471,25 @@ public class PgServer implements Service {
return null; return null;
} }
/**
* Check if the current session has access to this table.
* This method is called by the database.
*
* @param pgType the postgres type oid
* @param typeMod the type modifier (typically -1)
* @return A string name for the given type
*/
public static String formatType(Connection conn, int pgType, int typeMod) throws SQLException {
PreparedStatement prep = conn.prepareStatement("select typname from pg_catalog.pg_type where oid = ? and typtypmod = ?");
prep.setInt(1, pgType);
prep.setInt(2, typeMod);
ResultSet rs = prep.executeQuery();
if (rs.next()) {
return rs.getString(1);
}
return null;
}
/** /**
* Convert the SQL type to a PostgreSQL type * Convert the SQL type to a PostgreSQL type
* *
......
...@@ -43,7 +43,8 @@ create table pg_catalog.pg_type( ...@@ -43,7 +43,8 @@ create table pg_catalog.pg_type(
typtype varchar, typtype varchar,
typbasetype int, typbasetype int,
typtypmod int, typtypmod int,
typnotnull boolean typnotnull boolean,
typinput varchar
); );
grant select on pg_catalog.pg_type to public; grant select on pg_catalog.pg_type to public;
...@@ -56,7 +57,8 @@ select ...@@ -56,7 +57,8 @@ select
'c' typtype, 'c' typtype,
0 typbasetype, 0 typbasetype,
-1 typtypmod, -1 typtypmod,
false typnotnull false typnotnull,
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
...@@ -69,7 +71,8 @@ merge into pg_catalog.pg_type values( ...@@ -69,7 +71,8 @@ merge into pg_catalog.pg_type values(
'c', 'c',
0, 0,
-1, -1,
false false,
null
); );
merge into pg_catalog.pg_type values( merge into pg_catalog.pg_type values(
0, 0,
...@@ -79,7 +82,8 @@ merge into pg_catalog.pg_type values( ...@@ -79,7 +82,8 @@ merge into pg_catalog.pg_type values(
'c', 'c',
0, 0,
-1, -1,
false false,
null
); );
merge into pg_catalog.pg_type values( merge into pg_catalog.pg_type values(
22, 22,
...@@ -89,10 +93,24 @@ merge into pg_catalog.pg_type values( ...@@ -89,10 +93,24 @@ merge into pg_catalog.pg_type values(
'c', 'c',
0, 0,
-1, -1,
false false,
null
);
merge into pg_catalog.pg_type values(
2205,
'regproc',
(select oid from pg_catalog.pg_namespace where nspname = 'pg_catalog'),
4,
'b',
0,
-1,
false,
null
); );
create view pg_catalog.pg_class -- (oid, relname, relnamespace, relkind, relam, reltuples, relpages, relhasrules, relhasoids) create domain regproc as varchar_ignorecase;
create view pg_catalog.pg_class -- (oid, relname, relnamespace, relkind, relam, reltuples, reltablespace, relpages, relhasindex, relhasrules, relhasoids, relchecks, reltriggers)
as as
select select
id oid, id oid,
...@@ -101,9 +119,13 @@ select ...@@ -101,9 +119,13 @@ select
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,
0 reltablespace,
0 relpages, 0 relpages,
false relhasindex,
false relhasrules, false relhasrules,
false relhasoids false relhasoids,
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
from information_schema.tables from information_schema.tables
union all union all
select select
...@@ -113,9 +135,13 @@ select ...@@ -113,9 +135,13 @@ select
'i' relkind, 'i' relkind,
0 relam, 0 relam,
cast(0 as float) reltuples, cast(0 as float) reltuples,
0 reltablespace,
0 relpages, 0 relpages,
true relhasindex,
false relhasrules, false relhasrules,
false relhasoids false relhasoids,
cast(0 as smallint) relchecks,
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;
...@@ -215,6 +241,9 @@ create alias pg_catalog.pg_get_indexdef for "org.h2.server.pg.PgServer.getIndexC ...@@ -215,6 +241,9 @@ create alias pg_catalog.pg_get_indexdef for "org.h2.server.pg.PgServer.getIndexC
drop alias if exists pg_catalog.pg_get_expr; drop alias if exists pg_catalog.pg_get_expr;
create alias pg_catalog.pg_get_expr for "org.h2.server.pg.PgServer.getPgExpr"; create alias pg_catalog.pg_get_expr for "org.h2.server.pg.PgServer.getPgExpr";
drop alias if exists pg_catalog.format_type;
create alias pg_catalog.format_type for "org.h2.server.pg.PgServer.formatType";
drop alias if exists version; drop alias if exists version;
create alias version for "org.h2.server.pg.PgServer.getVersion"; create alias version for "org.h2.server.pg.PgServer.getVersion";
...@@ -341,3 +370,10 @@ select ...@@ -341,3 +370,10 @@ select
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(
inhrelid int,
inhparent int,
inhseqno int
);
grant select on pg_catalog.pg_inherits to public;
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论