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

Commit05a966f

Browse files
author
Barry Lind
committed
Applied patch from Paul Sorenson to correctly handle schema names in updateable result sets.
Applied patch from Rich Cullingford to fix a NPE in the absolute() method of result set.Applied patch from Tarjei Skorgenes to fix a NPE when logging is enabled. Modified Files: jdbc/org/postgresql/core/BaseResultSet.java jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java jdbc/org/postgresql/jdbc2/Array.java jdbc/org/postgresql/util/PSQLException.java
1 parentf93672e commit05a966f

File tree

4 files changed

+111
-33
lines changed

4 files changed

+111
-33
lines changed

‎src/interfaces/jdbc/org/postgresql/core/BaseResultSet.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 2003, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/BaseResultSet.java,v 1.1 2003/03/07 18:39:41 barry Exp $
9+
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/BaseResultSet.java,v 1.2 2003/03/08 06:06:55 barry Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -16,16 +16,19 @@
1616
importjava.sql.ResultSet;
1717
importjava.sql.ResultSetMetaData;
1818
importjava.sql.SQLException;
19+
importjava.text.SimpleDateFormat;
1920
importjava.util.Vector;
2021

2122
publicinterfaceBaseResultSet
2223
{
24+
2325
publicBaseStatementgetPGStatement();
2426

2527
publicvoidappend(BaseResultSetr);
2628
publicvoidclose()throwsSQLException;
2729
publicintgetColumnCount();
2830
publicStringgetCursorName()throwsSQLException;
31+
publicSimpleDateFormatgetDateFormat();
2932
publicStringgetFixedString(intcol)throwsSQLException;
3033
publiclonggetLastOID();
3134
publicResultSetMetaDatagetMetaData()throwsSQLException;
@@ -35,6 +38,8 @@ public interface BaseResultSet
3538
publicStringgetStatusString();
3639
publicStringgetString(intcolumnIndex)throwsSQLException;
3740
publicStringBuffergetStringBuffer();
41+
publicSimpleDateFormatgetTimestampFormat();
42+
publicSimpleDateFormatgetTimestampTZFormat();
3843
publicintgetTupleCount();
3944
publicbooleannext()throwsSQLException;
4045
publicbooleanreallyResultSet();

‎src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* AbstractJdbc1ResultSet.java
4+
* This class defines methods of the jdbc1 specification. This class is
5+
* extended by org.postgresql.jdbc2.AbstractJdbc2ResultSet which adds the
6+
* jdbc2 methods. The real ResultSet class (for jdbc1) is
7+
* org.postgresql.jdbc1.Jdbc1ResultSet
8+
*
9+
* Copyright (c) 2003, PostgreSQL Global Development Group
10+
*
11+
* IDENTIFICATION
12+
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.11 2003/03/08 06:06:55 barry Exp $
13+
*
14+
*-------------------------------------------------------------------------
15+
*/
116
packageorg.postgresql.jdbc1;
217

3-
418
importjava.math.BigDecimal;
519
importjava.io.*;
620
importjava.sql.*;
@@ -19,11 +33,6 @@
1933
importorg.postgresql.util.PGtokenizer;
2034
importorg.postgresql.util.PSQLException;
2135

22-
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.10 2003/03/07 18:39:44 barry Exp $
23-
* This class defines methods of the jdbc1 specification. This class is
24-
* extended by org.postgresql.jdbc2.AbstractJdbc2ResultSet which adds the jdbc2
25-
* methods. The real ResultSet class (for jdbc1) is org.postgresql.jdbc1.Jdbc1ResultSet
26-
*/
2736
publicabstractclassAbstractJdbc1ResultSetimplementsBaseResultSet
2837
{
2938

@@ -47,6 +56,10 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
4756
privateStringBuffersbuf =null;
4857
publicbyte[][]rowBuffer =null;
4958

59+
privateSimpleDateFormatm_tsFormat =null;
60+
privateSimpleDateFormatm_tstzFormat =null;
61+
privateSimpleDateFormatm_dateFormat =null;
62+
5063
publicabstractResultSetMetaDatagetMetaData()throwsSQLException;
5164

5265
publicAbstractJdbc1ResultSet(BaseStatementstatement,
@@ -1020,7 +1033,7 @@ public static Timestamp toTimestamp(String s, BaseResultSet resultSet, String pg
10201033
l_sbuf.append(":00");
10211034

10221035
// we'll use this dateformat string to parse the result.
1023-
df =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
1036+
df =rs.getTimestampTZFormat();
10241037
}
10251038
else
10261039
{
@@ -1029,11 +1042,11 @@ public static Timestamp toTimestamp(String s, BaseResultSet resultSet, String pg
10291042
if (pgDataType.equals("timestamptz"))
10301043
{
10311044
l_sbuf.append(" GMT");
1032-
df =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
1045+
df =rs.getTimestampTZFormat();
10331046
}
10341047
else
10351048
{
1036-
df =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");
1049+
df =rs.getTimestampFormat();
10371050
}
10381051
}
10391052
}
@@ -1044,11 +1057,11 @@ else if (slen == 19)
10441057
if (pgDataType.equals("timestamptz"))
10451058
{
10461059
l_sbuf.append(" GMT");
1047-
df =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
1060+
df =rs.getTimestampTZFormat();
10481061
}
10491062
else
10501063
{
1051-
df =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");
1064+
df =rs.getTimestampFormat();
10521065
}
10531066
}
10541067
else
@@ -1065,7 +1078,7 @@ else if (slen == 19)
10651078
// We must just have a date. This case is
10661079
// needed if this method is called on a date
10671080
// column
1068-
df =newSimpleDateFormat("yyyy-MM-dd");
1081+
df =rs.getDateFormat();
10691082
}
10701083

10711084
try
@@ -1075,8 +1088,7 @@ else if (slen == 19)
10751088
Driver.debug("the data after parsing is "
10761089
+l_sbuf.toString() +" with " +nanos +" nanos");
10771090

1078-
Timestampresult =
1079-
newTimestamp(df.parse(l_sbuf.toString()).getTime());
1091+
Timestampresult =newTimestamp(df.parse(l_sbuf.toString()).getTime());
10801092
result.setNanos(nanos);
10811093
returnresult;
10821094
}
@@ -1087,7 +1099,23 @@ else if (slen == 19)
10871099
}
10881100
}
10891101

