do_postgres-0.10.17/0000755000004100000410000000000013312076603014241 5ustar www-datawww-datado_postgres-0.10.17/tasks/0000755000004100000410000000000013312076603015366 5ustar www-datawww-datado_postgres-0.10.17/tasks/compile.rake0000644000004100000410000000606313312076603017667 0ustar www-datawww-databegin gem 'rake-compiler', '~>0.7' require 'rake/extensiontask' require 'rake/javaextensiontask' def gemspec @clean_gemspec ||= Gem::Specification::load(File.expand_path('../../do_postgres.gemspec', __FILE__)) end unless JRUBY Rake::ExtensionTask.new('do_postgres', gemspec) do |ext| postgres_lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'vendor', 'pgsql')) ext.lib_dir = "lib/#{gemspec.name}" # automatically add build options to avoid need of manual input if RUBY_PLATFORM =~ /mswin|mingw/ then ext.config_options << "--with-pgsql-server-include=#{postgres_lib}/include/server" ext.config_options << "--with-pgsql-client-include=#{postgres_lib}/include" ext.config_options << "--with-pgsql-win32-include=#{postgres_lib}/include/server/port/win32" ext.config_options << "--with-pgsql-client-lib=#{postgres_lib}/lib" else ext.cross_compile = true ext.cross_platform = ['x86-mingw32', 'x86-mswin32-60'] ext.cross_config_options << "--with-pgsql-server-include=#{postgres_lib}/include/server" ext.cross_config_options << "--with-pgsql-client-include=#{postgres_lib}/include" ext.cross_config_options << "--with-pgsql-win32-include=#{postgres_lib}/include/server/port/win32" ext.cross_config_options << "--with-pgsql-client-lib=#{postgres_lib}/lib" ext.cross_compiling do |gemspec| gemspec.post_install_message = <<-POST_INSTALL_MESSAGE ====================================================================================================== You've installed the binary version of #{gemspec.name}. It was built using PostgreSQL version #{BINARY_VERSION}. It's recommended to use the exact same version to avoid potential issues. At the time of building this gem, the necessary DLL files where available in the following download: http://wwwmaster.postgresql.org/redir/107/h/binary/v#{BINARY_VERSION}/win32/postgresql-#{BINARY_VERSION}-1-windows-binaries.zip You can put the following files available in this package in your Ruby bin directory, for example C:\\Ruby\\bin - lib\\libpq.dll - bin\\ssleay32.dll - bin\\libeay32.dll - bin\\libintl-8.dll - bin\\libiconv-2.dll - bin\\krb5_32.dll - bin\\comerr32.dll - bin\\k5sprt32.dll - bin\\gssapi32.dll ====================================================================================================== POST_INSTALL_MESSAGE end end end end Rake::JavaExtensionTask.new('do_postgres', gemspec) do |ext| ext.ext_dir = 'ext-java/src/main/java' ext.lib_dir = "lib/#{gemspec.name}" ext.debug = ENV.has_key?('DO_JAVA_DEBUG') && ENV['DO_JAVA_DEBUG'] ext.classpath = '../do_jdbc/lib/do_jdbc_internal.jar' ext.java_compiling do |gem| gem.add_dependency 'jdbc-postgres', '>=8.2' gem.add_dependency 'do_jdbc', '0.10.17' end end rescue LoadError warn "To compile, install rake-compiler (gem install rake-compiler)" end do_postgres-0.10.17/tasks/spec.rake0000644000004100000410000000052713312076603017170 0ustar www-datawww-datarequire 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec => [:clean, :compile]) do |spec| spec.pattern = './spec/**/*_spec.rb' end RSpec::Core::RakeTask.new(:rcov => [:clean, :compile]) do |rcov| rcov.pattern = "./spec/**/*_spec.rb" rcov.rcov = true rcov.rcov_opts = File.read('spec/rcov.opts').split(/\s+/) end do_postgres-0.10.17/tasks/retrieve.rake0000644000004100000410000000462513312076603020066 0ustar www-datawww-databegin gem 'rake-compiler', '~>0.7' require 'rake/clean' require 'rake/extensioncompiler' # download postgres library and headers directory "vendor" # only on Windows or cross platform compilation def dlltool(dllname, deffile, libfile) # define if we are using GCC or not if Rake::ExtensionCompiler.mingw_gcc_executable then dir = File.dirname(Rake::ExtensionCompiler.mingw_gcc_executable) tool = case RUBY_PLATFORM when /mingw/ File.join(dir, 'dlltool.exe') when /linux|darwin/ File.join(dir, "#{Rake::ExtensionCompiler.mingw_host}-dlltool") end return "#{tool} --dllname #{dllname} --def #{deffile} --output-lib #{libfile}" else if RUBY_PLATFORM =~ /mswin/ then tool = 'lib.exe' else fail "Unsupported platform for cross-compilation (please, contribute some patches)." end return "#{tool} /DEF:#{deffile} /OUT:#{libfile}" end end def copy(from, to) FileUtils.cp(from, to) end version = BINARY_VERSION file "vendor/postgresql-#{version}-1-windows-binaries.zip" => ['vendor'] do |t| url = "http://wwwmaster.postgresql.org/redir/107/h/binary/v#{version}/win32/#{File.basename(t.name)}" when_writing "downloading #{t.name}" do cd File.dirname(t.name) do sh "wget -c #{url} || curl -L -C - -O #{url}" end end end file "vendor/pgsql/include/pg_config.h" => ["vendor/postgresql-#{version}-1-windows-binaries.zip"] do |t| full_file = File.expand_path(t.prerequisites.last) when_writing "creating #{t.name}" do cd "vendor" do sh "unzip #{full_file} pgsql/bin/** pgsql/include/** pgsql/lib/**" end copy "ext/do_postgres/pg_config.h", "vendor/pgsql/include/pg_config.h" copy "ext/do_postgres/pg_config.h", "vendor/pgsql/include/server/pg_config.h" # update file timestamp to avoid Rake perform this extraction again. touch t.name end end # clobber vendored packages CLOBBER.include('vendor') # vendor:postgres task 'vendor:postgres' => ["vendor/pgsql/include/pg_config.h"] # hook into cross compilation vendored postgres dependency if RUBY_PLATFORM =~ /mingw|mswin/ then Rake::Task['compile'].prerequisites.unshift 'vendor:postgres' else if Rake::Task.tasks.map {|t| t.name }.include? 'cross' Rake::Task['cross'].prerequisites.unshift 'vendor:postgres' end end rescue LoadError end do_postgres-0.10.17/tasks/release.rake0000644000004100000410000000076413312076603017661 0ustar www-datawww-datadesc 'Builds all gems (native, binaries for JRuby and Windows)' task :build_all do `rake clean` `rake build` `rake java gem` `rake cross native gem RUBY_CC_VERSION=1.8.7:1.9.3:2.0.0:2.1.8:2.2.4:2.3.0` end desc 'Release all gems (native, binaries for JRuby and Windows)' task :release_all => :build_all do Dir["pkg/do_postgres-#{DataObjects::Postgres::VERSION}*.gem"].each do |gem_path| command = "gem push #{gem_path}" puts "Executing #{command.inspect}:" sh command end end do_postgres-0.10.17/spec/0000755000004100000410000000000013312076603015173 5ustar www-datawww-datado_postgres-0.10.17/spec/encoding_spec.rb0000644000004100000410000000161013312076603020316 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper')) require 'data_objects/spec/shared/encoding_spec' describe DataObjects::Postgres::Connection do unless JRUBY # Do NOT test this on JRuby: # # http://jdbc.postgresql.org/documentation/80/connect.html # # According to the Postgres documentation, as of Postgres 7.2, multibyte # support is enabled by default in the server. The underlying JDBC Driver # handles setting the internal client_encoding setting appropriately. It # can be overridden -- but for now, we won't support doing this. # it_should_behave_like 'a driver supporting different encodings' it_should_behave_like 'returning correctly encoded strings for the default database encoding' it_should_behave_like 'returning correctly encoded strings for the default internal encoding' end end do_postgres-0.10.17/spec/connection_spec.rb0000644000004100000410000000307513312076603020676 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper')) require 'data_objects/spec/shared/connection_spec' describe DataObjects::Postgres::Connection do before :all do @driver = CONFIG.scheme @user = CONFIG.user @password = CONFIG.pass @host = CONFIG.host @port = CONFIG.port @database = CONFIG.database end it_should_behave_like 'a Connection' it_should_behave_like 'a Connection with authentication support' it_should_behave_like 'a Connection allowing default database' unless JRUBY it_should_behave_like 'a Connection with JDBC URL support' if JRUBY describe 'byte array quoting' do before do @connection = DataObjects::Connection.new(CONFIG.uri) end after do @connection.close end # There are two possible byte array quotings available: hex or escape. # The default changed from escape to hex in version 9, so these specs # check for either. # # http://developer.postgresql.org/pgdocs/postgres/datatype-binary.html # http://developer.postgresql.org/pgdocs/postgres/release-9-0.html (E.3.2.3.) it 'should properly escape non-printable ASCII characters' do ["'\\001'", "'\\x01'"].should include @connection.quote_byte_array("\001") end it 'should properly escape bytes with the high bit set' do ["'\\210'", "'\\x88'"].should include @connection.quote_byte_array("\210") end it 'should not escape printable ASCII characters' do ["'a'", "'\\x61'"].should include @connection.quote_byte_array("a") end end end do_postgres-0.10.17/spec/command_spec.rb0000644000004100000410000000253213312076603020152 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper')) require 'data_objects/spec/shared/command_spec' describe DataObjects::Postgres::Command do it_should_behave_like 'a Command' it_should_behave_like 'a Command with async' describe 'query with RETURNING while not returning result' do before do @connection = DataObjects::Connection.new(CONFIG.uri) @select_command = @connection.create_command("SELECT name FROM users WHERE id = 900") @upsert_command = @connection.create_command(" WITH upsert AS (UPDATE users SET name = ? WHERE id = 900 RETURNING id) INSERT INTO users (id, name) SELECT 900, 'dbussink' WHERE NOT EXISTS (SELECT 1 FROM upsert)") end after do @connection.close end it "should work with a writable CTE acting as an Upsert" do reader = @select_command.execute_reader reader.to_a.size.should == 0 reader.close @upsert_command.execute_non_query('jwkoelewijn') reader = @select_command.execute_reader reader.next! reader.values[0].should == 'dbussink' reader.close @upsert_command.execute_non_query('jwkoelewijn') reader = @select_command.execute_reader reader.next! reader.values[0].should == 'jwkoelewijn' reader.close end end end do_postgres-0.10.17/spec/spec_helper.rb0000644000004100000410000001217313312076603020015 0ustar www-datawww-data$TESTING=true JRUBY = RUBY_PLATFORM =~ /java/ require 'rubygems' require 'rspec' require 'date' require 'ostruct' require 'fileutils' require 'win32console' if RUBY_PLATFORM =~ /mingw|mswin/ driver_lib = File.expand_path('../../lib', __FILE__) $LOAD_PATH.unshift(driver_lib) unless $LOAD_PATH.include?(driver_lib) # Prepend data_objects/do_jdbc in the repository to the load path. # DO NOT USE installed gems, except when running the specs from gem. repo_root = File.expand_path('../../..', __FILE__) (['data_objects'] << ('do_jdbc' if JRUBY)).compact.each do |lib| lib_path = "#{repo_root}/#{lib}/lib" $LOAD_PATH.unshift(lib_path) if File.directory?(lib_path) && !$LOAD_PATH.include?(lib_path) end require 'data_objects' require 'data_objects/spec/setup' require 'data_objects/spec/lib/pending_helpers' require 'do_postgres' DataObjects::Postgres.logger = DataObjects::Logger.new(STDOUT, :off) at_exit { DataObjects.logger.flush } CONFIG = OpenStruct.new CONFIG.scheme = 'postgres' CONFIG.user = ENV['DO_POSTGRES_USER'] || 'postgres' CONFIG.pass = ENV['DO_POSTGRES_PASS'] || '' CONFIG.user_info = unless CONFIG.pass.empty? "#{CONFIG.user}:#{CONFIG.pass}@" else "#{CONFIG.user}@" end CONFIG.host = ENV['DO_POSTGRES_HOST'] || 'localhost' CONFIG.port = ENV['DO_POSTGRES_PORT'] || '5432' CONFIG.database = ENV['DO_POSTGRES_DATABASE'] || '/do_test' CONFIG.driver = 'postgres' CONFIG.jdbc_driver = DataObjects::Postgres.const_get('JDBC_DRIVER') rescue nil CONFIG.uri = ENV["DO_POSTGRES_SPEC_URI"] ||"#{CONFIG.scheme}://#{CONFIG.user_info}#{CONFIG.host}:#{CONFIG.port}#{CONFIG.database}" CONFIG.jdbc_uri = CONFIG.uri.sub(/postgres/,"jdbc:postgresql") CONFIG.sleep = "SELECT pg_sleep(1)" module DataObjectsSpecHelpers def setup_test_environment conn = DataObjects::Connection.new(CONFIG.uri) conn.create_command(<<-EOF).execute_non_query DROP TABLE IF EXISTS "invoices" EOF conn.create_command(<<-EOF).execute_non_query DROP TABLE IF EXISTS "users" EOF conn.create_command(<<-EOF).execute_non_query DROP TABLE IF EXISTS "widgets" EOF conn.create_command(<<-EOF).execute_non_query CREATE TABLE "users" ( "id" SERIAL, "name" VARCHAR(200) default 'Billy' NULL, "fired_at" timestamp, PRIMARY KEY ("id") ); EOF conn.create_command(<<-EOF).execute_non_query CREATE TABLE "invoices" ( "invoice_number" varchar(50) NOT NULL, PRIMARY KEY ("invoice_number") ); EOF conn.create_command(<<-EOF).execute_non_query CREATE TABLE "widgets" ( "id" SERIAL, "code" char(8) default 'A14' NULL, "name" varchar(200) default 'Super Widget' NULL, "shelf_location" text NULL, "description" text NULL, "image_data" bytea NULL, "ad_description" text NULL, "ad_image" bytea NULL, "whitepaper_text" text NULL, "cad_drawing" bytea NULL, "flags" boolean default false, "number_in_stock" smallint default 500, "number_sold" integer default 0, "super_number" bigint default 9223372036854775807, "weight" float default 1.23, "cost1" double precision default 10.23, "cost2" decimal(8,2) default 50.23, "release_date" date default '2008-02-14', "release_datetime" timestamp default '2008-02-14 00:31:12', "release_timestamp" timestamp with time zone default '2008-02-14 00:31:31', PRIMARY KEY ("id") ); EOF 1.upto(16) do |n| conn.create_command(<<-EOF).execute_non_query(::Extlib::ByteArray.new("CAD \001 \000 DRAWING")) insert into widgets(code, name, shelf_location, description, image_data, ad_description, ad_image, whitepaper_text, cad_drawing, super_number, weight) VALUES ('W#{n.to_s.rjust(7,"0")}', 'Widget #{n}', 'A14', 'This is a description', 'IMAGE DATA', 'Buy this product now!', 'AD IMAGE DATA', 'String', ?, 1234, 13.4) EOF end conn.create_command(<<-EOF).execute_non_query update widgets set flags = true where id = 2 EOF conn.create_command(<<-EOF).execute_non_query update widgets set ad_description = NULL where id = 3 EOF conn.create_command(<<-EOF).execute_non_query update widgets set flags = NULL where id = 4 EOF conn.create_command(<<-EOF).execute_non_query update widgets set cost1 = NULL where id = 5 EOF conn.create_command(<<-EOF).execute_non_query update widgets set cost2 = NULL where id = 6 EOF conn.create_command(<<-EOF).execute_non_query update widgets set release_date = NULL where id = 7 EOF conn.create_command(<<-EOF).execute_non_query update widgets set release_datetime = NULL where id = 8 EOF conn.create_command(<<-EOF).execute_non_query update widgets set release_timestamp = NULL where id = 9 EOF conn.create_command(<<-EOF).execute_non_query update widgets set release_datetime = '2008-07-14 00:31:12' where id = 10 EOF conn.close end end RSpec.configure do |config| config.include(DataObjectsSpecHelpers) config.include(DataObjects::Spec::PendingHelpers) end do_postgres-0.10.17/spec/error/0000755000004100000410000000000013312076603016324 5ustar www-datawww-datado_postgres-0.10.17/spec/error/sql_error_spec.rb0000644000004100000410000000040313312076603021670 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/error/sql_error_spec' describe 'DataObjects::Postgres raising SQLError' do it_should_behave_like 'raising a SQLError' end do_postgres-0.10.17/spec/result_spec.rb0000644000004100000410000000355113312076603020054 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper')) require 'data_objects/spec/shared/result_spec' describe DataObjects::Postgres::Result do it_should_behave_like 'a Result' before do setup_test_environment end describe 'without using RETURNING' do before do @connection = DataObjects::Connection.new(CONFIG.uri) @result = @connection.create_command("INSERT INTO users (name) VALUES (?)").execute_non_query("monkey") end after do @connection.close end it { @result.should respond_to(:affected_rows) } describe 'affected_rows' do it 'should return the number of created rows' do @result.affected_rows.should == 1 end end it { @result.should respond_to(:insert_id) } describe 'insert_id' do it 'should return nil' do @result.insert_id.should be_nil end it 'should be retrievable through curr_val' do # This is actually the 4th record inserted reader = @connection.create_command("SELECT currval('users_id_seq')").execute_reader reader.next! reader.values.first.should == 1 end end end describe 'when using RETURNING' do before do @connection = DataObjects::Connection.new(CONFIG.uri) @result = @connection.create_command("INSERT INTO users (name) VALUES (?) RETURNING id").execute_non_query("monkey") end after do @connection.close end it { @result.should respond_to(:affected_rows) } describe 'affected_rows' do it 'should return the number of created rows' do @result.affected_rows.should == 1 end end it { @result.should respond_to(:insert_id) } describe 'insert_id' do it 'should return the generated key value' do @result.insert_id.should == 1 end end end end do_postgres-0.10.17/spec/typecast/0000755000004100000410000000000013312076603017027 5ustar www-datawww-datado_postgres-0.10.17/spec/typecast/string_spec.rb0000644000004100000410000000037513312076603021701 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/string_spec' describe 'DataObjects::Postgres with String' do it_should_behave_like 'supporting String' end do_postgres-0.10.17/spec/typecast/class_spec.rb0000644000004100000410000000037213312076603021475 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/class_spec' describe 'DataObjects::Postgres with Class' do it_should_behave_like 'supporting Class' end do_postgres-0.10.17/spec/typecast/nil_spec.rb0000644000004100000410000000053513312076603021153 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/nil_spec' describe 'DataObjects::Postgres with Nil' do it_should_behave_like 'supporting Nil' # it_should_behave_like 'supporting writing an Nil' it_should_behave_like 'supporting Nil autocasting' end do_postgres-0.10.17/spec/typecast/date_spec.rb0000644000004100000410000000162513312076603021307 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/date_spec' describe 'DataObjects::Postgres with Date' do it_should_behave_like 'supporting Date' it_should_behave_like 'supporting Date autocasting' describe 'exotic dates' do before do @connection = DataObjects::Connection.new(CONFIG.uri) @connection.create_command("INSERT INTO widgets (release_date) VALUES ('0001-01-01')").execute_non_query @command = @connection.create_command("SELECT release_date FROM widgets WHERE release_date = '0001-01-01'") @reader = @command.execute_reader @reader.next! @values = @reader.values end after do @reader.close @connection.close end it 'should return the number of created rows' do @values.first.should == Date.civil(1, 1, 1) end end end do_postgres-0.10.17/spec/typecast/boolean_spec.rb0000644000004100000410000000047113312076603022007 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/boolean_spec' describe 'DataObjects::Postgres with Boolean' do it_should_behave_like 'supporting Boolean' it_should_behave_like 'supporting Boolean autocasting' end do_postgres-0.10.17/spec/typecast/range_spec.rb0000644000004100000410000000037213312076603021464 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/range_spec' describe 'DataObjects::Postgres with Range' do it_should_behave_like 'supporting Range' end do_postgres-0.10.17/spec/typecast/datetime_spec.rb0000644000004100000410000000047513312076603022170 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/datetime_spec' describe 'DataObjects::Postgres with DateTime' do it_should_behave_like 'supporting DateTime' it_should_behave_like 'supporting DateTime autocasting' end do_postgres-0.10.17/spec/typecast/integer_spec.rb0000644000004100000410000000040013312076603022015 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/integer_spec' describe 'DataObjects::Postgres with Integer' do it_should_behave_like 'supporting Integer' end do_postgres-0.10.17/spec/typecast/other_spec.rb0000644000004100000410000000042213312076603021505 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/other_spec' describe 'DataObjects::H2 with other (unknown) type' do it_should_behave_like 'supporting other (unknown) type' end do_postgres-0.10.17/spec/typecast/byte_array_spec.rb0000644000004100000410000000040713312076603022530 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/byte_array_spec' describe 'DataObjects::Postgres with ByteArray' do it_should_behave_like 'supporting ByteArray' end do_postgres-0.10.17/spec/typecast/array_spec.rb0000644000004100000410000000037213312076603021506 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/array_spec' describe 'DataObjects::Postgres with Array' do it_should_behave_like 'supporting Array' end do_postgres-0.10.17/spec/typecast/bigdecimal_spec.rb0000644000004100000410000000050513312076603022446 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/bigdecimal_spec' describe 'DataObjects::Postgres with BigDecimal' do it_should_behave_like 'supporting BigDecimal' it_should_behave_like 'supporting BigDecimal autocasting' end do_postgres-0.10.17/spec/typecast/time_spec.rb0000644000004100000410000000045413312076603021327 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/time_spec' describe 'DataObjects::Postgres with Time' do it_should_behave_like 'supporting Time' it_should_behave_like 'supporting sub second Time' end do_postgres-0.10.17/spec/typecast/float_spec.rb0000644000004100000410000000046113312076603021474 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) require 'data_objects/spec/shared/typecast/float_spec' describe 'DataObjects::Postgres with Float' do it_should_behave_like 'supporting Float' it_should_behave_like 'supporting Float autocasting' end do_postgres-0.10.17/spec/reader_spec.rb0000644000004100000410000000033713312076603017777 0ustar www-datawww-data# encoding: utf-8 require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper')) require 'data_objects/spec/shared/reader_spec' describe DataObjects::Postgres::Reader do it_should_behave_like 'a Reader' end do_postgres-0.10.17/do_postgres.gemspec0000644000004100000410000000747413312076603020152 0ustar www-datawww-data######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- # stub: do_postgres 0.10.17 ruby lib # stub: ext/do_postgres/extconf.rb Gem::Specification.new do |s| s.name = "do_postgres".freeze s.version = "0.10.17" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.require_paths = ["lib".freeze] s.authors = ["Dirkjan Bussink".freeze] s.date = "2016-01-24" s.description = "Implements the DataObjects API for PostgreSQL".freeze s.email = "d.bussink@gmail.com".freeze s.extensions = ["ext/do_postgres/extconf.rb".freeze] s.extra_rdoc_files = ["ChangeLog.markdown".freeze, "LICENSE".freeze, "README.markdown".freeze] s.files = ["ChangeLog.markdown".freeze, "LICENSE".freeze, "README.markdown".freeze, "Rakefile".freeze, "ext/do_postgres/compat.h".freeze, "ext/do_postgres/do_common.c".freeze, "ext/do_postgres/do_common.h".freeze, "ext/do_postgres/do_postgres.c".freeze, "ext/do_postgres/error.h".freeze, "ext/do_postgres/extconf.rb".freeze, "ext/do_postgres/pg_config.h".freeze, "lib/do_postgres.rb".freeze, "lib/do_postgres/encoding.rb".freeze, "lib/do_postgres/transaction.rb".freeze, "lib/do_postgres/version.rb".freeze, "spec/command_spec.rb".freeze, "spec/connection_spec.rb".freeze, "spec/encoding_spec.rb".freeze, "spec/error/sql_error_spec.rb".freeze, "spec/reader_spec.rb".freeze, "spec/result_spec.rb".freeze, "spec/spec_helper.rb".freeze, "spec/typecast/array_spec.rb".freeze, "spec/typecast/bigdecimal_spec.rb".freeze, "spec/typecast/boolean_spec.rb".freeze, "spec/typecast/byte_array_spec.rb".freeze, "spec/typecast/class_spec.rb".freeze, "spec/typecast/date_spec.rb".freeze, "spec/typecast/datetime_spec.rb".freeze, "spec/typecast/float_spec.rb".freeze, "spec/typecast/integer_spec.rb".freeze, "spec/typecast/nil_spec.rb".freeze, "spec/typecast/other_spec.rb".freeze, "spec/typecast/range_spec.rb".freeze, "spec/typecast/string_spec.rb".freeze, "spec/typecast/time_spec.rb".freeze, "tasks/compile.rake".freeze, "tasks/release.rake".freeze, "tasks/retrieve.rake".freeze, "tasks/spec.rake".freeze] s.rubyforge_project = "dorb".freeze s.rubygems_version = "2.5.2.1".freeze s.summary = "DataObjects PostgreSQL Driver".freeze s.test_files = ["spec/command_spec.rb".freeze, "spec/connection_spec.rb".freeze, "spec/encoding_spec.rb".freeze, "spec/error/sql_error_spec.rb".freeze, "spec/reader_spec.rb".freeze, "spec/result_spec.rb".freeze, "spec/spec_helper.rb".freeze, "spec/typecast/array_spec.rb".freeze, "spec/typecast/bigdecimal_spec.rb".freeze, "spec/typecast/boolean_spec.rb".freeze, "spec/typecast/byte_array_spec.rb".freeze, "spec/typecast/class_spec.rb".freeze, "spec/typecast/date_spec.rb".freeze, "spec/typecast/datetime_spec.rb".freeze, "spec/typecast/float_spec.rb".freeze, "spec/typecast/integer_spec.rb".freeze, "spec/typecast/nil_spec.rb".freeze, "spec/typecast/other_spec.rb".freeze, "spec/typecast/range_spec.rb".freeze, "spec/typecast/string_spec.rb".freeze, "spec/typecast/time_spec.rb".freeze] if s.respond_to? :specification_version then s.specification_version = 3 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_runtime_dependency(%q.freeze, ["= 0.10.17"]) s.add_development_dependency(%q.freeze, ["~> 0.7"]) s.add_development_dependency(%q.freeze, ["~> 2.5"]) else s.add_dependency(%q.freeze, ["= 0.10.17"]) s.add_dependency(%q.freeze, ["~> 0.7"]) s.add_dependency(%q.freeze, ["~> 2.5"]) end else s.add_dependency(%q.freeze, ["= 0.10.17"]) s.add_dependency(%q.freeze, ["~> 0.7"]) s.add_dependency(%q.freeze, ["~> 2.5"]) end end do_postgres-0.10.17/LICENSE0000644000004100000410000000206713312076603015253 0ustar www-datawww-dataCopyright (c) 2007 - 2011 Yehuda Katz, Dirkjan Bussink Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. do_postgres-0.10.17/Rakefile0000644000004100000410000000203213312076603015703 0ustar www-datawww-datarequire 'pathname' require 'rubygems' require 'bundler' require 'rubygems/package_task' Bundler::GemHelper.install_tasks require 'rake' require 'rake/clean' ROOT = Pathname(__FILE__).dirname.expand_path require ROOT + 'lib/do_postgres/version' JRUBY = RUBY_PLATFORM =~ /java/ IRONRUBY = defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ironruby' WINDOWS = Gem.win_platform? || (JRUBY && ENV_JAVA['os.name'] =~ /windows/i) SUDO = WINDOWS ? '' : ('sudo' unless ENV['SUDOLESS']) BINARY_VERSION = '8.4.12' CLEAN.include(%w[ {tmp,pkg}/ **/*.{o,so,bundle,jar,log,a,gem,dSYM,obj,pdb,exp,DS_Store,rbc,db} ext/do_postgres/Makefile ext-java/target ]) if JRUBY Rake::Task['build'].clear_actions if Rake::Task.task_defined?('build') Rake::Task['install'].clear_actions if Rake::Task.task_defined?('install') task :build => [ :java, :gem ] task :install do sh "#{Config::CONFIG['RUBY_INSTALL_NAME']} -S gem install pkg/do_postgres-#{DataObjects::Postgres::VERSION}-java.gem" end end FileList['tasks/**/*.rake'].each { |task| import task } do_postgres-0.10.17/lib/0000755000004100000410000000000013312076603015007 5ustar www-datawww-datado_postgres-0.10.17/lib/do_postgres.rb0000644000004100000410000000205713312076603017670 0ustar www-datawww-datarequire 'data_objects' if RUBY_PLATFORM =~ /java/ require 'do_jdbc' require 'java' module DataObjects module Postgres JDBC_DRIVER = 'org.postgresql.Driver' end end begin java.lang.Thread.currentThread.getContextClassLoader().loadClass(DataObjects::Postgres::JDBC_DRIVER, true) rescue java.lang.ClassNotFoundException require 'jdbc/postgres' # the JDBC driver, packaged as a gem Jdbc::Postgres.load_driver if Jdbc::Postgres.respond_to?(:load_driver) end # Another way of loading the JDBC Class. This seems to be more reliable # than Class.forName() within the data_objects.Connection Java class, # which is currently not working as expected. java_import DataObjects::Postgres::JDBC_DRIVER end begin require 'do_postgres/do_postgres' rescue LoadError if RUBY_PLATFORM =~ /mingw|mswin/ then RUBY_VERSION =~ /(\d+.\d+)/ require "do_postgres/#{$1}/do_postgres" else raise end end require 'do_postgres/version' require 'do_postgres/transaction' if RUBY_PLATFORM !~ /java/ require 'do_postgres/encoding' do_postgres-0.10.17/lib/do_postgres/0000755000004100000410000000000013312076603017337 5ustar www-datawww-datado_postgres-0.10.17/lib/do_postgres/version.rb0000644000004100000410000000010713312076603021347 0ustar www-datawww-datamodule DataObjects module Postgres VERSION = '0.10.17' end end do_postgres-0.10.17/lib/do_postgres/encoding.rb0000644000004100000410000000253513312076603021457 0ustar www-datawww-datamodule DataObjects module Postgres module Encoding MAP = { "Big5" => "BIG5", "GB2312" => "EUC_CN", "EUC-JP" => "EUC_JP", "EUC-KR" => "EUC_KR", "EUC-TW" => "EUC_TW", "GB18030" => "GB18030", "GBK" => "GBK", "ISO-8859-5" => "ISO_8859_5", "ISO-8859-6" => "ISO_8859_6", "ISO-8859-7" => "ISO_8859_7", "ISO-8859-8" => "ISO_8859_8", "KOI8-U" => "KOI8", "ISO-8859-1" => "LATIN1", "ISO-8859-2" => "LATIN2", "ISO-8859-3" => "LATIN3", "ISO-8859-4" => "LATIN4", "ISO-8859-9" => "LATIN5", "ISO-8859-10" => "LATIN6", "ISO-8859-13" => "LATIN7", "ISO-8859-14" => "LATIN8", "ISO-8859-15" => "LATIN9", "ISO-8859-16" => "LATIN10", "Emacs-Mule" => "MULE_INTERNAL", "SJIS" => "SJIS", "US-ASCII" => "SQL_ASCII", "CP949" => "UHC", "UTF-8" => "UTF8", "IBM866" => "WIN866", "Windows-874" => "WIN874", "Windows-1250" => "WIN1250", "Windows-1251" => "WIN1251", "Windows-1252" => "WIN1252", "Windows-1256" => "WIN1256", "Windows-1258" => "WIN1258" } end end end do_postgres-0.10.17/lib/do_postgres/transaction.rb0000644000004100000410000000167113312076603022216 0ustar www-datawww-data module DataObjects module Postgres class Transaction < DataObjects::Transaction def begin cmd = "BEGIN" connection.create_command(cmd).execute_non_query end def begin_prepared cmd = "BEGIN" connection.create_command(cmd).execute_non_query end def commit cmd = "COMMIT" connection.create_command(cmd).execute_non_query end def commit_prepared cmd = "COMMIT PREPARED '#{id}'" connection.create_command(cmd).execute_non_query end def rollback cmd = "ROLLBACK" connection.create_command(cmd).execute_non_query end def rollback_prepared cmd = "ROLLBACK PREPARED '#{id}'" connection.create_command(cmd).execute_non_query end def prepare cmd = "PREPARE TRANSACTION '#{id}'" connection.create_command(cmd).execute_non_query end end end end do_postgres-0.10.17/README.markdown0000644000004100000410000000600313312076603016741 0ustar www-datawww-data# do_postgres * ## Description A PostgreSQL driver for DataObjects. ## Features/Problems This driver implements the DataObjects API for the PostgreSQL relational database. ## Synopsis An example of usage: ```ruby # default user (postgres, postgres), default port (5432) DataObjects::Connection.new("postgres://host/database") # specified user, specified port DataObjects::Connection.new("postgres://user:pass@host:8888/database") @connection = DataObjects::Connection.new("postgres://localhost/employees") @reader = @connection.create_command('SELECT * FROM users').execute_reader @reader.next! ``` ## Requirements This driver is provided for the following platforms: * Ruby MRI (1.8.6/7), 1.9: tested on Linux, Mac OS X and Windows platforms. * JRuby 1.3.1 + (1.4+ recommended). * Rubinius (experimental). Additionally you should have the following prerequisites: * `data_objects` gem * `do_jdbc` gem (shared library), if running on JRuby. ## Install To install the gem: ```ruby gem install do_postgres ``` To compile and install from source: * Install rake-compiler: `gem install rake-compiler`. * For MRI/Rubinius extensions: * Install the `gcc` compiler. On OS X, you should install XCode tools. On Ubuntu, run `apt-get install build-essential`. * Install Ruby and PostgreSQL client. * Install the Ruby and PostgreSQL development headers. * On Debian-Linux distributions, you can install the following packages with `apt`: `ruby-dev` `libpostgresql-dev`. * If you want to cross-compile for Windows: * Install MinGW: * On Debian-Linux distributions, you can install the following package with `apt`: `mingw32`. * On OS X, this can install the following package with MacPorts: `i386-mingw32-gcc`. * Run `rake-compiler cross-ruby`. * Run `rake-compiler update-config`. * For JRuby extensions: * Install the Java Development Kit (provided if you are on a recent version of Mac OS X) from . * Install a recent version of JRuby. Ensure `jruby` is in your `PATH` and/or you have configured the `JRUBY_HOME` environment variable to point to your JRuby installation. * Install `data_objects` and `do_jdbc` with `jruby -S rake install`. * Then, install this driver with `(jruby -S) rake install`. For more information, see the PostgreSQL driver wiki page: . ## Developers Follow the above installation instructions. Additionally, you'll need: * `rspec` gem for running specs. * `YARD` gem for generating documentation. See the DataObjects wiki for more comprehensive information on installing and contributing to the JRuby-variant of this driver: . To run specs: rake spec To run specs without compiling extensions first: rake spec_no_compile To run individual specs: rake spec SPEC=spec/connection_spec.rb ## License This code is licensed under an **MIT (X11) License**. Please see the accompanying `LICENSE` file. do_postgres-0.10.17/ChangeLog.markdown0000644000004100000410000000475113312076603017643 0ustar www-datawww-data## 0.10.17 2016-01-24 * Fix memory leak * Fix bug with DateTime and wrong timezone offsets ## 0.10.16 2015-05-17 * Fix compile issue with do\_postgres on stock OS X Ruby ## 0.10.15 2015-02-15 * Ruby 2.2 support * Double after free fix in do\_postgres * Windows support on 2.1.x and 2.2.x ## 0.10.14 2014-02-13 * Don't do DNS lookup in transaction loading * Set datestyle to ISO ## 0.10.13 2013-05-27 * Fix segfault on invalid API usage * Windows binary for Ruby 2.0 ## 0.10.12 2013-01-21 * jdbc-postgres driver loading fix ## 0.10.11 2012-12-29 * Rename C symbols to prevent name collitions ## 0.10.10 2012-10-11 No changes ## 0.10.9 2012-08-13 * Improved RETURNING handling on JRuby * Allow for an empty database name ## 0.10.8 2012-02-10 * Ruby 1.9.3 compatibility on Windows * Fix crash issue when reading a reader twice ## 0.10.7 2011-10-13 * Ruby 1.9.3 compatibility ## 0.10.6 2011-05-22 Bugfixes * Fix an issue on some platforms when multiple DO drivers are loaded ## 0.10.5 2011-05-03 No changes ## 0.10.4 2011-04-28 New features * Add save point to transactions (all) * JRuby 1.9 mode support (encodings etc.) Bugfixes * Fix segfault when no tuples are returned from a non select statement (do\_postgres) * Fix bug when using nested transactions in concurrent scenarios (all) * Use column aliases instead of names (jruby) * DST calculation fixes (all) * Fix handling sub second precision for Time objects (do\_postgres) Other * Refactor to DRY up the adapters (all) * Many style fixes * Switch back to RSpec ## 0.10.3 2011-01-30 * Reworked transactions * Fix a DST bug that could cause datetimes in the wrong timezone ## 0.10.2 2010-05-19 * Make Encoding.default_internal aware * Rework logging for making callbacks possible * Remove handling Object types directly ## 0.10.1 2010-01-08 * Support for Ruby 1.8 and 1.9 on Windows. * Switch to Jeweler for Gem building tasks (this change may be temporary). * Switch to using Bacon for running specs: This should make specs friendlier to new Ruby implementations that are not yet 100% MRI-compatible, and in turn, pave the road for our own IronRuby and MacRuby support. * Switch to the newly added rake-compiler `JavaExtensionTask` for compiling JRuby extensions, instead of our (broken) home-grown solution. ## 0.9.12 2009-05-17 * Improvements * Windows support ## 0.9.11 2009-01-19 * Improvements * Ruby 1.9 support * Fixes * Fix build issue on certain platforms introduces with 0.9.10 ## 0.9.9 2008-11-27 * No changes since 0.9.8 do_postgres-0.10.17/ext/0000755000004100000410000000000013312076603015041 5ustar www-datawww-datado_postgres-0.10.17/ext/do_postgres/0000755000004100000410000000000013312076603017371 5ustar www-datawww-datado_postgres-0.10.17/ext/do_postgres/do_common.h0000644000004100000410000001011213312076603021507 0ustar www-datawww-data#ifndef _DO_COMMON_H_ #define _DO_COMMON_H_ #include // Needed for defining error.h struct errcodes { int error_no; const char *error_name; const char *exception; }; #define ERRCODE(name,message) {name, #name, message} #ifdef _WIN32 typedef signed __int64 do_int64; #else typedef signed long long int do_int64; #endif #ifdef HAVE_RUBY_ENCODING_H #include #define DATA_OBJECTS_STR_NEW2(str, encoding, internal_encoding) \ ({ \ VALUE _string = rb_str_new2((const char *)str); \ if(encoding != -1) { \ rb_enc_associate_index(_string, encoding); \ } \ if(internal_encoding) { \ _string = rb_str_export_to_enc(_string, internal_encoding); \ } \ _string; \ }) #define DATA_OBJECTS_STR_NEW(str, len, encoding, internal_encoding) \ ({ \ VALUE _string = rb_str_new((const char *)str, (long)len); \ if(encoding != -1) { \ rb_enc_associate_index(_string, encoding); \ } \ if(internal_encoding) { \ _string = rb_str_export_to_enc(_string, internal_encoding); \ } \ _string; \ }) #else #define DATA_OBJECTS_STR_NEW2(str, encoding, internal_encoding) \ rb_str_new2((const char *)str) #define DATA_OBJECTS_STR_NEW(str, len, encoding, internal_encoding) \ rb_str_new((const char *)str, (long)len) #endif // To store rb_intern values extern ID DO_ID_NEW; extern ID DO_ID_NEW_DATE; extern ID DO_ID_CONST_GET; extern ID DO_ID_RATIONAL; extern ID DO_ID_ESCAPE; extern ID DO_ID_STRFTIME; extern ID DO_ID_LOG; // Reference to Extlib module extern VALUE mExtlib; extern VALUE rb_cByteArray; // References to DataObjects base classes extern VALUE mDO; extern VALUE cDO_Quoting; extern VALUE cDO_Connection; extern VALUE cDO_Command; extern VALUE cDO_Result; extern VALUE cDO_Reader; extern VALUE cDO_Logger; extern VALUE cDO_Logger_Message; extern VALUE cDO_Extension; extern VALUE eDO_ConnectionError; extern VALUE eDO_DataError; // References to Ruby classes that we'll need extern VALUE rb_cDate; extern VALUE rb_cDateTime; extern VALUE rb_cBigDecimal; extern void data_objects_debug(VALUE connection, VALUE string, struct timeval *start); extern char *data_objects_get_uri_option(VALUE query_hash, const char *key); extern void data_objects_assert_file_exists(char *file, const char *message); extern VALUE data_objects_build_query_from_args(VALUE klass, int count, VALUE *args); extern void data_objects_reduce(do_int64 *numerator, do_int64 *denominator); extern int data_objects_jd_from_date(int year, int month, int day); extern VALUE data_objects_seconds_to_offset(long seconds_offset); extern VALUE data_objects_timezone_to_offset(int hour_offset, int minute_offset); extern VALUE data_objects_parse_date(const char *date); extern VALUE data_objects_parse_time(const char *date); extern VALUE data_objects_parse_date_time(const char *date); extern VALUE data_objects_cConnection_character_set(VALUE self); extern VALUE data_objects_cConnection_is_using_socket(VALUE self); extern VALUE data_objects_cConnection_ssl_cipher(VALUE self); extern VALUE data_objects_cConnection_quote_time(VALUE self, VALUE value); extern VALUE data_objects_cConnection_quote_date_time(VALUE self, VALUE value); extern VALUE data_objects_cConnection_quote_date(VALUE self, VALUE value); extern VALUE data_objects_cCommand_set_types(int argc, VALUE *argv, VALUE self); extern VALUE data_objects_cReader_values(VALUE self); extern VALUE data_objects_cReader_fields(VALUE self); extern VALUE data_objects_cReader_field_count(VALUE self); extern void data_objects_common_init(void); extern VALUE data_objects_const_get(VALUE scope, const char *constant); static inline void data_objects_define_errors(VALUE scope, const struct errcodes *errors) { const struct errcodes *e; for (e = errors; e->error_name; e++) { rb_const_set(scope, rb_intern(e->error_name), INT2NUM(e->error_no)); } } extern void data_objects_raise_error(VALUE self, const struct errcodes *errors, int errnum, VALUE message, VALUE query, VALUE state); extern VALUE data_objects_typecast(const char *value, long length, const VALUE type, int encoding); #define RSTRING_NOT_MODIFIED #endif do_postgres-0.10.17/ext/do_postgres/compat.h0000644000004100000410000000165313312076603021032 0ustar www-datawww-data#ifndef RUBY_COMPAT_H #define RUBY_COMPAT_H /* * Rules for better ruby C extensions: * * Never use the R macros directly, always use R_ * * Never compare with RBASIC(obj)->klass, always use * rb_obj_is_instance_of() * * Never use RHASH(obj)->tbl or RHASH_TBL(). * */ // Array #ifndef RARRAY_PTR #define RARRAY_PTR(obj) RARRAY(obj)->ptr #endif #ifndef RARRAY_LEN #define RARRAY_LEN(obj) RARRAY(obj)->len #endif // String #ifndef RSTRING_PTR #define RSTRING_PTR(obj) RSTRING(obj)->ptr #endif #ifndef RSTRING_LEN #define RSTRING_LEN(obj) RSTRING(obj)->len #endif #ifndef rb_str_ptr #define rb_str_ptr(str) RSTRING_PTR(str) #endif #ifndef rb_str_ptr_readonly #define rb_str_ptr_readonly(str) RSTRING_PTR(str) #endif #ifndef rb_str_flush #define rb_str_flush(str) #endif #ifndef rb_str_update #define rb_str_update(str) #endif #ifndef rb_str_len #define rb_str_len(str) RSTRING_LEN(str) #endif #endif do_postgres-0.10.17/ext/do_postgres/error.h0000644000004100000410000003060413312076603020676 0ustar www-datawww-data#ifndef _DO_POSTGRES_ERROR_H_ #define _DO_POSTGRES_ERROR_H_ #include "do_common.h" static struct errcodes do_postgres_errors[] = { #ifdef ERRCODE_CONNECTION_EXCEPTION ERRCODE(ERRCODE_CONNECTION_EXCEPTION, "ConnectionError"), #endif #ifdef ERRCODE_CONNECTION_DOES_NOT_EXIST ERRCODE(ERRCODE_CONNECTION_DOES_NOT_EXIST, "ConnectionError"), #endif #ifdef ERRCODE_CONNECTION_FAILURE ERRCODE(ERRCODE_CONNECTION_FAILURE, "ConnectionError"), #endif #ifdef ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION ERRCODE(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION, "ConnectionError"), #endif #ifdef ERRCODE_SQLSERVER_REJECTED_ESTABLISHMENT_OF_SQLCONNECTION ERRCODE(ERRCODE_SQLSERVER_REJECTED_ESTABLISHMENT_OF_SQLCONNECTION, "ConnectionError"), #endif #ifdef ERRCODE_TRANSACTION_RESOLUTION_UNKNOWN ERRCODE(ERRCODE_TRANSACTION_RESOLUTION_UNKNOWN, "ConnectionError"), #endif #ifdef ERRCODE_PROTOCOL_VIOLATION ERRCODE(ERRCODE_PROTOCOL_VIOLATION, "ConnectionError"), #endif #ifdef ERRCODE_DATA_EXCEPTION ERRCODE(ERRCODE_DATA_EXCEPTION, "DataError"), #endif #ifdef ERRCODE_ARRAY_ELEMENT_ERROR ERRCODE(ERRCODE_ARRAY_ELEMENT_ERROR, "DataError"), #endif #ifdef ERRCODE_ARRAY_SUBSCRIPT_ERROR ERRCODE(ERRCODE_ARRAY_SUBSCRIPT_ERROR, "DataError"), #endif #ifdef ERRCODE_CHARACTER_NOT_IN_REPERTOIRE ERRCODE(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE, "DataError"), #endif #ifdef ERRCODE_DATETIME_FIELD_OVERFLOW ERRCODE(ERRCODE_DATETIME_FIELD_OVERFLOW, "DataError"), #endif #ifdef ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ERRCODE(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE, "DataError"), #endif #ifdef ERRCODE_DIVISION_BY_ZERO ERRCODE(ERRCODE_DIVISION_BY_ZERO, "DataError"), #endif #ifdef ERRCODE_ERROR_IN_ASSIGNMENT ERRCODE(ERRCODE_ERROR_IN_ASSIGNMENT, "DataError"), #endif #ifdef ERRCODE_ESCAPE_CHARACTER_CONFLICT ERRCODE(ERRCODE_ESCAPE_CHARACTER_CONFLICT, "DataError"), #endif #ifdef ERRCODE_INDICATOR_OVERFLOW ERRCODE(ERRCODE_INDICATOR_OVERFLOW, "DataError"), #endif #ifdef ERRCODE_INTERVAL_FIELD_OVERFLOW ERRCODE(ERRCODE_INTERVAL_FIELD_OVERFLOW, "DataError"), #endif #ifdef ERRCODE_INVALID_ARGUMENT_FOR_LOG ERRCODE(ERRCODE_INVALID_ARGUMENT_FOR_LOG, "DataError"), #endif #ifdef ERRCODE_INVALID_ARGUMENT_FOR_NTILE ERRCODE(ERRCODE_INVALID_ARGUMENT_FOR_NTILE, "DataError"), #endif #ifdef ERRCODE_INVALID_ARGUMENT_FOR_NTH_VALUE ERRCODE(ERRCODE_INVALID_ARGUMENT_FOR_NTH_VALUE, "DataError"), #endif #ifdef ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION ERRCODE(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION, "DataError"), #endif #ifdef ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION ERRCODE(ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION, "DataError"), #endif #ifdef ERRCODE_INVALID_CHARACTER_VALUE_FOR_CAST ERRCODE(ERRCODE_INVALID_CHARACTER_VALUE_FOR_CAST, "DataError"), #endif #ifdef ERRCODE_INVALID_DATETIME_FORMAT ERRCODE(ERRCODE_INVALID_DATETIME_FORMAT, "DataError"), #endif #ifdef ERRCODE_INVALID_ESCAPE_CHARACTER ERRCODE(ERRCODE_INVALID_ESCAPE_CHARACTER, "DataError"), #endif #ifdef ERRCODE_INVALID_ESCAPE_OCTET ERRCODE(ERRCODE_INVALID_ESCAPE_OCTET, "DataError"), #endif #ifdef ERRCODE_INVALID_ESCAPE_SEQUENCE ERRCODE(ERRCODE_INVALID_ESCAPE_SEQUENCE, "DataError"), #endif #ifdef ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER ERRCODE(ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER, "DataError"), #endif #ifdef ERRCODE_INVALID_INDICATOR_PARAMETER_VALUE ERRCODE(ERRCODE_INVALID_INDICATOR_PARAMETER_VALUE, "DataError"), #endif #ifdef ERRCODE_INVALID_LIMIT_VALUE ERRCODE(ERRCODE_INVALID_LIMIT_VALUE, "DataError"), #endif #ifdef ERRCODE_INVALID_PARAMETER_VALUE ERRCODE(ERRCODE_INVALID_PARAMETER_VALUE, "DataError"), #endif #ifdef ERRCODE_INVALID_REGULAR_EXPRESSION ERRCODE(ERRCODE_INVALID_REGULAR_EXPRESSION, "DataError"), #endif #ifdef ERRCODE_INVALID_TIME_ZONE_DISPLACEMENT_VALUE ERRCODE(ERRCODE_INVALID_TIME_ZONE_DISPLACEMENT_VALUE, "DataError"), #endif #ifdef ERRCODE_INVALID_USE_OF_ESCAPE_CHARACTER ERRCODE(ERRCODE_INVALID_USE_OF_ESCAPE_CHARACTER, "DataError"), #endif #ifdef ERRCODE_MOST_SPECIFIC_TYPE_MISMATCH ERRCODE(ERRCODE_MOST_SPECIFIC_TYPE_MISMATCH, "DataError"), #endif #ifdef ERRCODE_NULL_VALUE_NOT_ALLOWED ERRCODE(ERRCODE_NULL_VALUE_NOT_ALLOWED, "DataError"), #endif #ifdef ERRCODE_NULL_VALUE_NO_INDICATOR_PARAMETER ERRCODE(ERRCODE_NULL_VALUE_NO_INDICATOR_PARAMETER, "DataError"), #endif #ifdef ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE ERRCODE(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE, "DataError"), #endif #ifdef ERRCODE_STRING_DATA_LENGTH_MISMATCH ERRCODE(ERRCODE_STRING_DATA_LENGTH_MISMATCH, "DataError"), #endif #ifdef ERRCODE_STRING_DATA_RIGHT_TRUNCATION ERRCODE(ERRCODE_STRING_DATA_RIGHT_TRUNCATION, "DataError"), #endif #ifdef ERRCODE_SUBSTRING_ERROR ERRCODE(ERRCODE_SUBSTRING_ERROR, "DataError"), #endif #ifdef ERRCODE_TRIM_ERROR ERRCODE(ERRCODE_TRIM_ERROR, "DataError"), #endif #ifdef ERRCODE_UNTERMINATED_C_STRING ERRCODE(ERRCODE_UNTERMINATED_C_STRING, "DataError"), #endif #ifdef ERRCODE_ZERO_LENGTH_CHARACTER_STRING ERRCODE(ERRCODE_ZERO_LENGTH_CHARACTER_STRING, "DataError"), #endif #ifdef ERRCODE_FLOATING_POINT_EXCEPTION ERRCODE(ERRCODE_FLOATING_POINT_EXCEPTION, "DataError"), #endif #ifdef ERRCODE_INVALID_TEXT_REPRESENTATION ERRCODE(ERRCODE_INVALID_TEXT_REPRESENTATION, "DataError"), #endif #ifdef ERRCODE_INVALID_BINARY_REPRESENTATION ERRCODE(ERRCODE_INVALID_BINARY_REPRESENTATION, "DataError"), #endif #ifdef ERRCODE_BAD_COPY_FILE_FORMAT ERRCODE(ERRCODE_BAD_COPY_FILE_FORMAT, "DataError"), #endif #ifdef ERRCODE_UNTRANSLATABLE_CHARACTER ERRCODE(ERRCODE_UNTRANSLATABLE_CHARACTER, "DataError"), #endif #ifdef ERRCODE_NOT_AN_XML_DOCUMENT ERRCODE(ERRCODE_NOT_AN_XML_DOCUMENT, "DataError"), #endif #ifdef ERRCODE_INVALID_XML_DOCUMENT ERRCODE(ERRCODE_INVALID_XML_DOCUMENT, "DataError"), #endif #ifdef ERRCODE_INVALID_XML_CONTENT ERRCODE(ERRCODE_INVALID_XML_CONTENT, "DataError"), #endif #ifdef ERRCODE_INVALID_XML_COMMENT ERRCODE(ERRCODE_INVALID_XML_COMMENT, "DataError"), #endif #ifdef ERRCODE_INVALID_XML_PROCESSING_INSTRUCTION ERRCODE(ERRCODE_INVALID_XML_PROCESSING_INSTRUCTION, "DataError"), #endif #ifdef ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION ERRCODE(ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION, "IntegrityError"), #endif #ifdef ERRCODE_RESTRICT_VIOLATION ERRCODE(ERRCODE_RESTRICT_VIOLATION, "IntegrityError"), #endif #ifdef ERRCODE_NOT_NULL_VIOLATION ERRCODE(ERRCODE_NOT_NULL_VIOLATION, "IntegrityError"), #endif #ifdef ERRCODE_FOREIGN_KEY_VIOLATION ERRCODE(ERRCODE_FOREIGN_KEY_VIOLATION, "IntegrityError"), #endif #ifdef ERRCODE_UNIQUE_VIOLATION ERRCODE(ERRCODE_UNIQUE_VIOLATION, "IntegrityError"), #endif #ifdef ERRCODE_CHECK_VIOLATION ERRCODE(ERRCODE_CHECK_VIOLATION, "IntegrityError"), #endif #ifdef ERRCODE_WITH_CHECK_OPTION_VIOLATION ERRCODE(ERRCODE_WITH_CHECK_OPTION_VIOLATION, "IntegrityError"), #endif #ifdef ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION ERRCODE(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION, "SyntaxError"), #endif #ifdef ERRCODE_SYNTAX_ERROR ERRCODE(ERRCODE_SYNTAX_ERROR, "SyntaxError"), #endif #ifdef ERRCODE_INSUFFICIENT_PRIVILEGE ERRCODE(ERRCODE_INSUFFICIENT_PRIVILEGE, "SyntaxError"), #endif #ifdef ERRCODE_CANNOT_COERCE ERRCODE(ERRCODE_CANNOT_COERCE, "SyntaxError"), #endif #ifdef ERRCODE_GROUPING_ERROR ERRCODE(ERRCODE_GROUPING_ERROR, "SyntaxError"), #endif #ifdef ERRCODE_WINDOWING_ERROR ERRCODE(ERRCODE_WINDOWING_ERROR, "SyntaxError"), #endif #ifdef ERRCODE_INVALID_RECURSION ERRCODE(ERRCODE_INVALID_RECURSION, "SyntaxError"), #endif #ifdef ERRCODE_INVALID_FOREIGN_KEY ERRCODE(ERRCODE_INVALID_FOREIGN_KEY, "SyntaxError"), #endif #ifdef ERRCODE_INVALID_NAME ERRCODE(ERRCODE_INVALID_NAME, "SyntaxError"), #endif #ifdef ERRCODE_NAME_TOO_LONG ERRCODE(ERRCODE_NAME_TOO_LONG, "SyntaxError"), #endif #ifdef ERRCODE_RESERVED_NAME ERRCODE(ERRCODE_RESERVED_NAME, "SyntaxError"), #endif #ifdef ERRCODE_DATATYPE_MISMATCH ERRCODE(ERRCODE_DATATYPE_MISMATCH, "SyntaxError"), #endif #ifdef ERRCODE_INDETERMINATE_DATATYPE ERRCODE(ERRCODE_INDETERMINATE_DATATYPE, "SyntaxError"), #endif #ifdef ERRCODE_WRONG_OBJECT_TYPE ERRCODE(ERRCODE_WRONG_OBJECT_TYPE, "SyntaxError"), #endif #ifdef ERRCODE_UNDEFINED_COLUMN ERRCODE(ERRCODE_UNDEFINED_COLUMN, "SyntaxError"), #endif #ifdef ERRCODE_UNDEFINED_CURSOR ERRCODE(ERRCODE_UNDEFINED_CURSOR, "SyntaxError"), #endif #ifdef ERRCODE_UNDEFINED_DATABASE ERRCODE(ERRCODE_UNDEFINED_DATABASE, "SyntaxError"), #endif #ifdef ERRCODE_UNDEFINED_FUNCTION ERRCODE(ERRCODE_UNDEFINED_FUNCTION, "SyntaxError"), #endif #ifdef ERRCODE_UNDEFINED_PSTATEMENT ERRCODE(ERRCODE_UNDEFINED_PSTATEMENT, "SyntaxError"), #endif #ifdef ERRCODE_UNDEFINED_SCHEMA ERRCODE(ERRCODE_UNDEFINED_SCHEMA, "SyntaxError"), #endif #ifdef ERRCODE_UNDEFINED_TABLE ERRCODE(ERRCODE_UNDEFINED_TABLE, "SyntaxError"), #endif #ifdef ERRCODE_UNDEFINED_PARAMETER ERRCODE(ERRCODE_UNDEFINED_PARAMETER, "SyntaxError"), #endif #ifdef ERRCODE_UNDEFINED_OBJECT ERRCODE(ERRCODE_UNDEFINED_OBJECT, "SyntaxError"), #endif #ifdef ERRCODE_DUPLICATE_COLUMN ERRCODE(ERRCODE_DUPLICATE_COLUMN, "SyntaxError"), #endif #ifdef ERRCODE_DUPLICATE_CURSOR ERRCODE(ERRCODE_DUPLICATE_CURSOR, "SyntaxError"), #endif #ifdef ERRCODE_DUPLICATE_DATABASE ERRCODE(ERRCODE_DUPLICATE_DATABASE, "SyntaxError"), #endif #ifdef ERRCODE_DUPLICATE_FUNCTION ERRCODE(ERRCODE_DUPLICATE_FUNCTION, "SyntaxError"), #endif #ifdef ERRCODE_DUPLICATE_PSTATEMENT ERRCODE(ERRCODE_DUPLICATE_PSTATEMENT, "SyntaxError"), #endif #ifdef ERRCODE_DUPLICATE_SCHEMA ERRCODE(ERRCODE_DUPLICATE_SCHEMA, "SyntaxError"), #endif #ifdef ERRCODE_DUPLICATE_TABLE ERRCODE(ERRCODE_DUPLICATE_TABLE, "SyntaxError"), #endif #ifdef ERRCODE_DUPLICATE_ALIAS ERRCODE(ERRCODE_DUPLICATE_ALIAS, "SyntaxError"), #endif #ifdef ERRCODE_DUPLICATE_OBJECT ERRCODE(ERRCODE_DUPLICATE_OBJECT, "SyntaxError"), #endif #ifdef ERRCODE_AMBIGUOUS_COLUMN ERRCODE(ERRCODE_AMBIGUOUS_COLUMN, "SyntaxError"), #endif #ifdef ERRCODE_AMBIGUOUS_FUNCTION ERRCODE(ERRCODE_AMBIGUOUS_FUNCTION, "SyntaxError"), #endif #ifdef ERRCODE_AMBIGUOUS_PARAMETER ERRCODE(ERRCODE_AMBIGUOUS_PARAMETER, "SyntaxError"), #endif #ifdef ERRCODE_AMBIGUOUS_ALIAS ERRCODE(ERRCODE_AMBIGUOUS_ALIAS, "SyntaxError"), #endif #ifdef ERRCODE_INVALID_COLUMN_REFERENCE ERRCODE(ERRCODE_INVALID_COLUMN_REFERENCE, "SyntaxError"), #endif #ifdef ERRCODE_INVALID_COLUMN_DEFINITION ERRCODE(ERRCODE_INVALID_COLUMN_DEFINITION, "SyntaxError"), #endif #ifdef ERRCODE_INVALID_CURSOR_DEFINITION ERRCODE(ERRCODE_INVALID_CURSOR_DEFINITION, "SyntaxError"), #endif #ifdef ERRCODE_INVALID_DATABASE_DEFINITION ERRCODE(ERRCODE_INVALID_DATABASE_DEFINITION, "SyntaxError"), #endif #ifdef ERRCODE_INVALID_FUNCTION_DEFINITION ERRCODE(ERRCODE_INVALID_FUNCTION_DEFINITION, "SyntaxError"), #endif #ifdef ERRCODE_INVALID_PSTATEMENT_DEFINITION ERRCODE(ERRCODE_INVALID_PSTATEMENT_DEFINITION, "SyntaxError"), #endif #ifdef ERRCODE_INVALID_SCHEMA_DEFINITION ERRCODE(ERRCODE_INVALID_SCHEMA_DEFINITION, "SyntaxError"), #endif #ifdef ERRCODE_INVALID_TABLE_DEFINITION ERRCODE(ERRCODE_INVALID_TABLE_DEFINITION, "SyntaxError"), #endif #ifdef ERRCODE_INVALID_OBJECT_DEFINITION ERRCODE(ERRCODE_INVALID_OBJECT_DEFINITION, "SyntaxError"), #endif #ifdef ERRCODE_INVALID_TRANSACTION_STATE ERRCODE(ERRCODE_INVALID_TRANSACTION_STATE, "TransactionError"), #endif #ifdef ERRCODE_ACTIVE_SQL_TRANSACTION ERRCODE(ERRCODE_ACTIVE_SQL_TRANSACTION, "TransactionError"), #endif #ifdef ERRCODE_BRANCH_TRANSACTION_ALREADY_ACTIVE ERRCODE(ERRCODE_BRANCH_TRANSACTION_ALREADY_ACTIVE, "TransactionError"), #endif #ifdef ERRCODE_HELD_CURSOR_REQUIRES_SAME_ISOLATION_LEVEL ERRCODE(ERRCODE_HELD_CURSOR_REQUIRES_SAME_ISOLATION_LEVEL, "TransactionError"), #endif #ifdef ERRCODE_INAPPROPRIATE_ACCESS_MODE_FOR_BRANCH_TRANSACTION ERRCODE(ERRCODE_INAPPROPRIATE_ACCESS_MODE_FOR_BRANCH_TRANSACTION, "TransactionError"), #endif #ifdef ERRCODE_INAPPROPRIATE_ISOLATION_LEVEL_FOR_BRANCH_TRANSACTION ERRCODE(ERRCODE_INAPPROPRIATE_ISOLATION_LEVEL_FOR_BRANCH_TRANSACTION, "TransactionError"), #endif #ifdef ERRCODE_NO_ACTIVE_SQL_TRANSACTION_FOR_BRANCH_TRANSACTION ERRCODE(ERRCODE_NO_ACTIVE_SQL_TRANSACTION_FOR_BRANCH_TRANSACTION, "TransactionError"), #endif #ifdef ERRCODE_READ_ONLY_SQL_TRANSACTION ERRCODE(ERRCODE_READ_ONLY_SQL_TRANSACTION, "TransactionError"), #endif #ifdef ERRCODE_SCHEMA_AND_DATA_STATEMENT_MIXING_NOT_SUPPORTED ERRCODE(ERRCODE_SCHEMA_AND_DATA_STATEMENT_MIXING_NOT_SUPPORTED, "TransactionError"), #endif #ifdef ERRCODE_NO_ACTIVE_SQL_TRANSACTION ERRCODE(ERRCODE_NO_ACTIVE_SQL_TRANSACTION, "TransactionError"), #endif #ifdef ERRCODE_IN_FAILED_SQL_TRANSACTION ERRCODE(ERRCODE_IN_FAILED_SQL_TRANSACTION, "TransactionError"), #endif {0, NULL, NULL} }; #endif do_postgres-0.10.17/ext/do_postgres/pg_config.h0000644000004100000410000005127513312076603021507 0ustar www-datawww-data/* src/include/pg_config.h. Generated by configure. */ /* src/include/pg_config.h.in. Generated from configure.in by autoheader. */ /* This file is generated from MingW ./configure, and with the following * changes to be valid for Visual C++ (and compatible): * * HAVE_CBRT, HAVE_FUNCNAME_FUNC, HAVE_GETOPT, HAVE_GETOPT_H, * HAVE_GETOPT_LONG, HAVE_RINT, HAVE_STRINGS_H, HAVE_STRTOLL, * HAVE_STRTOULL, HAVE_STRUCT_OPTION, ENABLE_THREAD_SAFETY * */ /* Define to the type of arg 1 of 'accept' */ #define ACCEPT_TYPE_ARG1 unsigned int /* Define to the type of arg 2 of 'accept' */ #define ACCEPT_TYPE_ARG2 struct sockaddr * /* Define to the type of arg 3 of 'accept' */ #define ACCEPT_TYPE_ARG3 int /* Define to the return type of 'accept' */ #define ACCEPT_TYPE_RETURN unsigned int PASCAL /* The alignment requirement of a `double'. */ #define ALIGNOF_DOUBLE 8 /* The alignment requirement of a `int'. */ #define ALIGNOF_INT 4 /* The alignment requirement of a `long'. */ #define ALIGNOF_LONG 4 /* The alignment requirement of a `long long int'. */ #define ALIGNOF_LONG_LONG_INT 8 /* The alignment requirement of a `short'. */ #define ALIGNOF_SHORT 2 /* Define to the default TCP port number on which the server listens and to which clients will try to connect. This can be overridden at run-time, but it's convenient if your clients have the right default compiled in. (--with-pgport=PORTNUM) */ #define DEF_PGPORT 5432 /* Define to the default TCP port number as a string constant. */ #define DEF_PGPORT_STR "5432" /* Define to 1 if you want National Language Support. (--enable-nls) */ /* #undef ENABLE_NLS */ /* Define to 1 to build client libraries as thread-safe code. (--enable-thread-safety) */ #define ENABLE_THREAD_SAFETY 1 /* Define to 1 if getpwuid_r() takes a 5th argument. */ /* #undef GETPWUID_R_5ARG */ /* Define to 1 if gettimeofday() takes only 1 argument. */ /* #undef GETTIMEOFDAY_1ARG */ #ifdef GETTIMEOFDAY_1ARG # define gettimeofday(a,b) gettimeofday(a) #endif /* Define to 1 if you have the `atexit' function. */ #define HAVE_ATEXIT 1 /* Define to 1 if you have the `cbrt' function. */ //#define HAVE_CBRT 1 /* Define to 1 if you have the `class' function. */ /* #undef HAVE_CLASS */ /* Define to 1 if you have the `crypt' function. */ /* #undef HAVE_CRYPT */ /* Define to 1 if you have the header file. */ /* #undef HAVE_CRYPT_H */ /* Define to 1 if you have the declaration of `fdatasync', and to 0 if you don't. */ #define HAVE_DECL_FDATASYNC 0 /* Define to 1 if you have the declaration of `F_FULLFSYNC', and to 0 if you don't. */ #define HAVE_DECL_F_FULLFSYNC 0 /* Define to 1 if you have the declaration of `snprintf', and to 0 if you don't. */ #define HAVE_DECL_SNPRINTF 1 /* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you don't. */ #define HAVE_DECL_VSNPRINTF 1 /* Define to 1 if you have the header file. */ /* #undef HAVE_DLD_H */ /* Define to 1 if you have the `dlopen' function. */ /* #undef HAVE_DLOPEN */ /* Define to 1 if you have the header file. */ /* #undef HAVE_EDITLINE_HISTORY_H */ /* Define to 1 if you have the header file. */ /* #undef HAVE_EDITLINE_READLINE_H */ /* Define to 1 if you have the `fcvt' function. */ #define HAVE_FCVT 1 /* Define to 1 if you have the `fdatasync' function. */ /* #undef HAVE_FDATASYNC */ /* Define to 1 if you have finite(). */ #define HAVE_FINITE 1 /* Define to 1 if you have the `fpclass' function. */ /* #undef HAVE_FPCLASS */ /* Define to 1 if you have the `fp_class' function. */ /* #undef HAVE_FP_CLASS */ /* Define to 1 if you have the `fp_class_d' function. */ /* #undef HAVE_FP_CLASS_D */ /* Define to 1 if you have the header file. */ /* #undef HAVE_FP_CLASS_H */ /* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ /* #undef HAVE_FSEEKO */ /* Define to 1 if your compiler understands __func__. */ //#define HAVE_FUNCNAME__FUNC 1 /* Define to 1 if your compiler understands __FUNCTION__. */ #define HAVE_FUNCNAME__FUNCTION 1 /* Define to 1 if you have getaddrinfo(). */ /* #undef HAVE_GETADDRINFO */ /* Define to 1 if you have the `gethostbyname_r' function. */ /* #undef HAVE_GETHOSTBYNAME_R */ /* Define to 1 if you have the `getopt' function. */ //#define HAVE_GETOPT 1 /* Define to 1 if you have the header file. */ //#define HAVE_GETOPT_H 1 /* Define to 1 if you have the `getopt_long' function. */ //#define HAVE_GETOPT_LONG 1 /* Define to 1 if you have the `getpeereid' function. */ /* #undef HAVE_GETPEEREID */ /* Define to 1 if you have the `getpwuid_r' function. */ /* #undef HAVE_GETPWUID_R */ /* Define to 1 if you have the `getrusage' function. */ /* #undef HAVE_GETRUSAGE */ /* Define to 1 if you have the header file. */ /* #undef HAVE_HISTORY_H */ /* Define to 1 if you have the header file. */ /* #undef HAVE_IEEEFP_H */ /* Define to 1 if you have the `inet_aton' function. */ /* #undef HAVE_INET_ATON */ /* Define to 1 if the system has the type `int64'. */ /* #undef HAVE_INT64 */ /* Define to 1 if the system has the type `int8'. */ /* #undef HAVE_INT8 */ /* Define to 1 if you have the header file. */ #define HAVE_INTTYPES_H 1 /* Define to 1 if you have the global variable 'int optreset'. */ #define HAVE_INT_OPTRESET 1 /* Define to 1 if you have the global variable 'int timezone'. */ #define HAVE_INT_TIMEZONE /* Define to 1 if you have support for IPv6. */ #define HAVE_IPV6 1 /* Define to 1 if you have isinf(). */ #define HAVE_ISINF 1 /* Define to 1 if you have the header file. */ /* #undef HAVE_KERNEL_IMAGE_H */ /* Define to 1 if you have the header file. */ /* #undef HAVE_KERNEL_OS_H */ /* Define to 1 if `e_data' is member of `krb5_error'. */ /* #undef HAVE_KRB5_ERROR_E_DATA */ /* Define to 1 if `text.data' is member of `krb5_error'. */ /* #undef HAVE_KRB5_ERROR_TEXT_DATA */ /* Define to 1 if `client' is member of `krb5_ticket'. */ /* #undef HAVE_KRB5_TICKET_CLIENT */ /* Define to 1 if `enc_part2' is member of `krb5_ticket'. */ /* #undef HAVE_KRB5_TICKET_ENC_PART2 */ /* Define to 1 if you have the header file. */ /* #undef HAVE_LANGINFO_H */ /* Define to 1 if you have the header file. */ /* #undef HAVE_LDAP_H */ /* Define to 1 if you have the `crypto' library (-lcrypto). */ /* #undef HAVE_LIBCRYPTO */ /* Define to 1 if you have the `eay32' library (-leay32). */ /* #undef HAVE_LIBEAY32 */ /* Define to 1 if you have the `ldap' library (-lldap). */ /* #undef HAVE_LIBLDAP */ /* Define to 1 if you have the `pam' library (-lpam). */ /* #undef HAVE_LIBPAM */ /* Define if you have a function readline library */ /* #undef HAVE_LIBREADLINE */ /* Define to 1 if you have the `ssl' library (-lssl). */ /* #undef HAVE_LIBSSL */ /* Define to 1 if you have the `ssleay32' library (-lssleay32). */ /* #undef HAVE_LIBSSLEAY32 */ /* Define to 1 if you have the `wldap32' library (-lwldap32). */ /* #undef HAVE_LIBWLDAP32 */ /* Define to 1 if you have the `z' library (-lz). */ /* #undef HAVE_LIBZ */ /* Define to 1 if constants of type 'long long int' should have the suffix LL. */ #if (_MSC_VER > 1200) #define HAVE_LL_CONSTANTS 1 #endif /* Define to 1 if `long int' works and is 64 bits. */ /* #undef HAVE_LONG_INT_64 */ /* Define to 1 if `long long int' works and is 64 bits. */ #if (_MSC_VER > 1200) #define HAVE_LONG_LONG_INT_64 #endif /* Define to 1 if you have the `memmove' function. */ #define HAVE_MEMMOVE 1 /* Define to 1 if you have the header file. */ #define HAVE_MEMORY_H 1 /* Define to 1 if you have the header file. */ #define HAVE_NETINET_IN_H 1 /* Define to 1 if you have the header file. */ /* #undef HAVE_NETINET_TCP_H */ /* Define to 1 if you have the `on_exit' function. */ /* #undef HAVE_ON_EXIT */ /* Define to 1 if you have the header file. */ /* #undef HAVE_PAM_PAM_APPL_H */ /* Define to 1 if you have the `poll' function. */ /* #undef HAVE_POLL */ /* Define to 1 if you have the header file. */ /* #undef HAVE_POLL_H */ /* Define to 1 if you have the POSIX signal interface. */ /* #undef HAVE_POSIX_SIGNALS */ /* Define to 1 if you have the `pstat' function. */ /* #undef HAVE_PSTAT */ /* Define to 1 if the PS_STRINGS thing exists. */ /* #undef HAVE_PS_STRINGS */ /* Define if you have POSIX threads libraries and header files. */ /* #undef HAVE_PTHREAD */ /* Define to 1 if you have the header file. */ #define HAVE_PWD_H 1 /* Define to 1 if you have the `random' function. */ /* #undef HAVE_RANDOM */ /* Define to 1 if you have the header file. */ /* #undef HAVE_READLINE_H */ /* Define to 1 if you have the header file. */ /* #undef HAVE_READLINE_HISTORY_H */ /* Define to 1 if you have the header file. */ /* #undef HAVE_READLINE_READLINE_H */ /* Define to 1 if you have the `readlink' function. */ /* #undef HAVE_READLINK */ /* Define to 1 if you have the `replace_history_entry' function. */ /* #undef HAVE_REPLACE_HISTORY_ENTRY */ /* Define to 1 if you have the `rint' function. */ /*#define HAVE_RINT 1*/ /* Define to 1 if you have the global variable 'rl_completion_append_character'. */ /* #undef HAVE_RL_COMPLETION_APPEND_CHARACTER */ /* Define to 1 if you have the `rl_completion_matches' function. */ /* #undef HAVE_RL_COMPLETION_MATCHES */ /* Define to 1 if you have the `rl_filename_completion_function' function. */ /* #undef HAVE_RL_FILENAME_COMPLETION_FUNCTION */ /* Define to 1 if you have the header file. */ /* #undef HAVE_SECURITY_PAM_APPL_H */ /* Define to 1 if you have the `setproctitle' function. */ /* #undef HAVE_SETPROCTITLE */ /* Define to 1 if you have the `setsid' function. */ /* #undef HAVE_SETSID */ /* Define to 1 if you have the `sigprocmask' function. */ /* #undef HAVE_SIGPROCMASK */ /* Define to 1 if you have sigsetjmp(). */ /* #undef HAVE_SIGSETJMP */ /* Define to 1 if the system has the type `sig_atomic_t'. */ #define HAVE_SIG_ATOMIC_T 1 /* Define to 1 if you have the `snprintf' function. */ /* #undef HAVE_SNPRINTF */ /* Define to 1 if you have spinlocks. */ #define HAVE_SPINLOCKS 1 /* Define to 1 if you have the `srandom' function. */ /* #undef HAVE_SRANDOM */ /* Define to 1 if you have the header file. */ #define HAVE_STDINT_H 1 /* Define to 1 if you have the header file. */ #define HAVE_STDLIB_H 1 /* Define to 1 if you have the `strdup' function. */ #define HAVE_STRDUP 1 /* Define to 1 if you have the `strerror' function. */ #ifndef HAVE_STRERROR #define HAVE_STRERROR 1 #endif /* Define to 1 if you have the `strerror_r' function. */ /* #undef HAVE_STRERROR_R */ /* Define to 1 if cpp supports the ANSI # stringizing operator. */ #define HAVE_STRINGIZE 1 /* Define to 1 if you have the header file. */ /*#define HAVE_STRINGS_H 1 */ /* Define to 1 if you have the header file. */ #define HAVE_STRING_H 1 /* Define to 1 if you have the `strtol' function. */ #define HAVE_STRTOL 1 /* Define to 1 if you have the `strtoll' function. */ //#define HAVE_STRTOLL 1 /* Define to 1 if you have the `strtoq' function. */ /* #undef HAVE_STRTOQ */ /* Define to 1 if you have the `strtoul' function. */ #define HAVE_STRTOUL 1 /* Define to 1 if you have the `strtoull' function. */ //#define HAVE_STRTOULL 1 /* Define to 1 if you have the `strtouq' function. */ /* #undef HAVE_STRTOUQ */ /* Define to 1 if the system has the type `struct addrinfo'. */ #if (_MSC_VER > 1200) #define HAVE_STRUCT_ADDRINFO 1 #endif /* Define to 1 if the system has the type `struct cmsgcred'. */ /* #undef HAVE_STRUCT_CMSGCRED */ /* Define to 1 if the system has the type `struct fcred'. */ /* #undef HAVE_STRUCT_FCRED */ /* Define to 1 if the system has the type `struct option'. */ //#define HAVE_STRUCT_OPTION 1 /* Define to 1 if `sa_len' is member of `struct sockaddr'. */ /* #undef HAVE_STRUCT_SOCKADDR_SA_LEN */ /* Define to 1 if the system has the type `struct sockaddr_storage'. */ #if (_MSC_VER > 1200) #define HAVE_STRUCT_SOCKADDR_STORAGE 1 #endif /* Define to 1 if `ss_family' is member of `struct sockaddr_storage'. */ #if (_MSC_VER > 1200) #define HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1 #endif /* Define to 1 if `ss_len' is member of `struct sockaddr_storage'. */ /* #undef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN */ /* Define to 1 if `__ss_family' is member of `struct sockaddr_storage'. */ /* #undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY */ /* Define to 1 if `__ss_len' is member of `struct sockaddr_storage'. */ /* #undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN */ /* Define to 1 if the system has the type `struct sockaddr_un'. */ /* #undef HAVE_STRUCT_SOCKADDR_UN */ /* Define to 1 if the system has the type `struct sockcred'. */ /* #undef HAVE_STRUCT_SOCKCRED */ /* Define to 1 if `tm_zone' is member of `struct tm'. */ /* #undef HAVE_STRUCT_TM_TM_ZONE */ /* Define to 1 if you have the header file. */ /* #undef HAVE_SUPPORTDEFS_H */ /* Define to 1 if you have the `symlink' function. */ #define HAVE_SYMLINK 1 /* Define to 1 if you have the `sysconf' function. */ /* #undef HAVE_SYSCONF */ /* Define to 1 if you have the syslog interface. */ /* #undef HAVE_SYSLOG */ /* Define to 1 if you have the header file. */ /* #undef HAVE_SYS_IPC_H */ /* Define to 1 if you have the header file. */ /* #undef HAVE_SYS_POLL_H */ /* Define to 1 if you have the header file. */ /* #undef HAVE_SYS_PSTAT_H */ /* Define to 1 if you have the header file. */ /* #undef HAVE_SYS_SELECT_H */ /* Define to 1 if you have the header file. */ /* #undef HAVE_SYS_SEM_H */ /* Define to 1 if you have the header file. */ /* #undef HAVE_SYS_SHM_H */ /* Define to 1 if you have the header file. */ #define HAVE_SYS_SOCKET_H 1 /* Define to 1 if you have the header file. */ #define HAVE_SYS_STAT_H 1 /* Define to 1 if you have the header file. */ /* #define HAVE_SYS_TIME_H 1 */ /* Define to 1 if you have the header file. */ #define HAVE_SYS_TYPES_H 1 /* Define to 1 if you have the header file. */ /* #undef HAVE_SYS_UN_H */ /* Define to 1 if you have the header file. */ /* #undef HAVE_TERMIOS_H */ /* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use `HAVE_STRUCT_TM_TM_ZONE' instead. */ /* #undef HAVE_TM_ZONE */ /* Define to 1 if you have the `towlower' function. */ #define HAVE_TOWLOWER 1 /* Define to 1 if you have the external array `tzname'. */ /* #undef HAVE_TZNAME */ /* Define to 1 if the system has the type `uint64'. */ /* #undef HAVE_UINT64 */ /* Define to 1 if the system has the type `uint8'. */ /* #undef HAVE_UINT8 */ /* Define to 1 if the system has the type `union semun'. */ /* #undef HAVE_UNION_SEMUN */ /* Define to 1 if you have the header file. */ #define HAVE_UNISTD_H 1 /* Define to 1 if you have unix sockets. */ /* #undef HAVE_UNIX_SOCKETS */ /* Define to 1 if you have the `unsetenv' function. */ /* #undef HAVE_UNSETENV */ /* Define to 1 if you have the `utime' function. */ #define HAVE_UTIME 1 /* Define to 1 if you have the `utimes' function. */ /* #undef HAVE_UTIMES */ /* Define to 1 if you have the header file. */ #define HAVE_UTIME_H 1 /* Define to 1 if you have the `vsnprintf' function. */ #define HAVE_VSNPRINTF 1 /* Define to 1 if you have the `waitpid' function. */ /* #undef HAVE_WAITPID */ /* Define to 1 if you have the header file. */ #define HAVE_WCHAR_H 1 /* Define to 1 if you have the `wcstombs' function. */ #define HAVE_WCSTOMBS 1 /* Define to 1 if you have the header file. */ #define HAVE_WCTYPE_H 1 /* Define to 1 if you have the header file. */ /* #undef HAVE_WINLDAP_H */ /* Define to the appropriate snprintf format for 64-bit ints, if any. */ #define INT64_FORMAT "%lld" /* Define to build with Kerberos 5 support. (--with-krb5) */ /* #undef KRB5 */ /* Define to the location of locale files. */ /* #undef LOCALEDIR */ /* Define as the maximum alignment requirement of any C data type. */ #define MAXIMUM_ALIGNOF 8 /* Define bytes to use libc memset(). */ #define MEMSET_LOOP_LIMIT 1024 /* Define to the address where bug reports for this package should be sent. */ #define PACKAGE_BUGREPORT "pgsql-bugs@postgresql.org" /* Define to the full name of this package. */ #define PACKAGE_NAME "PostgreSQL" /* Define to the full name and version of this package. */ #define PACKAGE_STRING "PostgreSQL 8.3.7" /* Define to the version of this package. */ #define PACKAGE_VERSION "8.3.7" /* PostgreSQL version as a string */ #define PG_VERSION "8.3.7" /* PostgreSQL version as a number */ #define PG_VERSION_NUM 80307 /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "postgresql" /* Define to the name of the default PostgreSQL service principal in Kerberos. (--with-krb-srvnam=NAME) */ #define PG_KRB_SRVNAM "postgres" /* A string containing the version number, platform, and C compiler */ #define __STRINGIFY(x) #x #define __STRINGIFY2(z) __STRINGIFY(z) #define PG_VERSION_STR "PostgreSQL 8.3.7, compiled by Visual C++ build " __STRINGIFY2(_MSC_VER) /* Define to the necessary symbol if this constant uses a non-standard name on your system. */ /* #undef PTHREAD_CREATE_JOINABLE */ /* The size of a `size_t', as computed by sizeof. */ #define SIZEOF_SIZE_T 4 /* The size of a `unsigned long', as computed by sizeof. */ #define SIZEOF_UNSIGNED_LONG 4 /* Define to 1 if you have the ANSI C header files. */ #define STDC_HEADERS 1 /* Define to 1 if strerror_r() returns a int. */ /* #undef STRERROR_R_INT */ /* Define to 1 if your declares `struct tm'. */ /* #undef TM_IN_SYS_TIME */ /* Define to the appropriate snprintf format for unsigned 64-bit ints, if any. */ #define UINT64_FORMAT "%llu" /* Define to 1 to build with assertion checks. (--enable-cassert) */ /* #undef USE_ASSERT_CHECKING */ /* Define to 1 to build with Bonjour support. (--with-bonjour) */ /* #undef USE_BONJOUR */ /* Define to 1 if you want 64-bit integer timestamp and interval support. (--enable-integer-datetimes) */ /* #undef USE_INTEGER_DATETIMES */ /* Define to 1 to build with LDAP support. (--with-ldap) */ /* #undef USE_LDAP */ /* Define to select named POSIX semaphores. */ /* #undef USE_NAMED_POSIX_SEMAPHORES */ /* Define to 1 to build with PAM support. (--with-pam) */ /* #undef USE_PAM */ /* Use replacement snprintf() functions. */ #define USE_REPL_SNPRINTF 1 /* Define to build with (Open)SSL support. (--with-openssl) */ /* #undef USE_SSL */ /* Define to select SysV-style semaphores. */ /* #undef USE_SYSV_SEMAPHORES */ /* Define to select SysV-style shared memory. */ #define USE_SYSV_SHARED_MEMORY 1 /* Define to select unnamed POSIX semaphores. */ /* #undef USE_UNNAMED_POSIX_SEMAPHORES */ /* Define to select Win32-style semaphores. */ #define USE_WIN32_SEMAPHORES /* Number of bits in a file offset, on hosts where this is settable. */ /* #undef _FILE_OFFSET_BITS */ /* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */ /* #undef _LARGEFILE_SOURCE */ /* Define for large files, on AIX-style hosts. */ /* #undef _LARGE_FILES */ /* Define to empty if `const' does not conform to ANSI C. */ /* #undef const */ /* Define as `__inline' if that's what the C compiler calls it, or to nothing if it is not supported. */ /* #undef inline */ /* Define to empty if the C compiler does not understand signed types. */ /* #undef signed */ /* Define to empty if the keyword `volatile' does not work. Warning: valid code using `volatile' can become incorrect without. Disable with care. */ /* #undef volatile */ #define LOCALEDIR "/share/locale" /* defines added by config steps */ #ifndef IGNORE_CONFIGURED_SETTINGS #define USE_LDAP 1 #define HAVE_LIBZ 1 #define USE_SSL 1 #define HAVE_UUID_H #define HAVE_LIBXML2 #define USE_LIBXML #define KRB5 1 #define HAVE_KRB5_ERROR_TEXT_DATA 1 #define HAVE_KRB5_TICKET_ENC_PART2 1 #define HAVE_KRB5_FREE_UNPARSED_NAME 1 #define ENABLE_GSS 1 #define VAL_CONFIGURE "--enable-thread-safety --enable-nls --with-ldap --with-ossp-uuid --with-libxml --with-libxslt --with-krb5 --with-tcl --with-perl --with-python" #endif /* IGNORE_CONFIGURED_SETTINGS */ do_postgres-0.10.17/ext/do_postgres/extconf.rb0000644000004100000410000000340713312076603021370 0ustar www-datawww-dataENV["RC_ARCHS"] = "" if RUBY_PLATFORM =~ /darwin/ require 'mkmf' require 'date' # Allow for custom compiler to be specified. RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC'] def config_value(type) ENV["POSTGRES_#{type.upcase}"] || pg_config(type) end def pg_config(type) IO.popen("pg_config --#{type}").readline.chomp rescue nil end # The preheader argument wasn't introduced till Ruby 1.9.3. def have_header_with_preheader(header, preheader) if method(:have_header).arity == -2 have_header(header, preheader) else have_header(header) end end def have_build_env (have_library('pq') || have_library('libpq')) && have_header('libpq-fe.h') && have_header('libpq/libpq-fs.h') && have_header('postgres.h') && have_header_with_preheader('mb/pg_wchar.h', 'postgres.h') && have_header_with_preheader('catalog/pg_type.h', 'postgres.h') end $CFLAGS << ' -UENABLE_NLS -DHAVE_GETTIMEOFDAY -DHAVE_CRYPT' if RUBY_PLATFORM =~ /mswin|mingw/ unless DateTime.respond_to?(:new!) $CFLAGS << ' -DHAVE_NO_DATETIME_NEWBANG' end dir_config('pgsql-server', config_value('includedir-server'), config_value('libdir')) dir_config('pgsql-client', config_value('includedir'), config_value('libdir')) dir_config('pgsql-win32') if RUBY_PLATFORM =~ /mswin|mingw/ desired_functions = %w(localtime_r gmtime_r PQsetClientEncoding pg_encoding_to_char PQfreemem rb_thread_fd_select) compat_functions = %w(PQescapeString PQexecParams) if have_build_env desired_functions.each(&method(:have_func)) $CFLAGS << ' -Wall ' unless RUBY_PLATFORM =~ /mswin/ if RUBY_VERSION < '1.8.6' $CFLAGS << ' -DRUBY_LESS_THAN_186' end create_makefile("do_postgres/do_postgres") else puts 'Could not find PostgreSQL build environment (libraries & headers): Makefile not created' exit(1) end do_postgres-0.10.17/ext/do_postgres/do_postgres.c0000644000004100000410000004703113312076603022072 0ustar www-datawww-data#include #include #include #include #include /* Undefine constants Postgres also defines */ #undef PACKAGE_BUGREPORT #undef PACKAGE_NAME #undef PACKAGE_STRING #undef PACKAGE_TARNAME #undef PACKAGE_VERSION #ifdef _WIN32 /* On Windows this stuff is also defined by Postgres, but we don't want to use Postgres' version actually */ #undef fsync #undef ftruncate #undef fseeko #undef ftello #undef stat #undef vsnprintf #undef snprintf #undef sprintf #undef printf #endif #ifdef _WIN32 #define do_postgres_cCommand_execute do_postgres_cCommand_execute_sync #else #define do_postgres_cCommand_execute do_postgres_cCommand_execute_async #endif #ifndef HAVE_RB_THREAD_FD_SELECT #define rb_fdset_t fd_set #define rb_fd_isset(n, f) FD_ISSET(n, f) #define rb_fd_init(f) FD_ZERO(f) #define rb_fd_zero(f) FD_ZERO(f) #define rb_fd_set(n, f) FD_SET(n, f) #define rb_fd_clr(n, f) FD_CLR(n, f) #define rb_fd_term(f) #define rb_thread_fd_select rb_thread_select #endif #include #include #include #include #include #ifndef _WIN32 #include #endif #include "error.h" #include "compat.h" #include "do_common.h" VALUE mDO_Postgres; VALUE mDO_PostgresEncoding; VALUE cDO_PostgresConnection; VALUE cDO_PostgresCommand; VALUE cDO_PostgresResult; VALUE cDO_PostgresReader; void do_postgres_full_connect(VALUE self, PGconn *db); /* ===== Typecasting Functions ===== */ VALUE do_postgres_infer_ruby_type(Oid type) { switch(type) { case BITOID: case VARBITOID: case INT2OID: case INT4OID: case INT8OID: return rb_cInteger; case FLOAT4OID: case FLOAT8OID: return rb_cFloat; case NUMERICOID: case CASHOID: return rb_cBigDecimal; case BOOLOID: return rb_cTrueClass; case TIMESTAMPTZOID: case TIMESTAMPOID: return rb_cDateTime; case DATEOID: return rb_cDate; case BYTEAOID: return rb_cByteArray; default: return rb_cString; } } VALUE do_postgres_typecast(const char *value, long length, const VALUE type, int encoding) { if (type == rb_cTrueClass) { return *value == 't' ? Qtrue : Qfalse; } else if (type == rb_cByteArray) { size_t new_length = 0; char *unescaped = (char *)PQunescapeBytea((unsigned char*)value, &new_length); VALUE byte_array = rb_funcall(rb_cByteArray, DO_ID_NEW, 1, rb_str_new(unescaped, new_length)); PQfreemem(unescaped); return byte_array; } else { return data_objects_typecast(value, length, type, encoding); } } void do_postgres_raise_error(VALUE self, PGresult *result, VALUE query) { VALUE message = rb_str_new2(PQresultErrorMessage(result)); char *sql_state = PQresultErrorField(result, PG_DIAG_SQLSTATE); int postgres_errno = MAKE_SQLSTATE(sql_state[0], sql_state[1], sql_state[2], sql_state[3], sql_state[4]); VALUE str = rb_str_new2(sql_state); PQclear(result); data_objects_raise_error(self, do_postgres_errors, postgres_errno, message, query, str); } /* ====== Public API ======= */ VALUE do_postgres_cConnection_dispose(VALUE self) { VALUE connection_container = rb_iv_get(self, "@connection"); if (connection_container == Qnil) { return Qfalse; } PGconn *db = DATA_PTR(connection_container); if (!db) { return Qfalse; } PQfinish(db); rb_iv_set(self, "@connection", Qnil); return Qtrue; } VALUE do_postgres_cConnection_quote_string(VALUE self, VALUE string) { PGconn *db = DATA_PTR(rb_iv_get(self, "@connection")); const char *source = rb_str_ptr_readonly(string); int error = 0; long source_len = rb_str_len(string); long buffer_len = source_len * 2 + 3; // Overflow check if(buffer_len <= source_len) { rb_raise(rb_eArgError, "Input string is too large to be safely quoted"); } char *escaped; // Allocate space for the escaped version of 'string' // http://www.postgresql.org/docs/8.3/static/libpq-exec.html#LIBPQ-EXEC-ESCAPE-STRING if (!(escaped = calloc(buffer_len, sizeof(char)))) { rb_memerror(); } long quoted_length; VALUE result; // Escape 'source' using the current charset in use on the conection 'db' quoted_length = PQescapeStringConn(db, escaped + 1, source, source_len, &error); if(error) { rb_raise(eDO_DataError, "%s", PQerrorMessage(db)); } // Wrap the escaped string in single-quotes, this is DO's convention escaped[0] = escaped[quoted_length + 1] = '\''; result = DATA_OBJECTS_STR_NEW(escaped, quoted_length + 2, FIX2INT(rb_iv_get(self, "@encoding_id")), NULL); free(escaped); return result; } VALUE do_postgres_cConnection_quote_byte_array(VALUE self, VALUE string) { PGconn *db = DATA_PTR(rb_iv_get(self, "@connection")); const unsigned char *source = (unsigned char *)rb_str_ptr_readonly(string); size_t source_len = rb_str_len(string); unsigned char *escaped; unsigned char *escaped_quotes; size_t quoted_length = 0; VALUE result; // Allocate space for the escaped version of 'string' // http://www.postgresql.org/docs/8.3/static/libpq-exec.html#LIBPQ-EXEC-ESCAPE-STRING escaped = PQescapeByteaConn(db, source, source_len, "ed_length); if(!escaped) { rb_memerror(); } if (!(escaped_quotes = calloc(quoted_length + 1, sizeof(unsigned char)))) { rb_memerror(); } memcpy(escaped_quotes + 1, escaped, quoted_length * sizeof(unsigned char)); // Wrap the escaped string in single-quotes, this is DO's convention (replace trailing \0) escaped_quotes[0] = escaped_quotes[quoted_length] = '\''; result = rb_str_new((const char *)escaped_quotes, quoted_length + 1); PQfreemem(escaped); free(escaped_quotes); return result; } #ifdef _WIN32 PGresult * do_postgres_cCommand_execute_sync(VALUE self, VALUE connection, PGconn *db, VALUE query) { char *str = StringValuePtr(query); PGresult *response; while ((response = PQgetResult(db))) { PQclear(response); } struct timeval start; gettimeofday(&start, NULL); response = PQexec(db, str); if (!response) { if (PQstatus(db) != CONNECTION_OK) { PQreset(db); if (PQstatus(db) == CONNECTION_OK) { response = PQexec(db, str); } else { do_postgres_full_connect(connection, db); response = PQexec(db, str); } } if(!response) { rb_raise(eDO_ConnectionError, PQerrorMessage(db)); } } data_objects_debug(connection, query, &start); return response; } #else PGresult * do_postgres_cCommand_execute_async(VALUE self, VALUE connection, PGconn *db, VALUE query) { PGresult *response; char* str = StringValuePtr(query); while ((response = PQgetResult(db))) { PQclear(response); } struct timeval start; int retval; gettimeofday(&start, NULL); retval = PQsendQuery(db, str); if (!retval) { if (PQstatus(db) != CONNECTION_OK) { PQreset(db); if (PQstatus(db) == CONNECTION_OK) { retval = PQsendQuery(db, str); } else { do_postgres_full_connect(connection, db); retval = PQsendQuery(db, str); } } if (!retval) { rb_raise(eDO_ConnectionError, "%s", PQerrorMessage(db)); } } int socket_fd = PQsocket(db); rb_fdset_t rset; rb_fd_init(&rset); rb_fd_set(socket_fd, &rset); while (1) { retval = rb_thread_fd_select(socket_fd + 1, &rset, NULL, NULL, NULL); if (retval < 0) { rb_fd_term(&rset); rb_sys_fail(0); } if (retval == 0) { continue; } if (PQconsumeInput(db) == 0) { rb_fd_term(&rset); rb_raise(eDO_ConnectionError, "%s", PQerrorMessage(db)); } if (PQisBusy(db) == 0) { break; } } rb_fd_term(&rset); data_objects_debug(connection, query, &start); return PQgetResult(db); } #endif VALUE do_postgres_cConnection_initialize(VALUE self, VALUE uri) { rb_iv_set(self, "@using_socket", Qfalse); VALUE r_host = rb_funcall(uri, rb_intern("host"), 0); if (r_host != Qnil) { rb_iv_set(self, "@host", r_host); } VALUE r_user = rb_funcall(uri, rb_intern("user"), 0); if (r_user != Qnil) { rb_iv_set(self, "@user", r_user); } VALUE r_password = rb_funcall(uri, rb_intern("password"), 0); if (r_password != Qnil) { rb_iv_set(self, "@password", r_password); } VALUE r_path = rb_funcall(uri, rb_intern("path"), 0); if (r_path != Qnil) { rb_iv_set(self, "@path", r_path); } VALUE r_port = rb_funcall(uri, rb_intern("port"), 0); if (r_port != Qnil) { r_port = rb_funcall(r_port, rb_intern("to_s"), 0); rb_iv_set(self, "@port", r_port); } // Pull the querystring off the URI VALUE r_query = rb_funcall(uri, rb_intern("query"), 0); rb_iv_set(self, "@query", r_query); const char *encoding = data_objects_get_uri_option(r_query, "encoding"); if (!encoding) { encoding = data_objects_get_uri_option(r_query, "charset"); if (!encoding) { encoding = "UTF-8"; } } rb_iv_set(self, "@encoding", rb_str_new2(encoding)); PGconn *db = NULL; do_postgres_full_connect(self, db); rb_iv_set(self, "@uri", uri); return Qtrue; } void do_postgres_full_connect(VALUE self, PGconn *db) { VALUE r_host; char *host = NULL; if ((r_host = rb_iv_get(self, "@host")) != Qnil) { host = StringValuePtr(r_host); } VALUE r_user; char *user = NULL; if ((r_user = rb_iv_get(self, "@user")) != Qnil) { user = StringValuePtr(r_user); } VALUE r_password; char *password = NULL; if ((r_password = rb_iv_get(self, "@password")) != Qnil) { password = StringValuePtr(r_password); } VALUE r_port; const char *port = "5432"; if ((r_port = rb_iv_get(self, "@port")) != Qnil) { port = StringValuePtr(r_port); } VALUE r_path; char *path = NULL; char *database = NULL; if ((r_path = rb_iv_get(self, "@path")) != Qnil) { path = StringValuePtr(r_path); database = strtok(path, "/"); } if (!database || !*database) { database = NULL; } VALUE r_query = rb_iv_get(self, "@query"); const char *search_path = data_objects_get_uri_option(r_query, "search_path"); db = PQsetdbLogin( host, port, NULL, NULL, database, user, password ); if (PQstatus(db) == CONNECTION_BAD) { rb_raise(eDO_ConnectionError, "%s", PQerrorMessage(db)); } PGresult *result; if (search_path) { char *search_path_query; if (!(search_path_query = calloc(256, sizeof(char)))) { rb_memerror(); } snprintf(search_path_query, 256, "set search_path to %s;", search_path); r_query = rb_str_new2(search_path_query); result = do_postgres_cCommand_execute(Qnil, self, db, r_query); if (PQresultStatus(result) != PGRES_COMMAND_OK) { free(search_path_query); do_postgres_raise_error(self, result, r_query); } free(search_path_query); } const char *backslash_off = "SET backslash_quote = off"; const char *standard_strings_on = "SET standard_conforming_strings = on"; const char *warning_messages = "SET client_min_messages = warning"; const char *date_format = "SET datestyle = ISO"; VALUE r_options; r_options = rb_str_new2(backslash_off); result = do_postgres_cCommand_execute(Qnil, self, db, r_options); if (PQresultStatus(result) != PGRES_COMMAND_OK) { rb_warn("%s", PQresultErrorMessage(result)); } r_options = rb_str_new2(standard_strings_on); result = do_postgres_cCommand_execute(Qnil, self, db, r_options); if (PQresultStatus(result) != PGRES_COMMAND_OK) { rb_warn("%s", PQresultErrorMessage(result)); } r_options = rb_str_new2(warning_messages); result = do_postgres_cCommand_execute(Qnil, self, db, r_options); if (PQresultStatus(result) != PGRES_COMMAND_OK) { rb_warn("%s", PQresultErrorMessage(result)); } r_options = rb_str_new2(date_format); result = do_postgres_cCommand_execute(Qnil, self, db, r_options); if (PQresultStatus(result) != PGRES_COMMAND_OK) { rb_warn("%s", PQresultErrorMessage(result)); } VALUE encoding = rb_iv_get(self, "@encoding"); #ifdef HAVE_PQSETCLIENTENCODING VALUE pg_encoding = rb_hash_aref(data_objects_const_get(mDO_PostgresEncoding, "MAP"), encoding); if (pg_encoding != Qnil) { if (PQsetClientEncoding(db, rb_str_ptr_readonly(pg_encoding))) { rb_raise(eDO_ConnectionError, "Couldn't set encoding: %s", rb_str_ptr_readonly(encoding)); } else { #ifdef HAVE_RUBY_ENCODING_H rb_iv_set(self, "@encoding_id", INT2FIX(rb_enc_find_index(rb_str_ptr_readonly(encoding)))); #endif rb_iv_set(self, "@pg_encoding", pg_encoding); } } else { rb_warn("Encoding %s is not a known Ruby encoding for PostgreSQL\n", rb_str_ptr_readonly(encoding)); rb_iv_set(self, "@encoding", rb_str_new2("UTF-8")); #ifdef HAVE_RUBY_ENCODING_H rb_iv_set(self, "@encoding_id", INT2FIX(rb_enc_find_index("UTF-8"))); #endif rb_iv_set(self, "@pg_encoding", rb_str_new2("UTF8")); } #endif rb_iv_set(self, "@connection", Data_Wrap_Struct(rb_cObject, 0, 0, db)); } VALUE do_postgres_cCommand_execute_non_query(int argc, VALUE *argv, VALUE self) { VALUE connection = rb_iv_get(self, "@connection"); VALUE postgres_connection = rb_iv_get(connection, "@connection"); if (postgres_connection == Qnil) { rb_raise(eDO_ConnectionError, "This connection has already been closed."); } VALUE query = data_objects_build_query_from_args(self, argc, argv); PGconn *db = DATA_PTR(postgres_connection); PGresult *response; int status; response = do_postgres_cCommand_execute(self, connection, db, query); status = PQresultStatus(response); VALUE affected_rows = Qnil; VALUE insert_id = Qnil; if (status == PGRES_TUPLES_OK) { if (PQgetlength(response, 0, 0) == 0) { insert_id = Qnil; } else { insert_id = INT2NUM(atoi(PQgetvalue(response, 0, 0))); } affected_rows = INT2NUM(atoi(PQcmdTuples(response))); } else if (status == PGRES_COMMAND_OK) { insert_id = Qnil; affected_rows = INT2NUM(atoi(PQcmdTuples(response))); } else { do_postgres_raise_error(self, response, query); } PQclear(response); return rb_funcall(cDO_PostgresResult, DO_ID_NEW, 3, self, affected_rows, insert_id); } VALUE do_postgres_cCommand_execute_reader(int argc, VALUE *argv, VALUE self) { VALUE connection = rb_iv_get(self, "@connection"); VALUE postgres_connection = rb_iv_get(connection, "@connection"); if (postgres_connection == Qnil) { rb_raise(eDO_ConnectionError, "This connection has already been closed."); } VALUE query = data_objects_build_query_from_args(self, argc, argv); PGconn *db = DATA_PTR(postgres_connection); PGresult *response = do_postgres_cCommand_execute(self, connection, db, query); int status = PQresultStatus(response); if(status != PGRES_TUPLES_OK && status != PGRES_COMMAND_OK) { do_postgres_raise_error(self, response, query); } int field_count = PQnfields(response); VALUE reader = rb_funcall(cDO_PostgresReader, DO_ID_NEW, 0); rb_iv_set(reader, "@connection", connection); rb_iv_set(reader, "@reader", Data_Wrap_Struct(rb_cObject, 0, 0, response)); rb_iv_set(reader, "@opened", Qfalse); rb_iv_set(reader, "@field_count", INT2NUM(field_count)); rb_iv_set(reader, "@row_count", INT2NUM(PQntuples(response))); VALUE field_names = rb_ary_new(); VALUE field_types = rb_iv_get(self, "@field_types"); int infer_types = 0; if (field_types == Qnil || 0 == RARRAY_LEN(field_types)) { field_types = rb_ary_new(); infer_types = 1; } else if (RARRAY_LEN(field_types) != field_count) { // Whoops... wrong number of types passed to set_types. Close the reader and raise // and error rb_funcall(reader, rb_intern("close"), 0); rb_raise(rb_eArgError, "Field-count mismatch. Expected %ld fields, but the query yielded %d", RARRAY_LEN(field_types), field_count); } int i; for (i = 0; i < field_count; i++) { rb_ary_push(field_names, rb_str_new2(PQfname(response, i))); if (infer_types == 1) { rb_ary_push(field_types, do_postgres_infer_ruby_type(PQftype(response, i))); } } rb_iv_set(reader, "@position", INT2NUM(0)); rb_iv_set(reader, "@fields", field_names); rb_iv_set(reader, "@field_types", field_types); return reader; } VALUE do_postgres_cReader_close(VALUE self) { VALUE reader_container = rb_iv_get(self, "@reader"); if (reader_container == Qnil) { return Qfalse; } PGresult *reader = DATA_PTR(reader_container); if (!reader) { return Qfalse; } PQclear(reader); rb_iv_set(self, "@reader", Qnil); rb_iv_set(self, "@opened", Qfalse); return Qtrue; } VALUE do_postgres_cReader_next(VALUE self) { VALUE reader = rb_iv_get(self, "@reader"); if(reader == Qnil) { rb_raise(eDO_ConnectionError, "This result set has already been closed."); return Qfalse; } PGresult *pg_reader = DATA_PTR(reader); int row_count = NUM2INT(rb_iv_get(self, "@row_count")); int field_count = NUM2INT(rb_iv_get(self, "@field_count")); VALUE field_types = rb_iv_get(self, "@field_types"); int position = NUM2INT(rb_iv_get(self, "@position")); if (position > (row_count - 1)) { rb_iv_set(self, "@values", Qnil); return Qfalse; } rb_iv_set(self, "@opened", Qtrue); int enc = -1; #ifdef HAVE_RUBY_ENCODING_H VALUE encoding_id = rb_iv_get(rb_iv_get(self, "@connection"), "@encoding_id"); if (encoding_id != Qnil) { enc = FIX2INT(encoding_id); } #endif VALUE array = rb_ary_new(); VALUE field_type; VALUE value; int i; for (i = 0; i < field_count; i++) { field_type = rb_ary_entry(field_types, i); // Always return nil if the value returned from Postgres is null if (!PQgetisnull(pg_reader, position, i)) { value = do_postgres_typecast(PQgetvalue(pg_reader, position, i), PQgetlength(pg_reader, position, i), field_type, enc); } else { value = Qnil; } rb_ary_push(array, value); } rb_iv_set(self, "@values", array); rb_iv_set(self, "@position", INT2NUM(position+1)); return Qtrue; } void Init_do_postgres() { data_objects_common_init(); mDO_Postgres = rb_define_module_under(mDO, "Postgres"); mDO_PostgresEncoding = rb_define_module_under(mDO_Postgres, "Encoding"); cDO_PostgresConnection = rb_define_class_under(mDO_Postgres, "Connection", cDO_Connection); rb_define_method(cDO_PostgresConnection, "initialize", do_postgres_cConnection_initialize, 1); rb_define_method(cDO_PostgresConnection, "dispose", do_postgres_cConnection_dispose, 0); rb_define_method(cDO_PostgresConnection, "character_set", data_objects_cConnection_character_set , 0); rb_define_method(cDO_PostgresConnection, "quote_string", do_postgres_cConnection_quote_string, 1); rb_define_method(cDO_PostgresConnection, "quote_byte_array", do_postgres_cConnection_quote_byte_array, 1); cDO_PostgresCommand = rb_define_class_under(mDO_Postgres, "Command", cDO_Command); rb_define_method(cDO_PostgresCommand, "set_types", data_objects_cCommand_set_types, -1); rb_define_method(cDO_PostgresCommand, "execute_non_query", do_postgres_cCommand_execute_non_query, -1); rb_define_method(cDO_PostgresCommand, "execute_reader", do_postgres_cCommand_execute_reader, -1); cDO_PostgresResult = rb_define_class_under(mDO_Postgres, "Result", cDO_Result); cDO_PostgresReader = rb_define_class_under(mDO_Postgres, "Reader", cDO_Reader); rb_define_method(cDO_PostgresReader, "close", do_postgres_cReader_close, 0); rb_define_method(cDO_PostgresReader, "next!", do_postgres_cReader_next, 0); rb_define_method(cDO_PostgresReader, "values", data_objects_cReader_values, 0); rb_define_method(cDO_PostgresReader, "fields", data_objects_cReader_fields, 0); rb_define_method(cDO_PostgresReader, "field_count", data_objects_cReader_field_count, 0); rb_global_variable(&cDO_PostgresResult); rb_global_variable(&cDO_PostgresReader); data_objects_define_errors(mDO_Postgres, do_postgres_errors); } do_postgres-0.10.17/ext/do_postgres/do_common.c0000644000004100000410000003404113312076603021511 0ustar www-datawww-data#include #include #include #include #include #ifndef _WIN32 #include #endif #include "do_common.h" /* * Common variables ("globals") */ // To store rb_intern values ID DO_ID_NEW; ID DO_ID_NEW_DATE; ID DO_ID_CONST_GET; ID DO_ID_RATIONAL; ID DO_ID_ESCAPE; ID DO_ID_STRFTIME; ID DO_ID_LOG; // Reference to Extlib module VALUE mExtlib; VALUE rb_cByteArray; // References to DataObjects base classes VALUE mDO; VALUE cDO_Quoting; VALUE cDO_Connection; VALUE cDO_Command; VALUE cDO_Result; VALUE cDO_Reader; VALUE cDO_Logger; VALUE cDO_Logger_Message; VALUE cDO_Extension; VALUE eDO_ConnectionError; VALUE eDO_DataError; // References to Ruby classes that we'll need VALUE rb_cDate; VALUE rb_cDateTime; VALUE rb_cBigDecimal; /* * Common Functions */ VALUE data_objects_const_get(VALUE scope, const char *constant) { return rb_funcall(scope, DO_ID_CONST_GET, 1, rb_str_new2(constant)); } void data_objects_debug(VALUE connection, VALUE string, struct timeval *start) { struct timeval stop; VALUE message; do_int64 duration; gettimeofday(&stop, NULL); duration = (stop.tv_sec - start->tv_sec) * 1000000 + stop.tv_usec - start->tv_usec; message = rb_funcall(cDO_Logger_Message, DO_ID_NEW, 3, string, rb_time_new(start->tv_sec, start->tv_usec), INT2NUM(duration)); rb_funcall(connection, DO_ID_LOG, 1, message); } void data_objects_raise_error(VALUE self, const struct errcodes *errors, int errnum, VALUE message, VALUE query, VALUE state) { const char *exception_type = "SQLError"; const struct errcodes *e; VALUE uri, exception; for (e = errors; e->error_name; e++) { if (e->error_no == errnum) { // return the exception type for the matching error exception_type = e->exception; break; } } uri = rb_funcall(rb_iv_get(self, "@connection"), rb_intern("to_s"), 0); exception = rb_funcall( data_objects_const_get(mDO, exception_type), DO_ID_NEW, 5, message, INT2NUM(errnum), state, query, uri ); rb_exc_raise(exception); } char *data_objects_get_uri_option(VALUE query_hash, const char *key) { VALUE query_value; char *value = NULL; if (!rb_obj_is_kind_of(query_hash, rb_cHash)) { return NULL; } query_value = rb_hash_aref(query_hash, rb_str_new2(key)); if (Qnil != query_value) { value = StringValuePtr(query_value); } return value; } void data_objects_assert_file_exists(char *file, const char *message) { if (file) { if (rb_funcall(rb_cFile, rb_intern("exist?"), 1, rb_str_new2(file)) == Qfalse) { rb_raise(rb_eArgError, "%s", message); } } } VALUE data_objects_build_query_from_args(VALUE klass, int count, VALUE *args) { int i; VALUE array = rb_ary_new(); for (i = 0; i < count; i++) { rb_ary_push(array, args[i]); } return rb_funcall(klass, DO_ID_ESCAPE, 1, array); } // Find the greatest common denominator and reduce the provided numerator and denominator. // This replaces calles to Rational.reduce! which does the same thing, but really slowly. void data_objects_reduce(do_int64 *numerator, do_int64 *denominator) { do_int64 a = *numerator, b = *denominator, c; while (a != 0) { c = a; a = b % a; b = c; } *numerator /= b; *denominator /= b; } // Generate the date integer which Date.civil_to_jd returns int data_objects_jd_from_date(int year, int month, int day) { int a, b; if (month <= 2) { year -= 1; month += 12; } a = year / 100; b = 2 - a + (a / 4); return (int)(floor(365.25 * (year + 4716)) + floor(30.6001 * (month + 1)) + day + b - 1524); } VALUE data_objects_seconds_to_offset(long seconds_offset) { do_int64 num = seconds_offset; do_int64 den = 86400; data_objects_reduce(&num, &den); return rb_funcall(rb_mKernel, DO_ID_RATIONAL, 2, rb_ll2inum(num), rb_ll2inum(den)); } VALUE data_objects_timezone_to_offset(int hour_offset, int minute_offset) { do_int64 seconds = 0; seconds += hour_offset * 3600; seconds += minute_offset * 60; return data_objects_seconds_to_offset(seconds); } VALUE data_objects_parse_date(const char *date) { static char const *const _fmt_date = "%4d-%2d-%2d"; int year = 0, month = 0, day = 0; switch (sscanf(date, _fmt_date, &year, &month, &day)) { case 0: case EOF: return Qnil; } if(!year && !month && !day) { return Qnil; } return rb_funcall(rb_cDate, DO_ID_NEW, 3, INT2NUM(year), INT2NUM(month), INT2NUM(day)); } VALUE data_objects_parse_time(const char *date) { static char const* const _fmt_datetime = "%4d-%2d-%2d%*c%2d:%2d:%2d%7lf"; int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0, usec = 0; double subsec = 0; switch (sscanf(date, _fmt_datetime, &year, &month, &day, &hour, &min, &sec, &subsec)) { case 0: case EOF: return Qnil; } usec = (int) (subsec * 1000000); /* Mysql TIMESTAMPS can default to 0 */ if ((year + month + day + hour + min + sec + usec) == 0) { return Qnil; } return rb_funcall(rb_cTime, rb_intern("local"), 7, INT2NUM(year), INT2NUM(month), INT2NUM(day), INT2NUM(hour), INT2NUM(min), INT2NUM(sec), INT2NUM(usec)); } VALUE data_objects_parse_date_time(const char *date) { static char const* const _fmt_datetime_tz_normal = "%4d-%2d-%2d%*c%2d:%2d:%2d%3d:%2d"; static char const* const _fmt_datetime_tz_subsec = "%4d-%2d-%2d%*c%2d:%2d:%2d.%*d%3d:%2d"; int tokens_read; const char *fmt_datetime; VALUE offset; int year, month, day, hour, min, sec, hour_offset, minute_offset; struct tm timeinfo; time_t target_time; time_t gmt_offset; int dst_adjustment; if (*date == '\0') { return Qnil; } /* * We handle the following cases: * - Date (default to midnight) [3 tokens, missing 5] * - DateTime [6 tokens, missing 2] * - DateTime with hour, possibly minute TZ offset [7-8 tokens] */ fmt_datetime = strchr(date, '.') ? _fmt_datetime_tz_subsec : _fmt_datetime_tz_normal; tokens_read = sscanf(date, fmt_datetime, &year, &month, &day, &hour, &min, &sec, &hour_offset, &minute_offset); if(!year && !month && !day && !hour && !min && !sec) { return Qnil; } switch (tokens_read) { case 8: minute_offset *= hour_offset < 0 ? -1 : 1; break; case 7: /* Only got TZ hour offset, so assume 0 for minute */ minute_offset = 0; break; case 3: /* Only got Date */ hour = 0; min = 0; sec = 0; /* Fall through */ case 6: /* Only got DateTime */ /* * Interpret the DateTime from the local system TZ. If target date would * end up in DST, assume adjustment of a 1 hour shift. * * FIXME: The DST adjustment calculation won't be accurate for timezones * that observe fractional-hour shifts. But that's a real minority for * now.. */ timeinfo.tm_year = year - 1900; timeinfo.tm_mon = month - 1; // 0 - 11 timeinfo.tm_mday = day; timeinfo.tm_hour = hour; timeinfo.tm_min = min; timeinfo.tm_sec = sec; timeinfo.tm_isdst = -1; target_time = mktime(&timeinfo); dst_adjustment = timeinfo.tm_isdst ? 3600 : 0; /* * Now figure out seconds from UTC. For that we need a UTC/GMT-adjusted * time_t, which we get from mktime(gmtime(current_time)). * * NOTE: Some modern libc's have tm_gmtoff in struct tm, but we can't count * on that. */ #ifdef HAVE_GMTIME_R gmtime_r(&target_time, &timeinfo); #else timeinfo = *gmtime(&target_time); #endif gmt_offset = target_time - mktime(&timeinfo) + dst_adjustment; hour_offset = ((int)gmt_offset / 3600); minute_offset = ((int)gmt_offset % 3600 / 60); break; default: /* Any other combo of missing tokens and we can't do anything */ rb_raise(eDO_DataError, "Couldn't parse date: %s", date); } offset = data_objects_timezone_to_offset(hour_offset, minute_offset); return rb_funcall(rb_cDateTime, DO_ID_NEW, 7, INT2NUM(year), INT2NUM(month), INT2NUM(day), INT2NUM(hour), INT2NUM(min), INT2NUM(sec), offset); } VALUE data_objects_cConnection_character_set(VALUE self) { return rb_iv_get(self, "@encoding"); } VALUE data_objects_cConnection_is_using_socket(VALUE self) { return rb_iv_get(self, "@using_socket"); } VALUE data_objects_cConnection_ssl_cipher(VALUE self) { return rb_iv_get(self, "@ssl_cipher"); } VALUE data_objects_cConnection_quote_time(VALUE self, VALUE value) { return rb_funcall(value, DO_ID_STRFTIME, 1, rb_str_new2("'%Y-%m-%d %H:%M:%S'")); } VALUE data_objects_cConnection_quote_date_time(VALUE self, VALUE value) { // TODO: Support non-local dates. we need to call #new_offset on the date to be // quoted and pass in the current locale's date offset (self.new_offset((hours * 3600).to_r / 86400) return rb_funcall(value, DO_ID_STRFTIME, 1, rb_str_new2("'%Y-%m-%d %H:%M:%S'")); } VALUE data_objects_cConnection_quote_date(VALUE self, VALUE value) { return rb_funcall(value, DO_ID_STRFTIME, 1, rb_str_new2("'%Y-%m-%d'")); } /* * Accepts an array of Ruby types (Fixnum, Float, String, etc...) and turns them * into Ruby-strings so we can easily typecast later */ VALUE data_objects_cCommand_set_types(int argc, VALUE *argv, VALUE self) { VALUE entry, sub_entry; int i, j; VALUE type_strings = rb_ary_new(); VALUE array = rb_ary_new(); for (i = 0; i < argc; i++) { rb_ary_push(array, argv[i]); } for (i = 0; i < RARRAY_LEN(array); i++) { entry = rb_ary_entry(array, i); if (TYPE(entry) == T_CLASS) { rb_ary_push(type_strings, entry); } else if (TYPE(entry) == T_ARRAY) { for (j = 0; j < RARRAY_LEN(entry); j++) { sub_entry = rb_ary_entry(entry, j); if (TYPE(sub_entry) == T_CLASS) { rb_ary_push(type_strings, sub_entry); } else { rb_raise(rb_eArgError, "Invalid type given"); } } } else { rb_raise(rb_eArgError, "Invalid type given"); } } rb_iv_set(self, "@field_types", type_strings); return array; } VALUE data_objects_cReader_values(VALUE self) { VALUE state = rb_iv_get(self, "@opened"); VALUE values = rb_iv_get(self, "@values"); if (state == Qnil || state == Qfalse || values == Qnil) { rb_raise(eDO_DataError, "Reader is not initialized"); } return rb_iv_get(self, "@values"); } VALUE data_objects_cReader_fields(VALUE self) { return rb_iv_get(self, "@fields"); } VALUE data_objects_cReader_field_count(VALUE self) { return rb_iv_get(self, "@field_count"); } void data_objects_common_init(void) { rb_require("bigdecimal"); rb_require("rational"); rb_require("date"); rb_require("data_objects"); // Needed by data_objects_const_get DO_ID_CONST_GET = rb_intern("const_get"); // Get references classes needed for Date/Time parsing rb_cDate = data_objects_const_get(rb_mKernel, "Date"); rb_cDateTime = data_objects_const_get(rb_mKernel, "DateTime"); rb_cBigDecimal = data_objects_const_get(rb_mKernel, "BigDecimal"); DO_ID_NEW = rb_intern("new"); #ifdef RUBY_LESS_THAN_186 DO_ID_NEW_DATE = rb_intern("new0"); #else DO_ID_NEW_DATE = rb_intern("new!"); #endif DO_ID_CONST_GET = rb_intern("const_get"); DO_ID_RATIONAL = rb_intern("Rational"); DO_ID_ESCAPE = rb_intern("escape_sql"); DO_ID_STRFTIME = rb_intern("strftime"); DO_ID_LOG = rb_intern("log"); // Get references to the Extlib module mExtlib = data_objects_const_get(rb_mKernel, "Extlib"); rb_cByteArray = data_objects_const_get(mExtlib, "ByteArray"); // Get references to the DataObjects module and its classes mDO = data_objects_const_get(rb_mKernel, "DataObjects"); cDO_Quoting = data_objects_const_get(mDO, "Quoting"); cDO_Connection = data_objects_const_get(mDO, "Connection"); cDO_Command = data_objects_const_get(mDO, "Command"); cDO_Result = data_objects_const_get(mDO, "Result"); cDO_Reader = data_objects_const_get(mDO, "Reader"); cDO_Logger = data_objects_const_get(mDO, "Logger"); cDO_Logger_Message = data_objects_const_get(cDO_Logger, "Message"); cDO_Extension = data_objects_const_get(mDO, "Extension"); eDO_ConnectionError = data_objects_const_get(mDO, "ConnectionError"); eDO_DataError = data_objects_const_get(mDO, "DataError"); rb_global_variable(&DO_ID_NEW_DATE); rb_global_variable(&DO_ID_RATIONAL); rb_global_variable(&DO_ID_CONST_GET); rb_global_variable(&DO_ID_ESCAPE); rb_global_variable(&DO_ID_LOG); rb_global_variable(&DO_ID_NEW); rb_global_variable(&rb_cDate); rb_global_variable(&rb_cDateTime); rb_global_variable(&rb_cBigDecimal); rb_global_variable(&rb_cByteArray); rb_global_variable(&mDO); rb_global_variable(&cDO_Logger_Message); rb_global_variable(&eDO_ConnectionError); rb_global_variable(&eDO_DataError); tzset(); } /* * Common typecasting logic that can be used or overriden by Adapters. */ extern VALUE data_objects_typecast(const char *value, long length, const VALUE type, int encoding) { #ifdef HAVE_RUBY_ENCODING_H rb_encoding *internal_encoding = rb_default_internal_encoding(); #else void *internal_encoding = NULL; #endif if (type == rb_cInteger) { return rb_cstr2inum(value, 10); } else if (type == rb_cString) { return DATA_OBJECTS_STR_NEW(value, length, encoding, internal_encoding); } else if (type == rb_cFloat) { return rb_float_new(rb_cstr_to_dbl(value, Qfalse)); } else if (type == rb_cBigDecimal) { return rb_funcall(rb_cBigDecimal, DO_ID_NEW, 1, rb_str_new(value, length)); } else if (type == rb_cDate) { return data_objects_parse_date(value); } else if (type == rb_cDateTime) { return data_objects_parse_date_time(value); } else if (type == rb_cTime) { return data_objects_parse_time(value); } else if (type == rb_cTrueClass) { return (!value || strcmp("0", value) == 0) ? Qfalse : Qtrue; } else if (type == rb_cByteArray) { return rb_funcall(rb_cByteArray, DO_ID_NEW, 1, rb_str_new(value, length)); } else if (type == rb_cClass) { return rb_funcall(mDO, rb_intern("full_const_get"), 1, rb_str_new(value, length)); } else if (type == rb_cNilClass) { return Qnil; } else { return DATA_OBJECTS_STR_NEW(value, length, encoding, internal_encoding); } }