Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed some thread safety issues with DB2

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@331 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 6f711551d4f03db37b14687c7f5d331631efd2fc 1 parent 3e74ea8
@dhh dhh authored
Showing with 23 additions and 20 deletions.
  1. +23 −20 activerecord/lib/active_record/connection_adapters/db2_adapter.rb
View
43 activerecord/lib/active_record/connection_adapters/db2_adapter.rb
@@ -45,12 +45,14 @@ def insert(sql, name = nil, pk = nil, id_value = nil)
def execute(sql, name = nil)
rows_affected = 0
+
log(sql, name, @connection) do |connection|
stmt = DB2::Statement.new(connection)
stmt.exec_direct(sql)
rows_affected = stmt.row_count
stmt.free
end
+
rows_affected
end
@@ -84,6 +86,7 @@ def add_limit!(sql, limit)
def columns(table_name, name = nil)
stmt = DB2::Statement.new(@connection)
result = []
+
stmt.columns(table_name.upcase).each do |c|
c_name = c[3].downcase
c_default = c[12] == 'NULL' ? nil : c[12]
@@ -91,36 +94,36 @@ def columns(table_name, name = nil)
c_type += "(#{c[6]})" if !c[6].nil? && c[6] != ''
result << Column.new(c_name, c_default, c_type)
end
+
stmt.free
result
end
private
-
- def last_insert_id
- row = select_one(<<-GETID.strip)
- with temp(id) as (values (identity_val_local())) select * from temp
- GETID
- row['id'].to_i
- end
-
- def select(sql, name = nil)
- stmt = nil
- log(sql, name, @connection) do |connection|
- stmt = DB2::Statement.new(connection)
- stmt.exec_direct(sql)
+ def last_insert_id
+ row = select_one(<<-GETID.strip)
+ with temp(id) as (values (identity_val_local())) select * from temp
+ GETID
+ row['id'].to_i
end
- rows = []
- while row = stmt.fetch_as_hash
- rows << row
+ def select(sql, name = nil)
+ stmt = nil
+ log(sql, name, @connection) do |connection|
+ stmt = DB2::Statement.new(connection)
+ stmt.exec_direct(sql + " with ur")
+ end
+
+ rows = []
+ while row = stmt.fetch_as_hash
+ rows << row
+ end
+ stmt.free
+ rows
end
- stmt.free
- rows
- end
end
end
end
rescue LoadError
# DB2 driver is unavailable.
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.