Re: Preparing an unload statement
Posted in 1996
Apostolos Varnas (tvarnas@compulink.gr) wrote:
: Craig Ostrom wrote:
: >
: > As Online 5 does not have a table-level backup facility, I am writing one in
: > 4gl. Problem is, I get a syntax error when trying to prepare the unload
: > statement for subsequent execution. The statement is:
: > unload to "ae.unl" select * from ae;
: > This works in isql but not in 4gl. Does anyone know if unload statements are
: > invalid in 4gl?
: >
: > Thanks for your effort in advance.Craig,
: you cannot prepare an unload statement.
: Why you have to prepare it ?
It's true you can't PREPARE an UNLOAD statement, and in Craig's example
there's no reason to. But say you want to build the SELECT at run time
(based on user-provided conditions, you can put the SELECT in a string
like so:
LET sqltxt = "select * from ae"
unload to "ae.unl" sqltxt
This is from the 4gl 6.0 manuals, but I know I've done something like
this in pre-6.0 versions as well.
And, on 2nd thought, this coule be handy for Craig's task:
DECLARE c_systables CURSOR FOR
SELECT tabname FROM systables
WHERE tabid > 99
FOREACH c_systables INTO ltabname
CALL unload_table(ltabname)
END FOREACH
...
FUNCTION unload_table(ltabname)
DEFINE ltabname LIKE systables.tabname
DEFINE unlfile CHAR(20)
DEFINE sqltxt CHAR(80)
LET unlfile = ltabname CLIPPED, ".unl"
LET sqltxt = "SELECT * FROM ", ltabname CLIPPED
UNLOAD TO unlfile sqltxt
END FUNCTION
=======================================================================
Dennis J. Pimple dennisp@informix.com Opinions expressed
Principal Consultant -------------------- are mine, and do not
Informix Software Inc Voice: 303-850-0210 necessarily reflect
Denver Colorado USA Fax: 303-779-4025 those of my employer.