Re: pg_select in a tcl script - Mailing list pgsql-interfaces

From Andreas Kretzer
Subject Re: pg_select in a tcl script
Date
Msg-id 3C80CDD3.776AA9AA@kretzer-berlin.de
Whole thread Raw
In response to pg_select in a tcl script  (Steve Burger <steve@customware.aust.com>)
List pgsql-interfaces
<tt>ljb wrote:</tt><blockquote type="CITE"><tt>steve@customware.aust.com wrote:</tt><br /><tt>> Hi</tt><br
/><tt>></tt><br/><tt>> The documentation for pg_select says that "the return result is either</tt><br /><tt>>
anerror message or a handle for a query result".</tt><br /><tt>></tt><br /><tt>> How can I catch this output? and
Howdo I determine if it is an error or</tt><br /><tt>> a handle?</tt><br /><tt>></tt><br /><tt>> I have
tried</tt><br/><tt>></tt><br /><tt>>     set res [pg_select ...]</tt><br /><tt>>     pg_result res
-status</tt><br/><tt>> complains that res is not a result handle, it seems to be a null
value.</tt><tt></tt><p><tt>Noresult handle is returned.  pg_select creates, uses, and then destroys</tt><br /><tt>the
resultstructure before it returns. Where in the documentation did</tt><br /><tt>you see the above
quote?</tt></blockquote><tt>Thedocumentation of the Tcl binding is not very complete ... :-(</tt><br /><tt>Perhaps I
should(some day) write some stuff for it ... (I'm doing</tt><br /><tt>a lot of stuff with it -- so maybe it's a good
ideato write all that</tt><br /><tt>from a pratical point of view).</tt><tt></tt><p><tt>To your
question:</tt><tt></tt><p><tt>pg_selectloops over a set of records. If something is wrong, the loop</tt><br /><tt>is
justnot executed. So the typical use of pg_select could look like</tt><br /><tt>this:</tt><tt></tt><p><tt>    set query
"SELECT* FROM something WHERE anyitem = $searchval;"</tt><br /><tt>    pg_select $conn $query tmp {</tt><br
/><tt>       puts "$tmp(anyitem) $tmp(anotheritem) $tmp(whatsoever)"</tt><br /><tt>    }</tt><tt></tt><p><tt>The fields
inthe result are placed in the array 'tmp' with the column</tt><br /><tt>names used as array index. Pay attention to
columnswith duplicate names</tt><br /><tt>(if you are selecting from more than one set). Use 'AS
some_other_name'</tt><br/><tt>to overcome ambiguity of the items.</tt><tt></tt><p><tt>There seems to be no way to find
outif there are just no matching rows</tt><br /><tt>or if something is wrong with the connection or your code
...</tt><tt></tt><p><tt>Asfar as the SELECT statement is static you can ensure correctness by</tt><br /><tt>intensive
testsduring development (just make sure that there are rows</tt><br /><tt>matching your request). Any dynamically setup
queryis hard to check.</tt><tt></tt><p><tt>Hope this helps</tt><tt></tt><p><tt>Andreas</tt> 

pgsql-interfaces by date:

Previous
From: jtv
Date:
Subject: Re: Beating Oracle
Next
From: ljb
Date:
Subject: May we use libpgtcl pg_execute? / Was: pg_select...