Re: Can't put LIKE parameter in parameter dict?

Marcos Sánchez Provencio <[email protected]> Fri, 11 Jun 2004 21:29:00 +0200
Newsgroups gmane.comp.python.sybase
Message-ID <[email protected]>
It might be that the db server/api takes incorrect decisions about the
type of the parameter...

You may try casting the parameter:

 and symbol like cast(@s as varchar(100))

By the way, you might use sigle quotes around string constants, it is
more portable (triple quotes around sql looks better too ;-)

El jue, 10-06-2004 a las 15:18, Skip Montanaro escribió:
> Can someone explain why these two seemingly identical queries return
> different results?  Can't LIKE wildcards be given in parameter dictionaries?
> 
>     >>> c.execute('select distinct symbol, open_time, close_time,'
>     ...           '                session_start, session_end, instrument'
>     ...           '  from underlying_sessions'
>     ...           '  where instrument = @i'
>     ...           '    and symbol like "M%"',
>     ...           {"@i": "E"})
>     >>> len(c.fetchall())
>     402
>     >>> c.execute('select distinct symbol, open_time, close_time,'
>     ...           '                session_start, session_end, instrument'
>     ...           '  from underlying_sessions'
>     ...           '  where instrument = @i'
>     ...           '    and symbol like @s',
>     ...           {"@i": "E",
>     ...            "@s": "M%"})
>     >>> len(c.fetchall())
>     0
> 
> Thanks,