Ruby - Postgresql Istruzioni per l'uso

Ruby
Nota tutta la procedura si intende utilizzata in ambiente shell bash e PostgreSQL compilato in /usr/local/pgsql direttamente dal codice sorgente

Scarichiamo il pacchetto

$ wget -c ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p72.tar.gz
$ tar xvfz ruby-1.8.7-p72.tar.gz
$cd ruby-1.8.7-p72

$ ./configure --prefix=/usr/local/ruby
$ make
$ sudo su
# make install

lanciamo ruby con
# /usr/local/ruby/bin/ruby --version
# ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-linux]

Modulo Ruby - PG
$ wget -c http://rubyforge.org/frs/download.php/54107/ruby-pg-0.8.0.tar.gz

$ tar xvfz ruby-pg-0.8.0.tar.gz
$ cd ruby-pg-0.8.0

$ export PATH=$PATH:/usr/local/pgsql/bin/

$ /usr/local/ruby/bin/ruby ext/extconf.rb --with-pgsql-include=/usr/local/pgsql/include --with-pgsql-lib=/usr/local/pgsql/lib

$ make
$ sudo su
# make install

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

def main
pghost = "127.0.0.1"
pgport = "5432"
pgoptions = nil
pgtty = nil
dbname = "testdb"
login = "postgres"
password = nil
begin
conn = PGconn.connect(pghost,pgport,pgoptions,pgtty,dbname,login,password)
if $DEBUG
fd = open("/tmp/trace.out","w")
conn.trace(fd)
end
res = conn.exec("BEGIN")
res.clear
res = conn.query("select id_user,firstname,email from users order by 2")

res.each do |row|
puts "#{row['id_user']} #{row['firstname']} #{row['email']}"
end
end

res.clear
res = conn.exec("COMMIT")
res.clear
conn.close

end
main

Back to top

Privacy Policy | Project hosted by linuxtime.it | pgTheme is a Drupal 6.x Theme creato da Massimiliano Marini per PSQL.it
Original Theme Designed by tinysofa for The Official Site of PostgreSQL