aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-01-04 10:55:34 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-01-04 10:55:34 +0000
commit6f711551d4f03db37b14687c7f5d331631efd2fc (patch)
treef2abbc71288c121fa271210b909c04d421ede2b8
parent3e74ea89bce85a1e004841421ce6b06a2e47a52f (diff)
downloadrails-6f711551d4f03db37b14687c7f5d331631efd2fc.tar.gz
rails-6f711551d4f03db37b14687c7f5d331631efd2fc.tar.bz2
rails-6f711551d4f03db37b14687c7f5d331631efd2fc.zip
Fixed some thread safety issues with DB2
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@331 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activerecord/lib/active_record/connection_adapters/db2_adapter.rb43
1 files changed, 23 insertions, 20 deletions
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