1090-
1091-
1102+
publicSimpleDateFormatgetTimestampTZFormat() {
1103+
if (m_tstzFormat ==null) {
1104+
m_tstzFormat =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
1105+
}
1106+
returnm_tstzFormat;
1107+
}
1108+
publicSimpleDateFormatgetTimestampFormat() {
1109+
if (m_tsFormat ==null) {
1110+
m_tsFormat =newSimpleDateFormat ("yyyy-MM-dd HH:mm:ss");
1111+
}
1112+
returnm_tsFormat;
1113+
}
1114+
publicSimpleDateFormatgetDateFormat() {
1115+
if (m_dateFormat ==null) {
1116+
m_dateFormat =newSimpleDateFormat("yyyy-MM-dd");
1117+
}
1118+
returnm_dateFormat;
1119+
}
10921120
}
10931121

‎src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
importorg.postgresql.util.PSQLException;
1717

1818

19-
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2ResultSet.java,v 1.15 2003/03/07 18:39:45 barry Exp $
19+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2ResultSet.java,v 1.16 2003/03/08 06:06:55 barry Exp $
2020
* This class defines methods of the jdbc2 specification. This class extends
2121
* org.postgresql.jdbc1.AbstractJdbc1ResultSet which provides the jdbc1
2222
* methods. The real Statement class (for jdbc2) is org.postgresql.jdbc2.Jdbc2ResultSet
@@ -188,6 +188,10 @@ public boolean absolute(int index) throws SQLException
188188

189189
current_row =internalIndex;
190190
this_row = (byte[][])rows.elementAt(internalIndex);
191+
192+
rowBuffer =newbyte[this_row.length][];
193+
System.arraycopy(this_row,0,rowBuffer,0,this_row.length);
194+
191195
returntrue;
192196
}
193197

