[comp.databases] Informix 4GL CONSTRUCT question

eboneste@bbn.com (Liz Bonesteel) (10/03/90)

I have been trying to build a query on two forms, using the following
basic algorithm:

	ascertain which form is open
	CONSTRUCT the query on that form
	close the form and open the next form
	CONSTRUCT the query on that form
	concatenate the queries and PREPARE the select statement

The program compiles, but when I try to run it I get an error:
						      
	An illegal character has been found in this statement.

This error occurs in the PREPARE statement.

Does anybody know of a way around this, or is it really impossible to
query on multible forms in 4GL?

(If it makes a difference, and it usually does, I am running version
.04D on a VAX 8600 running VMS.)

Any leads will be greatly appreciated.

Thanks,

Liz

davek@informix.com (David Kosenko) (10/04/90)

In article <59771@bbn.BBN.COM> eboneste@BBN.COM (Liz Bonesteel) writes:
>	ascertain which form is open
>	CONSTRUCT the query on that form
>	close the form and open the next form
>	CONSTRUCT the query on that form
>	concatenate the queries and PREPARE the select statement
>
>The program compiles, but when I try to run it I get an error:
>						      
>	An illegal character has been found in this statement.
>
>This error occurs in the PREPARE statement.
>
>Does anybody know of a way around this, or is it really impossible to
>query on multible forms in 4GL?

I suspect the problem has nothing to do with the CONSTRUCT itself; indeed,
what you are doing is possible and often desirable.  The problem is with
the character string you build - the parser has found a problem with
the query string you are using.  When you concatenate the queries, are
you including an AND to join the results of the two constructs?  Remember
that a construct returns a bunch of boolean conditions that are meant
to be tacked on following a WHERE clause; if you plug two constructed
clauses together you need to put that AND in to link the conditions
together.

Dave Kosenko
Informix Prof. Services

randall@informix.com (Randall Rhea) (10/05/90)

In article <1990Oct4.141922.5268@informix.com> davek@informix.com (David Kosenko) writes:
>In article <59771@bbn.BBN.COM> eboneste@BBN.COM (Liz Bonesteel) writes:
>>	ascertain which form is open
>>	CONSTRUCT the query on that form
>>	close the form and open the next form
>>	CONSTRUCT the query on that form
>>	concatenate the queries and PREPARE the select statement
>>
>>The program compiles, but when I try to run it I get an error:
>>						      
>>	An illegal character has been found in this statement.
>>
>>This error occurs in the PREPARE statement.
>>

I have done this before in 4GL, so as Dave Kosenko points out, there is
nothing inherently wrong with the CONSTRUCT statement.  Have you looked
at the strings that the CONSTRUCT is producing?  Perhaps some strange
characters are getting into them.  Something like this should work:

         CONSTRUCT [BY NAME] p_text1 .......
         ...
		 CONSTRUCT [BY NAME] p_text2 ......
         LET p_text3 = p_text1 CLIPPED, " AND ", p_text2 CLIPPED 

I would look at the string "p_text3" for weird characters.  A simple C function
can be compiled into your 4GL program to dump a string into a file on the disk:

#include <stdio.h>
#include <ctype.h>

outfile(nargs)
int nargs;
{
	char filestr[256];
	char filecpy[256];
	FILE *fopen(), *fp;
	int len, i;

	if(nargs != 1) {
		fprintf(stderr,"usage:  outfile(string)");
		exit(1);
	}

	for(i=0;i<256;i++){
		filestr[i] = NULL;
		filecpy[i] = NULL;
	}
 
	popquote(filecpy,255);
	len = strlen(filecpy);
	strncpy(filestr,filecpy,len);
	len = strlen(filestr);
	filestr[len]=NULL; 

	/* create file for writing  */

	if((fp = fopen("outfile.4go","w")) == NULL){ 
		fprintf(stderr,"outfile(): cannot create outfile.4go");
		exit(1);
	}

	/* put the string into the file */

	if((fputs(filestr,fp)) == EOF){
		fprintf(stderr,"outfile(): cannot write to outfile.4go");
		exit(1);
	}

	fclose(fp);
}

