File: import_sampledata.tcl

package info (click to toggle)
pgtcl 1%3A1.9%2Bgit20120911-3
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,240 kB
  • ctags: 315
  • sloc: ansic: 4,475; tcl: 634; sh: 149; makefile: 36; sql: 11
file content (34 lines) | stat: -rw-r--r-- 869 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#
# program to insert the sampledata.txt data set into pgtest_people
#
# $Id$
#

package require Pgtcl

if {[file exists conninfo.tcl]} {
    source conninfo.tcl
}

proc doit {} {
    set fp [open sampledata.txt]

    if {[info exists ::conninfo]} {
        set conn [pg_connect -connlist [array get ::conninfo]]
    } else {
        set conn [pg_connect -conninfo ""]
    }

    while {[gets $fp line] >= 0} {
	set statement "insert into pgtest_people values ([pg_quote [lindex $line 0]], [pg_quote [lindex $line 1]], [pg_quote [lindex $line 2]], [pg_quote [lindex $line 3]], [pg_quote [lindex $line 4]], [pg_quote [lindex $line 5]]);"

	set result [pg_exec $conn $statement]
        if {[pg_result $result -status] != "PGRES_COMMAND_OK"} {
	    puts "[pg_result $result -error] executing '$statement'"
	}
	pg_result $result -clear
    }
}

if !$tcl_interactive doit