Sha256: 2d3f3ec60ec211655f23a7557c75dad669298da80c32feac385a9d8ccc8e8dc5

Contents?: true

Size: 1.72 KB

Versions: 49

Compression:

Stored size: 1.72 KB

Contents

require 'active_record/connection_adapters/sqlite_adapter'

gem 'sqlite3', '~> 1.3.4'
require 'sqlite3'

module ActiveRecord
  class Base
    # sqlite3 adapter reuses sqlite_connection.
    def self.sqlite3_connection(config) # :nodoc:
      # Require database.
      unless config[:database]
        raise ArgumentError, "No database file specified. Missing argument: database"
      end

      # Allow database path relative to Rails.root, but only if
      # the database path is not the special path that tells
      # Sqlite to build a database only in memory.
      if defined?(Rails.root) && ':memory:' != config[:database]
        config[:database] = File.expand_path(config[:database], Rails.root)
      end

      unless 'sqlite3' == config[:adapter]
        raise ArgumentError, 'adapter name should be "sqlite3"'
      end

      db = SQLite3::Database.new(
        config[:database],
        :results_as_hash => true
      )

      db.busy_timeout(config[:timeout]) if config[:timeout]

      ConnectionAdapters::SQLite3Adapter.new(db, logger, config)
    end
  end

  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
        if @connection.respond_to?(:encoding)
          @connection.encoding.to_s
        else
          @connection.execute('PRAGMA encoding')[0]['encoding']
        end
      end

    end
  end
end

Version data entries

49 entries across 49 versions & 2 rubygems

Version Path
activerecord-3.1.12 lib/active_record/connection_adapters/sqlite3_adapter.rb
activerecord-3.1.11 lib/active_record/connection_adapters/sqlite3_adapter.rb
activerecord-3.1.10 lib/active_record/connection_adapters/sqlite3_adapter.rb
activerecord-3.1.9 lib/active_record/connection_adapters/sqlite3_adapter.rb
dirty_history-0.7.3 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/sqlite3_adapter.rb
dirty_history-0.7.2 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/sqlite3_adapter.rb
dirty_history-0.7.1 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/sqlite3_adapter.rb
dirty_history-0.7.0 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/sqlite3_adapter.rb
dirty_history-0.6.7 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/sqlite3_adapter.rb
dirty_history-0.6.6 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/sqlite3_adapter.rb
dirty_history-0.6.5 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/sqlite3_adapter.rb
dirty_history-0.6.4 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/sqlite3_adapter.rb
activerecord-3.1.8 lib/active_record/connection_adapters/sqlite3_adapter.rb
dirty_history-0.6.3 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/sqlite3_adapter.rb
activerecord-3.1.7 lib/active_record/connection_adapters/sqlite3_adapter.rb
dirty_history-0.6.2 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/sqlite3_adapter.rb
dirty_history-0.6.1 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/sqlite3_adapter.rb
dirty_history-0.6.0 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/sqlite3_adapter.rb
activerecord-3.1.6 lib/active_record/connection_adapters/sqlite3_adapter.rb
dirty_history-0.5.4 dirty_history/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/sqlite3_adapter.rb