Sha256: a4d4fa24a0ea03d6e605968a7e92db46e220866c237cba2d64412bf9c48e99e8

Contents?: true

Size: 1.26 KB

Versions: 7

Compression:

Stored size: 1.26 KB

Contents

#! /usr/bin/env ruby
#
# original file src/test/examples/testlibpq.c
# 
require 'pg'

def main
  pghost = nil
  pgport = nil
  pgoptions = nil
  pgtty = nil
  dbname = "template1"
  begin
    conn = PGconn.connect(pghost,pgport,pgoptions,pgtty,dbname)
    if $DEBUG
      fd = open("/tmp/trace.out","w")
      conn.trace(fd)
    end 
    res = conn.exec("BEGIN")
    res.clear
    res = conn.exec("DECLARE myportal CURSOR FOR select * from pg_database")
    res.clear

    res = conn.exec("FETCH ALL in myportal")
    if (res.result_status != PGresult::PGRES_TUPLES_OK)
      raise PGerror,"FETCH ALL command didn't return tuples properly\n"
    end

    for fld in res.fields
      printf("%-15s",fld)
    end
    printf("\n\n")

    res.values.each do |tupl|
      tupl.each do |fld|
	printf("%-15s",fld)
      end
      printf("\n")
    end
    res = conn.exec("CLOSE myportal")
    res = conn.exec("END")
    res.clear
    conn.close

    if $DEBUG
      fl.close
    end
  rescue PGError
    if (conn.status == PGconn::CONNECTION_BAD)
      printf(STDERR, "We have lost the connection to the backend, so ")
      printf(STDERR, "further processing is impossible.  ")
      printf(STDERR, "Terminating.\n")
    else
      printf(STDERR, conn.error)
    end
    exit(1)
  end
end

main

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pg-0.12.2-x86-mingw32 sample/test1.rb
pg-0.12.2 sample/test1.rb
pg-0.12.1 sample/test1.rb
pg-0.12.0-x86-mingw32 sample/test1.rb
pg-0.12.0 sample/test1.rb
pg-0.12.0.pre263 sample/test1.rb
pg-0.12.0pre258 sample/test1.rb