In your 4GL program, you could then have:

	CALL outfile(p_text3)

You can then look at the contents of "outfile.4go" to see the string.
The above function is for UNIX, of course ... I'm not sure how it would
work in VMS.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Randall Rhea                                          Informix Software, Inc. 
Senior Programmer/Analyst, MIS                    uunet!pyramid!infmx!randall
**** THE ABOVE IS NOT ENDORSED OR SUPPORTED BY INFORMIX SOFTWARE, INC. ******
-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Randall Rhea                                          Informix Software, Inc. 
Senior Programmer/Analyst, MIS                    uunet!pyramid!infmx!randall

eboneste@bbn.com (Liz Bonesteel) (10/05/90)

Since I've received several (thanks, folks!) responses to this
question, all suggesting the same course of action, I thought I'd try
to be a little more clear in the statement of my problem.

	CONSTRUCT p1query ON (...fields...) FROM (...fields...)
	CONSTRUCT p2query ON (...fields...) FROM (...fields...)

	LET s1 = "SELECT * FROM stattbl WHERE ", p1query CLIPPED, " AND ", 
	    p2query CLIPPED

	PREPARE s_1 FROM s1

This doesn't work.  However, if I define s1 and s2 and prepare the two
queries separately (not helpful for the application, but an
interesting exercise nonetheless), I have no problems.

I've hit "you can't get there from here" problems with this package
before, and I'm beginning to think this is one of them.

Liz

lbrintle@umaxc.weeg.uiowa.edu (Lee Brintle,Advantage,337-5200,3374010) (10/05/90)

From article <1990Oct4.235559.22686@informix.com>, by randall@informix.com (Randall Rhea):
> 
> I would look at the string "p_text3" for weird characters.  A simple C
> function can be compiled into your 4GL program to dump a string into a
> file on the disk:

Uh... the startlog() and errorlog() functions will do the same thing (look
in the Function ``Library'' section) without having to include C code 
(which can be a real bother under RDS, since you have to make your own 
runner).  Also, some implementations of the RDS don't allow you to complile
all C programs (mine is one of them, alas).



> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> Randall Rhea                                          Informix Software, Inc
> Senior Programmer/Analyst, MIS                    uunet!pyramid!infmx!randall
> **** THE ABOVE IS NOT ENDORSED OR SUPPORTED BY INFORMIX SOFTWARE, INC. ******
> -- 
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> Randall Rhea                                          Informix Software, Inc
> Senior Programmer/Analyst, MIS                    uunet!pyramid!infmx!randall


Lee Brintle
Advantage Information Management

aland@informix.com (alan denney) (10/11/90)

In article <59822@bbn.BBN.COM> eboneste@BBN.COM (Liz Bonesteel) writes:
>
>Since I've received several (thanks, folks!) responses to this
>question, all suggesting the same course of action, I thought I'd try
>to be a little more clear in the statement of my problem.
>
>	CONSTRUCT p1query ON (...fields...) FROM (...fields...)
>	CONSTRUCT p2query ON (...fields...) FROM (...fields...)
>
>	LET s1 = "SELECT * FROM stattbl WHERE ", p1query CLIPPED, " AND ", 
>	    p2query CLIPPED
>	PREPARE s_1 FROM s1
>
>This doesn't work.  However, if I define s1 and s2 and prepare the two
>queries separately (not helpful for the application, but an
>interesting exercise nonetheless), I have no problems.

But, what goes into the two strings?  After you run the CONSTRUCTs,
try displaying the contents of the two p?query strings and/or the
final s1 string and see if the contents make sense.  (Is s1 big enough
to handle an arbitrarily complex query?)

--
Alan Denney      aland@informix.com      {pyramid|uunet}!infmx!aland

I'm Pro-Anarchy...   and I Vote!