vonloxley / sqsh

Clone of the original project https://sourceforge.net/projects/sqsh/
GNU General Public License v2.0
10 stars 8 forks source link

Regression: Variable expansion does not work inside single quotes #4

Closed boekhold closed 1 year ago

boekhold commented 1 year ago

Hi,

When I used sqsh 2.5.16.1 with Sybase, I could use a \func definition such as:

\func -x \tables
    \if [ $# -ne 1 ]
        \echo "usage: \tables <partial table name>"
        \return 1
    \fi
    select  u.name, substring(o.name, 1, 64)
    from    sysobjects o, sysusers u
    where       o.type = 'U'
            and o.name like '%${1}%'
            and o.uid = u.uid
    order by 2 asc
    go
\done

\tables Data

And it would give me a list of tables having Data in their name, plus the user who owns it.

This does not work anymore, because the ${1} isn't getting expanded to the provided value in the current version. Seems at some time some logic was introduced to NOT expand variables that are enclosed by single quotes?

This basically makes it impossible for me to pass filter conditions to a function...

If you don't have time to look into this, perhaps you can only point me to the correct code location so I can attempt a fix on my own?

boekhold commented 1 year ago

Seems to come from this commit: https://github.com/vonloxley/sqsh/commit/bdec3b8f787c046cef5640a06bfba200e97d015a

boekhold commented 1 year ago

I've figured it out. I need to "escape" the single quotes using double-back-slashes like:

\func -x \tables
    \if [ $# -ne 1 ]
        \echo "usage: \tables <partial table name>"
        \return 1
    \fi
    select  u.name, substring(o.name, 1, 64)
    from    sysobjects o, sysusers u
    where       o.type = 'U'
            and o.name like \\'%${1}%\\'
            and o.uid = u.uid
    order by 2 asc
    go
\done

Closing the issue.