9
9
* Copyright (c) 2003, PostgreSQL Global Development Group
10
10
*
11
11
* IDENTIFICATION
12
- * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.14 2003/08/06 05:53:13 barry Exp $
12
+ * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.15 2003/08/24 22:10:09 barry Exp $
13
13
*
14
14
*-------------------------------------------------------------------------
15
15
*/
@@ -176,7 +176,7 @@ public String getString(int columnIndex) throws SQLException
176
176
return null ;
177
177
178
178
Encoding encoding = connection .getEncoding ();
179
- return encoding .decode (this_row [columnIndex - 1 ] );
179
+ return trimString ( columnIndex , encoding .decode (this_row [columnIndex - 1 ]) );
180
180
}
181
181
182
182
public boolean getBoolean (int columnIndex ) throws SQLException
@@ -303,11 +303,11 @@ else if (connection.haveMinimumCompatibleVersion("7.2"))
303
303
//Version 7.2 supports the bytea datatype for byte arrays
304
304
if (fields [columnIndex - 1 ].getPGType ().equals ("bytea" ))
305
305
{
306
- return PGbytea .toBytes (this_row [columnIndex - 1 ]);
306
+ return trimBytes ( columnIndex , PGbytea .toBytes (this_row [columnIndex - 1 ]) );
307
307
}
308
308
else
309
309
{
310
- return this_row [columnIndex - 1 ];
310
+ return trimBytes ( columnIndex , this_row [columnIndex - 1 ]) ;
311
311
}
312
312
}
313
313
else
@@ -320,11 +320,11 @@ else if (connection.haveMinimumCompatibleVersion("7.2"))
320
320
LargeObject lob = lom .open (getInt (columnIndex ));
321
321
byte buf [] = lob .read (lob .size ());
322
322
lob .close ();
323
- return buf ;
323
+ return trimBytes ( columnIndex , buf ) ;
324
324
}
325
325
else
326
326
{
327
- return this_row [columnIndex - 1 ];
327
+ return trimBytes ( columnIndex , this_row [columnIndex - 1 ]) ;
328
328
}
329
329
}
330
330
}
@@ -1143,7 +1143,54 @@ else if (slen == 19)
1143
1143
}
1144
1144
}
1145
1145
}
1146
+
1147
+ private boolean isColumnTrimmable (int columnIndex ) throws SQLException
1148
+ {
1149
+ switch (fields [columnIndex -1 ].getSQLType ())
1150
+ {
1151
+ case Types .CHAR :
1152
+ case Types .VARCHAR :
1153
+ case Types .LONGVARCHAR :
1154
+ case Types .BINARY :
1155
+ case Types .VARBINARY :
1156
+ case Types .LONGVARBINARY :
1157
+ return true ;
1158
+ }
1159
+ return false ;
1160
+ }
1146
1161
1162
+ private byte [] trimBytes (int p_columnIndex , byte [] p_bytes ) throws SQLException
1163
+ {
1164
+ int l_maxSize = statement .getMaxFieldSize ();
1165
+ //we need to trim if maxsize is set and the length is greater than maxsize and the
1166
+ //type of this column is a candidate for trimming
1167
+ if (l_maxSize > 0 && p_bytes .length > l_maxSize && isColumnTrimmable (p_columnIndex ))
1168
+ {
1169
+ byte [] l_bytes = new byte [l_maxSize ];
1170
+ System .arraycopy (p_bytes , 0 , l_bytes , 0 , l_maxSize );
1171
+ return l_bytes ;
1172
+ }
1173
+ else
1174
+ {
1175
+ return p_bytes ;
1176
+ }
1177
+ }
1178
+
1179
+ private String trimString (int p_columnIndex , String p_string ) throws SQLException
1180
+ {
1181
+ int l_maxSize = statement .getMaxFieldSize ();
1182
+ //we need to trim if maxsize is set and the length is greater than maxsize and the
1183
+ //type of this column is a candidate for trimming
1184
+ if (l_maxSize > 0 && p_string .length () > l_maxSize && isColumnTrimmable (p_columnIndex ))
1185
+ {
1186
+ return p_string .substring (0 ,l_maxSize );
1187
+ }
1188
+ else
1189
+ {
1190
+ return p_string ;
1191
+ }
1192
+ }
1193
+
1147
1194
public SimpleDateFormat getTimestampTZFormat () {
1148
1195
if (m_tstzFormat == null ) {
1149
1196
m_tstzFormat = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss z" );
0 commit comments