[comp.databases] INFORMIX sql-server via sendmail possible ??

ekkel@idca.tds.PHILIPS.nl (Erik Ekkel) (04/28/89)

I'm reading this newsgroup for a short time now, so it could be that this
question is already discussed.

---

I'm wondering if it is possible to build with INFORMIX ESQL f.i. a program
that reads from stdin a sql-query and produces the result to stdout 
and the errors to stderr. This would be nice to use in combination with 
sendmail to set-up a small sql-server for queries to a remote database
(when there are no other remote possibilities !).

I don't want to reinvent everything, so maybe somebody has an idea or even
a working program.

Many thanks.
-- 
    __
   /                   Erik Ekkel, Philips PTDSN (+31 55 433301)
  /--   __  o  /       Domain: ekkel@idca.tds.philips.nl
 /___ _/ (_(_ /(       Uucp  : ...!mcvax!philapd!ekkel

ken@jose.UUCP (Ken MacLeod) (05/12/89)

In article <739@wc11.idca.tds.philips.nl>, ekkel@idca.tds.PHILIPS.nl (Erik Ekkel) writes:
> I'm wondering if it is possible to build with INFORMIX ESQL f.i. a program
> that reads from stdin a sql-query and produces the result to stdout 
> and the errors to stderr. This would be nice to use in combination with 
> sendmail to set-up a small sql-server for queries to a remote database
> (when there are no other remote possibilities !).

  What follows after my .sig is a code fragment out of a working program I've
got.  Since you have to use a PREPARE, it only works with SELECTs, I don't
know how you can hook straight into SQL from esql (yet...).  This is a
backend program that works on a remote system.  The front end system does
a query by form and saves out the parameters that will become the WHERE
clause, that info is placed into a file and UUX'd to the backend program
on the remote system.

  UseNet is wonderfull...  If you hadn't mentioned mail in your message
this would have never occurred to me.  ISQL will work perfectly for
whatever SQL querys are wanted.  I'll play with writing a program to
take mail messages on stdin and feeding it to ISQL.  Since this would
be so useful for us, I don't think my boss will mind my spending a few
moments :-), stay tuned...

 -- Ken
   ken@jose.uucp
   {uunet!iconsys,utah-cs}!caeco!jose!ken

-----------  Code  ------------
BusinessLabels ()

{
	char optionsLine[512];
$	char query[512];
$	char membernumber[10], businessname[27], address1[24], address2[24],
	    city[14], state[3], zip[10];
$	short membernumberind, businessnameind, address1ind, address2ind,
	    cityind, stateind, zipind;

	gets (optionsLine);
	strcpy (query, "SELECT memb_no, bus_name, addr_1, addr_2, city, state, zip FROM bus_member WHERE ");
	strcat (query, optionsLine);
$	PREPARE businessquery
		FROM $query;
	if (sqlca.sqlcode != 0) {
		fprintf (stderr, "[%s:BusinessLabels:%d] ERROR: Unable to prepare query, error %d.\n",
		    programName, __LINE__, sqlca.sqlcode);
		exit (1);
	}
$	DECLARE businesscursor
		CURSOR FOR businessquery;
	if (sqlca.sqlcode != 0) {
		fprintf (stderr, "[%s:BusinessLabels:%d] ERROR: Unable to declare cursor, error %d.\n",
		    programName, __LINE__, sqlca.sqlcode);
		exit (1);
	}
$	OPEN businesscursor;
	if (sqlca.sqlcode != 0) {
		fprintf (stderr, "[%s:BusinessLabels:%d] ERROR: Unable to open cursor, error %d.\n",
		    programName, __LINE__, sqlca.sqlcode);
		exit (1);
	}
	while (1) {
$		FETCH businesscursor
			INTO $membernumber:membernumberind,
			    $businessname:businessnameind,
			    $address1:address1ind, $address2:address2ind,
			    $city:cityind, $state:stateind, $zip:zipind;
		/* ... OTHER CODE ... */
	}
}