Re: pg_select in a tcl script

From: Andreas Kretzer <andi(at)kretzer-berlin(dot)de>
To: Postgres Interface List <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: pg_select in a tcl script
Date: 2002-03-02 13:04:19
Message-ID: 3C80CDD3.776AA9AA@kretzer-berlin.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

ljb wrote:

> steve(at)customware(dot)aust(dot)com wrote:
> > Hi
> >
> > The documentation for pg_select says that "the return result is either
> > an error message or a handle for a query result".
> >
> > How can I catch this output? and How do I determine if it is an error or
> > a handle?
> >
> > I have tried
> >
> > set res [pg_select ...]
> > pg_result res -status
> > complains that res is not a result handle, it seems to be a null value.
>
> No result handle is returned. pg_select creates, uses, and then destroys
> the result structure before it returns. Where in the documentation did
> you see the above quote?

The documentation of the Tcl binding is not very complete ... :-(
Perhaps I should (some day) write some stuff for it ... (I'm doing
a lot of stuff with it -- so maybe it's a good idea to write all that
from a pratical point of view).

To your question:

pg_select loops over a set of records. If something is wrong, the loop
is just not executed. So the typical use of pg_select could look like
this:

set query "SELECT * FROM something WHERE anyitem = $searchval;"
pg_select $conn $query tmp {
puts "$tmp(anyitem) $tmp(anotheritem) $tmp(whatsoever)"
}

The fields in the result are placed in the array 'tmp' with the column
names used as array index. Pay attention to columns with duplicate names
(if you are selecting from more than one set). Use 'AS some_other_name'
to overcome ambiguity of the items.

There seems to be no way to find out if there are just no matching rows
or if something is wrong with the connection or your code ...

As far as the SELECT statement is static you can ensure correctness by
intensive tests during development (just make sure that there are rows
matching your request). Any dynamically setup query is hard to check.

Hope this helps

Andreas

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message John Oakes 2002-03-03 00:43:04 Re: jdbc
Previous Message jtv 2002-03-02 11:22:18 Re: Beating Oracle