diff --git a/.gemtest b/.gemtest new file mode 100644 index 0000000..e69de29 diff --git a/Contributors b/Contributors index 27ab864..0990d6d 100644 --- a/Contributors +++ b/Contributors @@ -1,32 +1,37 @@ -Dennis Vshivkov -Gabriel Emerson -Noboru Saitou -Akinori MUSHA -Andy Yu -Ceri Storey -Gavin Kistner -Henry T. So Jr. -Jeremy Henty - -Leon Brooks -Martin Hedenfalk - -MoonWolf - -Nate Haggard -Neil Conway -Noboru Matui -Okada Jun -Shirai,Kaoru -Riley -shibata - -ts -Yuta TSUBOI -Lugovoi Nikolai -Jeff Davis -Bertram Scharpf -Michael Granger -Mahlon E. Smith + +Thanks to all the great people that have contributed code, suggestions, and patches through the years. If you contribute a patch, please include a patch for this file that adds your name to the list. + +* Dennis Vshivkov +* Gabriel Emerson +* Noboru Saitou +* Akinori MUSHA +* Andy Yu +* Ceri Storey +* Gavin Kistner +* Henry T. So Jr. +* Jeremy Henty +* +* Leon Brooks +* Martin Hedenfalk +* Yukihiro Matsumoto +* Eiji Matsumoto +* MoonWolf +* +* Nate Haggard +* Neil Conway +* Noboru Matui +* Okada Jun +* Shirai,Kaoru +* Riley +* shibata +* +* ts +* Yuta TSUBOI +* Lugovoi Nikolai +* Jeff Davis +* Bertram Scharpf +* Michael Granger +* Mahlon E. Smith + Jason Yanowitz diff --git a/History.md b/History.md new file mode 100644 index 0000000..357af08 --- /dev/null +++ b/History.md @@ -0,0 +1,41 @@ +## 0.11.0 [2011-02-09] Michael Granger + +Enhancements: + +* Added a PGresult#values method to fetch all result rows as an Array of + Arrays. Thanks to Jason Yanowitz (JYanowitz at enovafinancial dot com) for + the patch. + + +## 0.10.1 [2011-01-19] Michael Granger + +Bugfixes: + +* Add an include guard for pg.h +* Simplify the common case require of the ext +* Include the extconf header +* Fix compatibility with versions of PostgreSQL without PQgetCancel. (fixes #36) +* Fix require for natively-compiled extension under Windows. (fixes #55) +* Change rb_yield_splat() to rb_yield_values() for compatibility with Rubinius. (fixes #54) + + +## 0.10.0 [2010-12-01] Michael Granger + +Enhancements: + +* Added support for the payload of NOTIFY events (w/Mahlon E. Smith) +* Updated the build system with Rubygems suggestions from RubyConf 2010 + +Bugfixes: + +* Fixed issue with PGconn#wait_for_notify that caused it to miss notifications that happened after + the LISTEN but before the wait_for_notify. + +## 0.9.0 [2010-02-28] Michael Granger + +Bugfixes. + +## 0.8.0 [2009-03-28] Jeff Davis + +Bugfixes, better Windows support. + diff --git a/Manifest.txt b/Manifest.txt new file mode 100644 index 0000000..cda427a --- /dev/null +++ b/Manifest.txt @@ -0,0 +1,38 @@ +.gemtest +BSD +ChangeLog +Contributors +GPL +History.md +LICENSE +Manifest.txt +README.OS_X.md +README.ja.md +README.md +README.windows.md +Rakefile +ext/compat.c +ext/compat.h +ext/extconf.rb +ext/pg.c +ext/pg.h +ext/vc/pg.sln +ext/vc/pg_18/pg.vcproj +ext/vc/pg_19/pg_19.vcproj +lib/pg.rb +sample/async_api.rb +sample/copyfrom.rb +sample/losample.rb +sample/notify_wait.rb +sample/psql.rb +sample/psqlHelp.rb +sample/test1.rb +sample/test2.rb +sample/test4.rb +sample/test_binary_values.rb +spec/data/expected_trace.out +spec/data/random_binary_data +spec/lib/helpers.rb +spec/m17n_spec.rb +spec/pgconn_spec.rb +spec/pgresult_spec.rb diff --git a/README.OS_X b/README.OS_X deleted file mode 100644 index 7ed6f84..0000000 --- a/README.OS_X +++ /dev/null @@ -1,19 +0,0 @@ -= Compiling on MacOS X - -If you are building/installing ruby-pg on MacOS X, and the installation doesn't work at first, here are a few things you can try. - -== Compiling With the Correct Architecture - -OS X supports both architecture-specific binaries (e.g. i386), as well as universal binaries (i.e. i386 & ppc). If ruby is built as a universal binary and postgresql is not, you need to specify the path to the appropriate pg_config binary or set the environment variable ARCHFLAGS appropriately. - -For example, if you're using the stock Ruby binary, and PostgreSQL 8.4.x installed from MacPorts (without specifying the {{{+universal}}} variant), do: - - gem install -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config - -Alternatively, if the build system can't figure out which architectures it should include, you may need to set the 'ARCHFLAGS' environment variable explicitly: - - sudo env ARCHFLAGS='-arch i386' gem install pg - -or, if you're building from source: - - rake compile ARCHFLAGS="-arch i386" diff --git a/README.OS_X.md b/README.OS_X.md new file mode 100644 index 0000000..16505f0 --- /dev/null +++ b/README.OS_X.md @@ -0,0 +1,18 @@ +# Compiling on MacOS X + +If you are building/installing ruby-pg on MacOS X, and the installation doesn't work at first, here are a few things you can try. + +OS X supports both architecture-specific binaries (e.g. i386), as well as universal binaries (i.e. i386 & ppc). If Ruby is built as a universal binary and PostgreSQL is not, you need to specify the path to the appropriate pg_config binary or set the environment variable ARCHFLAGS appropriately. + +For example, if you're using the Ruby binary that comes with OSX, and PostgreSQL 9.0.2 installed from MacPorts (without specifying the `+universal' variant), do: + + gem install -- --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config + +Alternatively, if the build system can't figure out which architectures it should include, you may need to set the 'ARCHFLAGS' environment variable explicitly: + + sudo env ARCHFLAGS='-arch i386' gem install pg + +or, if you're building from source: + + rake compile ARCHFLAGS="-arch i386" + diff --git a/README.ja b/README.ja deleted file mode 100644 index 0e7dc2a..0000000 --- a/README.ja +++ /dev/null @@ -1,183 +0,0 @@ - PostgreSQL用拡張ライブラリ version 0.7.1 - - まつもと ゆきひろ - まつもと えいじ - - 世話人: 斉藤 登 - -- What's this ? - -本ライブラリは、RubyからPostgreSQLへアクセスするための拡張ライブラリです。 -サポートしているPostgreSQLのバージョンは、6.5/7.0/7.1/7.2 です。6.3以前の -バージョンでも(ちょっとした変更で)動作すると思いますが、テストしていません。 - -- How to install ? - *** requirement *** - PostgreSQL moduleを使うんですから,当然PostgreSQLは必要ですね.今のところ - ローカルにPostgreSQLがインストールされていることを前提にしていますが, - 必要なヘッダとlibpqさえあれば,サーバは必ずしもローカルで動作している必要 - はありません. - - デフォルトでは,PostgreSQLが/usr/local/pgsql配下にインストールされている - としています.別の場所にインストールしている場合には,環境変数PGLIBにlibpq - ライブラリが置いてあるdirectoryに設定して下さい。 - - 任意の場所で,このアーカイブを展開してください.後は - - ruby extconf.rb - make - su (もし必要なら) - make install - - とするだけです.PostgreSQLのインクルードファイル、ライブラリファイルの - インストール場所が標準の位置ではなくコンパイラが見付けることができない - 場合には - - --with-pgsql-include-dir=<インクルードファイルディレクトリ> - --with-pgsql-lib-dir=<ライブラリディレクトリ> -または - --with-pgsql-dir=<ディレクトリ> - これは以下のように指定したときとおなじです。 - --with-pgsql-include-dir=<ディレクトリ>/include - --with-pgsql-lib-dir=<ディレクトリ>/lib - - - 例えば - - ruby extconf.rb --with-pgsql-include-dir=/usr/local/pgsql/include \ - --with-pgsql-lib-dir=/usr/local/pgsql/lib -または - ruby extconf.rb --with-pgsql-dir=/usr/local/pgsql - - のように指定してください。 - -- How to use ? - - require "postgres" - -としてから御使用下さい。 - -- What function can I use ? - -基本的に、Cのlibpqインタフェースで定義されている関数はサポートしています。 -ver 0.6.0 から新しく Large Object インターフェイスが追加されました。 - -サポートしているメソッドの一覧は以下の通りです。 - -PGconnクラス: - - クラスメソッド - new - connect - setdb - setdblogin - escape - quote - escape_bytea - - メソッド - db - host - options - port - tty - status - error - finish - close - reset - user - trace - untrace - - exec - query - async_exec - async_query - get_notify - insert_table - putline - getline - endcopy - notifies - - lo_import - lo_export - lo_create - lo_open - lo_unlink - - client_encoding - set_client_encoding - -PGresultクラス: - -メソッド - each - [] - status - result - fields - num_tuples - num_fields - fieldname - fieldnum - type - size - getvalue - getlength - cmdstatus - print - clear - -PGlargeクラス: - -メソッド - open - close - read - write - lseek - tell - unlink - oid - size - export - -- Acknowledgement - -本拡張ライブラリを作成するにあたって、ruby-list, ruby-dev, -ruby-talk,及び pgsql-jpメーリングリストのメンバーに、多くの有益な -アドバイスを頂きました。ここに感謝の意を表します。 - -- Copying - -本拡張ライブラリの著作権は、まつもと ゆきひろとまつもと えいじが -保持します。 - -本拡張ライブラリは、Ruby本体と同じ配布条件に従って再配布すること -ができます。Ruby本体の配布条件については、Ruby配布物中のREADME.jp -に書かれています。 - -現在は斉藤 登が maintainer を承っているので、問い合わせはこちらの方に -お願いします。 - -- Author - - まつもと ゆきひろ - Author of Ruby - - まつもと えいじ - One of users who loves Ruby - -このふたりは兄弟ではありません。 :-) - -- Special Thanks - - Guy Decoux ts - -- maintainer - - 斉藤 登 - まつもとでなくてすいません :-) - diff --git a/README.ja.md b/README.ja.md new file mode 100644 index 0000000..07d11cf --- /dev/null +++ b/README.ja.md @@ -0,0 +1,6 @@ +# pg + +* https://bitbucket.org/ged/ruby-pg + +This file needs translation. Anyone who is willing to volunteer, please mail . + diff --git a/README b/README.md similarity index 50% rename from README rename to README.md index cd37da6..2c115b9 100644 --- a/README +++ b/README.md @@ -1,54 +1,75 @@ -= ruby-pg: Ruby interface to PostgreSQL RDBMS +# pg -This is the extension library to access a PostgreSQL database from Ruby. This -library works with PostgreSQL 7.4 and later. +* https://bitbucket.org/ged/ruby-pg -== Requirements +## Description + +Pg is the Ruby interface to the [PostgreSQL RDBMS][postgresql]. + +It works with PostgreSQL 8.2 and later. + + +## Requirements * Ruby 1.8.7-p174 or later. -* PostgreSQL 7.4 or later installed. +* PostgreSQL 8.2.x or later installed. It may work with earlier versions as well, but those are not regularly tested. -== How To Install + +## How To Install Install via RubyGems: - gem install pg - -Or install from source: - - rake install + gem install pg You may need to specify the path to the 'pg_config' program installed with Postgres: - rake -- --with-pg-config= + gem install pg -- --with-pg-config= -For example, on a Mac with PostgreSQL installed via MacPorts -(port install postgresql84): +For example, on a Mac with PostgreSQL installed via MacPorts (`port install +postgresql90`): - rake install -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config + gem install pg -- \ + --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config -See README.OS_X for more information about installing under MacOS X, and -README.windows for Windows build/installation instructions. +See README.OS_X.md for more information about installing under MacOS X, and +README.windows.md for Windows build/installation instructions. -== Copying + +## Contributing + +To report bugs, suggest features, or check out the source with Mercurial, +[check out the project page][bitbucket]. If you prefer Git, there's also a +[Github mirror][github]. + +After checking out the source, run: + + $ rake newb + +This task will install any missing dependencies, run the tests/specs, and +generate the API documentation. + + +## Copying This library is copyrighted by the authors. Authors: + * Yukihiro Matsumoto - Author of Ruby. * Eiji Matsumoto - One of users who loves Ruby. * Jeff Davis Thanks to: + * Noboru Saitou - Past maintainer. * Dave Lee - Past maintainer. * Guy Decoux (ts) Maintainers: -* Jeff Davis + * Michael Granger You may redistribute this software under the terms of the Ruby license, @@ -60,9 +81,14 @@ under the terms of the BSD license, included in the file "BSD". Portions copyright LAIKA, Inc. -== Acknowledgments + +## Acknowledgments We are thankful to the people at the ruby-list and ruby-dev mailing lists. And to the people who developed PostgreSQL. +[postgresql]:http://www.postgresql.org/ +[bitbucket]:http://bitbucket.org/ged/ruby-pg +[github]:https://github.com/ged/ruby-pg + diff --git a/README.windows b/README.windows.md similarity index 76% rename from README.windows rename to README.windows.md index d6ae226..28c0eeb 100644 --- a/README.windows +++ b/README.windows.md @@ -1,5 +1,4 @@ - -= Compiling on MS Windows +# Compiling 'pg' on MS Windows In order to build this extension on MS Windows you will need a couple things. @@ -24,13 +23,13 @@ In order to build ruby-pg, just run 'rake'. If the pg_config.exe executable is not in your PATH, you'll need to explicitly point ruby-pg to where your PostgreSQL headers and libraries are with something like this: - rake --with-pg-dir=c:/progra~1/postgr~1/8.3 + rake --with-pg-dir=c:/progra~1/postgr~1/8.3 Adjust your path accordingly. BE SURE TO USE THE SHORT PATH NAMES! If you try to use a path with spaces in it, the nmake.exe program will choke. -== Cross compiling for mswin32 +## Cross compiling for mswin32 Using rake-compiler a cross compiled pg-gem can be build on a linux host for the win32 platform. The generated gem is statically linked against libpq and @@ -39,37 +38,38 @@ There are no runtime dependencies to any but the standard Windows DLLs. Install mingw32. On a debian based system this should work: - apt-get install mingw32 + apt-get install mingw32 On MacOS X, if you have MacPorts installed: - port install i386-mingw32-gcc + port install i386-mingw32-gcc Install the rake-compiler: - gem install rake-compiler + gem install rake-compiler Download and cross compile ruby 1.8 and 1.9 for win32: - rake-compiler cross-ruby VERSION=1.8.7-p334 - rake-compiler cross-ruby VERSION=1.9.2-p180 + rake-compiler cross-ruby VERSION=1.8.7-p334 + rake-compiler cross-ruby VERSION=1.9.2-p180 Download and cross compile pg for win32: - rake cross native gem + rake cross native gem + or with custom versions: - rake cross native gem RUBY_CC_VERSION=1.8.7:1.9.2 OPENSSL_VERSION=1.0.0d POSTGRESQL_VERSION=9.0.3 + + rake cross native gem RUBY_CC_VERSION=1.8.7:1.9.2 OPENSSL_VERSION=1.0.0d POSTGRESQL_VERSION=9.0.3 If everything works, there should be pg-VERSION-x86-mswin32.gem in the pkg directory. -If you have any problems you can submit them via the project's issue-tracker: +## Reporting Problems - http://bitbucket.org/ged/ruby-pg/issues/new/ +If you have any problems you can submit them via [the project's issue-tracker][bitbucket], or you can join the mailing list: -Or you can join the mailing list: - - ruby-pg-general@rubyforge.org + ruby-pg-general@rubyforge.org And submit questions, problems, or solutions, so that it can be improved. + diff --git a/Rakefile b/Rakefile index 989452c..9cfe898 100644 --- a/Rakefile +++ b/Rakefile @@ -1,364 +1,134 @@ -#!rake -*- ruby -*- -# -# pg rakefile -# -# Based on various other Rakefiles, especially one by Ben Bleything -# -# Copyright (c) 2007-2010 The FaerieMUD Consortium -# -# Authors: -# * Michael Granger -# - -BEGIN { - require 'rbconfig' - require 'pathname' - basedir = Pathname.new( __FILE__ ).dirname - - libdir = basedir + "lib" - extdir = libdir + Config::CONFIG['sitearch'] - - $LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s ) - $LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s ) - $LOAD_PATH.unshift( extdir.to_s ) unless $LOAD_PATH.include?( extdir.to_s ) -} - -begin - require 'readline' - include Readline -rescue LoadError - # Fall back to a plain prompt - def readline( text ) - $stderr.print( text.chomp ) - return $stdin.gets - end -end - -begin - require 'rubygems' -rescue LoadError - module Gem - class Specification; end - end -end +#!/usr/bin/env rake require 'rbconfig' -require 'rake' -require 'rake/testtask' -require 'rake/packagetask' +require 'pathname' +require 'tmpdir' + +begin + require 'rake/extensiontask' +rescue LoadError + abort "This Rakefile requires rake-compiler (gem install rake-compiler)" +end + +begin + require 'hoe' +rescue LoadError + abort "This Rakefile requires hoe (gem install hoe)" +end + require 'rake/clean' -# require 'rake/191_compat.rb' -$dryrun = false +# Build directory constants +BASEDIR = Pathname( __FILE__ ).dirname +SPECDIR = BASEDIR + 'spec' +LIBDIR = BASEDIR + 'lib' +EXTDIR = BASEDIR + 'ext' +PKGDIR = BASEDIR + 'pkg' +TMPDIR = BASEDIR + 'tmp' -### Config constants -BASEDIR = Pathname.new( __FILE__ ).dirname.relative_path_from( Pathname.getwd ) -BINDIR = BASEDIR + 'bin' -LIBDIR = BASEDIR + 'lib' -EXTDIR = BASEDIR + 'ext' -DOCSDIR = BASEDIR + 'docs' -PKGDIR = BASEDIR + 'pkg' -DATADIR = BASEDIR + 'data' +DLEXT = Config::CONFIG['DLEXT'] +EXT = LIBDIR + "pg_ext.#{DLEXT}" -MANUALDIR = DOCSDIR + 'manual' +TESTING_TMPDIRS = Rake::FileList[ "#{Dir.tmpdir}/tmp_test_*" ] -PROJECT_NAME = 'pg' -PKG_NAME = PROJECT_NAME.downcase -PKG_SUMMARY = 'A Ruby interface to the PostgreSQL RDBMS' +CLOBBER.include( *TESTING_TMPDIRS ) +CLEAN.include( PKGDIR.to_s, TMPDIR.to_s ) -# Cruisecontrol stuff -CC_BUILD_LABEL = ENV['CC_BUILD_LABEL'] -CC_BUILD_ARTIFACTS = ENV['CC_BUILD_ARTIFACTS'] || 'artifacts' +# Set up Hoe plugins +Hoe.plugin :mercurial +Hoe.plugin :signing -VERSION_FILE = LIBDIR + '../ext/pg.c' -if VERSION_FILE.exist? && buildrev = ENV['CC_BUILD_LABEL'] - PKG_VERSION = VERSION_FILE.read[ /VERSION\s*=\s*['"](\d+\.\d+\.\d+)['"]/, 1 ] + '.' + buildrev -elsif VERSION_FILE.exist? - PKG_VERSION = VERSION_FILE.read[ /VERSION\s*=\s*['"](\d+\.\d+\.\d+)['"]/, 1 ] +Hoe.plugins.delete :rubyforge +Hoe.plugins.delete :compiler + + +# Hoe specification +$hoespec = Hoe.spec 'pg' do + self.readme_file = 'README.md' + self.history_file = 'History.md' + + self.developer 'Jeff Davis', 'ruby-pg@j-davis.com' + self.developer 'Michael Granger', 'ged@FaerieMUD.org' + + self.dependency 'rake-compiler', '~> 0.7' + self.dependency 'rspec', '~> 2.4', :developer + + self.spec_extras[:licenses] = ['BSD', 'Ruby', 'GPL'] + self.spec_extras[:extensions] = [ 'ext/extconf.rb' ] + + self.require_ruby_version( '>= 1.8.7' ) + + self.hg_sign_tags = true if self.plugin?( :mercurial ) + + self.rdoc_locations << "deveiate:/usr/local/www/public/code/#{remote_rdoc_dir}" end -PKG_VERSION = '0.0.0' unless defined?( PKG_VERSION ) && !PKG_VERSION.nil? +ENV['VERSION'] ||= $hoespec.spec.version.to_s -PKG_FILE_NAME = "#{PKG_NAME.downcase}-#{PKG_VERSION}" -GEM_FILE_NAME = "#{PKG_FILE_NAME}.gem" +# Tests should pass before checking in +task 'hg:precheckin' => :spec -# Universal VCS constants -DEFAULT_EDITOR = 'vi' -COMMIT_MSG_FILE = 'commit-msg.txt' -FILE_INDENT = " " * 12 -LOG_INDENT = " " * 3 +# Support for 'rvm specs' +task :specs => :spec -EXTCONF = EXTDIR + 'extconf.rb' +# Compile before testing +task :spec => :compile -ARTIFACTS_DIR = Pathname.new( CC_BUILD_ARTIFACTS ) - -TEXT_FILES = Rake::FileList.new( %w[Rakefile ChangeLog README* LICENSE] ) -BIN_FILES = Rake::FileList.new( "#{BINDIR}/*" ) -LIB_FILES = Rake::FileList.new( "#{LIBDIR}/**/*.rb" ) -EXT_FILES = Rake::FileList.new( "#{EXTDIR}/**/*.{c,h,rb}" ) -DATA_FILES = Rake::FileList.new( "#{DATADIR}/**/*" ) - -SPECDIR = BASEDIR + 'spec' -SPECLIBDIR = SPECDIR + 'lib' -SPEC_FILES = Rake::FileList.new( "#{SPECDIR}/**/*_spec.rb", "#{SPECLIBDIR}/**/*.rb" ) - -TESTDIR = BASEDIR + 'tests' -TEST_FILES = Rake::FileList.new( "#{TESTDIR}/**/*.tests.rb" ) - -RAKE_TASKDIR = BASEDIR + 'rake' -RAKE_TASKLIBS = Rake::FileList.new( "#{RAKE_TASKDIR}/*.rb" ) -PKG_TASKLIBS = Rake::FileList.new( "#{RAKE_TASKDIR}/{191_compat,helpers,packaging,rdoc,testing}.rb" ) -PKG_TASKLIBS.include( "#{RAKE_TASKDIR}/manual.rb" ) if MANUALDIR.exist? - -RAKE_TASKLIBS_URL = 'http://repo.deveiate.org/rake-tasklibs' - -LOCAL_RAKEFILE = BASEDIR + 'Rakefile.local' - -EXTRA_PKGFILES = Rake::FileList.new -EXTRA_PKGFILES.include( "#{BASEDIR}/README.*" ) -EXTRA_PKGFILES.include( "#{BASEDIR}/GPL" ) -EXTRA_PKGFILES.include( "#{BASEDIR}/BSD" ) -EXTRA_PKGFILES.include( "#{BASEDIR}/Contributors" ) - -RELEASE_FILES = TEXT_FILES + - SPEC_FILES + - TEST_FILES + - BIN_FILES + - LIB_FILES + - EXT_FILES + - DATA_FILES + - RAKE_TASKLIBS + - EXTRA_PKGFILES - - -RELEASE_FILES << LOCAL_RAKEFILE.to_s if LOCAL_RAKEFILE.exist? - -RELEASE_ANNOUNCE_ADDRESSES = [ - "Ruby-Talk List ", -] - -COVERAGE_MINIMUM = ENV['COVERAGE_MINIMUM'] ? Float( ENV['COVERAGE_MINIMUM'] ) : 85.0 -RCOV_EXCLUDES = 'spec,tests,/Library/Ruby,/var/lib,/usr/local/lib' -RCOV_OPTS = [ - '--exclude', RCOV_EXCLUDES, - '--xrefs', - '--save', - '--callsites', - #'--aggregate', 'coverage.data' # <- doesn't work as of 0.8.1.2.0 - ] - - -### Load some task libraries that need to be loaded early -if !RAKE_TASKDIR.exist? - $stderr.puts "It seems you don't have the build task directory. Shall I fetch it " - ans = readline( "for you? [y]" ) - ans = 'y' if !ans.nil? && ans.empty? - - if ans =~ /^y/i - $stderr.puts "Okay, fetching #{RAKE_TASKLIBS_URL} into #{RAKE_TASKDIR}..." - system 'hg', 'clone', RAKE_TASKLIBS_URL, "./#{RAKE_TASKDIR}" - if ! $?.success? - fail "Damn. That didn't work. Giving up; maybe try manually fetching?" - end - else - $stderr.puts "Then I'm afraid I can't continue. Best of luck." - fail "Rake tasklibs not present." - end - - RAKE_TASKLIBS.include( "#{RAKE_TASKDIR}/*.rb" ) +# gem-testers support +task :test do + # rake-compiler always wants to copy the compiled extension into lib/, but + # we don't want testers to have to re-compile, especially since that + # often fails because they can't (and shouldn't have to) write to tmp/ in + # the installed gem dir. So we clear the task rake-compiler set up + # to break the dependency between :spec and :compile when running under + # rubygems-test, and then run :spec. + Rake::Task[ EXT.to_s ].clear + Rake::Task[ :spec ].execute end -require RAKE_TASKDIR + 'helpers.rb' -include RakefileHelpers - -# Set the build ID if the mercurial executable is available -if hg = which( 'hg' ) - id = `#{hg} id -n`.chomp - PKG_BUILD = (id.chomp[ /^[[:xdigit:]]+/ ] || '1') -else - PKG_BUILD = '0' -end -SNAPSHOT_PKG_NAME = "#{PKG_FILE_NAME}.#{PKG_BUILD}" -SNAPSHOT_GEM_NAME = "#{SNAPSHOT_PKG_NAME}.gem" - -# Documentation constants -API_DOCSDIR = DOCSDIR + 'api' -README_FILE = TEXT_FILES.find {|path| path =~ /^README/ } || 'README' -RDOC_OPTIONS = [ - '--tab-width=4', - '--show-hash', - '--include', BASEDIR.to_s, - "--main=#{README_FILE}", - "--title=#{PKG_NAME}", - ] -YARD_OPTIONS = [ - '--use-cache', - '--protected', - '-r', README_FILE, - '--exclude', 'extconf\\.rb', - '--files', 'ChangeLog,LICENSE', - '--output-dir', API_DOCSDIR.to_s, - '--title', "#{PKG_NAME} #{PKG_VERSION}", - ] - -# Release constants -SMTP_HOST = "mail.faeriemud.org" -SMTP_PORT = 465 # SMTP + SSL - -# Project constants -PROJECT_HOST = 'deveiate.org' -PROJECT_PUBDIR = '/usr/local/www/public/code/' -PROJECT_DOCDIR = "#{PROJECT_PUBDIR}/#{PKG_NAME}" -PROJECT_SCPPUBURL = "#{PROJECT_HOST}:#{PROJECT_PUBDIR}" -PROJECT_SCPDOCURL = "#{PROJECT_HOST}:#{PROJECT_DOCDIR}" - -GEM_PUBHOST = 'rubygems.org' - -# Gem dependencies: gemname => version -DEPENDENCIES = { -} - -# Developer Gem dependencies: gemname => version -DEVELOPMENT_DEPENDENCIES = { - 'rake' => '~> 0.8.7', - 'rcodetools' => '~> 0.7.0.0', - 'rcov' => '~> 0.8.1.2.0', - 'yard' => '~> 0.6.1', - 'RedCloth' => '~> 4.2.3', - 'rspec' => '~> 2.0.1', - 'ruby-termios' => '~> 0.9.6', - 'text-format' => '~> 1.0.0', - 'tmail' => '~> 1.2.3.1', - 'rake-compiler' => '~>0.7.0', -} - -# Non-gem requirements: packagename => version -REQUIREMENTS = { - 'PostgreSQL' => '>=7.4', -} - -# RubyGem specification -GEMSPEC = Gem::Specification.new do |gem| - gem.name = PKG_NAME.downcase - gem.version = PKG_VERSION - - gem.summary = PKG_SUMMARY - gem.description = [ - "This is the extension library to access a PostgreSQL database from Ruby.", - "This library works with PostgreSQL 7.4 and later.", - ].join( "\n" ) - - gem.authors = ["Jeff Davis", "Michael Granger"] - gem.email = ["ruby-pg@j-davis.com", "ged@FaerieMUD.org"] - gem.homepage = 'http://bitbucket.org/ged/ruby-pg/' - gem.licenses = ["Ruby", "GPL", "BSD"] - - gem.has_rdoc = true - gem.rdoc_options = RDOC_OPTIONS - gem.extra_rdoc_files = TEXT_FILES - [ 'Rakefile' ] - - gem.bindir = BINDIR.relative_path_from(BASEDIR).to_s - gem.executables = BIN_FILES.select {|pn| File.executable?(pn) }. - collect {|pn| File.basename(pn) } - gem.require_paths << EXTDIR.relative_path_from( BASEDIR ).to_s if EXTDIR.exist? - - if EXTCONF.exist? - gem.extensions << EXTCONF.relative_path_from( BASEDIR ).to_s - end - - gem.files = RELEASE_FILES - gem.test_files = SPEC_FILES - - # signing key and certificate chain - gem.signing_key = '/Volumes/Keys/ged-private_gem_key.pem' - gem.cert_chain = [File.expand_path('~/.gem/ged-public_gem_cert.pem')] - - - gem.required_ruby_version = '>=1.8.7' - - DEPENDENCIES.each do |name, version| - version = '>= 0' if version.length.zero? - gem.add_runtime_dependency( name, version ) - end - - REQUIREMENTS.each do |name, version| - gem.requirements << [ name, version ].compact.join(' ') - end +desc "Turn on warnings and debugging in the build." +task :maint do + ENV['MAINTAINER_MODE'] = 'yes' end -$trace = Rake.application.options.trace ? true : false -$dryrun = Rake.application.options.dryrun ? true : false -$include_dev_dependencies = false +ENV['RUBY_CC_VERSION'] = '1.8.7:1.9.2' -# Load any remaining task libraries -RAKE_TASKLIBS.each do |tasklib| - next if tasklib.to_s =~ %r{/helpers\.rb$} +# Rake-compiler task +Rake::ExtensionTask.new do |ext| + ext.name = 'pg_ext' + ext.gem_spec = $hoespec.spec + ext.ext_dir = 'ext' + ext.lib_dir = 'lib' + ext.source_pattern = "*.{c,h}" + ext.cross_compile = true + ext.cross_platform = %w[i386-mswin32 i386-mingw32] +end + + +# Make the ChangeLog update if the repo has changed since it was last built +file '.hg/branch' do + abort "You need the Mercurial repo to make packages" +end +file 'ChangeLog' => '.hg/branch' do |task| + $stderr.puts "Updating the changelog..." begin - trace " loading tasklib %s" % [ tasklib ] - import tasklib - rescue ScriptError => err - fail "Task library '%s' failed to load: %s: %s" % - [ tasklib, err.class.name, err.message ] - trace "Backtrace: \n " + err.backtrace.join( "\n " ) - rescue => err - log "Task library '%s' failed to load: %s: %s. Some tasks may not be available." % - [ tasklib, err.class.name, err.message ] - trace "Backtrace: \n " + err.backtrace.join( "\n " ) + content = make_changelog() + rescue NameError + abort "Packaging tasks require the hoe-mercurial plugin (gem install hoe-mercurial)" + end + File.open( task.name, 'w', 0644 ) do |fh| + fh.print( content ) end end -# Load any project-specific rules defined in 'Rakefile.local' if it exists -import LOCAL_RAKEFILE if LOCAL_RAKEFILE.exist? +# Rebuild the ChangeLog immediately before release +task :prerelease => 'ChangeLog' -##################################################################### -### T A S K S -##################################################################### - -### Default task -task :default => [:clean, :local, :spec, :apidocs, :package] - -### Task the local Rakefile can append to -- no-op by default -task :local - -### Task: clean -CLEAN.include 'coverage', '**/*.orig', '**/*.rej' -CLOBBER.include 'artifacts', 'coverage.info', 'ChangeLog', PKGDIR - -### Task: changelog -file 'ChangeLog' do |task| - log "Updating #{task.name}" - - changelog = make_changelog() - File.open( task.name, 'w' ) do |fh| - fh.print( changelog ) - end -end - - -### Task: cruise (Cruisecontrol task) -desc "Cruisecontrol build" -task :cruise => [:clean, 'spec:quiet', :package] do |task| - raise "Artifacts dir not set." if ARTIFACTS_DIR.to_s.empty? - artifact_dir = ARTIFACTS_DIR.cleanpath + (CC_BUILD_LABEL || Time.now.strftime('%Y%m%d-%T')) - artifact_dir.mkpath - - coverage = BASEDIR + 'coverage' - if coverage.exist? && coverage.directory? - $stderr.puts "Copying coverage stats..." - FileUtils.cp_r( 'coverage', artifact_dir ) - end - - $stderr.puts "Copying packages..." - FileUtils.cp_r( FileList['pkg/*'].to_a, artifact_dir ) -end - - -desc "Update the build system to the latest version" -task :update_build do - log "Updating the build system" - run 'hg', '-R', RAKE_TASKDIR, 'pull', '-u' - log "Updating the Rakefile" - sh 'rake', '-f', RAKE_TASKDIR + 'Metarakefile' +desc "Stop any Postmaster instances that remain after testing." +task :cleanup_testing_dbs do + require 'spec/lib/helpers' + PgTestingHelpers.stop_existing_postmasters() + Rake::Task[:clean].invoke end diff --git a/Rakefile.local b/Rakefile.local deleted file mode 100644 index cb4ba9e..0000000 --- a/Rakefile.local +++ /dev/null @@ -1,312 +0,0 @@ -#!rake - -require 'uri' -require 'tempfile' -require 'rbconfig' - -MISCDIR = BASEDIR + 'misc' - -EXT_MAKEFILE = EXTDIR + 'Makefile' -EXT_SOURCES = FileList[ EXTDIR + '*.c' ] -EXT_SO = EXTDIR + "pg_ext.#{CONFIG['DLEXT']}" - -NUM_CPUS = if File.exist?('/proc/cpuinfo') - File.read('/proc/cpuinfo').scan('processor').length -elsif RUBY_PLATFORM.include?( 'darwin' ) - `system_profiler SPHardwareDataType | grep 'Cores' | awk '{print $5}'`.chomp -else - 1 -end - -# Cross-compilation constants -OPENSSL_VERSION = ENV['OPENSSL_VERSION'] || '1.0.0d' -POSTGRESQL_VERSION = ENV['POSTGRESQL_VERSION'] || '9.0.3' - -COMPILE_HOME = Pathname( "~/.rake-compiler" ).expand_path -STATIC_SOURCESDIR = COMPILE_HOME + 'sources' -STATIC_BUILDDIR = COMPILE_HOME + 'builds' - -# Static OpenSSL build vars -STATIC_OPENSSL_BUILDDIR = STATIC_BUILDDIR + "openssl-#{OPENSSL_VERSION}" - -OPENSSL_SOURCE_URI = - URI( "http://www.openssl.org/source/openssl-#{OPENSSL_VERSION}.tar.gz" ) -OPENSSL_TARBALL = STATIC_SOURCESDIR + File.basename( OPENSSL_SOURCE_URI.path ) -OPENSSL_MAKEFILE = STATIC_OPENSSL_BUILDDIR + 'Makefile' - -LIBSSLEAY32 = STATIC_OPENSSL_BUILDDIR + 'libssleay32.a' -LIBEAY32 = STATIC_OPENSSL_BUILDDIR + 'libeay32.a' - -OPENSSL_PATCHES = Rake::FileList[ MISCDIR + "openssl-#{OPENSSL_VERSION}.*.patch" ] - -# Static PostgreSQL build vars -STATIC_POSTGRESQL_BUILDDIR = STATIC_BUILDDIR + "postgresql-#{POSTGRESQL_VERSION}" -POSTGRESQL_SOURCE_URI = begin - uristring = "http://ftp9.us.postgresql.org/pub/mirrors/postgresql/source/" + - "v%s/postgresql-%s.tar.gz" % [ POSTGRESQL_VERSION, POSTGRESQL_VERSION ] - URI( uristring ) -end -POSTGRESQL_TARBALL = STATIC_SOURCESDIR + File.basename( POSTGRESQL_SOURCE_URI.path ) - -STATIC_POSTGRESQL_SRCDIR = STATIC_POSTGRESQL_BUILDDIR + 'src' -STATIC_POSTGRESQL_LIBDIR = STATIC_POSTGRESQL_SRCDIR + 'interfaces/libpq' -STATIC_POSTGRESQL_INCDIR = STATIC_POSTGRESQL_SRCDIR + 'include' - -POSTGRESQL_GLOBAL_MAKEFILE = STATIC_POSTGRESQL_SRCDIR + 'Makefile.global' -POSTGRESQL_SHLIB_MAKEFILE = STATIC_POSTGRESQL_SRCDIR + 'Makefile.shlib' -POSTGRESQL_SHLIB_MF_ORIG = STATIC_POSTGRESQL_SRCDIR + 'Makefile.shlib.orig' -POSTGRESQL_LIB = STATIC_POSTGRESQL_LIBDIR + 'libpq.a' - -CROSS_PREFIX = if RUBY_PLATFORM.include?( 'darwin' ) - 'i386-mingw32' -else - 'i586-mingw32msvc' -end - -# Make sure the spec data is packaged up with the gem -SPEC_DATA = Rake::FileList[ SPECDIR + 'data/*' ] -GEMSPEC.test_files += SPEC_DATA.to_a - -# Clean up any testing database directories -TESTING_TMPDIRS = Rake::FileList[ "#{BASEDIR}/tmp_test_*" ] -CLOBBER.include( STATIC_SOURCESDIR.to_s, *TESTING_TMPDIRS ) - -# clean intermediate files and folders -CLEAN.include( STATIC_BUILDDIR.to_s ) - - -##################################################################### -### T A S K S -##################################################################### - -# Make both the default task and the spec task depend on building the extension -task :local => :compile -task :spec => :compile -namespace :spec do - task :doc => [ :compile ] - task :quiet => [ :compile ] - task :html => [ :compile ] - task :text => [ :compile ] -end - -ENV['RUBY_CC_VERSION'] ||= '1.8.7:1.9.2' - -begin - require 'rake/clean' - require 'rake/extensiontask' - require 'rake/extensioncompiler' - - Rake::ExtensionTask.new do |ext| - ext.name = 'pg_ext' - ext.gem_spec = GEMSPEC - ext.ext_dir = EXTDIR.to_s - ext.lib_dir = LIBDIR.to_s - ext.source_pattern = "*.{c,h}" - - # If there's an explicit 'compile' argument, use everything after it as options. - if offset = ARGV.index( 'compile' ) - trace "config options = %p" % [ ARGV[(offset + 1)..-1] ] - ext.config_options = ARGV[ (offset + 1)..-1 ] - # Otherwise, just grab everything from the first option onward - elsif offset = ARGV.index( ARGV.find {|arg| arg =~ /^--/ } ) - trace "config options = %p" % [ ARGV[offset..-1] ] - ext.config_options = ARGV[ offset..-1 ] - else - trace "No config options (ARGV = %p)" % [ ARGV ] - end - - ext.cross_compile = true - ext.cross_platform = %w[i386-mswin32 i386-mingw32] - - # configure options only for cross compile - ext.cross_config_options += [ - "--with-pg-include=#{STATIC_POSTGRESQL_LIBDIR}", - "--with-opt-include=#{STATIC_POSTGRESQL_INCDIR}", - "--with-pg-lib=#{STATIC_POSTGRESQL_LIBDIR}", - "--with-opt-lib=#{STATIC_OPENSSL_BUILDDIR}", - "--enable-static-build", - ] - - end - - - - ##################################################################### - ### C R O S S - C O M P I L A T I O N - T A S K S - ##################################################################### - - - directory STATIC_SOURCESDIR.to_s - - # - # Static OpenSSL build tasks - # - directory STATIC_OPENSSL_BUILDDIR.to_s - - # openssl source file should be stored there - file OPENSSL_TARBALL => STATIC_SOURCESDIR do |t| - download( OPENSSL_SOURCE_URI, t.name ) - end - - # Extract the openssl builds - file STATIC_OPENSSL_BUILDDIR => OPENSSL_TARBALL do |t| - trace "extracting %s to %s" % [ OPENSSL_TARBALL, STATIC_OPENSSL_BUILDDIR.parent ] - STATIC_OPENSSL_BUILDDIR.mkpath - run 'tar', '-xzf', OPENSSL_TARBALL.to_s, '-C', STATIC_OPENSSL_BUILDDIR.parent.to_s - OPENSSL_MAKEFILE.unlink if OPENSSL_MAKEFILE.exist? - - OPENSSL_PATCHES.each do |patchfile| - trace " applying patch #{patchfile}..." - run 'patch', '-Np1', '-d', STATIC_OPENSSL_BUILDDIR.to_s, - '-i', File.expand_path( patchfile, BASEDIR ) - end - end - - CMD_PRELUDE = [ - 'env', - "CC=#{CROSS_PREFIX}-gcc", - "CFLAGS=-DDSO_WIN32", - "AR=#{CROSS_PREFIX}-ar", - "RANLIB=#{CROSS_PREFIX}-ranlib" - ] - - - # generate the makefile in a clean build location - file OPENSSL_MAKEFILE => STATIC_OPENSSL_BUILDDIR do |t| - Dir.chdir( STATIC_OPENSSL_BUILDDIR ) do - cmd = CMD_PRELUDE.dup - cmd << "./Configure" << 'mingw' - - run( *cmd ) - end - end - - desc "compile static openssl libraries" - task :openssl_libs => [ LIBSSLEAY32, LIBEAY32 ] - - task :compile_static_openssl => OPENSSL_MAKEFILE do |t| - Dir.chdir( STATIC_OPENSSL_BUILDDIR ) do - cmd = CMD_PRELUDE.dup - cmd << 'make' << "-j#{NUM_CPUS}" << 'build_libs' - - run( *cmd ) - end - end - - desc "compile static #{LIBEAY32}" - file LIBEAY32 => :compile_static_openssl do |t| - FileUtils.cp( STATIC_OPENSSL_BUILDDIR + 'libcrypto.a', LIBEAY32.to_s ) - end - - desc "compile static #{LIBSSLEAY32}" - file LIBSSLEAY32 => :compile_static_openssl do |t| - FileUtils.cp( STATIC_OPENSSL_BUILDDIR + 'libssl.a', LIBSSLEAY32.to_s ) - end - - - - # - # Static PostgreSQL build tasks - # - directory STATIC_POSTGRESQL_BUILDDIR.to_s - - - # postgresql source file should be stored there - file POSTGRESQL_TARBALL => STATIC_SOURCESDIR do |t| - download( POSTGRESQL_SOURCE_URI, t.name ) - end - - # Extract the postgresql sources - file STATIC_POSTGRESQL_BUILDDIR => POSTGRESQL_TARBALL do |t| - trace "extracting %s to %s" % [ POSTGRESQL_TARBALL, STATIC_POSTGRESQL_BUILDDIR.parent ] - STATIC_POSTGRESQL_BUILDDIR.mkpath - run 'tar', '-xzf', POSTGRESQL_TARBALL.to_s, '-C', STATIC_POSTGRESQL_BUILDDIR.parent.to_s - mv POSTGRESQL_SHLIB_MAKEFILE, POSTGRESQL_SHLIB_MF_ORIG - end - - # generate the makefile in a clean build location - file POSTGRESQL_GLOBAL_MAKEFILE => [ STATIC_POSTGRESQL_BUILDDIR, :openssl_libs ] do |t| - options = [ - '--target=i386-mingw32', - "--host=#{Rake::ExtensionCompiler.mingw_host}", - '--with-openssl', - '--without-zlib', - '--disable-shared', - ] - - Dir.chdir( STATIC_POSTGRESQL_BUILDDIR ) do - configure_path = STATIC_POSTGRESQL_BUILDDIR + 'configure' - cmd = [ configure_path.to_s, *options ] - cmd << "CFLAGS=-L#{STATIC_OPENSSL_BUILDDIR}" - cmd << "LDFLAGS=-L#{STATIC_OPENSSL_BUILDDIR}" - cmd << "LDFLAGS_SL=-L#{STATIC_OPENSSL_BUILDDIR}" - cmd << "LIBS=-lwsock32 -lws2_32 -lgdi32" - cmd << "CPPFLAGS=-I#{STATIC_OPENSSL_BUILDDIR}/include" - - run( *cmd ) - end - end - - - # patch the Makefile.shlib -- depend on the build dir so it's only - # rewritten if the tarball is re-extracted. - file POSTGRESQL_SHLIB_MAKEFILE => POSTGRESQL_SHLIB_MF_ORIG do |t| - tf = Tempfile.new( POSTGRESQL_SHLIB_MAKEFILE.basename ) - POSTGRESQL_SHLIB_MF_ORIG.open( File::RDONLY ) do |ifh| - ifh.each_line do |line| - tf.print( line.sub(/^(\s*haslibarule\s*=\s*yes)/, "# \\1 ") ) - end - end - tf.close - - FileUtils.mv( tf.path, t.name, :verbose => $trace ) - end - - - # make libpq.a - task POSTGRESQL_LIB => [ POSTGRESQL_GLOBAL_MAKEFILE, POSTGRESQL_SHLIB_MAKEFILE ] do |t| - Dir.chdir( POSTGRESQL_LIB.dirname ) do - sh 'make', "-j#{NUM_CPUS}", POSTGRESQL_LIB.basename.to_s, 'PORTNAME=win32' - end - end - - - #desc 'compile static libpg.a' - task :static_libpq => POSTGRESQL_LIB - - desc 'cross compile pg for win32' - task :cross do - ENV['CROSS_COMPILING'] = 'yes' - end - task :cross => [ :mingw32, :static_libpq ] - - task :mingw32 do - # Use Rake::ExtensionCompiler helpers to find the proper host - unless Rake::ExtensionCompiler.mingw_host then - warn "You need to install mingw32 cross compile functionality to be able to continue." - warn "Please refer to your distribution/package manager documentation about installation." - fail - end - end - -rescue LoadError => err - task :no_rake_compiler do - log "You'll need to install rake-compiler to compile this." - fail - end - - task :compile => :no_rake_compiler - task :cross => :no_rake_compiler - task :mingw32 => :no_rake_compiler - task :static_libpq => :no_rake_compiler -end - - -desc "Stop any Postmaster instances that remain after testing." -task :cleanup_testing_dbs do - require 'spec/lib/helpers' - PgTestingHelpers.stop_existing_postmasters() - Rake::Task[:clean].invoke -end - - diff --git a/doc/postgres.html b/doc/postgres.html deleted file mode 100644 index f3bfb50..0000000 --- a/doc/postgres.html +++ /dev/null @@ -1,278 +0,0 @@ - - - - - - - - - Postgres reference - - -
- [English | Japanese] -
-

