diff --git a/lib/pg/connection.rb b/lib/pg/connection.rb index cb9e64e16..a9052ce78 100644 --- a/lib/pg/connection.rb +++ b/lib/pg/connection.rb @@ -117,7 +117,7 @@ def inspect return str end - BinarySignature = "PGCOPY\n\377\r\n\0".b + BinarySignature = "PGCOPY\n\377\r\n\0" private_constant :BinarySignature # call-seq: diff --git a/spec/pg/basic_type_map_based_on_result_spec.rb b/spec/pg/basic_type_map_based_on_result_spec.rb index 80d1535df..e8c26e2f6 100644 --- a/spec/pg/basic_type_map_based_on_result_spec.rb +++ b/spec/pg/basic_type_map_based_on_result_spec.rb @@ -29,7 +29,7 @@ Ractor.make_shareable(basic_type_mapping) end - it "should be usable with Ractor", :ractor do + it "should be usable with Ractor in text format", :ractor do vals = Ractor.new(@conninfo) do |conninfo| conn = PG.connect(conninfo) basic_type_mapping = PG::BasicTypeMapBasedOnResult.new(conn) @@ -52,6 +52,29 @@ expect( vals ).to eq( [['b', '234', '{2,3}']] ) end + it "should be usable with Ractor in binary format", :ractor do + vals = Ractor.new(@conninfo) do |conninfo| + conn = PG.connect(conninfo) + basic_type_mapping = PG::BasicTypeMapBasedOnResult.new(conn) + conn.exec( "CREATE TEMP TABLE copytable (t TEXT, i INT)" ) + + # Retrieve table OIDs per empty result set. + res = conn.exec( "SELECT * FROM copytable LIMIT 0", [], 1) + tm = basic_type_mapping.build_column_map( res ) + row_encoder = PG::BinaryEncoder::CopyRow.new type_map: tm + + conn.copy_data( "COPY copytable FROM STDIN WITH (FORMAT binary)", row_encoder ) do |res| + conn.put_copy_data ['b', 234] + end + res = conn.exec( "SELECT * FROM copytable" ) + res.values + ensure + conn&.finish + end.take + + expect( vals ).to eq( [['b', '234']] ) + end + context "with usage of result oids for bind params encoder selection" do it "can type cast query params" do @conn.exec( "CREATE TEMP TABLE copytable (t TEXT, i INT, ai INT[], by BYTEA)" ) diff --git a/spec/pg/connection_spec.rb b/spec/pg/connection_spec.rb index a4bfd79ad..98af4160b 100644 --- a/spec/pg/connection_spec.rb +++ b/spec/pg/connection_spec.rb @@ -47,6 +47,16 @@ expect( vals ).to eq( [["123"]] ) end + it "connects using 7 arguments in a Ractor", :ractor do + vals = Ractor.new do + PG.connect( 'localhost', @port, nil, nil, :test, nil, nil ) do |conn| + conn.exec("SELECT 234").values + end + end.take + + expect( vals ).to eq( [["234"]] ) + end + describe "#inspect", :without_transaction do it "should print host, port and user of a fresh connection, but not more" do expect( @conn.inspect ).to match(//)