提交 c9818113 authored 作者: noelgrandin's avatar noelgrandin

Issue 472: PgServer does not work with any recent Postgres JDBC driver, patch from Andrew Franklin

上级 53d6f1f9
...@@ -40,6 +40,7 @@ Change Log ...@@ -40,6 +40,7 @@ Change Log
</li><li>Issue 471: CREATE VIEW does not check user rights, patch from Andrew Franklin </li><li>Issue 471: CREATE VIEW does not check user rights, patch from Andrew Franklin
</li><li>Issue 477: PgServer binary transmission of query params is unimplemented, patch from Andrew Franklin </li><li>Issue 477: PgServer binary transmission of query params is unimplemented, patch from Andrew Franklin
</li><li>Issue 479: Support for SUBSTRING without a FROM condition, patch from Andrew Franklin </li><li>Issue 479: Support for SUBSTRING without a FROM condition, patch from Andrew Franklin
</li><li>Issue 472: PgServer does not work with any recent Postgres JDBC driver, 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>
......
...@@ -456,6 +456,14 @@ public class PgServer implements Service { ...@@ -456,6 +456,14 @@ public class PgServer implements Service {
return 1; return 1;
} }
/**
* A fake wrapper around pg_get_expr(expr_text, relation_oid), in PG it decompiles the "internal form of an
* expression, assuming that any Vars in it refer to the relation indicated by the second parameter".
*/
public static String getPgExpr(String exprText, int relationOid) {
return null;
}
/** /**
* Convert the SQL type to a PostgreSQL type * Convert the SQL type to a PostgreSQL type
* *
......
...@@ -25,6 +25,7 @@ import java.sql.ResultSet; ...@@ -25,6 +25,7 @@ import java.sql.ResultSet;
import java.sql.ResultSetMetaData; import java.sql.ResultSetMetaData;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.sql.Types;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Properties; import java.util.Properties;
...@@ -341,8 +342,7 @@ public class PgServerThread implements Runnable { ...@@ -341,8 +342,7 @@ public class PgServerThread implements Runnable {
if (result) { if (result) {
try { try {
ResultSet rs = prep.getResultSet(); ResultSet rs = prep.getResultSet();
ResultSetMetaData meta = rs.getMetaData(); // the meta-data is sent in the prior 'Describe'
sendRowDescription(meta);
while (rs.next()) { while (rs.next()) {
sendDataRow(rs); sendDataRow(rs);
} }
...@@ -483,13 +483,21 @@ public class PgServerThread implements Runnable { ...@@ -483,13 +483,21 @@ public class PgServerThread implements Runnable {
private void writeDataColumn(ResultSet rs, int column, int pgType) throws Exception { private void writeDataColumn(ResultSet rs, int column, int pgType) throws Exception {
if (formatAsText(pgType)) { if (formatAsText(pgType)) {
String s = rs.getString(column); // plain text
if (s==null) { switch (pgType) {
writeInt(-1); case PgServer.PG_TYPE_BOOL:
} else { writeInt(1);
byte[] data = s.getBytes(getEncoding()); dataOut.writeByte(rs.getBoolean(column) ? 't' : 'f');
writeInt(data.length); break;
write(data); default:
String s = rs.getString(column);
if (s==null) {
writeInt(-1);
} else {
byte[] data = s.getBytes(getEncoding());
writeInt(data.length);
write(data);
}
} }
} else { } else {
// binary // binary
...@@ -540,7 +548,9 @@ public class PgServerThread implements Runnable { ...@@ -540,7 +548,9 @@ public class PgServerThread implements Runnable {
boolean text = (i >= formatCodes.length) || (formatCodes[i] == 0); boolean text = (i >= formatCodes.length) || (formatCodes[i] == 0);
int col = i + 1; int col = i + 1;
int paramLen = readInt(); int paramLen = readInt();
if (text) { if (paramLen==-1) {
prep.setNull(i, Types.NULL);
} else if (text) {
// plain text // plain text
byte[] data = DataUtils.newBytes(paramLen); byte[] data = DataUtils.newBytes(paramLen);
readFully(data); readFully(data);
...@@ -661,7 +671,7 @@ public class PgServerThread implements Runnable { ...@@ -661,7 +671,7 @@ public class PgServerThread implements Runnable {
String name = meta.getColumnName(i + 1); String name = meta.getColumnName(i + 1);
names[i] = name; names[i] = name;
int type = meta.getColumnType(i + 1); int type = meta.getColumnType(i + 1);
type = PgServer.convertType(type); int pgType = PgServer.convertType(type);
// the ODBC client needs the column pg_catalog.pg_index // the ODBC client needs the column pg_catalog.pg_index
// to be of type 'int2vector' // to be of type 'int2vector'
// if (name.equalsIgnoreCase("indkey") && // if (name.equalsIgnoreCase("indkey") &&
...@@ -669,8 +679,10 @@ public class PgServerThread implements Runnable { ...@@ -669,8 +679,10 @@ public class PgServerThread implements Runnable {
// type = PgServer.PG_TYPE_INT2VECTOR; // type = PgServer.PG_TYPE_INT2VECTOR;
// } // }
precision[i] = meta.getColumnDisplaySize(i + 1); precision[i] = meta.getColumnDisplaySize(i + 1);
server.checkType(type); if (type!=Types.NULL) {
types[i] = type; server.checkType(pgType);
}
types[i] = pgType;
} }
startMessage('T'); startMessage('T');
writeShort(columns); writeShort(columns);
...@@ -705,6 +717,8 @@ public class PgServerThread implements Runnable { ...@@ -705,6 +717,8 @@ public class PgServerThread implements Runnable {
private static int getTypeSize(int pgType, int precision) { private static int getTypeSize(int pgType, int precision) {
switch (pgType) { switch (pgType) {
case PgServer.PG_TYPE_BOOL:
return 1;
case PgServer.PG_TYPE_VARCHAR: case PgServer.PG_TYPE_VARCHAR:
return Math.max(255, precision + 10); return Math.max(255, precision + 10);
default: default:
......
...@@ -42,7 +42,9 @@ create table pg_catalog.pg_type( ...@@ -42,7 +42,9 @@ create table pg_catalog.pg_type(
typlen int, typlen int,
typtype varchar, typtype varchar,
typbasetype int, typbasetype int,
typtypmod int); typtypmod int,
typnotnull boolean
);
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
...@@ -53,7 +55,8 @@ select ...@@ -53,7 +55,8 @@ select
-1 typlen, -1 typlen,
'c' typtype, 'c' typtype,
0 typbasetype, 0 typbasetype,
-1 typtypmod -1 typtypmod,
false typnotnull
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
...@@ -65,7 +68,8 @@ merge into pg_catalog.pg_type values( ...@@ -65,7 +68,8 @@ merge into pg_catalog.pg_type values(
-1, -1,
'c', 'c',
0, 0,
-1 -1,
false
); );
merge into pg_catalog.pg_type values( merge into pg_catalog.pg_type values(
0, 0,
...@@ -74,7 +78,8 @@ merge into pg_catalog.pg_type values( ...@@ -74,7 +78,8 @@ merge into pg_catalog.pg_type values(
-1, -1,
'c', 'c',
0, 0,
-1 -1,
false
); );
merge into pg_catalog.pg_type values( merge into pg_catalog.pg_type values(
22, 22,
...@@ -83,7 +88,8 @@ merge into pg_catalog.pg_type values( ...@@ -83,7 +88,8 @@ merge into pg_catalog.pg_type values(
-1, -1,
'c', 'c',
0, 0,
-1 -1,
false
); );
create view pg_catalog.pg_class -- (oid, relname, relnamespace, relkind, relam, reltuples, relpages, relhasrules, relhasoids) create view pg_catalog.pg_class -- (oid, relname, relnamespace, relkind, relam, reltuples, relpages, relhasrules, relhasoids)
...@@ -140,7 +146,8 @@ select ...@@ -140,7 +146,8 @@ select
id oid, id oid,
0 adsrc, 0 adsrc,
0 adrelid, 0 adrelid,
0 adnum 0 adnum,
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;
...@@ -179,7 +186,7 @@ and t.table_name = c.table_name ...@@ -179,7 +186,7 @@ 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) create view pg_catalog.pg_index -- (oid, indexrelid, indrelid, indisclustered, indisunique, indisprimary, indexprs, indkey, indpred)
as as
select select
i.id oid, i.id oid,
...@@ -189,7 +196,8 @@ select ...@@ -189,7 +196,8 @@ select
not non_unique indisunique, not non_unique indisunique,
primary_key indisprimary, primary_key indisprimary,
cast('' as varchar_ignorecase) indexprs, cast('' as varchar_ignorecase) indexprs,
cast(1 as array) indkey cast(1 as array) indkey,
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
...@@ -201,6 +209,12 @@ grant select on pg_catalog.pg_index to public; ...@@ -201,6 +209,12 @@ 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";
drop alias if exists pg_catalog.pg_get_indexdef;
create alias pg_catalog.pg_get_indexdef for "org.h2.server.pg.PgServer.getIndexColumn";
drop alias if exists pg_catalog.pg_get_expr;
create alias pg_catalog.pg_get_expr for "org.h2.server.pg.PgServer.getPgExpr";
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";
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论