Postgres reference

-
- Last update: Sun, 4 Mar 2001 15:40:08 +0000 -
-
-
-

PGconn

-

- The class to access PostgreSQL database. All other functionality of libpq -save the large object to a file. -

-

-For example, to send query to the database on the localhost. -

-
-require "postgres"
-conn = PGconn.connect("localhost", 5432, "", "", "test1")
-# or: conn = PGconn.open('dbname=test1')
-res = conn.exec("select * from a;")
-    
-

super class:

- Object -

class methods:

-

- connect(pghost, - pgport, pgoptions, - pgtty, dbname, login, - passwd) - new(pghost, - pgport, pgoptions, - pgtty, dbname, login, - passwd) - open(string) -

-
-
Connect to the PostgreSQL server. Options are:
-
pghost : Server hostname(string) -
pgport : Server port number(integer) -
pgoptions : backend options(string) -
pgtty : tty to print backend debug message(string) -
dbname : connecting database name(string) -
login : login user name(string) -
passwd : login password(string) -
Options in string format (separated by whitespace) are:
-
host=name : Server hostname(string) (defaults to localhost) -
hostaddr=addr : Server host IP address(string) -
port=number : Server port number(integer) (default: 5432) -
options=string : backend options(string) (sent to server, not well explained) -
tty=anything : ignored, used to be debug TTY(string) -
dbname=name : connecting database name(string) (default: your username) -
user=username : login user name(string) (default: your username) -
password=censored : login password(string) -
sslmode=mode : how to treat SSL(string) (one of disable, allow, prefer, require) -
service=name : service name in pg_service.conf(string) -
connect_timeout=seconds : how long to wait for a connection(integer) (0 means forever) -
-

