Browse files

Merge remote branch 'bigfix/statement_block'

  • Loading branch information...
2 parents 90dfd5a + 2feb916 commit b81bdcad200fbd2bd3fcdf1b7d2d6b6369546538 @jeremyevans committed Feb 14, 2011
View
7 lib/sequel/adapters/jdbc/h2.rb
@@ -89,14 +89,11 @@ def connection_pool_default_options
# Use IDENTITY() to get the last inserted id.
def last_insert_id(conn, opts={})
- stmt = conn.createStatement
- begin
+ statement(conn) do |stmt|
rs = stmt.executeQuery('SELECT IDENTITY();')
rs.next
rs.getInt(1)
- ensure
- stmt.close
- end
+ end
end
def primary_key_index_re
View
5 lib/sequel/adapters/jdbc/mssql.rb
@@ -25,14 +25,11 @@ def dataset(opts=nil)
# Get the last inserted id using SCOPE_IDENTITY().
def last_insert_id(conn, opts={})
- stmt = conn.createStatement
- begin
+ statement(conn) do |stmt|
sql = opts[:prepared] ? 'SELECT @@IDENTITY' : 'SELECT SCOPE_IDENTITY()'
rs = log_yield(sql){stmt.executeQuery(sql)}
rs.next
rs.getInt(1)
- ensure
- stmt.close
end
end
View
5 lib/sequel/adapters/jdbc/mysql.rb
@@ -38,13 +38,10 @@ def last_insert_id(conn, opts={})
rs.close
end
else
- stmt = conn.createStatement
- begin
+ statement(conn) do |stmt|
rs = stmt.executeQuery('SELECT LAST_INSERT_ID()')
rs.next
rs.getInt(1)
- ensure
- stmt.close
end
end
end
View
7 lib/sequel/adapters/jdbc/postgresql.rb
@@ -16,14 +16,9 @@ module AdapterMethods
# a statement with the given sql and executes it.
def execute(sql, args=nil)
method = block_given? ? :executeQuery : :execute
- stmt = createStatement
- begin
+ @db.statement do |stmt|
rows = @db.log_yield(sql){stmt.send(method, sql)}
yield(rows) if block_given?
- rescue NativeException => e
- raise_error(e)
- ensure
- stmt.close
end
end
View
10 lib/sequel/adapters/jdbc/sqlite.rb
@@ -17,13 +17,10 @@ def dataset(opts=nil)
# Use last_insert_rowid() to get the last inserted id.
def last_insert_id(conn, opts={})
- stmt = conn.createStatement
- begin
+ statement(conn) do |stmt|
rs = stmt.executeQuery('SELECT last_insert_rowid()')
rs.next
rs.getInt(1)
- ensure
- stmt.close
end
end
@@ -36,11 +33,8 @@ def connection_pool_default_options
# Execute the connection pragmas on the connection.
def setup_connection(conn)
conn = super(conn)
- begin
- stmt = conn.createStatement
+ statement(conn) do |stmt|
connection_pragmas.each{|s| log_yield(s){stmt.execute(s)}}
- ensure
- stmt.close if stmt
end
conn
end

0 comments on commit b81bdca

Please sign in to comment.