|
Chapter 4. pgtcl - TCL 绑定库
4.1. 介绍pgtcl 是一个用于前端和 PostgreSQL 后端交互的 Tcl 包.它把大多数 libpq 库的函数/功能做成可用于 Tcl 脚本. 这个包最初是 Jolly Chen 写的. Table 4-1 给了我们一个在 pgtcl 里可用命令的概述. 这些命令在后面更多的内容里详细介绍. Table 4-1. pgtcl 命令
pg_lo_* 过程都是与 PostgreSQL 大对象特性交互的接口. 这些函数是仿照标准 Unix 文件系统接口的做法设计的. pg_lo_* 过程应该用于一个 BEGIN / COMMIT 事务块里头, 因为 pg_lo_open 返回的文件描述符只是在当前事务中有效. pg_lo_import 和 pg_lo_export 必须 在一个 BEGIN / END 事务块里面使用. Example 4-1 演示了一个如何使用这些过程的一个 小例子. Example 4-1. pgtcl 例子程序 # getDBs : # get the names of all the databases at a given host and port number # with the defaults being the localhost and port 5432 # return them in alphabetical order # # 获取给定主机和端口号上的所有数据库,缺省是 localhost 和端口 5432 # 并且按照字母顺序返回它们 # proc getDBs { {host "localhost"} {port "5432"} } { # datnames is the list to be result set conn [pg_connect template1 -host $host -port $port] set res [pg_exec $conn "SELECT datname FROM pg_database ORDER BY datname"] set ntups [pg_result $res -numTuples] for {set i 0} {$i < $ntups} {incr i} { lappend datnames [pg_result $res -getTuple $i] } pg_result $res -clear pg_disconnect $conn return $datnames } |