Sha256: f422698bb473387697bb5b6d6f07b43477f2c3911a637a7edbe71d0a459002aa

Contents?: true

Size: 804 Bytes

Versions: 5

Compression:

Stored size: 804 Bytes

Contents

# -*- ruby -*-1.9.1

require 'ysql'

db = YSQL.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

5 entries across 5 versions & 1 rubygems

Version Path
yugabytedb-ysql-0.7 sample/test_binary_values.rb
yugabytedb-ysql-0.6 sample/test_binary_values.rb
yugabytedb-ysql-0.5 sample/test_binary_values.rb
yugabytedb-ysql-0.4 sample/test_binary_values.rb
yugabytedb-ysql-0.3 sample/test_binary_values.rb