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
- #enumerate(*params, &blk) ⇒ JDBCHelper::Connection::ResultSetEnumerator
- #execute(*params) ⇒ Fixnum|ResultSetEnumerator
-
#execute_batch ⇒ Object
Executes the batch.
-
#parameter_count ⇒ Fixnum
Returns the number of parameters required.
-
#query(*params, &blk) ⇒ Array
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.
107 108 109 |
# File 'lib/jdbc-helper/connection/prepared_statement.rb', line 107 def fetch_size @fetch_size end |
Instance Method Details
#add_batch(*params) ⇒ NilClass
Adds to the batch
72 73 74 75 76 77 |
# File 'lib/jdbc-helper/connection/prepared_statement.rb', line 72 def add_batch(*params) check_closed set_params(params) @java_obj.add_batch end |
#clear_batch ⇒ NilClass
Clears the batch
88 89 90 91 92 |
# File 'lib/jdbc-helper/connection/prepared_statement.rb', line 88 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 |
#enumerate(*params, &blk) ⇒ JDBCHelper::Connection::ResultSetEnumerator
61 62 63 64 65 66 67 68 |
# File 'lib/jdbc-helper/connection/prepared_statement.rb', line 61 def enumerate(*params, &blk) check_closed return query(*params, &blk) if block_given? set_params(params) ResultSetEnumerator.new(measure_exec(:p_query) { @java_obj.execute_query }) end |
#execute(*params) ⇒ Fixnum|ResultSetEnumerator
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 measure_exec(:p_execute) { @java_obj.execute } ResultSetEnumerator.new(measure_exec(:p_query) { @java_obj.getResultSet }) else @java_obj.getUpdateCount end end |
#execute_batch ⇒ Object
Executes the batch
79 80 81 82 83 84 85 |
# File 'lib/jdbc-helper/connection/prepared_statement.rb', line 79 def execute_batch check_closed measure_exec(:p_execute_batch) { @java_obj.executeBatch } 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
Returns an Array if block is not given
51 52 53 54 55 56 57 58 |
# File 'lib/jdbc-helper/connection/prepared_statement.rb', line 51 def query(*params, &blk) check_closed set_params(params) # sorry, ignoring privacy @conn.send(:process_and_close_rset, measure_exec(:p_query) { @java_obj.execute_query }, &blk) 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.
97 98 99 100 101 102 |
# File 'lib/jdbc-helper/connection/prepared_statement.rb', line 97 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) measure_exec(:p_update) { @java_obj.execute_update } end |