aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb31
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb6
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql_adapter.rb15
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb27
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb5
5 files changed, 14 insertions, 70 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
index 08601da00a..26bf04f449 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
@@ -53,7 +53,7 @@ module ActiveRecord
def delete(sql, name = nil)
delete_sql(sql, name)
end
-
+
# Checks whether there is currently no transaction active. This is done
# by querying the database driver, and does not use the transaction
# house-keeping information recorded by #increment_open_transactions and
@@ -170,7 +170,7 @@ module ActiveRecord
end
end
end
-
+
# Begins the transaction (and turns off auto-committing).
def begin_db_transaction() end
@@ -181,33 +181,6 @@ module ActiveRecord
# done if the transaction block raises an exception or returns false.
def rollback_db_transaction() end
- # Alias for <tt>add_limit_offset!</tt>.
- def add_limit!(sql, options)
- add_limit_offset!(sql, options) if options
- end
-
- # Appends +LIMIT+ and +OFFSET+ options to an SQL statement, or some SQL
- # fragment that has the same semantics as LIMIT and OFFSET.
- #
- # +options+ must be a Hash which contains a +:limit+ option (required)
- # and an +:offset+ option (optional).
- #
- # This method *modifies* the +sql+ parameter.
- #
- # ===== Examples
- # add_limit_offset!('SELECT * FROM suppliers', {:limit => 10, :offset => 50})
- # generates
- # SELECT * FROM suppliers LIMIT 10 OFFSET 50
- def add_limit_offset!(sql, options)
- if limit = options[:limit]
- sql << " LIMIT #{sanitize_limit(limit)}"
- if offset = options[:offset]
- sql << " OFFSET #{offset.to_i}"
- end
- end
- sql
- end
-
# Appends a locking clause to an SQL statement.
# This method *modifies* the +sql+ parameter.
# # SELECT * FROM suppliers FOR UPDATE
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
index f44cd0bd5a..8e33681772 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -403,12 +403,6 @@ module ActiveRecord
"DISTINCT #{columns}"
end
- # ORDER BY clause for the passed order option.
- # PostgreSQL overrides this due to its stricter standards compliance.
- def add_order_by_for_association_limiting!(sql, options)
- sql << " ORDER BY #{options[:order]}"
- end
-
# Adds timestamps (created_at and updated_at) columns to the named table.
# ===== Examples
# add_timestamps(:suppliers)
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index 83cb9cff15..9173c8bca3 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -212,7 +212,7 @@ module ActiveRecord
def supports_migrations? #:nodoc:
true
end
-
+
def supports_savepoints? #:nodoc:
true
end
@@ -331,6 +331,7 @@ module ActiveRecord
super sql, name
id_value || @connection.insert_id
end
+ alias :create :insert_sql
def update_sql(sql, name = nil) #:nodoc:
super
@@ -367,18 +368,6 @@ module ActiveRecord
execute("RELEASE SAVEPOINT #{current_savepoint_name}")
end
- def add_limit_offset!(sql, options) #:nodoc:
- if limit = options[:limit]
- limit = sanitize_limit(limit)
- unless offset = options[:offset]
- sql << " LIMIT #{limit}"
- else
- sql << " LIMIT #{offset.to_i}, #{limit}"
- end
- end
- end
-
-
# SCHEMA STATEMENTS ========================================
def structure_dump #:nodoc:
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index e77ae93c21..fc8ca357e5 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -68,7 +68,7 @@ module ActiveRecord
# depending on the server specifics
super
end
-
+
# Maps PostgreSQL-specific data types to logical Rails types.
def simplified_type(field_type)
case field_type
@@ -103,7 +103,7 @@ module ActiveRecord
:string
# Arrays
when /^\D+\[\]$/
- :string
+ :string
# Object identifier types
when /^oid$/
:integer
@@ -112,7 +112,7 @@ module ActiveRecord
super
end
end
-
+
# Extracts the value from a PostgreSQL column default definition.
def self.extract_value_from_default(default)
case default
@@ -273,7 +273,7 @@ module ActiveRecord
def supports_ddl_transactions?
true
end
-
+
def supports_savepoints?
true
end
@@ -498,6 +498,7 @@ module ActiveRecord
end
end
end
+ alias :create :insert
# create a 2D array representing the result set
def result_as_array(res) #:nodoc:
@@ -564,7 +565,7 @@ module ActiveRecord
def rollback_db_transaction
execute "ROLLBACK"
end
-
+
if defined?(PGconn::PQTRANS_IDLE)
# The ruby-pg driver supports inspecting the transaction status,
# while the ruby-postgres driver does not.
@@ -909,20 +910,6 @@ module ActiveRecord
sql = "DISTINCT ON (#{columns}) #{columns}, "
sql << order_columns * ', '
end
-
- # Returns an ORDER BY clause for the passed order option.
- #
- # PostgreSQL does not allow arbitrary ordering when using DISTINCT ON, so we work around this
- # by wrapping the +sql+ string as a sub-select and ordering in that query.
- def add_order_by_for_association_limiting!(sql, options) #:nodoc:
- return sql if options[:order].blank?
-
- order = options[:order].split(',').collect { |s| s.strip }.reject(&:blank?)
- order.map! { |s| 'DESC' if s =~ /\bdesc$/i }
- order = order.zip((0...order.size).to_a).map { |s,i| "id_list.alias_#{i} #{s}" }.join(', ')
-
- sql.replace "SELECT * FROM (#{sql}) AS id_list ORDER BY #{order}"
- end
protected
# Returns the version of the connected PostgreSQL version.
@@ -1044,7 +1031,7 @@ module ActiveRecord
if res.ftype(cell_index) == MONEY_COLUMN_TYPE_OID
# Because money output is formatted according to the locale, there are two
# cases to consider (note the decimal separators):
- # (1) $12,345,678.12
+ # (1) $12,345,678.12
# (2) $12.345.678,12
case column = row[cell_index]
when /^-?\D+[\d,]+\.\d{2}$/ # (1)
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
index 5e5e30776a..8cbe08cd77 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -109,7 +109,7 @@ module ActiveRecord
def supports_add_column?
sqlite_version >= '3.1.6'
end
-
+
def disconnect!
super
@connection.close rescue nil
@@ -181,6 +181,7 @@ module ActiveRecord
def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) #:nodoc:
super || @connection.last_insert_row_id
end
+ alias :create :insert_sql
def select_rows(sql, name = nil)
execute(sql, name).map do |row|
@@ -355,7 +356,7 @@ module ActiveRecord
(options[:rename][column.name] ||
options[:rename][column.name.to_sym] ||
column.name) : column.name
-
+
@definition.column(column_name, column.type,
:limit => column.limit, :default => column.default,
:null => column.null)