Sha256: 9b4a4023b94e4b37a3136207145c5497152eb923fa8207116f6d0dd8bf677d3f

Contents?: true

Size: 801 Bytes

Versions: 123

Compression:

Stored size: 801 Bytes

Contents

# -*- ruby -*-1.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

123 entries across 123 versions & 4 rubygems

Version Path
pg-1.6.0.rc1-x86_64-linux sample/test_binary_values.rb
pg-1.6.0.rc1-x86-mingw32 sample/test_binary_values.rb
pg-1.6.0.rc1-x64-mingw32 sample/test_binary_values.rb
pg-1.6.0.rc1-x64-mingw-ucrt sample/test_binary_values.rb
pg-1.6.0.rc1 sample/test_binary_values.rb
pg-1.5.9-x86-mingw32 sample/test_binary_values.rb
pg-1.5.9-x64-mingw32 sample/test_binary_values.rb
pg-1.5.9-x64-mingw-ucrt sample/test_binary_values.rb
pg-1.5.9 sample/test_binary_values.rb
pg-1.5.8-x64-mingw32 sample/test_binary_values.rb
pg-1.5.8-x64-mingw-ucrt sample/test_binary_values.rb
pg-1.5.8-x86-mingw32 sample/test_binary_values.rb
pg-1.5.8 sample/test_binary_values.rb
pg-1.5.7-x86-mingw32 sample/test_binary_values.rb
pg-1.5.7-x64-mingw32 sample/test_binary_values.rb
pg-1.5.7-x64-mingw-ucrt sample/test_binary_values.rb
pg-1.5.7 sample/test_binary_values.rb
pg-1.5.6-x64-mingw-ucrt sample/test_binary_values.rb
pg-1.5.6-x64-mingw32 sample/test_binary_values.rb
pg-1.5.6-x86-mingw32 sample/test_binary_values.rb