postgres-pr 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/examples/client.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  $LOAD_PATH.unshift "../lib"
2
2
  require 'postgres-pr/message'
3
3
  require 'socket'
4
+ include PostgresPR
4
5
 
5
6
  s = UNIXSocket.new(ARGV.shift || "/tmp/.s.PGSQL.5432")
6
7
 
data/examples/server.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  $LOAD_PATH.unshift "../lib"
2
2
  require 'postgres-pr/message'
3
3
  require 'socket'
4
+ include PostgresPR
4
5
 
5
6
  s = UNIXServer.open(ARGV.shift || raise).accept
6
7
  startup = true
@@ -1,12 +1,13 @@
1
1
  #
2
2
  # Author:: Michael Neumann
3
- # Copyright:: (c) 2004 by Michael Neumann
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
- raise unless @mutex.nil?
23
-
24
- @mutex = Mutex.new
25
-
26
- @mutex.synchronize {
27
- @params = {}
28
- establish_connection(uri)
29
-
30
- @conn << StartupMessage.new(PROTO_VERSION, 'user' => user, 'database' => database).dump
31
-
32
- loop do
33
- msg = Message.read(@conn)
34
-
35
- case msg
36
- when AuthentificationClearTextPassword
37
- raise ArgumentError, "no password specified" if password.nil?
38
- @conn << PasswordMessage.new(password).dump
39
-
40
- when AuthentificationCryptPassword
41
- raise ArgumentError, "no password specified" if password.nil?
42
- @conn << PasswordMessage.new(password.crypt(msg.salt)).dump
43
-
44
- when AuthentificationMD5Password
45
- raise ArgumentError, "no password specified" if password.nil?
46
- require 'digest/md5'
47
-
48
- m = Digest::MD5.hexdigest(password + user)
49
- m = Digest::MD5.hexdigest(m + msg.salt)
50
- m = 'md5' + m
51
- @conn << PasswordMessage.new(m).dump
52
-
53
- when AuthentificationKerberosV4, AuthentificationKerberosV5, AuthentificationSCMCredential
54
- raise "unsupported authentification"
55
-
56
- when AuthentificationOk
57
- when ErrorResponse
58
- raise msg.field_values.join("\t")
59
- when NoticeResponse
60
- # TODO
61
- when ParameterStatus
62
- @params[msg.key] = msg.value
63
- when BackendKeyData
64
- # TODO
65
- #p msg
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
- @mutex.synchronize {
85
- @conn << Query.dump(sql)
86
-
87
- result = Result.new
88
- errors = []
89
-
90
- loop do
91
- msg = Message.read(@conn)
92
- case msg
93
- when DataRow
94
- result.rows << msg.columns
95
- when CommandComplete
96
- result.cmd_tag = msg.cmd_tag
97
- when ReadyForQuery
98
- break
99
- when RowDescription
100
- result.fields = msg.fields
101
- when CopyInResponse
102
- when CopyOutResponse
103
- when EmptyQueryResponse
104
- when ErrorResponse
105
- # TODO
106
- errors << msg
107
- when NoticeResponse
108
- p msg
109
- else
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
- raise errors.map{|e| e.field_values.join("\t") }.join("\n") unless errors.empty?
112
+ raise errors.map{|e| e.field_values.join("\t") }.join("\n") unless errors.empty?
115
113
 
116
- result
117
- }
114
+ result
118
115
  end
119
116
 
120
117
  DEFAULT_PORT = 5432
@@ -1,6 +1,7 @@
1
1
  #
2
2
  # Author:: Michael Neumann
3
- # Copyright:: (c) 2004 by Michael Neumann
3
+ # Copyright:: (c) 2005 by Michael Neumann
4
+ # License:: Same as Ruby's or BSD
4
5
  #
5
6
 
6
7
  require 'buffer'
@@ -22,6 +22,10 @@ class PGconn
22
22
  @conn = PostgresPR::Connection.new(database, user, auth, uri)
23
23
  end
24
24
 
25
+ def close
26
+ @conn.close
27
+ end
28
+
25
29
  attr_reader :db
26
30
 
27
31
  def query(sql)
@@ -0,0 +1,3 @@
1
+ module PostgresPR
2
+ Version = "0.3.3"
3
+ end
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.2
7
- date: 2005-01-04
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