On failure, it raises PGError exception.

-

methods:

-
-
db -
Returns the connected database name. -
host -
Returns the connected server name. -
user -
Returns the authenticated user name. -
options -
Returns backend option string. -
port -
Returns the connected server port number. -
tty -
Returns the connected pgtty. -
error -
Returns the error message about connection. -
finish -
close -
Closes the backend connection. -
reset -
Resets the backend connection. This method closes the backend - connection and tries to re-connect. -
trace(port) -
Enables tracing message passing between backend. The trace - message will be written to the port object, which is the - instance of the class File. -
untrace -
Disables the message tracing. -
exec(sql) -
Sends SQL query request specified by sql to the - PostgreSQL. Returns the PGresult - instance on success. On failure, it raises PGError - exception. -
query(sql) -
Sends SQL query request specified by sql to the - PostgreSQL.Returns an Array as the resulting tuple on success. - On failure, it returns nil, and error detail can be obtained - by error. -
async_exec(sql) -
Sends SQL asynchronous query request specified by sql - to the PostgreSQL. Returns the PGresult - instance on success. On failure, it raises PGError - exception. -
async_query(sql) -
Sends SQL asynchronous query request specified by sql - to the PostgreSQL.Returns an Array as the resulting tuple on - success. On failure, it returns nil, and error detail can be - obtained by error. -
get_notify -
Returns the array of the unprocessed notifiers. - If there is no unprocessed notifier, it returns nil. -
insert_table(table, - array) -
Inserts contents of the array into the - table. -
getline -
Reads a line from the backend server into internal buffer. - Returns nil for EOF, 0 for success, 1 for buffer overflowed. - You need to ensure single "." from backend to confirm - transmission completion. The sample program psql.rb - treats this copy protocol right. -
putline(string) -
Sends the string to the backend server. - Users must send a single "." to denote the end of data transmission. -
endcopy -
Waits until the backend completes the copying. You should call - this method after putline, or getline.Returns nil on success, - raises an exception otherwise. -
set_client_encoding -
Set client encoding(String). -
client_encoding -
Returns client encoding(String). -
set_notice_processor(proc) -
Control reporting of notice and warning messages generated by the - backend server (with Proc or anything else responding to :call). - Pass nil to disable processing of the messages. - -
lo_import(file) -
Import a file to a large object. Return the PGlarge instance on success. On failure, it raises PGError exception. -
lo_export(oid, file) -
Save a large object of oid to a file. -
lo_create([mode]) -
Return the PGlarge instance on success. On failure, it raises PGError exception. -
lo_open(oid, [mode]) -
Open a large object of oid. Return the PGlarge instance on success. The mode argument specifies the mode for the opened large object, which is either "INV_READ", or "INV_WRITE". If mode On failure, it raises PGError exception. If mode omitted, the default is "INV_READ" -
lo_unlink(oid) -
Unlink (deletes) the postgres large object of oid. -
-
-
-
-

