提交 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
</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 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>
<h2>Version 1.3.172 (2013-05-25)</h2>
......
......@@ -456,6 +456,14 @@ public class PgServer implements Service {
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
*
......
......@@ -25,6 +25,7 @@ import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Properties;
......@@ -341,8 +342,7 @@ public class PgServerThread implements Runnable {
if (result) {
try {
ResultSet rs = prep.getResultSet();
ResultSetMetaData meta = rs.getMetaData();
sendRowDescription(meta);
// the meta-data is sent in the prior 'Describe'
while (rs.next()) {
sendDataRow(rs);
}
......@@ -483,13 +483,21 @@ public class PgServerThread implements Runnable {
private void writeDataColumn(ResultSet rs, int column, int pgType) throws Exception {
if (formatAsText(pgType)) {
String s = rs.getString(column);
if (s==null) {
writeInt(-1);
} else {
byte[] data = s.getBytes(getEncoding());
writeInt(data.length);
write(data);
// plain text
switch (pgType) {
case PgServer.PG_TYPE_BOOL:
writeInt(1);
dataOut.writeByte(rs.getBoolean(column) ? 't' : 'f');
break;
default:
String s = rs.getString(column);
if (s==null) {
writeInt(-1);
} else {
byte[] data = s.getBytes(getEncoding());
writeInt(data.length);
write(data);
}
}
} else {
// binary
......@@ -540,7 +548,9 @@ public class PgServerThread implements Runnable {
boolean text = (i >= formatCodes.length) || (formatCodes[i] == 0);
int col = i + 1;
int paramLen = readInt();
if (text) {
if (paramLen==-1) {
prep.setNull(i, Types.NULL);
} else if (text) {
// plain text
byte[] data = DataUtils.newBytes(paramLen);
readFully(data);
......@@ -661,7 +671,7 @@ public class PgServerThread implements Runnable {
String name = meta.getColumnName(i + 1);
names[i] = name;
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
// to be of type 'int2vector'
// if (name.equalsIgnoreCase("indkey") &&
......@@ -669,8 +679,10 @@ public class PgServerThread implements Runnable {
// type = PgServer.PG_TYPE_INT2VECTOR;
// }
precision[i] = meta.getColumnDisplaySize(i + 1);
server.checkType(type);
types[i] = type;
if (type!=Types.NULL) {
server.checkType(pgType);
}
types[i] = pgType;
}
startMessage('T');
writeShort(columns);
......@@ -705,6 +717,8 @@ public class PgServerThread implements Runnable {
private static int getTypeSize(int pgType, int precision) {
switch (pgType) {
case PgServer.PG_TYPE_BOOL:
return 1;
case PgServer.PG_TYPE_VARCHAR:
return Math.max(255, precision + 10);
default:
......
......@@ -42,7 +42,9 @@ create table pg_catalog.pg_type(
typlen int,
typtype varchar,
typbasetype int,
typtypmod int);
typtypmod int,
typnotnull boolean
);
grant select on pg_catalog.pg_type to public;
insert into pg_catalog.pg_type
......@@ -53,7 +55,8 @@ select
-1 typlen,
'c' typtype,
0 typbasetype,
-1 typtypmod
-1 typtypmod,
false typnotnull
from information_schema.type_info
where pos = 0
and pg_convertType(data_type) <> 705; -- not unknown
......@@ -65,7 +68,8 @@ merge into pg_catalog.pg_type values(
-1,
'c',
0,
-1
-1,
false
);
merge into pg_catalog.pg_type values(
0,
......@@ -74,7 +78,8 @@ merge into pg_catalog.pg_type values(
-1,
'c',
0,
-1
-1,
false
);
merge into pg_catalog.pg_type values(
22,
......@@ -83,7 +88,8 @@ merge into pg_catalog.pg_type values(
-1,
'c',
0,
-1
-1,
false
);
create view pg_catalog.pg_class -- (oid, relname, relnamespace, relkind, relam, reltuples, relpages, relhasrules, relhasoids)
......@@ -140,7 +146,8 @@ select
id oid,
0 adsrc,
0 adrelid,
0 adnum
0 adnum,
null adbin
from information_schema.tables where 1=0;
grant select on pg_catalog.pg_attrdef to public;
......@@ -179,7 +186,7 @@ and t.table_name = c.table_name
and t.table_schema = c.table_schema;
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
select
i.id oid,
......@@ -189,7 +196,8 @@ select
not non_unique indisunique,
primary_key indisprimary,
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
where i.table_schema = t.table_schema
and i.table_name = t.table_name
......@@ -201,6 +209,12 @@ grant select on pg_catalog.pg_index to public;
drop alias if exists pg_get_indexdef;
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;
create alias version for "org.h2.server.pg.PgServer.getVersion";
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论