Re: rounded brackets in prepared statement

From: dmp <danap(at)ttc-cmc(dot)net>
To: Ladislav DANKO <ladislav(dot)danko(at)enaktyment(dot)cz>, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: rounded brackets in prepared statement
Date: 2013-02-13 02:32:18
Message-ID: 511AFB32.9080302@ttc-cmc.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

It appears that since the argument to your prepare statement is a WHERE
operation and you are using the ~, Match Regular Expression Case
Sensitive, operator then the input is deemed as such. So parenthesis
are valid constructs in these cases.

Example from Documentation: POSIX Regular Expression Patterns
Chapter 9. Functions & Operators

'abc' ~ '(b|d)' true
'abc' ~ '(^(b|c)' false

danap.

Ladislav DANKO wrote:
> Hi folks,
>
> my setup: Java 1.6, JDBC PostgreSQL JDBC4 driver 9.1-903.
>
> Why when I do:
>
> PreparedStatement ps = myConnection.prepareStatement("SELECT a,b,c FROM
> mytable WHERE category ~ ?");
> ps.setString(1, "my/super/category/a(bcdef");
> result = ps.executeQuery();
>
> I need to escape rounded bracket in setString in this way:
> ps.setString(1, "super/category/a(bcdef".replaceAll("\\(", "\\\\(")));
>
> I think it has somethink to do with regular expessions but ot know much
> more about it.
>
> --
> With kind regards,
>
> Ladislav DANKO

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Craig Ringer 2013-02-13 03:12:09 Re: [HACKERS] JPA + enum == Exception
Previous Message Bryan Varner 2013-02-13 02:28:54 Re: PostgreSQL XAResource & GlassFish 3.1.2.2