PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/rpm/redhat/8.1/postgresql-jdbc/F-11/postgresql-jdbc-unspec-string.patch

https://github.com/commandprompt/PGSQLRPMS
Patch | 279 lines | 244 code | 35 blank | 0 comment | 0 complexity | 9259dbf797621412692439aa57d9cfd3 MD5 | raw file
  1. This patch is based on
  2. http://gborg.postgresql.org/pipermail/pgjdbc-commit/2005-November/000416.html
  3. but omitting some changes relevant to logging. The changes are
  4. Add a new parameter 'stringtype' (values 'varchar' or 'unspecified') to
  5. control how parameters set via setString() are bound.
  6. Make compatible=7.4 use stringtype=unspecified.
  7. Rename Oid.INVALID -> Oid.UNSPECIFIED.
  8. Fix V3 parameter logic so that prepared statements are not reused when a
  9. non-NULL UNSPECIFIED parameter is set over the top of a previous
  10. parameter.
  11. Change testTypeChange() so it works with stringtype=unspecified.
  12. The stringtype=unspecified option is really important to minimize problems
  13. for applications being ported forward from the 7.4 postgresql JDBC driver.
  14. diff -Naur postgresql-jdbc-8.1-405.src.orig/org/postgresql/Driver.java.in postgresql-jdbc-8.1-405.src/org/postgresql/Driver.java.in
  15. --- postgresql-jdbc-8.1-405.src.orig/org/postgresql/Driver.java.in 2005-02-15 03:56:24.000000000 -0500
  16. +++ postgresql-jdbc-8.1-405.src/org/postgresql/Driver.java.in 2006-02-17 19:19:50.000000000 -0500
  17. @@ -420,9 +420,12 @@
  18. "When connecting to a pre-7.3 server, the database encoding to assume is in use." },
  19. { "compatible", Boolean.FALSE,
  20. "Force compatibility of some features with an older version of the driver.",
  21. - new String[] { "7.1", "7.2", "7.3" } },
  22. + new String[] { "7.1", "7.2", "7.3", "7.4", "8.0", "8.1" } },
  23. { "loginTimeout", Boolean.FALSE,
  24. - "The login timeout, in seconds; 0 means no timeout beyond the normal TCP connection timout." }
  25. + "The login timeout, in seconds; 0 means no timeout beyond the normal TCP connection timout." },
  26. + { "stringtype", Boolean.FALSE,
  27. + "The type to bind String parameters as (usually 'varchar'; 'unspecified' allows implicit casting to other types)",
  28. + new String[] { "varchar", "unspecified" } },
  29. };
  30. /**
  31. diff -Naur postgresql-jdbc-8.1-405.src.orig/org/postgresql/core/BaseConnection.java postgresql-jdbc-8.1-405.src/org/postgresql/core/BaseConnection.java
  32. --- postgresql-jdbc-8.1-405.src.orig/org/postgresql/core/BaseConnection.java 2005-08-01 02:54:14.000000000 -0400
  33. +++ postgresql-jdbc-8.1-405.src/org/postgresql/core/BaseConnection.java 2006-02-17 19:19:50.000000000 -0500
  34. @@ -143,4 +143,7 @@
  35. // Ew. Quick hack to give access to the connection-specific utils implementation.
  36. public TimestampUtils getTimestampUtils();
  37. +
  38. + // Get the bind-string-as-varchar config flag
  39. + public boolean getStringVarcharFlag();
  40. }
  41. diff -Naur postgresql-jdbc-8.1-405.src.orig/org/postgresql/core/Oid.java postgresql-jdbc-8.1-405.src/org/postgresql/core/Oid.java
  42. --- postgresql-jdbc-8.1-405.src.orig/org/postgresql/core/Oid.java 2005-07-04 14:50:28.000000000 -0400
  43. +++ postgresql-jdbc-8.1-405.src/org/postgresql/core/Oid.java 2006-02-17 19:19:50.000000000 -0500
  44. @@ -14,7 +14,7 @@
  45. * use.
  46. */
  47. public class Oid {
  48. - public static final int INVALID = 0;
  49. + public static final int UNSPECIFIED = 0;
  50. public static final int INT2 = 21;
  51. public static final int INT4 = 23;
  52. public static final int INT8 = 20;
  53. diff -Naur postgresql-jdbc-8.1-405.src.orig/org/postgresql/core/v3/SimpleParameterList.java postgresql-jdbc-8.1-405.src/org/postgresql/core/v3/SimpleParameterList.java
  54. --- postgresql-jdbc-8.1-405.src.orig/org/postgresql/core/v3/SimpleParameterList.java 2005-07-08 13:38:29.000000000 -0400
  55. +++ postgresql-jdbc-8.1-405.src/org/postgresql/core/v3/SimpleParameterList.java 2006-02-17 19:19:50.000000000 -0500
  56. @@ -62,10 +62,11 @@
  57. paramValues[index] = value ;
  58. direction[index] |= IN;
  59. - // If we are setting something to null, don't overwrite our existing type
  60. - // for it. We don't need the correct type info to send NULL and we
  61. - // don't want to overwrite and require a reparse.
  62. - if (oid == Oid.INVALID && paramTypes[index] != Oid.INVALID)
  63. + // If we are setting something to an UNSPECIFIED NULL, don't overwrite
  64. + // our existing type for it. We don't need the correct type info to
  65. + // send this value, and we don't want to overwrite and require a
  66. + // reparse.
  67. + if (oid == Oid.UNSPECIFIED && paramTypes[index] != Oid.UNSPECIFIED && value == NULL_OBJECT)
  68. return;
  69. paramTypes[index] = oid;
  70. @@ -170,7 +171,7 @@
  71. boolean hasUnresolvedTypes() {
  72. for (int i=0; i< paramTypes.length; i++) {
  73. - if (paramTypes[i] == Oid.INVALID)
  74. + if (paramTypes[i] == Oid.UNSPECIFIED)
  75. return true;
  76. }
  77. return false;
  78. @@ -178,7 +179,7 @@
  79. void setResolvedType(int index, int oid) {
  80. // only allow overwriting an unknown value
  81. - if (paramTypes[index-1] == Oid.INVALID) {
  82. + if (paramTypes[index-1] == Oid.UNSPECIFIED) {
  83. paramTypes[index-1] = oid;
  84. } else if (paramTypes[index-1] != oid) {
  85. throw new IllegalArgumentException("Can't change resolved type for param: " + index + " from " + paramTypes[index] + " to " + oid);
  86. diff -Naur postgresql-jdbc-8.1-405.src.orig/org/postgresql/jdbc2/AbstractJdbc2Connection.java postgresql-jdbc-8.1-405.src/org/postgresql/jdbc2/AbstractJdbc2Connection.java
  87. --- postgresql-jdbc-8.1-405.src.orig/org/postgresql/jdbc2/AbstractJdbc2Connection.java 2005-08-01 02:54:14.000000000 -0400
  88. +++ postgresql-jdbc-8.1-405.src/org/postgresql/jdbc2/AbstractJdbc2Connection.java 2006-02-17 19:19:50.000000000 -0500
  89. @@ -58,6 +58,9 @@
  90. // Connection's readonly state.
  91. public boolean readOnly = false;
  92. + // Bind String to UNSPECIFIED or VARCHAR?
  93. + public final boolean bindStringAsVarchar;
  94. +
  95. // Current warnings; there might be more on protoConnection too.
  96. public SQLWarning firstWarning = null;
  97. @@ -124,6 +127,23 @@
  98. Driver.debug(" prepare threshold = " + prepareThreshold);
  99. }
  100. + //
  101. + // String -> text or unknown?
  102. + //
  103. +
  104. + String stringType = info.getProperty("stringtype");
  105. + if (stringType != null) {
  106. + if (stringType.equalsIgnoreCase("unspecified"))
  107. + bindStringAsVarchar = false;
  108. + else if (stringType.equalsIgnoreCase("varchar"))
  109. + bindStringAsVarchar = true;
  110. + else
  111. + throw new PSQLException(GT.tr("Unsupported value for stringtype parameter: {0}", stringType),
  112. + PSQLState.INVALID_PARAMETER_VALUE);
  113. + } else {
  114. + bindStringAsVarchar = haveMinimumCompatibleVersion("8.0");
  115. + }
  116. +
  117. // Initialize timestamp stuff
  118. timestampUtils = new TimestampUtils(haveMinimumServerVersion("7.4"));
  119. @@ -1033,5 +1053,9 @@
  120. {
  121. return protoConnection.getProtocolVersion();
  122. }
  123. -}
  124. + public boolean getStringVarcharFlag()
  125. + {
  126. + return bindStringAsVarchar;
  127. + }
  128. +}
  129. diff -Naur postgresql-jdbc-8.1-405.src.orig/org/postgresql/jdbc2/AbstractJdbc2Statement.java postgresql-jdbc-8.1-405.src/org/postgresql/jdbc2/AbstractJdbc2Statement.java
  130. --- postgresql-jdbc-8.1-405.src.orig/org/postgresql/jdbc2/AbstractJdbc2Statement.java 2006-02-01 13:52:30.000000000 -0500
  131. +++ postgresql-jdbc-8.1-405.src/org/postgresql/jdbc2/AbstractJdbc2Statement.java 2006-02-17 19:19:50.000000000 -0500
  132. @@ -1066,7 +1066,7 @@
  133. case Types.STRUCT:
  134. case Types.NULL:
  135. case Types.OTHER:
  136. - oid = Oid.INVALID;
  137. + oid = Oid.UNSPECIFIED;
  138. break;
  139. default:
  140. // Bad Types value.
  141. @@ -1206,7 +1206,7 @@
  142. public void setString(int parameterIndex, String x) throws SQLException
  143. {
  144. checkClosed();
  145. - setString(parameterIndex, x, Oid.VARCHAR);
  146. + setString(parameterIndex, x, (connection.getStringVarcharFlag() ? Oid.VARCHAR : Oid.UNSPECIFIED));
  147. }
  148. protected void setString(int parameterIndex, String x, int oid) throws SQLException
  149. @@ -1519,7 +1519,7 @@
  150. private void setPGobject(int parameterIndex, PGobject x) throws SQLException {
  151. String typename = x.getType();
  152. int oid = connection.getPGType(typename);
  153. - if (oid == Oid.INVALID)
  154. + if (oid == Oid.UNSPECIFIED)
  155. throw new PSQLException(GT.tr("Unknown type {0}.", typename), PSQLState.INVALID_PARAMETER_TYPE);
  156. setString(parameterIndex, x.getValue(), oid);
  157. @@ -1585,7 +1585,7 @@
  158. break;
  159. case Types.VARCHAR:
  160. case Types.LONGVARCHAR:
  161. - setString(parameterIndex, pgType.toString());
  162. + setString(parameterIndex, pgType.toString(), Oid.VARCHAR);
  163. break;
  164. case Types.DATE:
  165. if (in instanceof java.sql.Date)
  166. @@ -2681,7 +2681,7 @@
  167. // backend looks for array types.
  168. String typename = "_" + x.getBaseTypeName();
  169. int oid = connection.getPGType(typename);
  170. - if (oid == Oid.INVALID)
  171. + if (oid == Oid.UNSPECIFIED)
  172. throw new PSQLException(GT.tr("Unknown type {0}.", typename), PSQLState.INVALID_PARAMETER_TYPE);
  173. setString(i, x.toString(), oid);
  174. @@ -2882,7 +2882,7 @@
  175. if (cal != null)
  176. cal = (Calendar)cal.clone();
  177. - // We must use INVALID here, or inserting a Date-with-timezone into a
  178. + // We must use UNSPECIFIED here, or inserting a Date-with-timezone into a
  179. // timestamptz field does an unexpected rotation by the server's TimeZone:
  180. //
  181. // We want to interpret 2005/01/01 with calendar +0100 as
  182. @@ -2901,7 +2901,7 @@
  183. // 2005-01-01 00:00:00+03
  184. // (1 row)
  185. - bindString(i, connection.getTimestampUtils().toString(cal, d), Oid.INVALID);
  186. + bindString(i, connection.getTimestampUtils().toString(cal, d), Oid.UNSPECIFIED);
  187. }
  188. public void setTime(int i, Time t, java.util.Calendar cal) throws SQLException
  189. @@ -2917,9 +2917,7 @@
  190. if (cal != null)
  191. cal = (Calendar)cal.clone();
  192. - // We don't need INVALID here as we only support inserting a Time into
  193. - // 'time' and 'timetz' columns.
  194. - bindString(i, connection.getTimestampUtils().toString(cal, t), Oid.INVALID);
  195. + bindString(i, connection.getTimestampUtils().toString(cal, t), Oid.UNSPECIFIED);
  196. }
  197. public void setTimestamp(int i, Timestamp t, java.util.Calendar cal) throws SQLException
  198. @@ -2934,7 +2932,7 @@
  199. if (cal != null)
  200. cal = (Calendar)cal.clone();
  201. - // Use INVALID as a compromise to get both TIMESTAMP and TIMESTAMPTZ working.
  202. + // Use UNSPECIFIED as a compromise to get both TIMESTAMP and TIMESTAMPTZ working.
  203. // This is because you get this in a +1300 timezone:
  204. //
  205. // template1=# select '2005-01-01 15:00:00 +1000'::timestamptz;
  206. @@ -2961,10 +2959,10 @@
  207. // time compared to the string we originally provided. But going straight
  208. // to timestamp is OK as the input parser for timestamp just throws away
  209. // the timezone part entirely. Since we don't know ahead of time what type
  210. - // we're actually dealing with, INVALID seems the lesser evil, even if it
  211. + // we're actually dealing with, UNSPECIFIED seems the lesser evil, even if it
  212. // does give more scope for type-mismatch errors being silently hidden.
  213. - bindString(i, connection.getTimestampUtils().toString(cal, t), Oid.INVALID); // Let the server infer the right type.
  214. + bindString(i, connection.getTimestampUtils().toString(cal, t), Oid.UNSPECIFIED); // Let the server infer the right type.
  215. }
  216. // ** JDBC 2 Extensions for CallableStatement**
  217. diff -Naur postgresql-jdbc-8.1-405.src.orig/org/postgresql/jdbc2/TypeInfoCache.java postgresql-jdbc-8.1-405.src/org/postgresql/jdbc2/TypeInfoCache.java
  218. --- postgresql-jdbc-8.1-405.src.orig/org/postgresql/jdbc2/TypeInfoCache.java 2006-02-09 11:29:20.000000000 -0500
  219. +++ postgresql-jdbc-8.1-405.src/org/postgresql/jdbc2/TypeInfoCache.java 2006-02-17 19:19:50.000000000 -0500
  220. @@ -140,7 +140,7 @@
  221. if (!((BaseStatement)_getOidStatement).executeWithFlags(QueryExecutor.QUERY_SUPPRESS_BEGIN))
  222. throw new PSQLException(GT.tr("No results were returned by the query."), PSQLState.NO_DATA);
  223. - oid = new Integer(Oid.INVALID);
  224. + oid = new Integer(Oid.UNSPECIFIED);
  225. ResultSet rs = _getOidStatement.getResultSet();
  226. if (rs.next()) {
  227. oid = new Integer(rs.getInt(1));
  228. @@ -154,7 +154,7 @@
  229. public String getPGType(int oid) throws SQLException
  230. {
  231. - if (oid == Oid.INVALID)
  232. + if (oid == Oid.UNSPECIFIED)
  233. return null;
  234. String pgTypeName = (String)_oidToPgName.get(new Integer(oid));
  235. diff -Naur postgresql-jdbc-8.1-405.src.orig/org/postgresql/test/jdbc2/ServerPreparedStmtTest.java postgresql-jdbc-8.1-405.src/org/postgresql/test/jdbc2/ServerPreparedStmtTest.java
  236. --- postgresql-jdbc-8.1-405.src.orig/org/postgresql/test/jdbc2/ServerPreparedStmtTest.java 2005-01-27 17:50:17.000000000 -0500
  237. +++ postgresql-jdbc-8.1-405.src/org/postgresql/test/jdbc2/ServerPreparedStmtTest.java 2006-02-17 19:19:50.000000000 -0500
  238. @@ -256,7 +256,7 @@
  239. }
  240. public void testTypeChange() throws Exception {
  241. - PreparedStatement pstmt = con.prepareStatement("SELECT ?");
  242. + PreparedStatement pstmt = con.prepareStatement("SELECT CAST (? AS TEXT)");
  243. ((PGStatement)pstmt).setUseServerPrepare(true);
  244. // Prepare with int parameter.