From 6f711551d4f03db37b14687c7f5d331631efd2fc Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 4 Jan 2005 10:55:34 +0000 Subject: Fixed some thread safety issues with DB2 git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@331 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../connection_adapters/db2_adapter.rb | 43 ++++++++++++---------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'activerecord/lib/active_record/connection_adapters') diff --git a/activerecord/lib/active_record/connection_adapters/db2_adapter.rb b/activerecord/lib/active_record/connection_adapters/db2_adapter.rb index 6014fff8b8..18c27144e6 100644 --- a/activerecord/lib/active_record/connection_adapters/db2_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/db2_adapter.rb @@ -45,12 +45,14 @@ begin 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 @@ begin 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 @@ begin 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 \ No newline at end of file -- cgit v1.2.3