home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.databases.ingres
- Path: sparky!uunet!wupost!darwin.sura.net!uvaarpa!cv3.cv.nrao.edu!mail-to-news-gateway
- From: CS_PAUL@GSBVAX.UCHICAGO.EDU (Paul Ford 312/702-0335)
- Subject: Re: select * with a 3-way join having same column names in ESQL/C
- Message-ID: <920729102620.29401bab@GSBVAX.UCHICAGO.EDU>
- Sender: daemon@nrao.edu
- Organization: National Radio Astronomy Observatory
- Date: Wed, 29 Jul 1992 15:26:20 GMT
- Lines: 65
-
- Alan Crosswell writes:
-
- >I had a code segment which said:
- >
- > exec sql declare x cursor for
- > select *
- > from hosts h, hwaddr hw, ip i
- > where h.hname=i.hname
- > and i.ipaddr=hw.ipaddr;
- >
- > exec sql fetch x into :hosts,:ip,:hwaddr;
- >
- > I got random wierd results under 6.3 and 6.4 include garbage data and
- > numeric type conversion error messages until I changed the code to select
- > explicit columns and fetch into explicit struct members in the same order.
-
- Your select results are in a different order than your fetch results. You
- might try fetching into the structures in the same order that you named the
- tables in the from clause:
-
- exec sql fetch x into :hosts, :hwaddr, :ip ;
-
- Or, you could force the result columns into the fetch order order by doing
-
- select h.*, i.*, hw.*
-
- But, I think your choice to name the result and fetch columns explicitly was
- the right one. You might consider some of the disadvantages of the * notation
- for anything but interactive SQL (in addition to the one you just ran into):
-
- * notation causes code to break when columns are added or reordered:
-
- When (not if) you change the structure of a table, by adding columns or
- reordering columns, your embedded code will break until you rerun
- DCLGEN, recompile and relink. On the other hand, if you've explicitly
- named every column in the select statement, your embedded program will
- continue to run without error. (What your program should do with the
- additional column is a separate issue.) Column deletions are still a
- problem, but they tend to be much rarer than additions.
-
- * notation makes code harder to read and maintain
-
- Naming all the result columns is a form of documentation. If your code
- has to be maintained in the future by someone less familiar with the
- tables (after a short interval that might be you :-) it is a lot easier
- to figure out what's coming from where with an explicit list of column
- names.
-
- Hard experience over many years has taught us _NEVER_ to use * notation in
- our 4GL or embedded 3GL select statments. The extra editing effort up
- front (a lot of cut and paste of lists of columns, usually started by
- sucking the DCLGEN file into the editor for the complete current list) pays
- for itself many times over in robustness and ease of maintenance. Don't
- forget that the time spent actually writing code ends up being only a small
- fraction of the total cost of developing and maintaining software.
-
- Paul Ford
- -----------------------------------------------------------------------
- GSB Computing Services 312.702.0335
- University of Chicago cs_paul@gsbvax.uchicago.edu
- 1101 E. 58th Street
- Chicago IL 60637
- -----------------------------------------------------------------------
-
-
-