diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2005-07-03 08:32:27 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2005-07-03 08:32:27 +0000 |
commit | 45c4b07f5a4e1d7c058d19345c0d0f808ce1abe7 (patch) | |
tree | a4ca0255b524a525683f34ecbbe5cb397706c54d /activerecord/lib/active_record/connection_adapters | |
parent | f51f12d81926ffe3845b6df9a51107edf4c997fe (diff) | |
download | rails-45c4b07f5a4e1d7c058d19345c0d0f808ce1abe7.tar.gz rails-45c4b07f5a4e1d7c058d19345c0d0f808ce1abe7.tar.bz2 rails-45c4b07f5a4e1d7c058d19345c0d0f808ce1abe7.zip |
r1611@asus: jeremy | 2005-07-03 04:21:52 -0700
No longer pass superfluous connection to AbstractAdapter#log.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1629 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
5 files changed, 41 insertions, 46 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 2bb68d1810..459b05413c 100755 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -392,17 +392,18 @@ module ActiveRecord protected - def log(sql, name, connection = nil) - connection ||= @connection + def log(sql, name) begin - if !@logger || @logger.level > Logger::INFO - yield connection - elsif block_given? - result = nil - bm = measure { result = yield connection } - @runtime += bm.real - log_info(sql, name, bm.real) - result + if block_given? + if @logger and @logger.level <= Logger::INFO + result = nil + bm = measure { result = yield } + @runtime += bm.real + log_info(sql, name, bm.real) + result + else + yield + end else log_info(sql, name, 0) nil diff --git a/activerecord/lib/active_record/connection_adapters/db2_adapter.rb b/activerecord/lib/active_record/connection_adapters/db2_adapter.rb index b7a164eddc..232764e37c 100644 --- a/activerecord/lib/active_record/connection_adapters/db2_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/db2_adapter.rb @@ -52,8 +52,8 @@ begin def execute(sql, name = nil) rows_affected = 0 - log(sql, name, @connection) do |connection| - stmt = DB2::Statement.new(connection) + log(sql, name) do + stmt = DB2::Statement.new(@connection) stmt.exec_direct(sql) rows_affected = stmt.row_count stmt.free @@ -126,9 +126,9 @@ begin def select(sql, name = nil) stmt = nil - log(sql, name, @connection) do |connection| - stmt = DB2::Statement.new(connection) - stmt.exec_direct(sql + " with ur") + log(sql, name) do + stmt = DB2::Statement.new(@connection) + stmt.exec_direct("#{sql} with ur") end rows = [] diff --git a/activerecord/lib/active_record/connection_adapters/oci_adapter.rb b/activerecord/lib/active_record/connection_adapters/oci_adapter.rb index ec3bac67d3..3988d1aa96 100644 --- a/activerecord/lib/active_record/connection_adapters/oci_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/oci_adapter.rb @@ -125,7 +125,7 @@ begin elsif offset > 0 sql = "select * from (select raw_sql_.*, rownum raw_rnum_ from (#{sql}) raw_sql_) where raw_rnum_ > #{offset}" end - cursor = log(sql, name, @connection) { @connection.exec sql } + cursor = log(sql, name) { @connection.exec sql } cols = cursor.get_col_names.map { |x| x.downcase } rows = [] while row = cursor.fetch @@ -167,16 +167,16 @@ begin if pk.nil? # Who called us? What does the sql look like? No idea! execute sql, name elsif id_value # Pre-assigned id - log(sql, name, @connection) { @connection.exec sql } + log(sql, name) { @connection.exec sql } else # Assume the sql contains a bind-variable for the id id_value = select_one("select rails_sequence.nextval id from dual")['id'] - log(sql, name, @connection) { @connection.exec sql, id_value } + log(sql, name) { @connection.exec sql, id_value } end id_value end def execute(sql, name = nil) - log(sql, name, @connection) { @connection.exec sql } + log(sql, name) { @connection.exec sql } end alias :update :execute diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index a76308b63e..fbf4aa398f 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -104,6 +104,7 @@ module ActiveRecord end def execute(sql, name = nil) + #log(sql, name, @connection) { |connection| connection.execute(sql) } log(sql, name) { @connection.execute(sql) } end @@ -127,7 +128,9 @@ module ActiveRecord execute(sql, name).map do |row| record = {} row.each_key do |key| - record[key.sub(/\w+\./, '')] = row[key] unless key.is_a?(Fixnum) + if key.is_a?(String) + record[key.sub(/^\w+\./, '')] = row[key] + end end record end diff --git a/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb index f685a0a787..36177bc895 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb @@ -196,11 +196,10 @@ module ActiveRecord def columns(table_name, name = nil) sql = "SELECT COLUMN_NAME as ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType, COL_LENGTH('#{table_name}', COLUMN_NAME) as Length, COLUMNPROPERTY(OBJECT_ID('#{table_name}'), COLUMN_NAME, 'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME = '#{table_name}'" - result = nil # Comment out if you want to have the Columns select statment logged. # Personnally, I think it adds unneccessary bloat to the log. # If you do comment it out, make sure to un-comment the "result" line that follows - log(sql, name, @connection) { |conn| result = conn.select_all(sql) } + result = log(sql, name) { @connection.select_all(sql) } #result = @connection.select_all(sql) columns = [] result.each { |field| columns << ColumnWithIdentity.new(field[:ColName], field[:DefaultValue].to_s.gsub!(/[()\']/,"") =~ /null/ ? nil : field[:DefaultValue], "#{field[:ColType]}(#{field[:Length]})", field[:IsIdentity] == 1 ? true : false, field[:Scale]) } @@ -223,8 +222,8 @@ module ActiveRecord end end end - log(sql, name, @connection) do |conn| - conn.execute(sql) + log(sql, name) do + @connection.execute(sql) select_one("SELECT @@IDENTITY AS Ident")["Ident"] end ensure @@ -242,14 +241,12 @@ module ActiveRecord if sql =~ /^INSERT/i insert(sql, name) elsif sql =~ /^UPDATE|DELETE/i - log(sql, name, @connection) do |conn| - conn.execute(sql) + log(sql, name) do + @connection.execute(sql) retVal = select_one("SELECT @@ROWCOUNT AS AffectedRows")["AffectedRows"] end else - log(sql, name, @connection) do |conn| - conn.execute(sql) - end + log(sql, name) { @connection.execute(sql) } end end @@ -259,27 +256,21 @@ module ActiveRecord alias_method :delete, :update def begin_db_transaction - begin - @connection["AutoCommit"] = false - rescue Exception => e - @connection["AutoCommit"] = true - end + @connection["AutoCommit"] = false + rescue Exception => e + @connection["AutoCommit"] = true end def commit_db_transaction - begin - @connection.commit - ensure - @connection["AutoCommit"] = true - end + @connection.commit + ensure + @connection["AutoCommit"] = true end def rollback_db_transaction - begin - @connection.rollback - ensure - @connection["AutoCommit"] = true - end + @connection.rollback + ensure + @connection["AutoCommit"] = true end def quote(value, column = nil) @@ -334,8 +325,8 @@ module ActiveRecord def select(sql, name = nil) rows = [] repair_special_columns(sql) - log(sql, name, @connection) do |conn| - conn.select_all(sql) do |row| + log(sql, name) do + @connection.select_all(sql) do |row| record = {} row.column_names.each do |col| record[col] = row[col] |