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)


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

Returns:

  • (NilClass)


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_batchNilClass

Clears the batch

Returns:

  • (NilClass)


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

#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

#execute(*params) ⇒ Fixnum|ResultSet

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 @java_obj.execute
    ResultSet.new(@java_obj.getResultSet)
  else
    @java_obj.getUpdateCount
  end
end

#execute_batchFixnum

Executes the batch

Returns:

  • (Fixnum)

    Sum of all successful update counts



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_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 Also known as: enumerate

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

Returns:

  • (NilClass)


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

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)
  @java_obj.execute_update
end