PGresult

-

- The class to represent the query result tuples. The object of this -class is created as the result of every query. You may need to invoke -clear method for the finished object for better memory performance. -

-

super class:

-

- Object -

-

methods:

-
-
status -
-
Returns the status of the query. The status value is - either: -
EMPTY_QUERY -
COMMAND_OK -
TUPLES_OK -
COPY_OUT -
COPY_IN -
-
result -
Returns the query result tuple in the array. -
fields -
Returns the array of the fields of the query result. -
num_tuples -
Returns the number of tuples of the query result. -
num_fields -
Returns the number of fields of the query result. -
fieldname(index) -
Returns the field name corresponding field index. -
fieldnum(name) -
Returns the index of the nameed field. -
type(index) -
Returns the integer corresponding the type of the field. - The field indicator starts from zero. -
size(index) -
Returns the size of the field in bytes. - Returns -1 if the field is variable sized. -
getvalue(tup_num, field_num) - -
Returns the field value. -
getlength(tup_num, field_num) - -
Returns the length of the field in bytes. -
cmdtuples -
the number of tuples (rows) affected by the SQL command. -
cmdstatus -
Returns the status string of the last query command. -
oid -
Returns the oid of the inserted row, or nil if - the last statement was not an INSERT -
clear -
Clears the PGresult object as the result - of the query. -
-
-
-
-

