Class: IBRuby::Statement

Inherits:
Object
  • Object
show all
Defined in:
lib/src.rb

Overview

This class represents a prepared SQL statement that may be executed more than once.

Constant Summary collapse

SELECT_STATEMENT =

A definition for a SQL statement type constant.

1
INSERT_STATEMENT =

A definition for a SQL statement type constant.

2
UPDATE_STATEMENT =

A definition for a SQL statement type constant.

3
DELETE_STATEMENT =

A definition for a SQL statement type constant.

4
DDL_STATEMENT =

A definition for a SQL statement type constant.

5
GET_SEGMENT_STATEMENT =

A definition for a SQL statement type constant.

6
PUT_SEGMENT_STATEMENT =

A definition for a SQL statement type constant.

7
EXECUTE_PROCEDURE_STATEMENT =

A definition for a SQL statement type constant.

8
START_TRANSACTION_STATEMENT =

A definition for a SQL statement type constant.

9
COMMIT_STATEMENT =

A definition for a SQL statement type constant.

10
ROLLBACK_STATEMENT =

A definition for a SQL statement type constant.

11
SELECT_FOR_UPDATE_STATEMENT =

A definition for a SQL statement type constant.

12
SET_GENERATOR_STATEMENT =

A definition for a SQL statement type constant.

13
SAVE_POINT_STATEMENT =

A definition for a SQL statement type constant.

14

Instance Method Summary collapse

Constructor Details

#initialize(connection, transaction, sql, dialect) ⇒ Statement

This is the constructor for the Statement class.

Parameters

connection

The Connection object that the SQL statement will be executed through.

transaction

The Transaction object that the SQL statement will be executed under.

sql

The SQL statement to be prepared for execution.

dialect

The InterBase dialect to be used in preparing the SQL statement.



567
568
# File 'lib/src.rb', line 567

def initialize(connection, transaction, sql, dialect)
end

Instance Method Details

#closeObject

This method releases the database resources associated with a Statement object and should be explicitly called when a Statement object is of no further use.

Exceptions

IBRubyError

Generated whenever a problem occurs closing the

statement object.


672
673
# File 'lib/src.rb', line 672

def close
end

#connectionObject

This is the accessor for the connection attribute.



574
575
# File 'lib/src.rb', line 574

def connection
end

#dialectObject

This is the accessor for the dialect attribute.



595
596
# File 'lib/src.rb', line 595

def dialect
end

#execute {|row| ... } ⇒ Object

This method executes the SQL statement within a Statement object. This method returns a ResultSet object if the statement executed was a SQL query. For non-query SQL statements (insert, update or delete) it returns an Integer indicating the number of affected rows. For all other statements the method returns nil. This method accepts a block taking a single parameter. If this block is provided and the statement is a query then the rows returned by the query will be passed, one at a time, to the block.

Exception

Exception

Generated if the Statement object actual requires some parameters or a problem occurs executing the SQL statement.

Yields:

  • (row)


630
631
632
# File 'lib/src.rb', line 630

def execute
   yield row
end

#execute_for(parameters) {|row| ... } ⇒ Object

This method executes the SQL statement within a Statement object and passes it a set of parameters. Parameterized statements use question marks as place holders for values that may change between calls to execute the statement. This method returns a ResultSet object if the statement executed was a SQL query. If the statement was a non-query SQL statement (insert, update or delete) then the method returns a count of the number of rows affected. For all other types of statement the method returns nil. This method accepts a block taking a single parameter. If this block is provided and the statement is a query then the rows returned by the query will be passed, one at a time, to the block.

Parameters

parameters

An array of the parameters for the statement. An effort will be made to convert the values passed in to the appropriate types but no guarantees are made (especially in the case of text fields, which will simply use to_s if the object passed is not a String).

Exception

Exception

Generated whenever a problem occurs translating one of the input parameters or executing the SQL statement.

Yields:

  • (row)


658
659
660
# File 'lib/src.rb', line 658

def execute_for(parameters)
   yield row
end

#parameter_countObject

This method fetches a count of the number of dynamic parameters for a statement object (i.e. the number of parameters that must be provided with values before the SQL statement can be executed).



612
613
# File 'lib/src.rb', line 612

def parameter_count
end

#sqlObject

This is the accessor for the SQL statement attribute.



588
589
# File 'lib/src.rb', line 588

def sql
end

#transactionObject

This is the accessor for the transaction attribute.



581
582
# File 'lib/src.rb', line 581

def transaction
end

#typeObject

This method is used to determine the type of a SQL statement. The method will return one of the constant SQL types defined within the class.



603
604
# File 'lib/src.rb', line 603

def type
end