Re: Declare cursor in dynamic ESQL
Posted in 1997
In article <60684m$5ff$1@owl.inetnebr.com>, Obi-Wan <bvh@inetnebr.com>
writes
>We're running Informix 7.1 on Solaris 2.5.1 using the GNU C compiler.
>No preprocessor or compiler warnings are given.
>
>Hardcoding the ESQL statement:
>
> EXEC SQL declare cust cursor for
> select cust_id
> from custinfo2
> where m_org_name like :m_org_name
> order by m_org_name;>
>works just fine. However, I now need to vary the "where" clause
>based on several conditions. I assume that using the prepare/execute
>features of dynamic ESQL is what I want. When I do:
>
> sprintf(cmd, "declare cust cursor for select cust_id from custinfo2
>where m_org_name like \\"HUNTER\\" order by m_org_name;");
> EXEC SQL prepare cmd_id2 from :cmd;
> EXEC SQL execute cmd_id2;
> EXEC SQL open cust;
>
>I get the following errors:
>
>after prepare, SQLSTATE = "42000" (Syntax error or access violation)
>after execute, SQLSTATE = "37000" (Syntax error or access violation in
> PREPARE or EXECUTE IMMEDIATE)
>after open, SQLSTATE = "07003" (Cursor specification cannot be executed)
>
>'cmd' is declared inside a DECLARE SECTION.
>
>What am I doing wrong? Is there a better way to go about this?
>
> -- Obi-Wan
Make sure you are passing the -fwriteable-strings option to gcc.
>
>--
>Ben "Obi-Wan" Hollingsworth email: bvh@inetnebr.com
>Vice President and System Administrator voice: (402)434-8680
> Internet Nebraska -- Nebraska's on-ramp to the information superhighway
--
David Williams