PGlarge

-

- The class to access large objects. The object of this class is created as the - result of lo_import, lo_create, and lo_open. -

-

super class:

-

- Object -

-

methods:

-
-
open([mode]) -
Open a large object. The mode argument specifies the mode for the opened large object, which is either "INV_READ","INV_READ". -
close -
Close a large object. Closed when they are garbage-collected. -
read([length]) -
Attempts to read length bytes from large object. If no length given, reads all data. -
write(str) -
Write the string to the large object. Return the number of bytes written. -
seek(offset, whence) -
Move the large object pointer to the offset. The value for whence are SEEK_SET, SEEK_CUR, and SEEK_END.Or it is 0,1,2. -
tell -
Return the current position of the large object pointer. -
unlink -
Delete large object. -
oid -
Return the large object oid. -
size -
Return the size of large object. -
export(file) -
Save a large object of oid to a file. -
-
-
-
- mailto: - Noboru Saitou -
- - diff --git a/doc/postgres.jp.html b/doc/postgres.jp.html deleted file mode 100644 index 71f28d1..0000000 --- a/doc/postgres.jp.html +++ /dev/null @@ -1,256 +0,0 @@ - - - - - - - - - - Postgres reference - - -
- [English | Japanese] -
-

Postgres reference

-
- Last update: Mon, 5 Mar 2001 00:34:55 +0900 -
-
-
-

