Sophie

Sophie

distrib > CentOS > 5 > x86_64 > by-pkgid > dc5bd15dd837bfdf58139cb74856b967 > files > 41

postgresql-tcl-8.1.23-10.el5_10.x86_64.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML
><HEAD
><TITLE
>Example - Connect and query with pg_execute</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Pgtcl Reference Manual"
HREF="index.html"><LINK
REL="UP"
TITLE="Example Programs"
HREF="pgtcl-examples.html"><LINK
REL="PREVIOUS"
TITLE="Example Programs"
HREF="pgtcl-examples.html"><LINK
REL="NEXT"
TITLE="Example - Get List of Databases"
HREF="pgtcl-example-dblist.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
NAME="creation"
CONTENT="2004-11-09T00:53:06"></HEAD
><BODY
CLASS="SECT1"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Pgtcl Reference Manual: The PostgreSQL Tcl Interface</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="pgtcl-examples.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 5. Example Programs</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="pgtcl-example-dblist.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="PGTCL-EXAMPLE-CNQ-EXECUTE"
>5.2. Example - Connect and query with pg_execute</A
></H1
><P
>This example is the same as the previous example, except
it uses <A
HREF="pg-execute.html"
>pg_execute</A
> instead of <A
HREF="pg-exec.html"
>pg_exec</A
> to
query the database. <CODE
CLASS="FUNCTION"
>pg_execute</CODE
> is simpler to use
in some circumstances, but less flexible since it does not return
a result handle.</P
><P
>In this example, we use the fact that <CODE
CLASS="FUNCTION"
>pg_execute</CODE
> will
store the query values as variables named by the result column names
(if not given the <VAR
CLASS="OPTION"
>-array name</VAR
> option), and if the query
returns a single row there is no need for a procedure body.</P
><DIV
CLASS="EXAMPLE"
><A
NAME="PGTCL-EXAMPLE-CNQ-EXECUTE-CODE"
></A
><P
><B
>Example 5-2. Connect to the database and get its version with pg_execute</B
></P
><PRE
CLASS="PROGRAMLISTING"
>set conn [pg_connect -conninfo "host=server.example.com dbname=template1 user=guest password=secret"]
pg_execute $conn "SELECT version() AS v"
puts "Server version is: $v"
pg_disconnect $conn</PRE
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="pgtcl-examples.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="pgtcl-example-dblist.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Example Programs</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="pgtcl-examples.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Example - Get List of Databases</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>