Sophie

Sophie

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

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 Programs</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Pgtcl Reference Manual"
HREF="index.html"><LINK
REL="PREVIOUS"
TITLE="pg_lo_export"
HREF="pg-lo-export.html"><LINK
REL="NEXT"
TITLE="Example - Connect and query with pg_execute"
HREF="pgtcl-example-cnq-execute.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
NAME="creation"
CONTENT="2004-11-09T00:53:06"></HEAD
><BODY
CLASS="CHAPTER"
><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="pg-lo-export.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="pgtcl-example-cnq-execute.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="CHAPTER"
><H1
><A
NAME="PGTCL-EXAMPLES"
></A
>Chapter 5. Example Programs</H1
><BLOCKQUOTE
CLASS="ABSTRACT"
><DIV
CLASS="ABSTRACT"
><P
></P
><A
NAME="AEN2592"
></A
><P
>This chapter contains several examples of <SPAN
CLASS="APPLICATION"
>pgtcl</SPAN
>.
Most of these are not self-contained programs, and in many cases error
checking has been omitted for clarity.
  </P
><P
></P
></DIV
></BLOCKQUOTE
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="PGTCL-EXAMPLE-CNQ-EXEC"
>5.1. Example - Connect and query with pg_exec</A
></H1
><P
>This example shows how to connect to the database
and get the server version string using <A
HREF="pg-exec.html"
>pg_exec</A
>.</P
><P
>Note that <TT
CLASS="LITERAL"
>pg_result ... -getTuple</TT
> always returns a Tcl
list of values, even if only a single column of data is produced by the query.
To get the first (or only) column value, you must use
<CODE
CLASS="FUNCTION"
>lindex</CODE
>.</P
><DIV
CLASS="EXAMPLE"
><A
NAME="PGTCL-EXAMPLE-CNQ-EXEC-CODE"
></A
><P
><B
>Example 5-1. Connect to the database and get its version with pg_exec</B
></P
><PRE
CLASS="PROGRAMLISTING"
>set conn [pg_connect -conninfo "host=server.example.com dbname=template1 user=guest password=secret"]
set result [pg_exec $conn "SELECT version()"]
set value [lindex [pg_result $result -getTuple 0] 0]
pg_result $result -clear
puts "Server version is: $value"
pg_disconnect $conn</PRE
></DIV
></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="pg-lo-export.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-cnq-execute.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>pg_lo_export</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Example - Connect and query with pg_execute</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>