PGconn

-

-PostgreSQLにアクセスするためのクラス。その他のメソッドはlibpqとほぼ同じインタフェースで提供されます。 -

-

-例えば、localhost 上の PostgreSQL に接続し、query を出すためには以下のようにして行います。 -

-
-require "postgres"
-conn = PGconn.connect("localhost", 5432, "", "", "test1")
-res = conn.exec("select * from a;")
-    
-

スーバークラス:

- Object -

クラスメソッド:

-

- connect(pghost, - pgport, pgoptions, - pgtty, dbname, login, - passwd) - new(pghost, - pgport, pgoptions, - pgtty, dbname, login, - passwd) - open(string) -

-
-
PostgreSQLサーバと接続します。オプションの意味は以下の通りです。
-
pghost : サーバのホスト名(文字列) -
pgport : サーバがlistenしているポート番号(整数) -
pgoptions : backendを起動する際のオプション(文字列) -
pgtty : backendがデバッグメッセージを表示するtty(文字列) -
dbname : 接続するデータベース名(文字列) -
login : ユーザ名(文字列) -
passwd : パスワード(文字列) -
オプションを文字列で渡す場合のフォーマットです。
-
host=name : サーバのホスト名(文字列) -
hostaddr=addr : サーバのIPアドレス(文字列) -
port=number サーバがlistenしているポート番号(整数) -
options=string : backendを起動する際のオプション(文字列) -
tty=anything : backendがデバッグメッセージを表示するtty(文字列) -
dbname=name : 接続するデータベース名(文字列) -
user=username : ユーザ名(文字列) -
password=censored : パスワード(文字列) -
sslmode=mode : SSLモードの指定(文字列) (disable, allow, prefer, require) -
service=name : 他のパラメータ用に使用されるサービス名(文字列) -
connect_timeout=seconds : 接続タイムアウト時間(整数) -
-

