Chapter5.Example Programs
Prev |  | Next

# Chapter5.Example Programs

本章は pgtcl の幾つかの用例を含む｡多くは､自己含有算譜ではない､又､多くの場合､明瞭さの為に不都合確認は略されている｡ This chapter contains several examples of pgtcl. Most of these are not self-contained programs, and in many cases error checking has been omitted for clarity.

## 5.1.Example - pg_exec で接続し問合せる Connect and query with pg_exec

この例では､pg_execを使って､ 如何にデータベースに接続し､そして､中央集中処理系の版番号を得るかを示す｡ This example shows how to connect to the database and get the server version string using pg_exec.

註意すべきは､pg_result ... -getTuple は､縦え､問合せによって データの一列が生成されても､常に値のtclリストを返す｡ 最初の(又は一個だけの)列の値をえるには､lindex を使う必要がある｡ Note that `pg_result ... -getTuple` 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 `lindex`.

Example5.1. pg_exeでデータベースに接続し版番号を取得する Connect to the database and get its version with pg_exec

    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

Prev |  | Next
4.6.Large Object Processing Commands | Home | 5.2.Example - Connect and query with pg_execute