Sorry. Beginners question...
Posted in 2000
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
I'm using informix4GL version 7 and want to pass a field name as a string into a prepared statement and execute the result into a variable. E.g let p_string1 = "select count(*) from temptable where field1 = ? " prepare p_sql1 from p_string1 execute p_sql1 into p_count using p_fieldName It doesn't like the execute line. It seems to be the write sytnax from the manuals. Thank you.
Vincent Kennedy wrote: > > I'm using informix4GL version 7 and want to pass a field name as a string > into a prepared statement and execute the result into a variable. > E.g > > let p_string1 = "select count(*) from temptable where field1 = ? " > prepare p_sql1 from p_string1 Question is: does I4GL v7 accept this? The examples I've seen in the manuals are for SQL, not 4GL. Might need to do: DECLARE c_sql1 cursor for p_sql1 OPEN c_sql1 using p_fieldName -- John Carlson Informix DBA WHSmith USA #include std_disclaimer.h /* These are my opinions, not my company's opinion */
Vincent Kennedy wrote: > > I'm using informix4GL version 7 and want to pass a field name as a string > into a prepared statement and execute the result into a variable. > E.g > > let p_string1 = "select count(*) from temptable where field1 = ? " > prepare p_sql1 from p_string1 Question is: does I4GL v7 accept this? The examples I've seen in the manuals are for SQL, not 4GL. Might need to do: DECLARE c_sql1 cursor for p_sql1 OPEN c_sql1 using p_fieldName FETCH c_sql1 into p_count -- John Carlson Informix DBA WHSmith USA #include std_disclaimer.h /* These are my opinions, not my company's opinion */
Vincent Kennedy wrote:
> I'm using informix4GL version 7 and want to pass a field name as a string
> into a prepared statement and execute the result into a variable.
> E.g
>
> let p_string1 = "select count(*) from temptable where field1 = ? "
> prepare p_sql1 from p_string1
> execute p_sql1 into p_count using p_fieldName
>
> It doesn't like the execute line. It seems to be the write sytnax from the
> manuals.
The I4GL manuals or the Informix Guide to SQL: Syntax manuals?
Which sub-version of I4GL (7.20 or 7.30)? You stand a better
chance of it working with 7.30 than with 7.20. However, in 7.30,
I'd expect to write:
SQL
SELECT COUNT(*) INTO $p_count
FROM temptable
WHERE field1 = $p_fieldName
END SQL
This avoids the memory leaks that arise from not freeing p_sql1 as well.
--
Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net)
Guardian of DBD::Informix v0.95 -- see http://www.perl.com/CPAN
#include <disclaimer.h>