失敗した場合は PGError 例外が発生します。

-

methods:

-
-
db -
接続したデータベース名を返します。 -
host -
接続したサーバ名を返します。 -
user -
サーバへ接続時に認証したユーザ名を返します。 -
options -
backendを起動する際に指定したoptionを返します。 -
port -
サーバへ接続する際に使用したポート番号を返します。 -
tty -
接続しているpgttyを返します。 -
error -
接続に関するエラーメッセージを返します。 -
finish -
close -
バックエンドとの接続を終了します。 -
reset -
バックエンドとの通信ポートをリセットします。この関数はバックエンドとのソケット接続を終了し、いずれかのバックエンドとの新しい接続の再確立を試みます。 -
trace(port) -
バックエンドとのメッセージの受渡しのトレースを有効にします。メッセージはportで指定された File クラスのインスタンスへ書き出されます。 -
untrace -
バックエンドとのメッセージの受渡しのトレースを無効にします。 -
exec(sql) -
sqlで指定されたSQL問い合わせ文をPostgreSQLへ送ります。 -問い合わせが成功した場合には、結果がPGresultクラスの -インスタンスとして返され、そうでない場合は例外が発生します。 -
query(sql) -
sqlで指定されたSQL問い合わせ文をPostgreSQLへ送ります。 -問い合わせが成功した場合には、結果が Array クラスの -インスタンスとして返され、そうでない場合は nil が返されます。 -
async_exec(sql) -
sqlで指定されたSQL問い合わせ文をPostgreSQLへ - 非同期で 送ります。問い合わせが成功した場合には、 - 結果がPGresultクラスの - インスタンスとして返され、そうでない場合は例外が発生します。 -
async_query(sql) -
sqlで指定されたSQL問い合わせ文をPostgreSQLへ - 非同期で 送ります。問い合わせが成功した場合には、結果が Array クラスの -インスタンスとして返され、そうでない場合は nil が返されます。 -
get_notify -
バックエンドから未処理の通知リストを得て、Array クラスのインスタンスとして返します。バックエンドからの未処理の通知がない場合には、nil が返されます。 -
insert_table(table, - array) -
tableで指定されたテーブルに対し、arrayの内容を挿入します。arrayは Array クラスのインスタンスでなければなりません。 -
getline -
バックエンドサーバから改行コードで終る行を読み取ります。fgets(3)と同様に、このメソッドはget(3)と同様に終端行をヌルに変換します。getlineはEOFの場合は、nil を、行全体を読み取った場合は0を、まだ改行コードを読み取っていない場合は1を返します。このメソッドを使用する時の注意点は、バックエンドサーバが結果の送信を完了したことを示す単一文字"."を新規行に送信したことを確認しなければならないことです。
-サンプルコードpsql.rbは、copyプロトコルを正しく扱うソースを含んでいます。 -
putline(string) -
stringで指定された文字列をバックエンドーサーバへ送信します。使用者はデータの送信が完了したことをバックエンドに示すために、単一文字"."を明示的に送信しなければなりません。 -
endcopy -
バックエンドと同期をとります。このメソッドはバックエンドがcopyを完了するまで待ちます。putlinegetlineを使用した場合に使用すべきメソッドです。copyがうまく完了した場合には nil が返り、そうでない場合は例外が発生します。 -
set_client_encoding -
クライアントの文字コードを指定します(文字列)。 -
client_encoding -
クライアントの文字コードを返します(文字列)。 - -
lo_import(file) -
fileをラージオブジェクトにインポートします。成功するとPGlargeクラスのインスタンスが返されます。失敗すると PGError 例外が発生します。 -
lo_export(oid, file) -
ラージオブジェクトを file に保存します。 -
lo_create([mode]) -
新しくラージオブジェクトをつくります。成功するとPGlarge クラスのインスタンスが返されます。失敗すると PGError 例外が発生します。 -
lo_open(oid, [mode]) -
oid のラージオブジェクトを開きます。成功するとPGlarge クラスのインスタンスが返されます。失敗すると PGError 例外が発生します。"INV_READ","INV_WRITE"のどちらかのモードを指定します。失敗すると PGError 例外が発生します。モードを省略した場合は"INV_READ"です。 -
lo_unlink(oid) -
oidのラージオブジェクトを削除します。 -
-
-
-
-

PGresult

-

-Queryの結果として得られたタップルをwrapするクラス.このクラス -のインスタンスは、queryを行うたびに生成されます。故に得られた -結果が不要になった場合には、clearを呼び出してメモリを解放する -ようにして下さい。 -

