Class: JDBCHelper::Connection::PreparedStatement

Inherits:
ParameterizedStatement show all
Defined in:
lib/jdbc-helper/connection/prepared_statement.rb

Overview

enum = pstmt.enumerate(10, 20)

Instance Attribute Summary collapse

Attributes inherited from ParameterizedStatement

#java_obj, #sql

Instance Method Summary collapse

Methods inherited from ParameterizedStatement

#closed?, #set_param

Instance Attribute Details

#fetch_sizeFixnum

Returns the fetch size of the prepared statement. If not set, nil is returned.

Returns:

  • (Fixnum)


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

Returns:

  • (NilClass)


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_batchNilClass

Clears the batch

Returns:

  • (NilClass)


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

#closeNilClass

Returns:

  • (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

Returns:



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_batchObject

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_countFixnum

Returns the number of parameters required

Returns:

  • (Fixnum)


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

Returns:

  • (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.

Returns:

  • (NilClass)


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

Returns:

  • (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