postgres-pr 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,7 +14,9 @@ class Connection
14
14
 
15
15
  # sync
16
16
 
17
- def initialize(database, user, auth=nil, uri = "unix:/tmp/.s.PGSQL.5432")
17
+ def initialize(database, user, auth=nil, uri = nil)
18
+ uri ||= "unix:/tmp/.s.PGSQL.5432"
19
+
18
20
  raise unless @mutex.nil?
19
21
 
20
22
  @mutex = Mutex.new
@@ -74,15 +76,13 @@ class Connection
74
76
  when CopyInResponse
75
77
  when CopyOutResponse
76
78
  when EmptyQueryResponse
77
- p "EMPTY!"
78
79
  when ErrorResponse
79
- p msg
80
- raise
80
+ # TODO
81
+ raise msg.inspect
81
82
  when NoticeResponse
82
83
  p msg
83
- # TODO
84
84
  else
85
- raise
85
+ # TODO
86
86
  end
87
87
  end
88
88
  result
data/lib/postgres.rb CHANGED
@@ -12,7 +12,9 @@ rescue LoadError
12
12
 
13
13
  def initialize(host, port, options, tty, database, user, auth)
14
14
  uri =
15
- if host[0] != ?/
15
+ if host.nil?
16
+ nil
17
+ elsif host[0] != ?/
16
18
  "tcp://#{ host }:#{ port }"
17
19
  else
18
20
  "unix:#{ host }/.s.PGSQL.#{ port }"
@@ -32,22 +34,22 @@ rescue LoadError
32
34
  end
33
35
 
34
36
  class PGresult
37
+ attr_reader :fields, :result
38
+
35
39
  def initialize(res)
36
40
  @res = res
37
- end
38
-
39
- def fields
40
- @res.fields.map {|f| f.name}
41
- end
42
-
43
- def result
44
- @res.rows.map {|row| row.map {|c| c || ""} }
41
+ @fields = @res.fields.map {|f| f.name}
42
+ @result = @res.rows
45
43
  end
46
44
 
47
45
  include Enumerable
48
46
 
49
47
  def each(&block)
50
- result.each(&block)
48
+ @result.each(&block)
49
+ end
50
+
51
+ def [](index)
52
+ @result[index]
51
53
  end
52
54
  end
53
55
  end
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.8.1
3
3
  specification_version: 1
4
4
  name: postgres-pr
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
6
+ version: 0.1.1
7
7
  date: 2004-11-18
8
8
  summary: A pure Ruby interface to the PostgreSQL database
9
9
  require_paths:
@@ -27,10 +27,10 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
27
27
  platform: ruby
28
28
  files:
29
29
  - lib/postgres-pr
30
- - lib/byteorder.rb
31
- - lib/postgres.rb
32
30
  - lib/binary_writer.rb
31
+ - lib/byteorder.rb
33
32
  - lib/binary_reader.rb
33
+ - lib/postgres.rb
34
34
  - lib/buffer.rb
35
35
  - lib/postgres-pr/typeconv
36
36
  - lib/postgres-pr/connection.rb