[PATCH] Escaping of SAVEPOINT names - Mailing list pgsql-jdbc

From Michael Paesold
Subject [PATCH] Escaping of SAVEPOINT names
Date
Msg-id 454E5534.5050007@gmx.at
Whole thread Raw
Responses Re: [PATCH] Escaping of SAVEPOINT names
List pgsql-jdbc
Escaping of savepoint names in org.postgresql.jdbc3.PSQLSavepoint is
incorrect. Backslashes in (double-quoted) savepoint names are doubled
for escaping, but AFAIK, and as my testing shows, savepoint names are
like identifiers, so regular identifier quoting applies to them.

Therefore backslashes should not be doubled, because they have no
special meaning in a double-quoted string.

While at it, don't use the string literal "\"" just to append a single
double-quote character to a string buffer.

Best Regards,
Michael Paesold
diff -crN pgjdbc.c5a36d75e073/org/postgresql/jdbc3/PSQLSavepoint.java pgjdbc/org/postgresql/jdbc3/PSQLSavepoint.java
*** pgjdbc.c5a36d75e073/org/postgresql/jdbc3/PSQLSavepoint.java    2006-11-05 22:08:31.000000000 +0100
--- pgjdbc/org/postgresql/jdbc3/PSQLSavepoint.java    2006-11-05 22:08:31.000000000 +0100
***************
*** 70,87 ****
          if (_isNamed)
          {
              // We need to quote and escape the name in case it
!             // contains spaces/quotes/backslashes.
              //
              StringBuffer sb = new StringBuffer(_name.length() + 2);
!             sb.append("\"");
              for (int i = 0; i < _name.length(); i++)
              {
                  char c = _name.charAt(i);
!                 if (c == '\\' || c == '"')
                      sb.append(c);
                  sb.append(c);
              }
!             sb.append("\"");
              return sb.toString();
          }

--- 70,87 ----
          if (_isNamed)
          {
              // We need to quote and escape the name in case it
!             // contains spaces/quotes/etc.
              //
              StringBuffer sb = new StringBuffer(_name.length() + 2);
!             sb.append('"');
              for (int i = 0; i < _name.length(); i++)
              {
                  char c = _name.charAt(i);
!                 if (c == '"')
                      sb.append(c);
                  sb.append(c);
              }
!             sb.append('"');
              return sb.toString();
          }


pgsql-jdbc by date:

Previous
From: Michael Paesold
Date:
Subject: JDBC Support for standard_conforming_strings
Next
From: Michael Paesold
Date:
Subject: [PATCH] Comments in PGbytea byte[] to pgstring conversion