On 26/05/20, Frank Millman ([email protected]) wrote:
> 
> 
> On 2020-05-26 3:08 PM, Rory Campbell-Lange wrote:
> > On 26/05/20, Frank Millman ([email protected]) wrote:
> > Does using %s instead of {}.format help solve the issue?
> 
> To reproduce my situation, you should place the '--' at the beginning of the
> following line (',%s as d').
> 
> As no parameters are now being substituted, I would expect to supply an
> empty tuple. In fact, the parameter is still required.

That makes sense, apologies.

However, this works as you suggest:

        In [33]: d.query("""
                ...: select 
                ...:     1 as a
                ...:     /*
                ...:     ,2 as b
                ...:     */
                ...:     -- ,'hi' as c
                ...:     -- ,%s as d
                ...: """, ("a string", )).results
        Out[33]: [Record(a=1)]

This doesn't work (as you suggest):

        In [35]: d.query("""
                ...: select 
                ...:     1 as a
                ...:     /*
                ...:     ,2 as b
                ...:     */
                ...:     -- ,'hi' as c
                ...:     -- ,%s as d
                ...: """, ()).results
        ERROR:root:An unexpected error occurred while tokenizing input
        The following traceback may be corrupted or invalid
        The error message is: ('EOF in multi-line string', (1, 0))

But this works:

        In [34]: d.query("""
                ...: select 
                ...:     1 as a
                ...:     /*
                ...:     ,2 as b
                ...:     */
                ...:     -- ,'hi' as c
                ...:     -- ,%s as d
                ...: """).results
        Out[34]: [Record(a=1)]

So perhaps simply don't provide the tuple in this case? This will also probably
work for your other backends.

Rory


Reply via email to