module Sequel::JDBC::SQLite::DatabaseMethods

Constants

DATABASE_ERROR_REGEXPS

Public Instance Methods

foreign_key_list(table, opts=OPTS) click to toggle source

Swallow pointless exceptions when the foreign key list pragma doesn't return any rows.

# File lib/sequel/adapters/jdbc/sqlite.rb, line 23
def foreign_key_list(table, opts=OPTS)
  super
rescue Sequel::DatabaseError => e
  raise unless foreign_key_error?(e)
  []
end
indexes(table, opts=OPTS) click to toggle source

Swallow pointless exceptions when the index list pragma doesn't return any rows.

Calls superclass method Sequel::SQLite::DatabaseMethods#indexes
# File lib/sequel/adapters/jdbc/sqlite.rb, line 32
def indexes(table, opts=OPTS)
  super
rescue Sequel::DatabaseError => e
  raise unless foreign_key_error?(e)
  {}
end

Private Instance Methods

connection_pool_default_options() click to toggle source

Default to a single connection for a memory database.

Calls superclass method
# File lib/sequel/adapters/jdbc/sqlite.rb, line 56
def connection_pool_default_options
  o = super
  uri == 'jdbc:sqlite::memory:' ? o.merge(:max_connections=>1) : o
end
database_error_regexps() click to toggle source
# File lib/sequel/adapters/jdbc/sqlite.rb, line 42
def database_error_regexps
  DATABASE_ERROR_REGEXPS
end
foreign_key_error?(exception) click to toggle source

Whether the given exception is due to a foreign key error.

# File lib/sequel/adapters/jdbc/sqlite.rb, line 71
def foreign_key_error?(exception)
  exception.message =~ /query does not return ResultSet/
end
last_insert_id(conn, opts=OPTS) click to toggle source

Use last_insert_rowid() to get the last inserted id.

# File lib/sequel/adapters/jdbc/sqlite.rb, line 47
def last_insert_id(conn, opts=OPTS)
  statement(conn) do |stmt|
    rs = stmt.executeQuery('SELECT last_insert_rowid()')
    rs.next
    rs.getLong(1)
  end
end
setup_connection(conn) click to toggle source

Execute the connection pragmas on the connection.

Calls superclass method
# File lib/sequel/adapters/jdbc/sqlite.rb, line 62
def setup_connection(conn)
  conn = super(conn)
  statement(conn) do |stmt|
    connection_pragmas.each{|s| log_connection_yield(s, conn){stmt.execute(s)}}
  end
  conn
end
setup_type_convertor_map() click to toggle source

Use getLong instead of getInt for converting integers on SQLite, since SQLite does not enforce a limit of 2**32. Work around regressions in jdbc-sqlite 3.8.7 for date and blob types.

Calls superclass method
# File lib/sequel/adapters/jdbc/sqlite.rb, line 77
def setup_type_convertor_map
  super
  @type_convertor_map[Java::JavaSQL::Types::INTEGER] = @type_convertor_map[Java::JavaSQL::Types::BIGINT]
  @basic_type_convertor_map[Java::JavaSQL::Types::INTEGER] = @basic_type_convertor_map[Java::JavaSQL::Types::BIGINT]
  x = @type_convertor_map[Java::JavaSQL::Types::DATE] = Object.new
  def x.call(r, i)
    if v = r.getString(i)
      Sequel.string_to_date(v)
    end
  end
  x = @type_convertor_map[Java::JavaSQL::Types::BLOB] = Object.new
  def x.call(r, i)
    if v = r.getBytes(i)
      Sequel::SQL::Blob.new(String.from_java_bytes(v))
    elsif !r.wasNull
      Sequel::SQL::Blob.new('')
    end
  end
end
sqlite_error_code(exception) click to toggle source

The result code for the exception, if the jdbc driver supports result codes for exceptions.

# File lib/sequel/adapters/jdbc/sqlite.rb, line 98
def sqlite_error_code(exception)
  exception.resultCode.code if exception.respond_to?(:resultCode)
end