5.2.用例 - pg_executeを使って接続し問合せする 5.2.Example - Connect and query with pg_execute
Prev | Chapter5.Example Programs | Next

## 5.2.Example - Connect and query with pg_execute

この用例は､データベースへの問合せに､ pg_exec の代りに､ pg_execute を使うことを除いて､ 前の用例と同じである｡pg_execute は幾つかの環境では使用は簡単だが､結果の把持子を返さないので､柔軟性に劣る｡ This example is the same as the previous example, except it uses pg_execute instead of pg_exec to query the database. `pg_execute` is simpler to use in some circumstances, but less flexible since it does not return a result handle.

この用例では､pg_executeは問合せの値を､結果列名( -array 名称指示項目がない場合)によって名付けられた変数として保存する事実を使う､又､もし問合せが､一個の行を返す場合は手続き函数本体の必要はない｡ In this example, we use the fact that `pg_execute` will store the query values as variables named by the result column names (if not given the `-array name` option), and if the query returns a single row there is no need for a procedure body.

Example5.2. pg_executeでデータベースに接続しその版番号を得る Connect to the database and get its version with pg_execute

    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

Prev | Up | Next
Chapter5.Example Programs | Home | 5.3.Example - Get List of Databases