Sha256: c8f424f686cf2b2db96b184ca20eb64021df77cf41b3dd98bbc7e91e98a77046

Contents?: true

Size: 806 Bytes

Versions: 93

Compression:

Stored size: 806 Bytes

Contents

#!/usr/bin/env ruby1.9.1

require 'pg'

db = PG.connect( :dbname => 'test' )
db.exec "DROP TABLE IF EXISTS test"
db.exec "CREATE TABLE test (a INTEGER, b BYTEA)"

a = 42
b = [1, 2, 3]
db.exec "INSERT INTO test(a, b) VALUES($1::int, $2::bytea)",
	[a, {:value => b.pack('N*'), :format => 1}]

db.exec( "SELECT a::int, b::bytea FROM test LIMIT 1", [], 1 ) do |res|

	res.nfields.times do |i|
		puts "Field %d is: %s, a %s (%s) column from table %p" % [
			i,
			res.fname( i ),
			db.exec( "SELECT format_type($1,$2)", [res.ftype(i), res.fmod(1)] ).getvalue(0,0),
			res.fformat( i ).zero? ? "string" : "binary",
			res.ftable( i ),
		]
	end

	res.each do |row|
		puts "a = #{row['a'].inspect}"
		puts "a (unpacked) = #{row['a'].unpack('N*').inspect}"
		puts "b = #{row['b'].unpack('N*').inspect}"
	end
end


Version data entries

93 entries across 93 versions & 6 rubygems

Version Path
jruby-pg-0.1-java sample/test_binary_values.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/pg-0.20.0/sample/test_binary_values.rb
pg-0.20.0-x86-mingw32 sample/test_binary_values.rb
pg-0.20.0-x64-mingw32 sample/test_binary_values.rb
pg-0.20.0 sample/test_binary_values.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/sample/test_binary_values.rb
pg-0.19.1.pre20170124220800-x64-mingw32 sample/test_binary_values.rb
pg-0.19.1.pre20170124220800-x86-mingw32 sample/test_binary_values.rb
pg-0.19.1.pre20170124220800 sample/test_binary_values.rb
pg-0.19.1.pre20170115074000-x64-mingw32 sample/test_binary_values.rb
pg-0.19.1.pre20170115074000-x86-mingw32 sample/test_binary_values.rb
pg-0.19.1.pre20170115074000 sample/test_binary_values.rb
pg-0.19.0.pre20170115074000 sample/test_binary_values.rb
pg-0.19.0-x86-mingw32 sample/test_binary_values.rb
pg-0.19.0-x64-mingw32 sample/test_binary_values.rb
pg-0.19.0 sample/test_binary_values.rb
pg-0.19.0.pre20160904200247-x86-mingw32 sample/test_binary_values.rb
pg-0.19.0.pre20160904200247-x64-mingw32 sample/test_binary_values.rb
pg-0.19.0.pre20160904200247 sample/test_binary_values.rb
pg-0.19.0.pre20160820113039-x86-mingw32 sample/test_binary_values.rb