postgres-pr 0.3.2 → 0.3.3
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.
- data/examples/client.rb +1 -0
- data/examples/server.rb +1 -0
- data/lib/postgres-pr/connection.rb +83 -86
- data/lib/postgres-pr/message.rb +2 -1
- data/lib/postgres-pr/postgres-compat.rb +4 -0
- data/lib/postgres-pr/version.rb +3 -0
- metadata +3 -2
data/examples/client.rb
CHANGED
data/examples/server.rb
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#
|
|
2
2
|
# Author:: Michael Neumann
|
|
3
|
-
# Copyright:: (c)
|
|
3
|
+
# Copyright:: (c) 2005 by Michael Neumann
|
|
4
|
+
# License:: Same as Ruby's or BSD
|
|
4
5
|
#
|
|
5
6
|
|
|
6
7
|
require 'postgres-pr/message'
|
|
8
|
+
require 'postgres-pr/version'
|
|
7
9
|
require 'uri'
|
|
8
10
|
require 'socket'
|
|
9
|
-
require 'thread'
|
|
10
11
|
|
|
11
12
|
module PostgresPR
|
|
12
13
|
|
|
@@ -14,63 +15,61 @@ PROTO_VERSION = 3 << 16 #196608
|
|
|
14
15
|
|
|
15
16
|
class Connection
|
|
16
17
|
|
|
17
|
-
# sync
|
|
18
|
-
|
|
19
18
|
def initialize(database, user, password=nil, uri = nil)
|
|
20
19
|
uri ||= DEFAULT_URI
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
when ReadyForQuery
|
|
67
|
-
# TODO: use transaction status
|
|
68
|
-
break
|
|
69
|
-
else
|
|
70
|
-
raise "unhandled message type"
|
|
71
|
-
end
|
|
21
|
+
@params = {}
|
|
22
|
+
establish_connection(uri)
|
|
23
|
+
|
|
24
|
+
@conn << StartupMessage.new(PROTO_VERSION, 'user' => user, 'database' => database).dump
|
|
25
|
+
|
|
26
|
+
loop do
|
|
27
|
+
msg = Message.read(@conn)
|
|
28
|
+
|
|
29
|
+
case msg
|
|
30
|
+
when AuthentificationClearTextPassword
|
|
31
|
+
raise ArgumentError, "no password specified" if password.nil?
|
|
32
|
+
@conn << PasswordMessage.new(password).dump
|
|
33
|
+
|
|
34
|
+
when AuthentificationCryptPassword
|
|
35
|
+
raise ArgumentError, "no password specified" if password.nil?
|
|
36
|
+
@conn << PasswordMessage.new(password.crypt(msg.salt)).dump
|
|
37
|
+
|
|
38
|
+
when AuthentificationMD5Password
|
|
39
|
+
raise ArgumentError, "no password specified" if password.nil?
|
|
40
|
+
require 'digest/md5'
|
|
41
|
+
|
|
42
|
+
m = Digest::MD5.hexdigest(password + user)
|
|
43
|
+
m = Digest::MD5.hexdigest(m + msg.salt)
|
|
44
|
+
m = 'md5' + m
|
|
45
|
+
@conn << PasswordMessage.new(m).dump
|
|
46
|
+
|
|
47
|
+
when AuthentificationKerberosV4, AuthentificationKerberosV5, AuthentificationSCMCredential
|
|
48
|
+
raise "unsupported authentification"
|
|
49
|
+
|
|
50
|
+
when AuthentificationOk
|
|
51
|
+
when ErrorResponse
|
|
52
|
+
raise msg.field_values.join("\t")
|
|
53
|
+
when NoticeResponse
|
|
54
|
+
# TODO
|
|
55
|
+
when ParameterStatus
|
|
56
|
+
@params[msg.key] = msg.value
|
|
57
|
+
when BackendKeyData
|
|
58
|
+
# TODO
|
|
59
|
+
#p msg
|
|
60
|
+
when ReadyForQuery
|
|
61
|
+
# TODO: use transaction status
|
|
62
|
+
break
|
|
63
|
+
else
|
|
64
|
+
raise "unhandled message type"
|
|
72
65
|
end
|
|
73
|
-
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def close
|
|
70
|
+
raise "connection already closed" if @conn.nil?
|
|
71
|
+
@conn.shutdown
|
|
72
|
+
@conn = nil
|
|
74
73
|
end
|
|
75
74
|
|
|
76
75
|
class Result
|
|
@@ -81,40 +80,38 @@ class Connection
|
|
|
81
80
|
end
|
|
82
81
|
|
|
83
82
|
def query(sql)
|
|
84
|
-
@
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
# TODO
|
|
111
|
-
end
|
|
83
|
+
@conn << Query.dump(sql)
|
|
84
|
+
|
|
85
|
+
result = Result.new
|
|
86
|
+
errors = []
|
|
87
|
+
|
|
88
|
+
loop do
|
|
89
|
+
msg = Message.read(@conn)
|
|
90
|
+
case msg
|
|
91
|
+
when DataRow
|
|
92
|
+
result.rows << msg.columns
|
|
93
|
+
when CommandComplete
|
|
94
|
+
result.cmd_tag = msg.cmd_tag
|
|
95
|
+
when ReadyForQuery
|
|
96
|
+
break
|
|
97
|
+
when RowDescription
|
|
98
|
+
result.fields = msg.fields
|
|
99
|
+
when CopyInResponse
|
|
100
|
+
when CopyOutResponse
|
|
101
|
+
when EmptyQueryResponse
|
|
102
|
+
when ErrorResponse
|
|
103
|
+
# TODO
|
|
104
|
+
errors << msg
|
|
105
|
+
when NoticeResponse
|
|
106
|
+
p msg
|
|
107
|
+
else
|
|
108
|
+
# TODO
|
|
112
109
|
end
|
|
110
|
+
end
|
|
113
111
|
|
|
114
|
-
|
|
112
|
+
raise errors.map{|e| e.field_values.join("\t") }.join("\n") unless errors.empty?
|
|
115
113
|
|
|
116
|
-
|
|
117
|
-
}
|
|
114
|
+
result
|
|
118
115
|
end
|
|
119
116
|
|
|
120
117
|
DEFAULT_PORT = 5432
|
data/lib/postgres-pr/message.rb
CHANGED
metadata
CHANGED
|
@@ -3,8 +3,8 @@ rubygems_version: 0.8.4
|
|
|
3
3
|
specification_version: 1
|
|
4
4
|
name: postgres-pr
|
|
5
5
|
version: !ruby/object:Gem::Version
|
|
6
|
-
version: 0.3.
|
|
7
|
-
date: 2005-01-
|
|
6
|
+
version: 0.3.3
|
|
7
|
+
date: 2005-01-06
|
|
8
8
|
summary: A pure Ruby interface to the PostgreSQL database
|
|
9
9
|
require_paths:
|
|
10
10
|
- lib
|
|
@@ -37,6 +37,7 @@ files:
|
|
|
37
37
|
- lib/postgres-pr/connection.rb
|
|
38
38
|
- lib/postgres-pr/message.rb
|
|
39
39
|
- lib/postgres-pr/postgres-compat.rb
|
|
40
|
+
- lib/postgres-pr/version.rb
|
|
40
41
|
- lib/postgres-pr/typeconv/array.rb
|
|
41
42
|
- lib/postgres-pr/typeconv/bytea.rb
|
|
42
43
|
- lib/postgres-pr/typeconv/conv.rb
|