提交 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 {
*/
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_BYTEA = 17;
private static final int PG_TYPE_BPCHAR = 1042;
......@@ -269,7 +274,7 @@ public class PgServer implements Service {
if (rs.next()) {
return rs.getString(1);
}
return null;
return "";
}
PreparedStatement prep = conn.prepareStatement("select column_name from information_schema.indexes where id=? and ordinal_position=?");
prep.setInt(1, indexId);
......@@ -278,7 +283,7 @@ public class PgServer implements Service {
if (rs.next()) {
return rs.getString(1);
}
return null;
return "";
}
/**
......
......@@ -516,9 +516,16 @@ public class PgServerThread implements Runnable {
int[] precision = new int[columns];
String[] names = new String[columns];
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);
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);
server.checkType(type);
types[i] = type;
......
......@@ -72,6 +72,15 @@ merge into pg_catalog.pg_type values(
0,
-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)
as
......@@ -134,10 +143,10 @@ select
t.id attrelid,
c.column_name attname,
pg_convertType(data_type) atttypid,
-1 attlen,
case when numeric_precision > 255 then -1 else numeric_precision end attlen,
c.ordinal_position attnum,
-1 atttypmod,
false attnotnull,
case c.is_nullable when 'YES' then false else true end attnotnull,
false attisdropped,
false atthasdef
from information_schema.tables t, information_schema.columns c
......@@ -149,10 +158,10 @@ select
i.id attrelid,
c.column_name attname,
pg_convertType(data_type) atttypid,
-1 attlen,
case when numeric_precision > 255 then -1 else numeric_precision end attlen,
c.ordinal_position attnum,
-1 atttypmod,
false attnotnull,
case c.is_nullable when 'YES' then false else true end attnotnull,
false attisdropped,
false atthasdef
from information_schema.tables t, information_schema.indexes i, information_schema.columns c
......@@ -171,11 +180,13 @@ select
not non_unique indisunique,
primary_key indisprimary,
cast('' as varchar_ignorecase) indexprs,
cast(0 as array) indkey
cast(1 as array) indkey
from information_schema.indexes i, information_schema.tables t
where i.table_schema = t.table_schema
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;
create alias pg_get_indexdef for "org.h2.server.pg.PgServer.getIndexColumn";
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论