Class: Rubyfb::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 Firebird dialect to be used in preparing the SQL statement.



572
573
# File 'lib/src.rb', line 572

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

FireRubyError

Generated whenever a problem occurs closing the statement object.



677
678
# File 'lib/src.rb', line 677

def close
end

#connectionObject

This is the accessor for the connection attribute.



579
580
# File 'lib/src.rb', line 579

def connection
end

#dialectObject

This is the accessor for the dialect attribute.



600
601
# File 'lib/src.rb', line 600

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)


635
636
637
# File 'lib/src.rb', line 635

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)


663
664
665
# File 'lib/src.rb', line 663

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



617
618
# File 'lib/src.rb', line 617

def parameter_count
end

#sqlObject

This is the accessor for the SQL statement attribute.



593
594
# File 'lib/src.rb', line 593

def sql
end

#transactionObject

This is the accessor for the transaction attribute.



586
587
# File 'lib/src.rb', line 586

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.



608
609
# File 'lib/src.rb', line 608

def type
end