提交 3f4f0e3f authored 作者: Thomas Mueller's avatar Thomas Mueller

ODBC: MS Access could not link to a table with a name containing '_'.

上级 276ad6f5
......@@ -2373,6 +2373,9 @@ public class Parser {
r = ValueExpression.get(ValueTimestamp.getNoCopy(ValueTimestamp.parseTimestamp(timestamp)));
} else if (equalsToken("E", name) && currentTokenType == VALUE && currentValue.getType() == Value.STRING) {
String text = currentValue.getString();
// the PostgreSQL ODBC driver uses
// LIKE E'PROJECT\\_DATA' instead of LIKE 'PROJECT\_DATA'
text = StringUtils.replaceAll(text, "\\\\", "\\");
read();
r = ValueExpression.get(ValueString.get(text));
} else {
......@@ -2476,11 +2479,21 @@ public class Parser {
}
if (readIf("::")) {
// PostgreSQL compatibility
Column col = parseColumn(null);
Function function = Function.getFunction(database, "CAST");
function.setDataType(col);
function.setParameter(0, r);
r = function;
if (readIf("REGCLASS")) {
FunctionAlias f = findFunctionAlias(Constants.SCHEMA_MAIN, "PG_GET_OID");
if (f == null) {
throw getSyntaxError();
}
Expression[] args = { r };
JavaFunction func = new JavaFunction(f, args);
r = func;
} else {
Column col = parseColumn(null);
Function function = Function.getFunction(database, "CAST");
function.setDataType(col);
function.setParameter(0, r);
r = function;
}
}
return r;
}
......@@ -4090,7 +4103,6 @@ public class Parser {
return command;
}
private AlterSequence parseAlterSequence() {
String sequenceName = readIdentifierWithSchema();
Sequence sequence = getSchema().getSequence(sequenceName);
......
......@@ -294,6 +294,27 @@ public class PgServer implements Service {
return rs.getString(1);
}
/**
* Get the OID of an object.
* This method is called by the database.
*
* @param conn the connection
* @param tableName the table name
* @return the oid
*/
public static int getOid(Connection conn, String tableName) throws SQLException {
if (tableName.startsWith("\"") && tableName.endsWith("\"")) {
tableName = tableName.substring(1, tableName.length() - 1);
}
PreparedStatement prep = conn.prepareStatement("select oid from pg_class where relname = ?");
prep.setString(1, tableName);
ResultSet rs = prep.executeQuery();
if (!rs.next()) {
return 0;
}
return rs.getInt(1);
}
/**
* Get the name of this encoding code.
* This method is called by the database.
......
......@@ -11,6 +11,9 @@ create schema pg_catalog;
drop alias if exists pg_convertType;
create alias pg_convertType deterministic for "org.h2.server.pg.PgServer.convertType";
drop alias if exists pg_get_oid;
create alias pg_get_oid deterministic for "org.h2.server.pg.PgServer.getOid";
create table pg_catalog.pg_version as select 1 as version;
create view pg_catalog.pg_roles -- (oid, rolname, rolcreaterole, rolcreatedb)
......
select E'test\\test';
> test\test;
create table a(id int) as select null;
create table b(id int references a(id)) as select null;
delete from a;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论