Class: JDBCHelper::Connection::PreparedStatement
- Inherits:
-
ParameterizedStatement
- Object
- ParameterizedStatement
- JDBCHelper::Connection::PreparedStatement
- Defined in:
- lib/jdbc-helper/connection/prepared_statement.rb
Overview
enum = pstmt.enumerate(10, 20)
Instance Attribute Summary collapse
-
#fetch_size ⇒ Fixnum
Returns the fetch size of the prepared statement.
Attributes inherited from ParameterizedStatement
Instance Method Summary collapse
-
#add_batch(*params) ⇒ NilClass
Adds to the batch.
-
#clear_batch ⇒ NilClass
Clears the batch.
- #close ⇒ NilClass
- #execute(*params) ⇒ Fixnum|ResultSet
-
#execute_batch ⇒ Fixnum
Executes the batch.
-
#parameter_count ⇒ Fixnum
Returns the number of parameters required.
-
#query(*params, &blk) ⇒ Array
(also: #enumerate)
Returns an Array if block is not given.
-
#set_fetch_size(fsz) ⇒ NilClass
(also: #fetch_size=)
Gives the JDBC driver a hint of the number of rows to fetch from the database by a single interaction.
- #update(*params) ⇒ Fixnum
Methods inherited from ParameterizedStatement
Instance Attribute Details
#fetch_size ⇒ Fixnum
Returns the fetch size of the prepared statement. If not set, nil is returned.
104 105 106 |
# File 'lib/jdbc-helper/connection/prepared_statement.rb', line 104 def fetch_size @fetch_size end |
Instance Method Details
#add_batch(*params) ⇒ NilClass
Adds to the batch
68 69 70 71 72 73 |
# File 'lib/jdbc-helper/connection/prepared_statement.rb', line 68 def add_batch(*params) check_closed set_params(params) @java_obj.add_batch end |
#clear_batch ⇒ NilClass
Clears the batch
85 86 87 88 89 |
# File 'lib/jdbc-helper/connection/prepared_statement.rb', line 85 def clear_batch check_closed @java_obj.clear_batch end |
#close ⇒ NilClass
24 25 26 27 28 |
# File 'lib/jdbc-helper/connection/prepared_statement.rb', line 24 def close @conn.send(:close_pstmt, self) @java_obj.close @java_obj = nil end |
#execute(*params) ⇒ Fixnum|ResultSet
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/jdbc-helper/connection/prepared_statement.rb', line 31 def execute(*params) check_closed set_params(params) if @java_obj.execute ResultSet.new(@java_obj.getResultSet) else @java_obj.getUpdateCount end end |
#execute_batch ⇒ Fixnum
Executes the batch
77 78 79 80 81 |
# File 'lib/jdbc-helper/connection/prepared_statement.rb', line 77 def execute_batch check_closed @java_obj.executeBatch.select { |e| e > 0 }.inject(:+) || 0 end |
#parameter_count ⇒ Fixnum
Returns the number of parameters required
19 20 21 |
# File 'lib/jdbc-helper/connection/prepared_statement.rb', line 19 def parameter_count @pmd.getParameterCount end |
#query(*params, &blk) ⇒ Array Also known as: enumerate
Returns an Array if block is not given
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/jdbc-helper/connection/prepared_statement.rb', line 51 def query(*params, &blk) check_closed set_params(params) enum = ResultSet.new(@java_obj.execute_query) if block_given? enum.each do |row| yield row end else enum end end |
#set_fetch_size(fsz) ⇒ NilClass Also known as: fetch_size=
Gives the JDBC driver a hint of the number of rows to fetch from the database by a single interaction. This is only a hint. It may no effect at all.
94 95 96 97 98 99 |
# File 'lib/jdbc-helper/connection/prepared_statement.rb', line 94 def set_fetch_size(fsz) check_closed @fetch_size = fsz @java_obj.set_fetch_size fsz end |
#update(*params) ⇒ Fixnum
43 44 45 46 47 48 |
# File 'lib/jdbc-helper/connection/prepared_statement.rb', line 43 def update(*params) check_closed set_params(params) @java_obj.execute_update end |