Added some casts to make it work when other drivers are loaded

This commit is contained in:
Ary Borenszweig 2016-07-14 15:21:59 -03:00
parent 84e1eed991
commit c3fce779fe
2 changed files with 16 additions and 8 deletions

View file

@ -18,7 +18,7 @@ class SQLite3::ResultSet < DB::ResultSet
when LibSQLite3::Code::DONE
false
else
raise Exception.new(@statement.connection)
raise Exception.new(sqlite3_statement.sqlite3_connection)
end
end
@ -41,7 +41,7 @@ class SQLite3::ResultSet < DB::ResultSet
when Type::NULL
nil
else
raise Exception.new(@statement.connection)
raise Exception.new(sqlite3_statement.sqlite3_connection)
end
@column_index += 1
value
@ -68,12 +68,16 @@ class SQLite3::ResultSet < DB::ResultSet
end
def to_unsafe
@statement.to_unsafe
sqlite3_statement.to_unsafe
end
# :nodoc:
private def step
LibSQLite3::Code.new LibSQLite3.step(@statement)
LibSQLite3::Code.new LibSQLite3.step(sqlite3_statement)
end
protected def sqlite3_statement
@statement.as(Statement)
end
private def moving_column

View file

@ -1,7 +1,7 @@
class SQLite3::Statement < DB::Statement
def initialize(connection, sql)
super(connection)
check LibSQLite3.prepare_v2(@connection, sql, sql.bytesize + 1, out @stmt, nil)
check LibSQLite3.prepare_v2(sqlite3_connection, sql, sql.bytesize + 1, out @stmt, nil)
end
protected def perform_query(args : Enumerable) : DB::ResultSet
@ -17,8 +17,8 @@ class SQLite3::Statement < DB::Statement
rs.move_next
rs.close
rows_affected = LibSQLite3.changes(connection).to_i64
last_id = LibSQLite3.last_insert_rowid(connection)
rows_affected = LibSQLite3.changes(sqlite3_connection).to_i64
last_id = LibSQLite3.last_insert_rowid(sqlite3_connection)
DB::ExecResult.new rows_affected, last_id
end
@ -65,7 +65,11 @@ class SQLite3::Statement < DB::Statement
end
private def check(code)
raise Exception.new(@connection) unless code == 0
raise Exception.new(sqlite3_connection) unless code == 0
end
protected def sqlite3_connection
@connection.as(Connection)
end
def to_unsafe