Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit 45c4b07f5a4e1d7c058d19345c0d0f808ce1abe7 1 parent f51f12d
@jeremy jeremy authored
View
21 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -392,17 +392,18 @@ def remove_column(table_name, column_name)
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
View
10 activerecord/lib/active_record/connection_adapters/db2_adapter.rb
@@ -52,8 +52,8 @@ 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)
+ log(sql, name) do
+ stmt = DB2::Statement.new(@connection)
stmt.exec_direct(sql)
rows_affected = stmt.row_count
stmt.free
@@ -126,9 +126,9 @@ def last_insert_id
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 = []
View
8 activerecord/lib/active_record/connection_adapters/oci_adapter.rb
@@ -125,7 +125,7 @@ def select_all(sql, name = nil)
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 @@ def insert(sql, name = nil, pk = nil, id_value = nil)
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
View
5 activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -104,6 +104,7 @@ def native_database_types
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 @@ def select_all(sql, name = nil)
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
View
43 activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb
@@ -196,11 +196,10 @@ def select_one(sql, name = nil)
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 @@ def insert(sql, name = nil, pk = nil, id_value = nil)
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 @@ def execute(sql, name = nil)
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 @@ def update(sql, name = nil)
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 @@ def create_database(name)
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]
Please sign in to comment.
Something went wrong with that request. Please try again.