postgres-pr 0.6.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/pg.rb +4 -0
- data/lib/postgres-pr/connection.rb +4 -1
- data/lib/postgres-pr/pg-compat.rb +174 -0
- data/lib/postgres-pr/postgres-compat.rb +17 -0
- data/lib/postgres-pr/version.rb +1 -1
- metadata +30 -40
- data/lib/postgres-pr/1q +0 -3
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dd57874846033434677cb95761d2b395d52c8f22
|
4
|
+
data.tar.gz: a6f12b3e76ae876fb340ce5bf3a11cfdac6a47af
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4ab7fd91747aadedc93b34f7b38633c0ed8f5cbd25198a2ee5c3f919cad132fe0962fb9ce8f2ff98a292d3f500aa1544d27a03108b49a9aabb4ea966a52742ee
|
7
|
+
data.tar.gz: a44a7d6859ce52815f20c8b4c99135de74d8d27c64aed9e07cb5b0def14c91acb197c64361e5de467394f0b5368d20dc3fe1f93d53a7306c0eaaf464fcc753c6
|
data/lib/pg.rb
ADDED
@@ -9,6 +9,9 @@ require 'postgres-pr/version'
|
|
9
9
|
require 'uri'
|
10
10
|
require 'socket'
|
11
11
|
|
12
|
+
class Error < ::StandardError; end
|
13
|
+
class DatabaseError < Error; end
|
14
|
+
|
12
15
|
module PostgresPR
|
13
16
|
|
14
17
|
PROTO_VERSION = 3 << 16 #196608
|
@@ -139,7 +142,7 @@ class Connection
|
|
139
142
|
end
|
140
143
|
end
|
141
144
|
|
142
|
-
raise errors.map{|e| e.field_values.join("\t") }.join("\n") unless errors.empty?
|
145
|
+
raise DatabaseError.new(errors.map{|e| e.field_values.join("\t") }.join("\n")) unless errors.empty?
|
143
146
|
|
144
147
|
result
|
145
148
|
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
# This is a compatibility layer for using the pure Ruby postgres-pr instead of
|
2
|
+
# the C interface of postgres.
|
3
|
+
|
4
|
+
require 'rexml/syncenumerator'
|
5
|
+
require 'postgres-pr/connection'
|
6
|
+
|
7
|
+
class PGconn
|
8
|
+
PQTRANS_IDLE = 0 #(connection idle)
|
9
|
+
PQTRANS_INTRANS = 2 #(idle, within transaction block)
|
10
|
+
PQTRANS_INERROR = 3 #(idle, within failed transaction)
|
11
|
+
PQTRANS_UNKNOWN = 4 #(cannot determine status)
|
12
|
+
|
13
|
+
class << self
|
14
|
+
alias connect new
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(host, port, options, tty, database, user, auth)
|
18
|
+
uri =
|
19
|
+
if host.nil?
|
20
|
+
nil
|
21
|
+
elsif host[0] != ?/
|
22
|
+
"tcp://#{ host }:#{ port }"
|
23
|
+
else
|
24
|
+
"unix:#{ host }/.s.PGSQL.#{ port }"
|
25
|
+
end
|
26
|
+
@host = host
|
27
|
+
@db = database
|
28
|
+
@user = user
|
29
|
+
@conn = PostgresPR::Connection.new(database, user, auth, uri)
|
30
|
+
end
|
31
|
+
|
32
|
+
def close
|
33
|
+
@conn.close
|
34
|
+
end
|
35
|
+
|
36
|
+
attr_reader :host, :db, :user
|
37
|
+
|
38
|
+
def query(sql)
|
39
|
+
PGresult.new(@conn.query(sql))
|
40
|
+
end
|
41
|
+
|
42
|
+
alias exec query
|
43
|
+
|
44
|
+
def transaction_status
|
45
|
+
@conn.transaction_status
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.escape(str)
|
49
|
+
str.gsub("'","''").gsub("\\", "\\\\\\\\")
|
50
|
+
end
|
51
|
+
|
52
|
+
def escape(str)
|
53
|
+
self.class.escape(str)
|
54
|
+
end
|
55
|
+
|
56
|
+
def notice_processor
|
57
|
+
@conn.notice_processor
|
58
|
+
end
|
59
|
+
|
60
|
+
def notice_processor=(np)
|
61
|
+
@conn.notice_processor = np
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.quote_ident(name)
|
65
|
+
%("#{name}")
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
class PGresult
|
71
|
+
include Enumerable
|
72
|
+
|
73
|
+
EMPTY_QUERY = 0
|
74
|
+
COMMAND_OK = 1
|
75
|
+
TUPLES_OK = 2
|
76
|
+
COPY_OUT = 3
|
77
|
+
COPY_IN = 4
|
78
|
+
BAD_RESPONSE = 5
|
79
|
+
NONFATAL_ERROR = 6
|
80
|
+
FATAL_ERROR = 7
|
81
|
+
|
82
|
+
def each(&block)
|
83
|
+
@result.each(&block)
|
84
|
+
end
|
85
|
+
|
86
|
+
def [](index)
|
87
|
+
@result[index]
|
88
|
+
end
|
89
|
+
|
90
|
+
def initialize(res)
|
91
|
+
@res = res
|
92
|
+
@fields = @res.fields.map {|f| f.name}
|
93
|
+
@result = []
|
94
|
+
@res.rows.each do |row|
|
95
|
+
@result << REXML::SyncEnumerator.new(fields, row).map {|name, value| [name, value]}
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# TODO: status, getlength, cmdstatus
|
100
|
+
|
101
|
+
attr_reader :result, :fields
|
102
|
+
|
103
|
+
def num_tuples
|
104
|
+
@result.size
|
105
|
+
end
|
106
|
+
|
107
|
+
alias :ntuples :num_tuples
|
108
|
+
|
109
|
+
def num_fields
|
110
|
+
@fields.size
|
111
|
+
end
|
112
|
+
|
113
|
+
alias :nfields :num_fields
|
114
|
+
|
115
|
+
def fieldname(index)
|
116
|
+
@fields[index]
|
117
|
+
end
|
118
|
+
|
119
|
+
def fieldnum(name)
|
120
|
+
@fields.index(name)
|
121
|
+
end
|
122
|
+
|
123
|
+
def type(index)
|
124
|
+
# TODO: correct?
|
125
|
+
@res.fields[index].type_oid
|
126
|
+
end
|
127
|
+
|
128
|
+
alias :ftype :type
|
129
|
+
|
130
|
+
def size(index)
|
131
|
+
raise
|
132
|
+
# TODO: correct?
|
133
|
+
@res.fields[index].typlen
|
134
|
+
end
|
135
|
+
|
136
|
+
def getvalue(tup_num, field_num)
|
137
|
+
@result[tup_num][field_num]
|
138
|
+
end
|
139
|
+
|
140
|
+
def status
|
141
|
+
if num_tuples > 0
|
142
|
+
TUPLES_OK
|
143
|
+
else
|
144
|
+
COMMAND_OK
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def cmdstatus
|
149
|
+
@res.cmd_tag || ''
|
150
|
+
end
|
151
|
+
|
152
|
+
# free the result set
|
153
|
+
def clear
|
154
|
+
@res = @fields = @result = nil
|
155
|
+
end
|
156
|
+
|
157
|
+
# Returns the number of rows affected by the SQL command
|
158
|
+
def cmdtuples
|
159
|
+
case @res.cmd_tag
|
160
|
+
when nil
|
161
|
+
return nil
|
162
|
+
when /^INSERT\s+(\d+)\s+(\d+)$/, /^(DELETE|UPDATE|MOVE|FETCH)\s+(\d+)$/
|
163
|
+
$2.to_i
|
164
|
+
else
|
165
|
+
nil
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
alias :cmd_tuples :cmdtuples
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
class PGError < Exception
|
174
|
+
end
|
@@ -4,6 +4,11 @@
|
|
4
4
|
require 'postgres-pr/connection'
|
5
5
|
|
6
6
|
class PGconn
|
7
|
+
PQTRANS_IDLE = 0 #(connection idle)
|
8
|
+
PQTRANS_INTRANS = 2 #(idle, within transaction block)
|
9
|
+
PQTRANS_INERROR = 3 #(idle, within failed transaction)
|
10
|
+
PQTRANS_UNKNOWN = 4 #(cannot determine status)
|
11
|
+
|
7
12
|
class << self
|
8
13
|
alias connect new
|
9
14
|
end
|
@@ -43,6 +48,10 @@ class PGconn
|
|
43
48
|
str.gsub("'","''").gsub("\\", "\\\\\\\\")
|
44
49
|
end
|
45
50
|
|
51
|
+
def escape(str)
|
52
|
+
self.class.escape(str)
|
53
|
+
end
|
54
|
+
|
46
55
|
def notice_processor
|
47
56
|
@conn.notice_processor
|
48
57
|
end
|
@@ -91,10 +100,14 @@ class PGresult
|
|
91
100
|
@result.size
|
92
101
|
end
|
93
102
|
|
103
|
+
alias :ntuples :num_tuples
|
104
|
+
|
94
105
|
def num_fields
|
95
106
|
@fields.size
|
96
107
|
end
|
97
108
|
|
109
|
+
alias :nfields :num_fields
|
110
|
+
|
98
111
|
def fieldname(index)
|
99
112
|
@fields[index]
|
100
113
|
end
|
@@ -107,6 +120,8 @@ class PGresult
|
|
107
120
|
# TODO: correct?
|
108
121
|
@res.fields[index].type_oid
|
109
122
|
end
|
123
|
+
|
124
|
+
alias :ftype :type
|
110
125
|
|
111
126
|
def size(index)
|
112
127
|
raise
|
@@ -146,6 +161,8 @@ class PGresult
|
|
146
161
|
nil
|
147
162
|
end
|
148
163
|
end
|
164
|
+
|
165
|
+
alias :cmd_tuples :cmdtuples
|
149
166
|
|
150
167
|
end
|
151
168
|
|
data/lib/postgres-pr/version.rb
CHANGED
metadata
CHANGED
@@ -1,73 +1,63 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: postgres-pr
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Michael Neumann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
date: 2009-12-15 00:00:00 +01:00
|
13
|
-
default_executable:
|
11
|
+
date: 2015-01-22 00:00:00.000000000 Z
|
14
12
|
dependencies: []
|
15
|
-
|
16
13
|
description:
|
17
14
|
email: mneumann@ntecs.de
|
18
15
|
executables: []
|
19
|
-
|
20
16
|
extensions: []
|
21
|
-
|
22
17
|
extra_rdoc_files: []
|
23
|
-
|
24
|
-
|
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
25
|
- lib/buffer.rb
|
26
26
|
- lib/byteorder.rb
|
27
|
+
- lib/pg.rb
|
27
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
|
28
32
|
- lib/postgres-pr/typeconv/TC_conv.rb
|
33
|
+
- lib/postgres-pr/typeconv/array.rb
|
29
34
|
- lib/postgres-pr/typeconv/bytea.rb
|
30
35
|
- lib/postgres-pr/typeconv/conv.rb
|
31
|
-
- lib/postgres-pr/typeconv/array.rb
|
32
|
-
- lib/postgres-pr/1q
|
33
|
-
- lib/postgres-pr/postgres-compat.rb
|
34
|
-
- lib/postgres-pr/message.rb
|
35
36
|
- lib/postgres-pr/version.rb
|
36
|
-
- lib/binary_reader.rb
|
37
|
-
- lib/binary_writer.rb
|
38
37
|
- lib/postgres.rb
|
39
38
|
- test/TC_message.rb
|
40
|
-
- examples/client.rb
|
41
|
-
- examples/og/test.rb
|
42
|
-
- examples/server.rb
|
43
|
-
- examples/test_connection.rb
|
44
|
-
has_rdoc: true
|
45
39
|
homepage: http://postgres-pr.rubyforge.org
|
46
40
|
licenses: []
|
47
|
-
|
41
|
+
metadata: {}
|
48
42
|
post_install_message:
|
49
43
|
rdoc_options: []
|
50
|
-
|
51
|
-
require_paths:
|
44
|
+
require_paths:
|
52
45
|
- lib
|
53
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
-
requirements:
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
55
48
|
- - ">="
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version:
|
58
|
-
|
59
|
-
|
60
|
-
requirements:
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
61
53
|
- - ">="
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version:
|
64
|
-
|
65
|
-
requirements:
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements:
|
66
57
|
- PostgreSQL >= 7.4
|
67
58
|
rubyforge_project: postgres-pr
|
68
|
-
rubygems_version:
|
59
|
+
rubygems_version: 2.2.2
|
69
60
|
signing_key:
|
70
|
-
specification_version:
|
61
|
+
specification_version: 4
|
71
62
|
summary: A pure Ruby interface to the PostgreSQL (>= 7.4) database
|
72
63
|
test_files: []
|
73
|
-
|
data/lib/postgres-pr/1q
DELETED