libpq PQexecParams & value placeholders

2018-12-14 Thread Oleg
Hi, all.

Do we really need a numeric value placeholders like $1 in command string?
Construction of such string for complex non-static queries is very annoying.
Why do we can't simply use $$ placeholder, which take the next value from an
array of values?

-- 
Олег Неманов (Oleg Nemanov)



Re: libpq PQexecParams & value placeholders

2018-12-14 Thread Dmitry Igrishin
пт, 14 дек. 2018 г. в 14:33, Oleg :
>
> Hi, all.
>
> Do we really need a numeric value placeholders like $1 in command string?
It's a syntax defined at the backend side.
(https://www.postgresql.org/docs/current/sql-prepare.html)

> Construction of such string for complex non-static queries is very annoying.
That's why there are libraries like Pgfe
(https://github.com/dmitigr/pgfe) or libpqtypes
(http://libpqtypes.esilo.com/)

> Why do we can't simply use $$ placeholder, which take the next value from an
> array of values?
Because $$ means a dollar-quoted opening tag
(https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-DOLLAR-QUOTING)



Re: libpq PQexecParams & value placeholders

2018-12-14 Thread Oleg
On Fri, Dec 14, 2018 at 02:47:12PM +0300, Dmitry Igrishin wrote:
> пт, 14 дек. 2018 г. в 14:33, Oleg :
> >
> > Hi, all.
> >
> > Do we really need a numeric value placeholders like $1 in command string?
> It's a syntax defined at the backend side.
> (https://www.postgresql.org/docs/current/sql-prepare.html)

I know this, but i can't understand why this approach is used.

> > Construction of such string for complex non-static queries is very annoying.
> That's why there are libraries like Pgfe
> (https://github.com/dmitigr/pgfe) or libpqtypes

This is C++ :-(.

> (http://libpqtypes.esilo.com/)

This is great! PQexecf() is what i need. Why this api is not the part of libpq?
Thank you for the link!

> > Why do we can't simply use $$ placeholder, which take the next value from an
> > array of values?
> Because $$ means a dollar-quoted opening tag
> (https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-DOLLAR-QUOTING)

Ok. We can use any other placeholder string for such purpose. But not numeric
placeholders - these are not convenient.


-- 
Олег Неманов (Oleg Nemanov)



loading jdbc Driver in servlet

2018-12-14 Thread Rob Sargent

Using java 1.8, postgresql-42.1.4.jar, embedded tomcat 9

It appears to me that I need to make the call 
"Class.forName("org.postgresql.Driver)" when the entry is in a servlet.  
Is this expected, within a servlet, or is this just /post hoc ergo 
propter hoc /at it finest and I changed something else (wittingly or 
not).  Same code outside of servlet does not need the forced loading of 
the class and the manual claims it's not need after java 1.6




Re: loading jdbc Driver in servlet

2018-12-14 Thread Dave Cramer
Strange, I wouldn't think so, but then I haven't used a raw servlet for so
long I have no idea.


Dave Cramer

da...@postgresintl.com
www.postgresintl.com


On Fri, 14 Dec 2018 at 13:29, Rob Sargent  wrote:

> Using java 1.8, postgresql-42.1.4.jar, embedded tomcat 9
>
> It appears to me that I need to make the call
> "Class.forName("org.postgresql.Driver)" when the entry is in a servlet.  Is
> this expected, within a servlet, or is this just *post hoc ergo propter
> hoc *at it finest and I changed something else (wittingly or not).  Same
> code outside of servlet does not need the forced loading of the class and
> the manual claims it's not need after java 1.6
>


Re: loading jdbc Driver in servlet

2018-12-14 Thread Rob Sargent


> On Dec 14, 2018, at 1:30 PM, Dave Cramer  wrote:
> 
> Strange, I wouldn't think so, but then I haven't used a raw servlet for so 
> long I have no idea.
> 
> 
> Dave Cramer
> 
> da...@postgresintl.com 
> www.postgresintl.com 
> 
> On Fri, 14 Dec 2018 at 13:29, Rob Sargent  > wrote:
> Using java 1.8, postgresql-42.1.4.jar, embedded tomcat 9
> 
> It appears to me that I need to make the call 
> "Class.forName("org.postgresql.Driver)" when the entry is in a servlet.  Is 
> this expected, within a servlet, or is this just post hoc ergo propter hoc at 
> it finest and I changed something else (wittingly or not).  Same code outside 
> of servlet does not need the forced loading of the class and the manual 
> claims it's not need after java 1.6
> 
I too am suspicious.  But the vagaries of javax are daunting.
But if I comment it out, as just now, “No suitable driver found...”.  I was 
days playing with configuration and such think that this very specific error 
message was telling me my CLASSPATH was wrong.

I wonder if I have an old javax installation (which I put in place just 
recently).






Re: loading jdbc Driver in servlet

2018-12-14 Thread Rob Sargent


> On Dec 14, 2018, at 2:02 PM, Rob Sargent  wrote:
> 
> 
> 
>> On Dec 14, 2018, at 1:30 PM, Dave Cramer > > wrote:
>> 
>> Strange, I wouldn't think so, but then I haven't used a raw servlet for so 
>> long I have no idea.
>> 
>> 
>> Dave Cramer
>> 
>> da...@postgresintl.com 
>> www.postgresintl.com 
>> 
>> On Fri, 14 Dec 2018 at 13:29, Rob Sargent > > wrote:
>> Using java 1.8, postgresql-42.1.4.jar, embedded tomcat 9
>> 
>> It appears to me that I need to make the call 
>> "Class.forName("org.postgresql.Driver)" when the entry is in a servlet.  Is 
>> this expected, within a servlet, or is this just post hoc ergo propter hoc 
>> at it finest and I changed something else (wittingly or not).  Same code 
>> outside of servlet does not need the forced loading of the class and the 
>> manual claims it's not need after java 1.6
>> 
> I too am suspicious.  But the vagaries of javax are daunting.
> But if I comment it out, as just now, “No suitable driver found...”.  I was 
> days playing with configuration and such think that this very specific error 
> message was telling me my CLASSPATH was wrong.
> 
> I wonder if I have an old javax installation (which I put in place just 
> recently).
> 
> 
I’m using javax.servlet-api-3.1.0.jar
> 
>