Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit454f44e

Browse files
committed
Attached is a patch to remove some redundant code in the JDBC driver.
* Merges identical code from org.postgresql.jdbc[1|2].Statement into org.postgresql.Statement.* Moves escapeSQL() method from Connection to Statement (the only place it's used)* Minor cleanup of the new isolation level stuff.* Minor cleanup of version string handling.Anders Bengtsson
1 parent13923be commit454f44e

File tree

4 files changed

+265
-508
lines changed

4 files changed

+265
-508
lines changed

‎src/interfaces/jdbc/org/postgresql/Connection.java

Lines changed: 31 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
importorg.postgresql.core.Encoding;
1212

1313
/**
14-
* $Id: Connection.java,v 1.24 2001/08/07 17:45:29 momjian Exp $
14+
* $Id: Connection.java,v 1.25 2001/08/10 14:42:07 momjian Exp $
1515
*
1616
* This abstract class is used by org.postgresql.Driver to open either the JDBC1 or
1717
* JDBC2 versions of the Connection class.
@@ -37,7 +37,6 @@ public abstract class Connection
3737
*/
3838
privateEncodingencoding =Encoding.defaultEncoding();
3939

40-
privateStringdbVersionLong;
4140
privateStringdbVersionNumber;
4241

4342
publicbooleanCONNECTION_OK =true;
@@ -257,8 +256,6 @@ protected void openConnection(String host, int port, Properties info, String dat
257256

258257
firstWarning =null;
259258

260-
StringdbEncoding;
261-
262259
// "pg_encoding_to_char(1)" will return 'EUC_JP' for a backend compiled with multibyte,
263260
// otherwise it's hardcoded to 'SQL_ASCII'.
264261
// If the backend doesn't know about multibyte we can't assume anything about the encoding
@@ -276,8 +273,10 @@ protected void openConnection(String host, int port, Properties info, String dat
276273
if (!resultSet.next()) {
277274
thrownewPSQLException("postgresql.con.failed","failed getting backend encoding");
278275
}
279-
dbVersionLong =resultSet.getString(1);
280-
dbEncoding =resultSet.getString(2);
276+
Stringversion =resultSet.getString(1);
277+
dbVersionNumber =extractVersionNumber(version);
278+
279+
StringdbEncoding =resultSet.getString(2);
281280
encoding =Encoding.getEncoding(dbEncoding,info.getProperty("charSet"));
282281

283282
// Initialise object handling
@@ -1002,25 +1001,22 @@ public void setTransactionIsolation(int level) throws SQLException {
10021001
//this can be simplified
10031002
isolationLevel =level;
10041003
StringisolationLevelSQL;
1005-
switch(isolationLevel) {
1006-
casejava.sql.Connection.TRANSACTION_READ_COMMITTED:
1007-
if (haveMinimumServerVersion("7.1")) {
1008-
isolationLevelSQL ="SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED";
1009-
}else {
1010-
isolationLevelSQL =getIsolationLevelSQL();
1011-
}
1012-
break;
1013-
1014-
casejava.sql.Connection.TRANSACTION_SERIALIZABLE:
1015-
if (haveMinimumServerVersion("7.1")) {
1016-
isolationLevelSQL ="SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE";
1017-
}else {
1018-
isolationLevelSQL =getIsolationLevelSQL();
1019-
}
1020-
break;
10211004

1022-
default:
1023-
thrownewPSQLException("postgresql.con.isolevel",newInteger(isolationLevel));
1005+
if (!haveMinimumServerVersion("7.1")) {
1006+
isolationLevelSQL =getIsolationLevelSQL();
1007+
}else {
1008+
isolationLevelSQL ="SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL ";
1009+
switch(isolationLevel) {
1010+
casejava.sql.Connection.TRANSACTION_READ_COMMITTED:
1011+
isolationLevelSQL +="READ COMMITTED";
1012+
break;
1013+
casejava.sql.Connection.TRANSACTION_SERIALIZABLE:
1014+
isolationLevelSQL +="SERIALIZABLE";
1015+
break;
1016+
default:
1017+
thrownewPSQLException("postgresql.con.isolevel",
1018+
newInteger(isolationLevel));
1019+
}
10241020
}
10251021
ExecSQL(isolationLevelSQL);
10261022
}
@@ -1094,59 +1090,23 @@ public void finalize() throws Throwable
10941090
close();
10951091
}
10961092

1097-
/**
1098-
* This is an attempt to implement SQL Escape clauses
1099-
*/
1100-
publicStringEscapeSQL(Stringsql) {
1101-
//if (DEBUG) { System.out.println ("parseSQLEscapes called"); }
1102-
1103-
// If we find a "{d", assume we have a date escape.
1104-
//
1105-
// Since the date escape syntax is very close to the
1106-
// native Postgres date format, we just remove the escape
1107-
// delimiters.
1108-
//
1109-
// This implementation could use some optimization, but it has
1110-
// worked in practice for two years of solid use.
1111-
intindex =sql.indexOf("{d");
1112-
while (index != -1) {
1113-
//System.out.println ("escape found at index: " + index);
1114-
StringBufferbuf =newStringBuffer(sql);
1115-
buf.setCharAt(index,' ');
1116-
buf.setCharAt(index +1,' ');
1117-
buf.setCharAt(sql.indexOf('}',index),' ');
1118-
sql =newString(buf);
1119-
index =sql.indexOf("{d");
1120-
}
1121-
//System.out.println ("modified SQL: " + sql);
1122-
returnsql;
1123-
}
1124-
1125-
/**
1126-
* What is the version of the server
1127-
*
1128-
* @return the database version
1129-
* @exception SQLException if a database access error occurs
1130-
*/
1131-
publicStringgetDBVersionNumber()throwsSQLException
1093+
privatestaticStringextractVersionNumber(StringfullVersionString)
11321094
{
1133-
if(dbVersionNumber ==null) {
1134-
StringTokenizerversionParts =newStringTokenizer(dbVersionLong);
1095+
StringTokenizerversionParts =newStringTokenizer(fullVersionString);
11351096
versionParts.nextToken();/* "PostgreSQL" */
1136-
dbVersionNumber =versionParts.nextToken();/* "X.Y.Z" */
1137-
}
1138-
returndbVersionNumber;
1097+
returnversionParts.nextToken();/* "X.Y.Z" */
11391098
}
11401099

1100+
/**
1101+
* Get server version number
1102+
*/
1103+
publicStringgetDBVersionNumber() {
1104+
returndbVersionNumber;
1105+
}
1106+
11411107
publicbooleanhaveMinimumServerVersion(Stringver)throwsSQLException
11421108
{
1143-
if (getDBVersionNumber().compareTo(ver)>=0)
1144-
returntrue;
1145-
else
1146-
returnfalse;
1109+
return (getDBVersionNumber().compareTo(ver) >=0);
11471110
}
1148-
1149-
1150-
11511111
}
11521112

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp