diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-03-22 09:34:33 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-03-22 09:34:33 -0700 |
commit | 2ef6270f8fbbefba8d4f10504497e198d8e7deea (patch) | |
tree | a90b640a9e59306e92fc4bcc2ab58d08b0341e23 /activerecord/lib/active_record/connection_adapters | |
parent | 6ab65bec611247bbd1dd62da0ee8c4dc44b37ec1 (diff) | |
parent | 2ddfdba9a0dab7d8499c3ad0d13583bddbac4f69 (diff) | |
download | rails-2ef6270f8fbbefba8d4f10504497e198d8e7deea.tar.gz rails-2ef6270f8fbbefba8d4f10504497e198d8e7deea.tar.bz2 rails-2ef6270f8fbbefba8d4f10504497e198d8e7deea.zip |
Merge branch 'master' into fuuu
* master:
Do not show optional (.:format) block for wildcard route [#6605 state:resolved]
pushing id insertion and prefetch primary keys down to Relation#insert
use prepared statements to fetch the last insert id
escaping binary data encoding when inserting to sqlite3. Thanks Naruse! [#6559 state:resolved]
schemas set by set_table_name are respected by the mysql adapter. [#5322 state:resolved]
Reapply extensions when using except and only
SJIS is an alias to Windows-31J in ruby trunk. Use SHIFT_JIS for this test
Improved resolver docs a bit
[action_view] docs for FileSystemResolver
[action_view] added custom patterns to template resolver
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
5 files changed, 36 insertions, 5 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 5c1ce173c8..756c221fad 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb @@ -272,6 +272,10 @@ module ActiveRecord execute "INSERT INTO #{quote_table_name(table_name)} (#{key_list.join(', ')}) VALUES (#{value_list.join(', ')})", 'Fixture Insert' end + def null_insert_value + Arel.sql 'DEFAULT' + end + def empty_insert_statement_value "VALUES(DEFAULT)" end diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index 368c5b2023..e1186209d3 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -504,14 +504,28 @@ module ActiveRecord show_variable 'collation_database' end - def tables(name = nil) #:nodoc: + def tables(name = nil, database = nil) #:nodoc: tables = [] - result = execute("SHOW TABLES", name) + result = execute(["SHOW TABLES", database].compact.join(' IN '), name) result.each { |field| tables << field[0] } result.free tables end + def table_exists?(name) + return true if super + + name = name.to_s + schema, table = name.split('.', 2) + + unless table # A table was provided without a schema + table = schema + schema = nil + end + + tables(nil, schema).include? table + end + def drop_table(table_name, options = {}) super(table_name, options) end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 576450bc3a..5a830a50fb 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -453,7 +453,7 @@ module ActiveRecord # If a pk is given, fallback to default sequence name. # Don't fetch last insert id for a table without a pk. if pk && sequence_name ||= default_sequence_name(table, pk) - last_insert_id(table, sequence_name) + last_insert_id(sequence_name) end end end @@ -1038,8 +1038,9 @@ module ActiveRecord end # Returns the current ID of a table's sequence. - def last_insert_id(table, sequence_name) #:nodoc: - Integer(select_value("SELECT currval('#{sequence_name}')")) + def last_insert_id(sequence_name) #:nodoc: + r = exec_query("SELECT currval($1)", 'SQL', [[nil, sequence_name]]) + Integer(r.rows.first.first) end # Executes a SELECT query and returns the results, performing any data type diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index c2cd9e8d5e..c3a7b039ff 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -34,6 +34,14 @@ module ActiveRecord module ConnectionAdapters #:nodoc: class SQLite3Adapter < SQLiteAdapter # :nodoc: + def quote(value, column = nil) + if value.kind_of?(String) && column && column.type == :binary && column.class.respond_to?(:string_to_binary) + s = column.class.string_to_binary(value).unpack("H*")[0] + "x'#{s}'" + else + super + end + end # Returns the current database encoding format as a string, eg: 'UTF-8' def encoding diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index 9ee6b88ab6..ae61d6ce94 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -336,6 +336,10 @@ module ActiveRecord alter_table(table_name, :rename => {column_name.to_s => new_column_name.to_s}) end + def null_insert_value + Arel.sql 'NULL' + end + def empty_insert_statement_value "VALUES(NULL)" end |