Class: SQLite3::TestDatabaseFlags

Inherits:
TestCase
  • Object
show all
Defined in:
lib/sqlite3-1.5.3-arm64-darwin/test/test_database_flags.rb,
lib/sqlite3-1.5.3-x86_64-darwin/test/test_database_flags.rb

Instance Method Summary collapse

Methods inherited from TestCase

#assert_nothing_raised

Instance Method Details

#setupObject



5
6
7
8
9
10
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database_flags.rb', line 5

def setup
  File.unlink 'test-flags.db' if File.exist?('test-flags.db')
  @db = SQLite3::Database.new('test-flags.db')
  @db.execute("CREATE TABLE foos (id integer)")
  @db.close
end

#teardownObject



12
13
14
15
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database_flags.rb', line 12

def teardown
  @db.close unless @db.closed?
  File.unlink 'test-flags.db' if File.exist?('test-flags.db')
end

#test_open_database_create_flagsObject



77
78
79
80
81
82
83
84
85
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database_flags.rb', line 77

def test_open_database_create_flags
  File.unlink 'test-flags.db'
  flags = SQLite3::Constants::Open::READWRITE | SQLite3::Constants::Open::CREATE
  @db = SQLite3::Database.new('test-flags.db', :flags => flags) do |db|
    db.execute("CREATE TABLE foos (id integer)")
    db.execute("INSERT INTO foos (id) VALUES (12)")
  end
  assert File.exist?('test-flags.db')
end

#test_open_database_exotic_flagsObject



87
88
89
90
91
92
93
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database_flags.rb', line 87

def test_open_database_exotic_flags
  flags = SQLite3::Constants::Open::READWRITE | SQLite3::Constants::Open::CREATE
  exotic_flags = SQLite3::Constants::Open::NOMUTEX | SQLite3::Constants::Open::TEMP_DB
  @db = SQLite3::Database.new('test-flags.db', :flags => flags | exotic_flags)
  @db.execute("INSERT INTO foos (id) VALUES (12)")
  assert @db.changes == 1
end

#test_open_database_flags_conflicts_with_readonlyObject



34
35
36
37
38
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database_flags.rb', line 34

def test_open_database_flags_conflicts_with_readonly
  assert_raise(RuntimeError) do
    @db = SQLite3::Database.new('test-flags.db', :flags => 2, :readonly => true)
  end
end

#test_open_database_flags_conflicts_with_readwriteObject



40
41
42
43
44
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database_flags.rb', line 40

def test_open_database_flags_conflicts_with_readwrite
  assert_raise(RuntimeError) do
    @db = SQLite3::Database.new('test-flags.db', :flags => 2, :readwrite => true)
  end
end

#test_open_database_flags_constantsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database_flags.rb', line 17

def test_open_database_flags_constants
  defined_to_date = [:READONLY, :READWRITE, :CREATE, :DELETEONCLOSE,
                     :EXCLUSIVE, :MAIN_DB, :TEMP_DB, :TRANSIENT_DB,
                     :MAIN_JOURNAL, :TEMP_JOURNAL, :SUBJOURNAL,
                     :MASTER_JOURNAL, :NOMUTEX, :FULLMUTEX]
  if SQLite3::SQLITE_VERSION_NUMBER > 3007002
    defined_to_date += [:AUTOPROXY, :SHAREDCACHE, :PRIVATECACHE, :WAL]
  end
  if SQLite3::SQLITE_VERSION_NUMBER > 3007007
    defined_to_date += [:URI]
  end
  if SQLite3::SQLITE_VERSION_NUMBER > 3007013
    defined_to_date += [:MEMORY]
  end
  assert defined_to_date.sort == SQLite3::Constants::Open.constants.sort
end

#test_open_database_misuse_flagsObject



70
71
72
73
74
75
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database_flags.rb', line 70

def test_open_database_misuse_flags
  assert_raise(SQLite3::MisuseException) do
    flags = SQLite3::Constants::Open::READONLY | SQLite3::Constants::Open::READWRITE # <== incompatible flags
    @db = SQLite3::Database.new('test-flags.db', :flags => flags)
  end
end

#test_open_database_readonly_flagsObject



46
47
48
49
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database_flags.rb', line 46

def test_open_database_readonly_flags
  @db = SQLite3::Database.new('test-flags.db', :flags => SQLite3::Constants::Open::READONLY)
  assert @db.readonly?
end

#test_open_database_readonly_flags_cant_openObject



56
57
58
59
60
61
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database_flags.rb', line 56

def test_open_database_readonly_flags_cant_open
  File.unlink 'test-flags.db'
  assert_raise(SQLite3::CantOpenException) do
    @db = SQLite3::Database.new('test-flags.db', :flags => SQLite3::Constants::Open::READONLY)
  end
end

#test_open_database_readwrite_flagsObject



51
52
53
54
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database_flags.rb', line 51

def test_open_database_readwrite_flags
  @db = SQLite3::Database.new('test-flags.db', :flags => SQLite3::Constants::Open::READWRITE)
  assert !@db.readonly?
end

#test_open_database_readwrite_flags_cant_openObject



63
64
65
66
67
68
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database_flags.rb', line 63

def test_open_database_readwrite_flags_cant_open
  File.unlink 'test-flags.db'
  assert_raise(SQLite3::CantOpenException) do
    @db = SQLite3::Database.new('test-flags.db', :flags => SQLite3::Constants::Open::READWRITE)
  end
end