GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
DBIx::Custom::Result(3) User Contributed Perl Documentation DBIx::Custom::Result(3)

DBIx::Custom::Result - Result of select statement

  # Result
  my $result = $dbi->select(table => 'book');

  # Fetch a row and put it into array reference
  while (my $row = $result->fetch) {
    my $author = $row->[0];
    my $title  = $row->[1];
  }
  
  # Fetch only a first row and put it into array reference
  my $row = $result->fetch_one;
  
  # Fetch all rows and put them into array of array reference
  my $rows = $result->fetch_all;

  # Fetch a row and put it into hash reference
  while (my $row = $result->fetch_hash) {
    my $title  = $row->{title};
    my $author = $row->{author};
  }
  
  # Fetch only a first row and put it into hash reference
  my $row = $result->fetch_hash_one;
  my $row = $result->one; # Alias for "fetch_hash_one"
  
  # Fetch all rows and put them into array of hash reference
  my $rows = $result->fetch_hash_all;
  my $rows = $result->all; # Alias for "fetch_hash_all"

  my $dbi = $result->dbi;
  $result = $result->dbi($dbi);

DBIx::Custom object.

  my $sth = $reuslt->sth
  $result = $result->sth($sth);

Statement handle of DBI.

DBIx::Custom::Result inherits all methods from Object::Simple and implements the following new ones.

  my $rows = $result->all;

Same as fetch_hash_all.

  my $row = $result->fetch;

Fetch a row and put it into array reference.

  my $rows = $result->fetch_all;

Fetch all rows and put them into array of array reference.

  my $row = $result->fetch_one;

Fetch only a first row and put it into array reference, and finish statement handle.

  my $row = $result->fetch_hash;

Fetch a row and put it into hash reference.

  my $rows = $result->fetch_hash_all;

Fetch all rows and put them into array of hash reference.

  my $row = $result->fetch_hash_one;

Fetch only a first row and put it into hash reference, and finish statement handle.

  my $rows = $result->fetch_hash_multi(5);

Fetch multiple rows and put them into array of hash reference.

  my $rows = $result->fetch_multi(5);

Fetch multiple rows and put them into array of array reference.

  $result->filter(title  => sub { uc $_[0] }, author => 'to_upper');
  $result->filter([qw/title author/] => 'to_upper');

Set filter for column. You can use subroutine or filter name as filter. This filter is executed after "type_rule" filter.

  my @list = $result->flat;

All values is added to flatten list.

  my @list = $dbi->select(['id', 'title'])->flat;

"flat" method return the following data.

  (1, 'Perl', 2, 'Ruby')

You can create key-value pair easily.

  my %titles = $dbi->select(['id', 'title'])->flat;

  my $key_value = $result->kv;

Get key-value pairs.

  my $books = $dbi->select(['id', 'title', 'author'])->kv;

If "all" method return the following data:

  [
    {id => 1, title => 'Perl', author => 'Ken'},
    {id => 2, title => 'Ruby', author => 'Taro'}
  ]

"kv" method return the following data.

  {
    1 => {title => 'Perl', author => 'Ken'},
    2 => {title => 'Ruby', author => 'Taro'}
  }

First column value become key.

  my $key_values = $result->kvs;

Get key-values pairs.

  my $books = $dbi->select(['author', 'title', 'price'])->kvs;

If "all" method return the following data:

  [
    {author => 'Ken', title => 'Perl', price => 1000},
    {author => 'Ken', title => 'Good', price => 2000},
    {author => 'Taro', title => 'Ruby', price => 3000}
    {author => 'Taro', title => 'Sky', price => 4000}
  ]

"kvs" method return the following data.

  {
    Ken => [
      {title => 'Perl', price => 1000},
      {title => 'Good', price => 2000}
    ],
    Taro => [
      {title => 'Ruby', price => 3000},
      {title => 'Sky', price => 4000}
    ]
  }
  my $header = $result->header;

Get header column names.

  my $row = $result->one;

Alias for "fetch_hash_one".

  my $stash = $result->stash;
  my $foo = $result->stash->{foo};
  $result->stash->{foo} = $foo;

Stash is hash reference to save some data.

  # Merge type rule
  $result->type_rule(
    # DATE
    9 => sub { ... },
    # DATETIME or TIMESTAMP
    11 => sub { ... }
  );

  # Replace type rule(by reference)
  $result->type_rule([
    # DATE
    9 => sub { ... },
    # DATETIME or TIMESTAMP
    11 => sub { ... }
  ]);

This is same as DBIx::Custom's "type_rule"'s <from>.

  $result = $result->type_rule_off;

Turn "from1" and "from2" type rule off. By default, type rule is on.

  $result = $result->type_rule_on;

Turn "from1" and "from2" type rule on. By default, type rule is on.

  $result = $result->type_rule1_off;

Turn "from1" type rule off. By default, type rule is on.

  $result = $result->type_rule1_on;

Turn "from1" type rule on. By default, type rule is on.

  $result = $result->type_rule2_off;

Turn "from2" type rule off. By default, type rule is on.

  $result = $result->type_rule2_on;

Turn "from2" type rule on. By default, type rule is on.

  my $value = $result->value;

Get first column's first value.

  my $count = $dbi->select('count(*)', table => 'book')->value;

This is almost same as the following one.

  my $count = $dbi->select('count(*)')->fetch_one->[0];

  my $values = $result->values;

Get first column's values.

  my $tables = $dbi->select('show tables')->values;

This is same as the following one.

  my $rows = $dbi->select('show tables')->fetch_all;
  my $tables = [map { $_->[0] } @$rows];
2017-03-28 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.