RE: SQLin 4GLNot Working ......
Posted in 1997
John,
as you have just discovered, you need to prepare statements if you want
to use dynamic table or column names.
Apart from the "INTO" clause, variables can only used where expressions are
allowed, and even then you must be careful not to confuse existing column
names with 4gl variables or variables you may have declared in your module.
What I mean to say is that, apart for trying to use table cTable, your first
select statement is wrong in another respect: it will not test whether
customer.status="DEAD", but that <some_integer>="DEAD", where <some_integer>
is the contents of the 4gl status variable at the time the select statement
is executed.
In general you should
* avoid using name of reserved words or system variables for column names
* or prefix the column name with the table name
* Or at least put a @ in front of the column name
Many a programmer has been baffled by some silly error like that :-)
Moreover, you don't need a foreach. An open/fetch/close will make clear
that your is a singleton select. Makes you code more understandable.
Ciao,
Marco
PS: please turn off HTML posting
____________________________________________________________________________
rem radioterapia, which I immeritately manage, seldom agrees with what I say
marco greco (Catania, Italy) Work:
marcog@ctonline.it rem radioterapia 39 95 447828 fax 446558
(was mar.greco@agora.stm.it) Achea 39 95 503117
--- On Sun, 02 Feb 1997 01:38:59 -0500 John Cokos <jcokos@ix.netcom.com>
wrote:
------------BA32E9F5BB31
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=us-ascii
I'm having trouble with the following statement....
LET cTable = "customers"
SELECT count(*) INTO nCount FROM cTable
WHERE status = "DEAD"
I get an error stating that cTable is not in the database.
I have tried the following, with the same results.
LET cSQL = "SELECT count(*) FROM ", cTable
" WHERE status = ", "\\"" DEAD, "\\""
PREPARE qSQL FROM cSQL
DECLARE q_cur CURSOR FOR qSQL
FOREACH q_cur INTO nCount
END FOREACH
If I do a ... MESSAGE cSQL after the above code, the select
statemente is correct
(customers appears, not cTable)
What am I missing here?
Thanks
John Cokos
--
[HTML copy of message snipped]
-----------------End of Original Message-----------------