Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial extraction from ActiveRecord
- Loading branch information
0 parents
commit 2b2859c
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2009 David Heinemeier Hansson | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Rails 3 removes the deprecated SQLite 2 adapter. We strongly recommend that you upgrade to SQLite 3 or higher. However, if that's not possible due to the unexplainable reasons, then this plugin should do the job. | ||
|
||
Install | ||
======= | ||
|
||
* Install the plugin : | ||
|
||
$ script/plugin install git://github.com/rails/sqlite2_adapter.git | ||
|
||
* Load the database adapter from your environment.rb | ||
|
||
Rails::Initializer.run do |config| | ||
..... | ||
|
||
Rails::Initializer.default.add :initialize_sqlite2, :before => :initialize_database do | ||
require 'active_record/connection_adapters/sqlite2_adapter' | ||
end | ||
end | ||
|
||
That's it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'active_record/connection_adapters/sqlite_adapter' | ||
|
||
module ActiveRecord | ||
class Base | ||
def self.sqlite_connection(config) # :nodoc: | ||
parse_sqlite_config!(config) | ||
|
||
unless self.class.const_defined?(:SQLite) | ||
require_library_or_gem(config[:adapter]) | ||
|
||
db = SQLite::Database.new(config[:database], 0) | ||
db.show_datatypes = "ON" if !defined? SQLite::Version | ||
db.results_as_hash = true if defined? SQLite::Version | ||
db.type_translation = false | ||
|
||
# "Downgrade" deprecated sqlite API | ||
if SQLite.const_defined?(:Version) | ||
ConnectionAdapters::SQLite2Adapter.new(db, logger, config) | ||
else | ||
ConnectionAdapters::DeprecatedSQLiteAdapter.new(db, logger, config) | ||
end | ||
end | ||
end | ||
end | ||
|
||
module ConnectionAdapters #:nodoc: | ||
class SQLite2Adapter < SQLiteAdapter # :nodoc: | ||
def table_structure(table_name) | ||
returning structure = execute("PRAGMA table_info(#{quote_table_name(table_name)})") do | ||
raise(ActiveRecord::StatementInvalid, "Could not find table '#{table_name}'") if structure.empty? | ||
end | ||
end | ||
|
||
def rename_table(name, new_name) | ||
move_table(name, new_name) | ||
end | ||
end | ||
|
||
class DeprecatedSQLiteAdapter < SQLite2Adapter # :nodoc: | ||
def insert(sql, name = nil, pk = nil, id_value = nil) | ||
execute(sql, name = nil) | ||
id_value || @connection.last_insert_rowid | ||
end | ||
end | ||
end | ||
end |