-

スーパークラス:

-

- Object -

-

メソッド:

-
-
status -
-
問い合わせ結果のステータスを返します。ステータスは以下の値のうちのいずれか一つを返します。 -
EMPTY_QUERY -
COMMAND_OK -
TUPLES_OK -
COPY_OUT -
COPY_IN -
-
result -
問い合わせ結果のタップル(インスタンス)を、配列で返します。 -
fields -
問い合わせの結果のフィールド(属性)を、配列で返します。 -
num_tuples -
問い合わせ結果のタップル(インスタンス)の数を返します。 -
num_fields -
問い合わせの結果のフィールド(属性)の数を返します。 -
fieldname(index) -
与えられたフィールド(属性)の索引(field index)に対応するフィールド(属性)の名前を返します。フィールド・インディケータは0から開始されます。 -
fieldnum(name) -
与えられたフィールド(属性)の名前に対応する、フィールド(属性)の索引を返します。 -
type(index) -
与えられたフィールド(属性)に対応するフィールドの型を返します。内部コーディングされている型が整数で返されます。フィールド・インディケータは0から開始されます。 -
size(index) -
与えられたフィールド(属性)に対応するフィールドのサイズをバイト数で返します。返されるサイズが-1の場合、フィールドは可変長です。フィールド・インディケータは0から開始されます。 -
getvalue(tup_num, field_num) - -
フィールド(属性)の値を返します。ほとんどの問い合わせに対して、getvalueによって返される値は、ヌルで終わるASCII文字列で表現されます。問い合わせの結果がバイナリカーソルであった場合、getvalueによって返される値は、バックエンド・サーバの内部フォーマットに依存したバイナリで表現されます。データを正しいタイプにキャストしたり、変換したりするのはプログラマの責任です。PGresultのインスタンスはqueryのたびに生成されます。不要になった場合は、プログラマが責任をもってclearを呼び出しメモリを解放して下さい。 -
getlength(tup_num, field_num) - -
フィールド(属性)の長さをバイトで返します。 -
cmdtuples -
最後の問い合わせコマンドの影響をうけた行数を返します。 -
cmdstatus -
最後の問い合わせコマンドのコマンドステータスを文字列で返します。 -
oid -
挿入された行のOIDを返します。 -
clear -
問い合わせの結果生成されたPGresultのインスタンスをクリアします。 -
-
-
-
-

PGlarge

-

- ラージオブジェクトにアクセスするためのクラス。このオブジェクトは lo_import, lo_create, lo_open の結果として返されます。 -

-

super class:

-

- Object -

-

methods:

-
-
open([mode]) -
ラージオブジェクトを開きます。 "INV_READ","INV_WRITE"のどちらかのモードを指定します。失敗すると PGError 例外が発生します。モードを省略した場合は"INV_READ"です。 -
close -
ラージオブジェクトを閉じます。以降このオブジェクトに対するアクセスは例外を発生します。 -
read([length]) -
length バイト読み込んでその文字列を返します。length が省略された時には、全てのデータを読み込みます。 -
write(str) -
strをラージオブジェクトに書き込みます。書き込んだバイト数を返します。 -
seek(offset, whence) -
ラージオブジェクトのポインタを offset 移動します。whence は SEEK_SET, SEEK_CUR, and SEEK_END が指定できます。それぞれ 0,1,2と数字で指定しても構いません。 -
tell -
ラージオブジェクトのポインタの現在の位置を返します。 -
unlink -
ラージオブジェクトを削除します。 -
oid -
ラージオブジェクトの oid を返します。 -
size -
ラージオブジェクトのサイズを返します。 -
export(file) -
fileにラージオブジェクトを書き出します。 -
-
-
-
- mailto: - Noboru Saitou -
- - - - diff --git a/ext/extconf.rb b/ext/extconf.rb index 64c3a8d..bc4cc8f 100644 --- a/ext/extconf.rb +++ b/ext/extconf.rb @@ -2,6 +2,11 @@ require 'pp' require 'mkmf' +if ENV['MAINTAINER_MODE'] + $stderr.puts "Maintainer mode enabled." + $CFLAGS << ' -Wall' << ' -ggdb' << ' -DDEBUG' +end + if pgdir = with_config( 'pg' ) ENV['PATH'] = "#{pgdir}/bin" + File::PATH_SEPARATOR + ENV['PATH'] end diff --git a/ext/mingw/Rakefile b/ext/mingw/Rakefile deleted file mode 100644 index 8a86812..0000000 --- a/ext/mingw/Rakefile +++ /dev/null @@ -1,24 +0,0 @@ -# We can't use Ruby's standard build procedures -# on Windows because the Ruby executable is -# built with VC++ while here we want to build -# with MingW. So just roll our own... - -require 'fileutils' -require 'rbconfig' - -EXTENSION_NAME = "pg.#{Config::CONFIG["DLEXT"]}" - -# This is called when the Windows GEM is installed! -task :install do - # Gems will pass these two environment variables: - # RUBYARCHDIR=#{dest_path} - # RUBYLIBDIR=#{dest_path} - - dest_path = ENV['RUBYLIBDIR'] - mkdir_p(dest_path) - - # Copy the extension - cp(EXTENSION_NAME, dest_path) -end - -task :default => :install \ No newline at end of file diff --git a/ext/mingw/build.rake b/ext/mingw/build.rake deleted file mode 100644 index 4e21e60..0000000 --- a/ext/mingw/build.rake +++ /dev/null @@ -1,40 +0,0 @@ -# We can't use Ruby's standard build procedures -# on Windows because the Ruby executable is -# built with VC++ while here we want to build -# with MingW. So just roll our own... - -require 'rake/clean' -require 'rbconfig' - -RUBY_INCLUDE_DIR = Config::CONFIG["archdir"] -RUBY_BIN_DIR = Config::CONFIG["bindir"] -RUBY_LIB_DIR = Config::CONFIG["libdir"] -RUBY_SHARED_LIB = Config::CONFIG["LIBRUBY"] -RUBY_SHARED_DLL = RUBY_SHARED_LIB.gsub(/lib$/, 'dll') - -EXTENSION_NAME = "pg.#{Config::CONFIG["DLEXT"]}" - -CLEAN.include('*.o') -CLOBBER.include(EXTENSION_NAME) - -task :default => "pg" - -DEFINES = "-DHAVE_LIBPQ_FE_H -DHAVE_LIBPQ_LIBPQ_FS_H -DHAVE_PQCONNECTIONUSEDPASSWORD -DHAVE_PQISTHREADSAFE -DHAVE_LO_CREATE -DHAVE_PQPREPARE -DHAVE_PQEXECPARAMS -DHAVE_PQESCAPESTRING -DHAVE_PQESCAPESTRINGCONN -DHAVE_PG_ENCODING_TO_CHAR -DHAVE_PQSETCLIENTENCODING" -LIBS = "-lpq -lm" -SRC = FileList['../*.c'] -OBJ = SRC.collect do |file_name| - File.basename(file_name).ext('o') -end - -SRC.each do |srcfile| - objfile = File.basename(srcfile).ext('o') - file objfile => srcfile do - command = "gcc -c -O2 -Wall #{DEFINES} -o #{objfile} -I/usr/local/include #{srcfile} -I#{RUBY_INCLUDE_DIR}" - sh "sh -c '#{command}'" - end -end - -file "pg" => OBJ do - command = "gcc -shared -o #{EXTENSION_NAME} #{OBJ} -L/usr/local/lib #{LIBS} #{RUBY_BIN_DIR}/#{RUBY_SHARED_DLL}" - sh "sh -c '#{command}'" -end \ No newline at end of file diff --git a/project.yml b/project.yml deleted file mode 100644 index 9cbf3de..0000000 --- a/project.yml +++ /dev/null @@ -1,34 +0,0 @@ ---- -project_name: pg -project_homepage: http://bitbucket.org/ged/ruby-pg/ -project_summary: A Ruby interface to the PostgreSQL RDBMS -project_description: |- - This is the extension library to access a PostgreSQL database from Ruby. - This library works with PostgreSQL 7.4 and later. -project_pubhost: deveiate.org -project_pubdir: /usr/local/www/public/code/ -project_licenses: -- Ruby -- GPL -- BSD -gem_pubhost: rubygems.org -release_mailto: Ruby-Talk List -release_smtphost: mail.faeriemud.org -post_install_message: "" -authors: - Jeff Davis: ruby-pg@j-davis.com - Michael Granger: ged@FaerieMUD.org -project_dependencies: {} -dev_dependencies: - rake-compiler: ~>0.7.0 -project_requirements: - PostgreSQL: ">=7.4" -additional_pkgfiles: -- README.* -- GPL -- BSD -- Contributors -excluded_pkgfiles: [] - -required_ruby_version: ">=1.8.7" -version_file: ../ext/pg.c