test/test_database.rb in extralite-1.23 vs test/test_database.rb in extralite-1.24
- old
+ new
@@ -167,12 +167,10 @@
r = @db.query_single_value('select null')
assert_nil r
end
-
-
def test_extension_loading
case RUBY_PLATFORM
when /linux/
@db.load_extension(File.join(__dir__, 'extensions/text.so'))
when /darwin/
@@ -289,32 +287,37 @@
db2 = Extralite::Database.new(fn)
db1.query('begin exclusive')
assert_raises(Extralite::BusyError) { db2.query('begin exclusive') }
- db2.busy_timeout = 0.3
+ db2.busy_timeout = 3
t0 = Time.now
t = Thread.new { sleep 0.1; db1.query('rollback') }
result = db2.query('begin exclusive')
t1 = Time.now
assert_equal [], result
assert t1 - t0 >= 0.1
db2.query('rollback')
+ t.join
# try to provoke a timeout
db1.query('begin exclusive')
- db2.busy_timeout = 0.1
+ db2.busy_timeout = nil
+ assert_raises(Extralite::BusyError) { db2.query('begin exclusive') }
+
+ db2.busy_timeout = 0.2
t0 = Time.now
t = Thread.new do
- sleep 0.5
+ sleep 3
ensure
db1.query('rollback')
end
assert_raises(Extralite::BusyError) { db2.query('begin exclusive') }
+
t1 = Time.now
- assert t1 - t0 >= 0.1
+ assert t1 - t0 >= 0.2
t.kill
t.join
db1.query('begin exclusive')
db2.busy_timeout = 0
@@ -328,9 +331,36 @@
assert_equal 2, @db.total_changes
@db.query('insert into t values (7, 8, 9)')
assert_equal 3, @db.total_changes
+ end
+
+ def test_database_errcode_errmsg
+ assert_equal 0, @db.errcode
+ assert_equal 'not an error', @db.errmsg
+
+ @db.query('select foo') rescue nil
+
+ assert_equal 1, @db.errcode
+ assert_equal 'no such column: foo', @db.errmsg
+
+ if Extralite.sqlite3_version >= '3.38.5'
+ assert_equal 7, @db.error_offset
+ end
+
+ @db.query('create table t2 (v not null)')
+
+ assert_raises(Extralite::Error) { @db.query('insert into t2 values (null)') }
+ assert_equal Extralite::SQLITE_CONSTRAINT_NOTNULL, @db.errcode
+ assert_equal 'NOT NULL constraint failed: t2.v', @db.errmsg
+ end
+
+
+ def test_close_with_open_prepared_statement
+ stmt = @db.prepare('select * from t')
+ stmt.query
+ @db.close
end
end
class ScenarioTest < MiniTest::Test
def setup