postgres-pr-encoding 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ # This is a compatibility layer for using the pure Ruby postgres-pr instead of
2
+ # the C interface of postgres.
3
+
4
+ begin
5
+ require 'postgres.so'
6
+ rescue LoadError
7
+ require 'postgres-pr/postgres-compat'
8
+ end
@@ -0,0 +1,103 @@
1
+ require 'test/unit'
2
+ require 'stringio'
3
+
4
+ class Module
5
+ def attr_accessor(*attrs)
6
+ @@attrs = [] unless defined?(@@attrs)
7
+ @@attrs += attrs
8
+
9
+ x = @@attrs.map {|a| "self.#{a} == o.#{a}"}.join(" && ")
10
+ class_eval %{
11
+ def ==(o)
12
+ #{ x }
13
+ end
14
+ }
15
+
16
+ @@attrs.each do |a|
17
+ class_eval %{
18
+ def #{a}() @#{a} end
19
+ def #{a}=(v) @#{a}=v end
20
+ }
21
+ end
22
+ end
23
+ end
24
+
25
+ $LOAD_PATH.unshift '../lib'
26
+ require 'postgres-pr/message'
27
+ include PostgresPR
28
+
29
+ class Buffer
30
+ alias old_content content
31
+ def content
32
+ self
33
+ end
34
+ end
35
+
36
+ class Message
37
+ attr_accessor :buffer
38
+
39
+ class << self
40
+ alias old_create create
41
+ def create(buffer)
42
+ obj = old_create(buffer)
43
+ obj.buffer = buffer
44
+ obj
45
+ end
46
+ end
47
+
48
+ alias old_dump dump
49
+
50
+ def dump(body_size=0, &block)
51
+ buf = old_dump(body_size, &block)
52
+ self.buffer = buf
53
+ buf.old_content
54
+ end
55
+ end
56
+
57
+ class StartupMessage
58
+ alias old_dump dump
59
+ def dump
60
+ buf = old_dump
61
+ self.buffer = buf
62
+ buf.old_content
63
+ end
64
+ end
65
+
66
+ class StringIO
67
+ alias readbytes read
68
+ end
69
+
70
+ class TC_Message < Test::Unit::TestCase
71
+
72
+ CASES = [
73
+ #[AuthentificationOk],
74
+ #[ErrorResponse],
75
+ [ParameterStatus, "key", "value"],
76
+ [BackendKeyData, 234234234, 213434],
77
+ [ReadyForQuery, ?T],
78
+ # TODO: RowDescription
79
+ [DataRow, ["a", "bbbbbb", "ccc", nil, nil, "ddddd", "e" * 10_000]],
80
+ [DataRow, []],
81
+ [CommandComplete, "INSERT"],
82
+ [StartupMessage, 196608, {"user" => "mneumann", "database" => "mneumann"}],
83
+ [Parse, "INSERT INTO blah values (?, ?)", ""],
84
+ [Query, "SELECT * FROM test\nWHERE a='test'"]
85
+ ]
86
+
87
+ def test_pack_unpack_feature
88
+ assert_equal ['a', 'b'], "a\000b\000".unpack('Z*Z*')
89
+ end
90
+
91
+ def test_marshal_unmarshal
92
+ CASES.each do |klass, *params|
93
+ msg = klass.new(*params)
94
+ new_msg = Message.read(StringIO.new(msg.dump), klass == StartupMessage)
95
+ assert_equal(msg, new_msg)
96
+
97
+ msg1, msg2 = klass.new(*params), klass.new(*params)
98
+ msg1.dump
99
+ msg2.dump; msg2.parse(msg2.buffer)
100
+ assert_equal(msg1, msg2)
101
+ end
102
+ end
103
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: postgres-pr-encoding
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Neumann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: mneumann@ntecs.de
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - examples/client.rb
20
+ - examples/og/test.rb
21
+ - examples/server.rb
22
+ - examples/test_connection.rb
23
+ - lib/binary_reader.rb
24
+ - lib/binary_writer.rb
25
+ - lib/buffer.rb
26
+ - lib/byteorder.rb
27
+ - lib/pg.rb
28
+ - lib/postgres-pr/connection.rb
29
+ - lib/postgres-pr/message.rb
30
+ - lib/postgres-pr/pg-compat.rb
31
+ - lib/postgres-pr/postgres-compat.rb
32
+ - lib/postgres-pr/typeconv/TC_conv.rb
33
+ - lib/postgres-pr/typeconv/array.rb
34
+ - lib/postgres-pr/typeconv/bytea.rb
35
+ - lib/postgres-pr/typeconv/conv.rb
36
+ - lib/postgres-pr/version.rb
37
+ - lib/postgres.rb
38
+ - test/TC_message.rb
39
+ homepage: http://postgres-pr.rubyforge.org
40
+ licenses: []
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements:
57
+ - PostgreSQL >= 7.4
58
+ rubyforge_project: postgres-pr
59
+ rubygems_version: 2.6.11
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: A pure Ruby interface to the PostgreSQL (>= 7.4) database
63
+ test_files: []