Skip to content

Commit 7692a76

Browse files
committed
* Implemented PGresult#cmdtuples method (compatibilty)
* new version
1 parent a566e31 commit 7692a76

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

lib/postgres-pr/connection.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def initialize(database, user, password=nil, uri = nil)
7474
end
7575

7676
class Result
77-
attr_accessor :rows, :fields
77+
attr_accessor :rows, :fields, :cmd_tag
7878
def initialize(rows=[], fields=[])
7979
@rows, @fields = rows, fields
8080
end
@@ -93,6 +93,7 @@ def query(sql)
9393
when DataRow
9494
result.rows << msg.columns
9595
when CommandComplete
96+
result.cmd_tag = msg.cmd_tag
9697
when ReadyForQuery
9798
break
9899
when RowDescription

lib/postgres-pr/postgres-compat.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,17 @@ def getvalue(tup_num, field_num)
9494
def clear
9595
@res = @fields = @result = nil
9696
end
97+
98+
# Returns the number of rows affected by the SQL command
99+
def cmdtuples
100+
case @res.cmd_tag
101+
when nil
102+
return nil
103+
when /^INSERT\s+(\d+)\s+(\d+)$/, /^(DELETE|UPDATE|MOVE|FETCH)\s+(\d+)$/
104+
$2.to_i
105+
else
106+
nil
107+
end
108+
end
109+
97110
end

postgres-pr.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ require 'rubygems'
22

33
spec = Gem::Specification.new do |s|
44
s.name = 'postgres-pr'
5-
s.version = '0.3.1'
5+
s.version = '0.3.2'
66
s.summary = 'A pure Ruby interface to the PostgreSQL database'
77

88
s.files = (Dir['lib/**/*'] + Dir['test/**/*'] +

0 commit comments

Comments
 (0)