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

ODBC: MS Access could not link to a table with unique index or primary key.

上级 ab39b595
...@@ -46,6 +46,11 @@ public class PgServer implements Service { ...@@ -46,6 +46,11 @@ public class PgServer implements Service {
*/ */
public static final int PG_TYPE_VARCHAR = 1043; public static final int PG_TYPE_VARCHAR = 1043;
/**
* The integer array type (for the column pg_index.indkey).
*/
public static final int PG_TYPE_INT2VECTOR = 22;
private static final int PG_TYPE_BOOL = 16; private static final int PG_TYPE_BOOL = 16;
private static final int PG_TYPE_BYTEA = 17; private static final int PG_TYPE_BYTEA = 17;
private static final int PG_TYPE_BPCHAR = 1042; private static final int PG_TYPE_BPCHAR = 1042;
...@@ -269,7 +274,7 @@ public class PgServer implements Service { ...@@ -269,7 +274,7 @@ public class PgServer implements Service {
if (rs.next()) { if (rs.next()) {
return rs.getString(1); return rs.getString(1);
} }
return null; return "";
} }
PreparedStatement prep = conn.prepareStatement("select column_name from information_schema.indexes where id=? and ordinal_position=?"); PreparedStatement prep = conn.prepareStatement("select column_name from information_schema.indexes where id=? and ordinal_position=?");
prep.setInt(1, indexId); prep.setInt(1, indexId);
...@@ -278,7 +283,7 @@ public class PgServer implements Service { ...@@ -278,7 +283,7 @@ public class PgServer implements Service {
if (rs.next()) { if (rs.next()) {
return rs.getString(1); return rs.getString(1);
} }
return null; return "";
} }
/** /**
......
...@@ -516,9 +516,16 @@ public class PgServerThread implements Runnable { ...@@ -516,9 +516,16 @@ public class PgServerThread implements Runnable {
int[] precision = new int[columns]; int[] precision = new int[columns];
String[] names = new String[columns]; String[] names = new String[columns];
for (int i = 0; i < columns; i++) { for (int i = 0; i < columns; i++) {
names[i] = meta.getColumnName(i + 1); String name = meta.getColumnName(i + 1);
names[i] = name;
int type = meta.getColumnType(i + 1); int type = meta.getColumnType(i + 1);
type = PgServer.convertType(type); type = PgServer.convertType(type);
// the ODBC client needs the column pg_catalog.pg_index
// to be of type 'int2vector'
// if (name.equalsIgnoreCase("indkey") &&
// "pg_index".equalsIgnoreCase(meta.getTableName(i + 1))) {
// type = PgServer.PG_TYPE_INT2VECTOR;
// }
precision[i] = meta.getColumnDisplaySize(i + 1); precision[i] = meta.getColumnDisplaySize(i + 1);
server.checkType(type); server.checkType(type);
types[i] = type; types[i] = type;
......
...@@ -72,6 +72,15 @@ merge into pg_catalog.pg_type values( ...@@ -72,6 +72,15 @@ merge into pg_catalog.pg_type values(
0, 0,
-1 -1
); );
merge into pg_catalog.pg_type values(
22,
'int2vector',
(select oid from pg_catalog.pg_namespace where nspname = 'pg_catalog'),
-1,
'c',
0,
-1
);
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)
as as
...@@ -134,10 +143,10 @@ select ...@@ -134,10 +143,10 @@ select
t.id attrelid, t.id attrelid,
c.column_name attname, c.column_name attname,
pg_convertType(data_type) atttypid, pg_convertType(data_type) atttypid,
-1 attlen, case when numeric_precision > 255 then -1 else numeric_precision end attlen,
c.ordinal_position attnum, c.ordinal_position attnum,
-1 atttypmod, -1 atttypmod,
false 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
...@@ -149,10 +158,10 @@ select ...@@ -149,10 +158,10 @@ select
i.id attrelid, i.id attrelid,
c.column_name attname, c.column_name attname,
pg_convertType(data_type) atttypid, pg_convertType(data_type) atttypid,
-1 attlen, case when numeric_precision > 255 then -1 else numeric_precision end attlen,
c.ordinal_position attnum, c.ordinal_position attnum,
-1 atttypmod, -1 atttypmod,
false 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
...@@ -171,11 +180,13 @@ select ...@@ -171,11 +180,13 @@ 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(0 as array) indkey cast(1 as array) indkey
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
and 1=0;
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";
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论