Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleanup SQLite AUTOINCREMENT: exclude sqlite_sequence table, factor o…

…ut feature availability check.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5520 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 50ee332c4aa97aa797e814d3ab6ae63a0f8351e2 1 parent fda4330
Jeremy Kemper jeremy authored
2  activerecord/CHANGELOG
View
@@ -6,7 +6,7 @@
* Don't inspect unloaded associations. #2905 [lmarlow]
-* SQLite: use AUTOINCREMENT primary key in >= 3.1.0. #6588 [careo]
+* SQLite: use AUTOINCREMENT primary key in >= 3.1.0. #6588, #6616 [careo, lukfugl]
* Cache inheritance_column. #6592 [Stefan Kaes]
14 activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
View
@@ -106,6 +106,10 @@ def supports_count_distinct? #:nodoc:
sqlite_version >= '3.2.6'
end
+ def supports_autoincrement? #:nodoc:
+ sqlite_version >= '3.1.0'
+ end
+
def native_database_types #:nodoc:
{
:primary_key => default_primary_key_type,
@@ -197,7 +201,13 @@ def add_lock!(sql, options) #:nodoc:
# SCHEMA STATEMENTS ========================================
def tables(name = nil) #:nodoc:
- execute("SELECT name FROM sqlite_master WHERE type = 'table'", name).map do |row|
+ sql = <<-SQL
+ SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+ SQL
+
+ execute(sql, name).map do |row|
row[0]
end
end
@@ -353,7 +363,7 @@ def sqlite_version
end
def default_primary_key_type
- if sqlite_version >= '3.1.0'
+ if supports_autoincrement?
'INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL'.freeze
else
'INTEGER PRIMARY KEY NOT NULL'.freeze
7 activerecord/test/fixtures/db_definitions/schema.rb
View
@@ -57,4 +57,11 @@ def create_table(*args, &block)
create_table :lock_without_defaults_cust, :force => true do |t|
t.column :custom_lock_version, :integer
end
+
+ # For sqlite 3.1.0+, make a table with a autoincrement column
+ if adapter_name == 'SQLite' and supports_autoincrement?
+ create_table :table_with_autoincrement, :force => true do |t|
+ t.column :name, :string
+ end
+ end
end
6 activerecord/test/schema_dumper_test.rb
View
@@ -8,7 +8,6 @@ class SchemaDumperTest < Test::Unit::TestCase
def standard_dump
stream = StringIO.new
ActiveRecord::SchemaDumper.ignore_tables = []
- ActiveRecord::SchemaDumper.ignore_tables << /^sqlite_/ if current_adapter?(:SQLiteAdapter)
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
stream.string
end
@@ -20,6 +19,11 @@ def test_schema_dump
assert_no_match %r{create_table "schema_info"}, output
end
+ def test_schema_dump_excludes_sqlite_sequence
+ output = standard_dump
+ assert_no_match %r{create_table "sqlite_sequence"}, output
+ end
+
def assert_line_up(lines, pattern, required = false)
return assert(true) if lines.empty?
matches = lines.map { |line| line.match(pattern) }
Please sign in to comment.
Something went wrong with that request. Please try again.