Re: rounded brackets in prepared statement - Mailing list pgsql-jdbc

From Ladislav DANKO
Subject Re: rounded brackets in prepared statement
Date
Msg-id 511CA443.5020900@enaktyment.cz
Whole thread Raw
In response to Re: rounded brackets in prepared statement  (dmp <danap@ttc-cmc.net>)
Responses Re: rounded brackets in prepared statement
List pgsql-jdbc
so JDBC driver is detecting matching type and if there's "=" (equal) then it's
doing escaping and if there is "~" (regular expression pattern) the i need to do
escaping by hand?

laco



On 13.2.2013 3:32, dmp wrote:
> 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
>


pgsql-jdbc by date:

Previous
From: Kevin Grittner
Date:
Subject: Re: PostgreSQL XAResource & GlassFish 3.1.2.2
Next
From: Florent Guillaume
Date:
Subject: Re: PostgreSQL XAResource & GlassFish 3.1.2.2