@@ -1319,18 +1323,10 @@ boolean isUpdateable() throws SQLException
13191323
else
13201324
{
13211325
// otherwise go and get the primary keys and create a hashtable of keys
1322-
// if the user has supplied a quoted table name
1323-
// remove the quotes, but preserve the case.
1324-
// otherwise fold to lower case.
1325-
StringquotelessTableName;
1326-
if (tableName.startsWith("\"") &&tableName.endsWith("\"")) {
1327-
quotelessTableName =tableName.substring(1,tableName.length()-1);
1328-
}else {
1329-
quotelessTableName =tableName.toLowerCase();
1330-
}
1331-
java.sql.ResultSetrs = ((java.sql.Connection)connection).getMetaData().getPrimaryKeys("","",quotelessTableName);
1332-
1333-
1326+
String[]s =quotelessTableName(tableName);
1327+
StringquotelessTableName =s[0];
1328+
StringquotelessSchemaName =s[1];
1329+
java.sql.ResultSetrs = ((java.sql.Connection)connection).getMetaData().getPrimaryKeys("",quotelessSchemaName,quotelessTableName);
13341330
for (;rs.next();i++ )
13351331
{
13361332
StringcolumnName =rs.getString(4);// get the columnName
@@ -1363,7 +1359,56 @@ boolean isUpdateable() throws SQLException
13631359
returnupdateable;
13641360
}
13651361

1366-
1362+
/** Cracks out the table name and schema (if it exists) from a fully
1363+
* qualified table name.
1364+
* @param fullname string that we are trying to crack.Test cases:<pre>
1365+
* Table: table ()
1366+
* "Table": Table ()
1367+
* Schema.Table: table (schema)
1368+
* "Schema"."Table": Table (Schema)
1369+
* "Schema"."Dot.Table": Dot.Table (Schema)
1370+
* Schema."Dot.Table": Dot.Table (schema)
1371+
* </pre>
1372+
* @return String array with element zero always being the tablename and
1373+
* element 1 the schema name which may be a zero length string.
1374+
*/
1375+
publicstaticString[]quotelessTableName(Stringfullname) {
1376+
StringBufferbuf =newStringBuffer(fullname);
1377+
String[]parts =newString[] {null,""};
1378+
StringBufferacc =newStringBuffer();
1379+
booleanbetweenQuotes =false;
1380+
for (inti =0;i <buf.length();i++) {
1381+
charc =buf.charAt(i);
1382+
switch (c) {
1383+
case'"':
1384+
if ((i <buf.length() -1) && (buf.charAt(i+1) =='"')) {
1385+
// two consecutive quotes - keep one
1386+
i++;
1387+
acc.append(c);// keep the quote
1388+
}
1389+
else {// Discard it
1390+
betweenQuotes = !betweenQuotes;
1391+
}
1392+
break;
1393+
case'.':
1394+
if (betweenQuotes) {// Keep it
1395+
acc.append(c);
1396+
}
1397+
else {// Have schema name
1398+
parts[1] =acc.toString();
1399+
acc =newStringBuffer();
1400+
}
1401+
break;
1402+
default:
1403+
acc.append((betweenQuotes) ?c :Character.toLowerCase(c));
1404+
break;
1405+
}
1406+
}
1407+
// Always put table in slot 0
1408+
parts[0] =acc.toString();
1409+
returnparts;
1410+
}
1411+
13671412
publicvoidparseQuery()
13681413
{
13691414
String[]l_sqlFragments = ((AbstractJdbc2Statement)statement).getSqlFragments();

‎src/interfaces/jdbc/org/postgresql/util/PSQLException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 2003, PostgreSQL Global Development Group
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/util/Attic/PSQLException.java,v 1.9 2003/03/07 18:39:46 barry Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/util/Attic/PSQLException.java,v 1.10 2003/03/08 06:06:55 barry Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -122,6 +122,6 @@ public String getMessage()
122122
*/
123123
publicStringtoString()
124124
{
125-
returnmessage;
125+
returnmessage !=null ?message :"";
126126
}
127127
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp