提交 52ea313c authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 35e27cd5
...@@ -85,7 +85,7 @@ public class PgServer implements Service { ...@@ -85,7 +85,7 @@ public class PgServer implements Service {
url = "pg://localhost:" + port; url = "pg://localhost:" + port;
int testing; int testing;
// log = true; log = true;
} }
public String getURL() { public String getURL() {
......
...@@ -25,6 +25,8 @@ import java.sql.SQLException; ...@@ -25,6 +25,8 @@ import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.sql.Types; import java.sql.Types;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Properties; import java.util.Properties;
import org.h2.Driver; import org.h2.Driver;
...@@ -60,6 +62,7 @@ public class PgServerThread implements Runnable { ...@@ -60,6 +62,7 @@ public class PgServerThread implements Runnable {
private String dateStyle = "ISO"; private String dateStyle = "ISO";
private HashMap prepared = new HashMap(); private HashMap prepared = new HashMap();
private HashMap portals = new HashMap(); private HashMap portals = new HashMap();
private HashSet types = new HashSet();
PgServerThread(Socket socket, PgServer server) { PgServerThread(Socket socket, PgServer server) {
this.server = server; this.server = server;
...@@ -210,7 +213,9 @@ Limitations: ...@@ -210,7 +213,9 @@ Limitations:
int count = readShort(); int count = readShort();
p.paramType = new int[count]; p.paramType = new int[count];
for(int i=0; i<count; i++) { for(int i=0; i<count; i++) {
p.paramType[i] = readInt(); int type = readInt();
checkType(type);
p.paramType[i] = type;
} }
try { try {
p.prep = conn.prepareStatement(p.sql); p.prep = conn.prepareStatement(p.sql);
...@@ -369,6 +374,12 @@ Limitations: ...@@ -369,6 +374,12 @@ Limitations:
} }
} }
private void checkType(int type) {
if(types.contains(new Integer(type))) {
error("Unsupported type: " + type, null);
}
}
private String getSQL(String s) { private String getSQL(String s) {
String lower = s.toLowerCase(); String lower = s.toLowerCase();
int todo; int todo;
...@@ -483,11 +494,14 @@ Limitations: ...@@ -483,11 +494,14 @@ Limitations:
startMessage('t'); startMessage('t');
writeShort(count); writeShort(count);
for(int i=0; i<count; i++) { for(int i=0; i<count; i++) {
int type;
if(p.paramType != null && p.paramType[i] != 0) { if(p.paramType != null && p.paramType[i] != 0) {
writeInt(p.paramType[i]); type = p.paramType[i];
} else { } else {
writeInt(TYPE_STRING); type = TYPE_STRING;
} }
checkType(type);
writeInt(type);
} }
sendMessage(); sendMessage();
} catch(SQLException e) { } catch(SQLException e) {
...@@ -510,7 +524,9 @@ Limitations: ...@@ -510,7 +524,9 @@ Limitations:
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); names[i] = meta.getColumnName(i + 1);
types[i] = meta.getColumnType(i + 1); int type = meta.getColumnType(i + 1);
checkType(type);
types[i] = type;
} }
startMessage('T'); startMessage('T');
writeShort(columns); writeShort(columns);
...@@ -531,10 +547,11 @@ Limitations: ...@@ -531,10 +547,11 @@ Limitations:
} }
private int getType(int type) { private int getType(int type) {
switch(type) { int testing;
case Types.VARCHAR: // switch(type) {
return 19; // case Types.VARCHAR:
} // return 19;
// }
return type; return type;
} }
...@@ -573,6 +590,7 @@ Limitations: ...@@ -573,6 +590,7 @@ Limitations:
} }
private void initDb() throws SQLException { private void initDb() throws SQLException {
int todoUseVersionOnlyInitWhenRequired;
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
Reader r = new InputStreamReader(getClass().getResourceAsStream("pg_catalog.sql")); Reader r = new InputStreamReader(getClass().getResourceAsStream("pg_catalog.sql"));
r = new BufferedReader(r); r = new BufferedReader(r);
...@@ -585,6 +603,11 @@ Limitations: ...@@ -585,6 +603,11 @@ Limitations:
stat.execute(sql); stat.execute(sql);
} }
reader.close(); reader.close();
ResultSet rs = stat.executeQuery("SELECT OID FROM PG_CATALOG.PG_TYPE");
while(rs.next()) {
types.add(new Integer(rs.getInt(1)));
}
} }
// private void sendResultSet(ResultSet rs) throws SQLException, IOException { // private void sendResultSet(ResultSet rs) throws SQLException, IOException {
......
...@@ -25,7 +25,7 @@ select ...@@ -25,7 +25,7 @@ select
from information_schema.schemata; from information_schema.schemata;
create table pg_catalog.pg_type( create table pg_catalog.pg_type(
oid int, oid int primary key,
typname varchar_ignorecase, typname varchar_ignorecase,
typnamespace int, typnamespace int,
typlen int, typlen int,
...@@ -41,7 +41,7 @@ select ...@@ -41,7 +41,7 @@ select
from information_schema.type_info from information_schema.type_info
where pos = 0; where pos = 0;
insert into pg_catalog.pg_type values( merge into pg_catalog.pg_type values(
1111, 1111,
'name', 'name',
(select oid from pg_catalog.pg_namespace where nspname = 'pg_catalog'), (select oid from pg_catalog.pg_namespace where nspname = 'pg_catalog'),
...@@ -144,7 +144,7 @@ select ...@@ -144,7 +144,7 @@ select
false indisclustered, false indisclustered,
not non_unique indisunique, not non_unique indisunique,
primary_key indisprimary, primary_key indisprimary,
cast(null as varchar_ignorecase) indexprs, cast('' as varchar_ignorecase) indexprs,
cast(0 as array) indkey cast(0 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
......
...@@ -747,7 +747,7 @@ class WebThread extends Thread { ...@@ -747,7 +747,7 @@ class WebThread extends Thread {
buff.append("setNode("+treeIndex+", 0, 0, 'info', '" + PageParser.escapeJavaScript(version)+ "', null);\n"); buff.append("setNode("+treeIndex+", 0, 0, 'info', '" + PageParser.escapeJavaScript(version)+ "', null);\n");
buff.append("refreshQueryTables();"); buff.append("refreshQueryTables();");
session.put("tree", buff.toString()); session.put("tree", buff.toString());
} catch(SQLException e) { } catch(Exception e) {
session.put("tree", ""); session.put("tree", "");
session.put("error", getStackTrace(0, e)); session.put("error", getStackTrace(0, e));
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论