Class DBI::Row
In: lib/dbi/row.rb
Parent: DelegateClass(Array)

DBI::Row is the representation of a row in a result set returned by the database.

It is responsible for containing and representing the result set, converting it to native Ruby types, and providing methods to sanely move through itself.

The DBI::Row class is a delegate of Array, rather than a subclass, because there are times when it should act like an Array, and others when it should act like a Hash (and still others where it should act like String, Regexp, etc). It also needs to store metadata about the row, such as column data type and index information, that users can then access.

Methods

[]   []=   by_field   by_index   clone   clone_with   convert_types   dup   each_with_name   new   set_values   to_a   to_h  

External Aliases

column_names -> field_names

Attributes

column_names  [R] 

Public Class methods

DBI::Row.new(columns, column_types, size_or_array=nil)

Returns a new DBI::Row object using columns. The size_or_array argument may either be an Integer or an Array. If it is not provided, it defaults to the length of columns.

Column types is a corresponding Array of Class/Module objects that conform to the DBI::Type interface. These will be used to convert types as they are returned.

DBI::Row is a delegate of the Array class, so all of the Array instance methods are available to your DBI::Row object (keeping in mind that initialize, [], and []= have been explicitly overridden).

Public Instance methods

Row#[]

row[int] row[array] row[regexp] row[arg, arg] row[arg, arg, …]

Sample: Row.new(["first","last","age"], ["Daniel", "Berger", "36"])

Retrieves row elements. Exactly what it retrieves depends on the kind and number of arguments used.

Zero arguments will raise an ArgumentError.

One argument will return a single result. This can be a String, Symbol, Integer, Range or Regexp and the appropriate result will be returned. Strings, Symbols and Regexps act like hash lookups, while Integers and Ranges act like Array index lookups.

Two arguments will act like the second form of Array#[], i.e it takes two integers, with the first number the starting point and the second number the length, and returns an array of values.

If three or more arguments are provided, an array of results is returned. The behavior for each argument is that of a single argument, i.e. Strings, Symbols, and Regexps act like hash lookups, while Integers and Ranges act like Array index lookups.

If no results are found, or an unhandled type is passed, then nil (or a nil element) is returned.

Assign a value to a Row object by element. You can assign using a single element reference, or by using a start and length similar to the second form of Array#[]=.

row[0] = "kirk" row[:last] = "haines" row[0, 2] = "test"

Value of the field named field_name or nil if not found.

Retrieve a value by index (rather than name).

Deprecated. Since Row delegates to Array, just use Row#at.

See Object#clone.

clone and dup here, however, are both deep copies via Marshal.

Create a new row with ‘new_values’, reusing the field name hash. Initial cloning is done deeply, via Marshal.

converts the types in the array to their specified representation from column types provided at construction time.

dup()

Alias for clone

Yields a column value by name (rather than index), along with the column name itself.

Replaces the contents of the internal array with new_values. elements are type converted at this time.

returns the underlying array (duplicated)

Returns the Row object as a hash, created by each_with_name.

[Validate]