Thread: [Fwd: Array.getArray ()]

[Fwd: Array.getArray ()]

From
Dmitry Tkach
Date:
I sent this patch about a month ago, but have never received any reply...
Did it get lost?

Thanks!

Dima

-------- Original Message --------

Hi, everybody!

I have run into a couple of problems having to do with parsing text
arrays in jdbc (Array.getArray ()):

- First of all, it skips backslashes, but does not really use them as
escape characters
(for example, if the array element has a string, looking like \"blah\",
it will (incorrectly) strip the double quotes;
- Secondly, it refuses to parse lines, that contains (properly escaped)
curly braces - for example {"{blah}", "{blah}"} or {\{blah\}, \{blah\}}...

The attached patch seems to fix those two problems (it is against
REL7_3_STABLE, but applies to the HEAD with no problems too).
Please let me know if you find anything wrong with it.

Thanks a lot!

Dima.



Index: Array.java
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc2/Array.java,v
retrieving revision 1.18
diff -C10 -r1.18 Array.java
*** Array.java    6 Sep 2002 21:23:06 -0000    1.18
--- Array.java    29 May 2003 19:37:19 -0000
***************
*** 84,116 ****
          {
              char[] chars = rawString.toCharArray();
              StringBuffer sbuf = new StringBuffer();
              boolean foundOpen = false;
              boolean insideString = false;
              for ( int i = 0; i < chars.length; i++ )
              {
                  if ( chars[i] == '\\' )
                      //escape character that we need to skip
                      i++;
!                 if ( chars[i] == '{' )
                  {
                      if ( foundOpen )  // Only supports 1-D arrays for now
                          throw org.postgresql.Driver.notImplemented();
                      foundOpen = true;
                      continue;
                  }
!                 if ( chars[i] == '"' )
                  {
                      insideString = !insideString;
                      continue;
                  }
!                 if ( (!insideString && chars[i] == ',') || chars[i] == '}' || i == chars.length - 1)
                  {
                      if ( chars[i] != '"' && chars[i] != '}' && chars[i] != ',' )
                          sbuf.append(chars[i]);
                      array.add( sbuf.toString() );
                      sbuf = new StringBuffer();
                      continue;
                  }
                  sbuf.append( chars[i] );
              }
          }
--- 84,117 ----
          {
              char[] chars = rawString.toCharArray();
              StringBuffer sbuf = new StringBuffer();
              boolean foundOpen = false;
              boolean insideString = false;
              for ( int i = 0; i < chars.length; i++ )
              {
                  if ( chars[i] == '\\' )
                      //escape character that we need to skip
                      i++;
!                 else if (!insideString && chars[i] == '{' )
                  {
                      if ( foundOpen )  // Only supports 1-D arrays for now
                          throw org.postgresql.Driver.notImplemented();
                      foundOpen = true;
                      continue;
                  }
!                 else if (chars[i] == '"')
                  {
                      insideString = !insideString;
                      continue;
                  }
!                 else if (!insideString && (chars[i] == ',' || chars[i] == '}') ||
!                             i == chars.length - 1)
                  {
                      if ( chars[i] != '"' && chars[i] != '}' && chars[i] != ',' )
                          sbuf.append(chars[i]);
                      array.add( sbuf.toString() );
                      sbuf = new StringBuffer();
                      continue;
                  }
                  sbuf.append( chars[i] );
              }
          }


Re: [Fwd: Array.getArray ()]

From
Barry Lind
Date:
Patch applied (finally).

--Barry

Dmitry Tkach wrote:
>
> I sent this patch about a month ago, but have never received any reply...
> Did it get lost?
>
> Thanks!
>
> Dima
>
> -------- Original Message --------
>
> Hi, everybody!
>
> I have run into a couple of problems having to do with parsing text
> arrays in jdbc (Array.getArray ()):
>
> - First of all, it skips backslashes, but does not really use them as
> escape characters
> (for example, if the array element has a string, looking like \"blah\",
> it will (incorrectly) strip the double quotes;
> - Secondly, it refuses to parse lines, that contains (properly escaped)
> curly braces - for example {"{blah}", "{blah}"} or {\{blah\}, \{blah\}}...
>
> The attached patch seems to fix those two problems (it is against
> REL7_3_STABLE, but applies to the HEAD with no problems too).
> Please let me know if you find anything wrong with it.
>
> Thanks a lot!
>
> Dima.
>
>
>
>
> ------------------------------------------------------------------------
>
> Index: Array.java
> ===================================================================
> RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc2/Array.java,v
> retrieving revision 1.18
> diff -C10 -r1.18 Array.java
> *** Array.java    6 Sep 2002 21:23:06 -0000    1.18
> --- Array.java    29 May 2003 19:37:19 -0000
> ***************
> *** 84,116 ****
>           {
>               char[] chars = rawString.toCharArray();
>               StringBuffer sbuf = new StringBuffer();
>               boolean foundOpen = false;
>               boolean insideString = false;
>               for ( int i = 0; i < chars.length; i++ )
>               {
>                   if ( chars[i] == '\\' )
>                       //escape character that we need to skip
>                       i++;
> !                 if ( chars[i] == '{' )
>                   {
>                       if ( foundOpen )  // Only supports 1-D arrays for now
>                           throw org.postgresql.Driver.notImplemented();
>                       foundOpen = true;
>                       continue;
>                   }
> !                 if ( chars[i] == '"' )
>                   {
>                       insideString = !insideString;
>                       continue;
>                   }
> !                 if ( (!insideString && chars[i] == ',') || chars[i] == '}' || i == chars.length - 1)
>                   {
>                       if ( chars[i] != '"' && chars[i] != '}' && chars[i] != ',' )
>                           sbuf.append(chars[i]);
>                       array.add( sbuf.toString() );
>                       sbuf = new StringBuffer();
>                       continue;
>                   }
>                   sbuf.append( chars[i] );
>               }
>           }
> --- 84,117 ----
>           {
>               char[] chars = rawString.toCharArray();
>               StringBuffer sbuf = new StringBuffer();
>               boolean foundOpen = false;
>               boolean insideString = false;
>               for ( int i = 0; i < chars.length; i++ )
>               {
>                   if ( chars[i] == '\\' )
>                       //escape character that we need to skip
>                       i++;
> !                 else if (!insideString && chars[i] == '{' )
>                   {
>                       if ( foundOpen )  // Only supports 1-D arrays for now
>                           throw org.postgresql.Driver.notImplemented();
>                       foundOpen = true;
>                       continue;
>                   }
> !                 else if (chars[i] == '"')
>                   {
>                       insideString = !insideString;
>                       continue;
>                   }
> !                 else if (!insideString && (chars[i] == ',' || chars[i] == '}') ||
> !                             i == chars.length - 1)
>                   {
>                       if ( chars[i] != '"' && chars[i] != '}' && chars[i] != ',' )
>                           sbuf.append(chars[i]);
>                       array.add( sbuf.toString() );
>                       sbuf = new StringBuffer();
>                       continue;
>                   }
>                   sbuf.append( chars[i] );
>               }
>           }
>
>
>
> ------------------------------------------------------------------------
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org