Skip to content

Commit

Permalink
Add an Database#sqlite_version method when connecting to SQLite, used…
Browse files Browse the repository at this point in the history
… to determine feature support

Currently, the only feature that uses this is the savepoint support,
which now checks that the SQLite version is at least 3.6.8 before
attempting to use savepoints.
  • Loading branch information
jeremyevans committed Apr 8, 2010
1 parent 4d86861 commit e63f16a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,5 +1,7 @@
=== HEAD

* Add an Database#sqlite_version method when connecting to SQLite, used to determine feature support (jeremyevans)

* Fix rolling back transactions when connecting to Oracle via JDBC (jeremyevans)

* Fix syntax errors when connecting to MSSQL via the dbi adapter (jeremyevans) (#292)
Expand Down
16 changes: 14 additions & 2 deletions lib/sequel/adapters/shared/sqlite.rb
Expand Up @@ -65,9 +65,21 @@ def pragma_set(name, value)
execute_ddl("PRAGMA #{name} = #{value}")
end

# SQLite supports savepoints
# The version of the server as an integer, where 3.6.19 = 30619.
# If the server version can't be determined, 0 is used.
def sqlite_version
return @server_version if defined?(@server_version)
@server_version = begin
v = get{sqlite_version{}}
[10000, 100, 1].zip(v.split('.')).inject(0){|a, m| a + m[0] * Integer(m[1])}
rescue
0
end
end

# SQLite 3.6.8+ supports savepoints.
def supports_savepoints?
true
sqlite_version >= 30608
end

# A symbol signifying the value of the synchronous PRAGMA.
Expand Down

0 comments on commit e63f16a

Please sign in to comment.