postgres-pr 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,9 @@
1
1
  $LOAD_PATH.unshift '../lib'
2
2
  require 'postgres-pr/connection'
3
3
 
4
- conn = Connection.new('mneumann', 'mneumann')
5
- p conn.query("DROP TABLE test; CREATE TABLE test (a VARCHAR(100))")
4
+ conn = PostgresPR::Connection.new('mneumann', 'mneumann')
5
+ p conn.query("DROP TABLE test") rescue nil
6
+ p conn.query("CREATE TABLE test (a VARCHAR(100))")
6
7
  p conn.query("INSERT INTO test VALUES ('hallo')")
7
8
  p conn.query("INSERT INTO test VALUES ('leute')")
8
9
  conn.query("COMMIT")
@@ -8,6 +8,8 @@ require 'uri'
8
8
  require 'socket'
9
9
  require 'thread'
10
10
 
11
+ module PostgresPR
12
+
11
13
  PROTO_VERSION = 3 << 16 #196608
12
14
 
13
15
  class Connection
@@ -140,3 +142,5 @@ class Connection
140
142
  end
141
143
  end
142
144
  end
145
+
146
+ end # module PostgresPR
@@ -6,6 +6,8 @@
6
6
  require 'buffer'
7
7
  require 'readbytes'
8
8
 
9
+ module PostgresPR
10
+
9
11
  class ParseError < RuntimeError; end
10
12
  class DumpError < RuntimeError; end
11
13
 
@@ -520,3 +522,5 @@ end
520
522
  class Terminate < Message
521
523
  register_message_type ?X
522
524
  end
525
+
526
+ end # module PostgresPR
@@ -0,0 +1,52 @@
1
+ # This is a compatibility layer for using the pure Ruby postgres-pr instead of
2
+ # the C interface of postgres.
3
+
4
+ require 'postgres-pr/connection'
5
+
6
+ class PGconn
7
+ class << self
8
+ alias connect new
9
+ end
10
+
11
+ def initialize(host, port, options, tty, database, user, auth)
12
+ uri =
13
+ if host.nil?
14
+ nil
15
+ elsif host[0] != ?/
16
+ "tcp://#{ host }:#{ port }"
17
+ else
18
+ "unix:#{ host }/.s.PGSQL.#{ port }"
19
+ end
20
+
21
+ @db = database
22
+ @conn = PostgresPR::Connection.new(database, user, auth, uri)
23
+ end
24
+
25
+ attr_reader :db
26
+
27
+ def query(sql)
28
+ PGresult.new(@conn.query(sql))
29
+ end
30
+
31
+ alias exec query
32
+ end
33
+
34
+ class PGresult
35
+ attr_reader :fields, :result
36
+
37
+ def initialize(res)
38
+ @res = res
39
+ @fields = @res.fields.map {|f| f.name}
40
+ @result = @res.rows
41
+ end
42
+
43
+ include Enumerable
44
+
45
+ def each(&block)
46
+ @result.each(&block)
47
+ end
48
+
49
+ def [](index)
50
+ @result[index]
51
+ end
52
+ end
data/lib/postgres.rb CHANGED
@@ -4,52 +4,5 @@
4
4
  begin
5
5
  require 'postgres.so'
6
6
  rescue LoadError
7
- require 'postgres-pr/connection'
8
- class PGconn
9
- class << self
10
- alias connect new
11
- end
12
-
13
- def initialize(host, port, options, tty, database, user, auth)
14
- uri =
15
- if host.nil?
16
- nil
17
- elsif host[0] != ?/
18
- "tcp://#{ host }:#{ port }"
19
- else
20
- "unix:#{ host }/.s.PGSQL.#{ port }"
21
- end
22
-
23
- @db = database
24
- @conn = Connection.new(database, user, auth, uri)
25
- end
26
-
27
- attr_reader :db
28
-
29
- def query(sql)
30
- PGresult.new(@conn.query(sql))
31
- end
32
-
33
- alias exec query
34
- end
35
-
36
- class PGresult
37
- attr_reader :fields, :result
38
-
39
- def initialize(res)
40
- @res = res
41
- @fields = @res.fields.map {|f| f.name}
42
- @result = @res.rows
43
- end
44
-
45
- include Enumerable
46
-
47
- def each(&block)
48
- @result.each(&block)
49
- end
50
-
51
- def [](index)
52
- @result[index]
53
- end
54
- end
7
+ require 'postgres-pr/postgres-compat'
55
8
  end
data/test/TC_message.rb CHANGED
@@ -24,6 +24,8 @@ end
24
24
 
25
25
  $LOAD_PATH.unshift '../lib'
26
26
  require 'postgres-pr/message'
27
+ include PostgresPR
28
+
27
29
  class Buffer
28
30
  alias old_content content
29
31
  def content
metadata CHANGED
@@ -3,8 +3,8 @@ 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.2.1
7
- date: 2004-11-22
6
+ version: 0.2.2
7
+ date: 2004-11-23
8
8
  summary: A pure Ruby interface to the PostgreSQL database
9
9
  require_paths:
10
10
  - lib
@@ -35,13 +35,14 @@ files:
35
35
  - lib/postgres-pr/connection.rb
36
36
  - lib/postgres-pr/typeconv
37
37
  - lib/postgres-pr/message.rb
38
+ - lib/postgres-pr/postgres-compat.rb
38
39
  - lib/postgres-pr/typeconv/array.rb
39
40
  - lib/postgres-pr/typeconv/bytea.rb
40
41
  - lib/postgres-pr/typeconv/conv.rb
41
42
  - lib/postgres-pr/typeconv/TC_conv.rb
42
43
  - test/TC_message.rb
43
- - examples/client.rb
44
44
  - examples/test_connection.rb
45
+ - examples/client.rb
45
46
  - examples/server.rb
46
47
  test_files: []
47
48
  rdoc_options: []