SQL::Statement::RAM - SQL::Statement::RAM documentation


SQL-Statement documentation Contained in the SQL-Statement distribution.

Index


Code Index:

NAME

Top

SQL::Statement::RAM

SYNOPSIS

Top

  SQL::Statement::RAM

DESCRIPTION

Top

This package contains support for the internally used SQL::Statement::RAM::Table.

INHERITANCE

Top

  SQL::Statement::RAM

  SQL::Statement::RAM::Table
  ISA SQL::Eval::Table

SQL::Statement::RAM::Table

Top

METHODS

new

Instantiates a new SQL::Statement::RAM::Table object, used for temporary tables.

    CREATE TEMP TABLE foo ....

fetch_row

Fetches the next row

push_row

As fetch_row except for writing

delete_current_row

Deletes the last fetched/pushed row

update_current_row

Updates the last fetched/pushed row

truncate

Truncates the table at the current position

push_names

Set the column names of the table

drop

Discards the table

seek

Seek the row pointer

CAPABILITIES

This table has following capabilities:

update_current_row

Using provided method update_current_row and capability inplace_update.

rowwise_update

By providing capability update_current_row.

inplace_update

By definition (appropriate flag set in constructor).

delete_current_row

Using provided method delete_current_row and capability inplace_delete.

rowwise_delete

By providing capability delete_current_row.

inplace_delete

By definition (appropriate flag set in constructor).

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc SQL::Statement

You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=SQL-Statement

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/SQL-Statement

* CPAN Ratings

http://cpanratings.perl.org/s/SQL-Statement

* Search CPAN

http://search.cpan.org/dist/SQL-Statement/

AUTHOR AND COPYRIGHT

Top


SQL-Statement documentation Contained in the SQL-Statement distribution.

############################
package SQL::Statement::RAM;
############################

use strict;
use warnings;

use vars qw($VERSION);
$VERSION = '1.33';

####################################
package SQL::Statement::RAM::Table;
####################################

use strict;
use warnings;

require SQL::Eval;

use vars qw(@ISA);
@ISA = qw(SQL::Eval::Table);

use Carp qw(croak);

sub new
{
    my ( $class, $tname, $col_names, $data_tbl ) = @_;
    my %table = (
                  NAME         => $tname,
                  index        => 0,
                  records      => $data_tbl,
                  col_names    => $col_names,
                  capabilities => {
                                    inplace_update => 1,
                                    inplace_delete => 1,
                                  },
                );
    my $self = $class->SUPER::new( \%table );
}

##################################
# fetch_row()
##################################
sub fetch_row
{
    my ( $self, $data ) = @_;

    return $self->{row} =
        ( $self->{records} and ( $self->{index} < scalar( @{ $self->{records} } ) ) )
      ? [ @{ $self->{records}->[ $self->{index}++ ] } ]
      : undef;
}

####################################
# insert_new_row()
####################################
sub insert_new_row
{
    my ( $self, $data, $fields ) = @_;
    push @{ $self->{records} }, [ @{$fields} ];
    return 1;
}

##################################
# delete_current_row()
##################################
sub delete_current_row
{
    my ( $self, $data, $fields ) = @_;
    my $currentRow = $self->{index} - 1;
    croak "No current row" unless ( $currentRow >= 0 );
    splice @{ $self->{records} }, $currentRow, 1;
    --$self->{index};
    return 1;
}

##################################
# update_current_row()
##################################
sub update_current_row
{
    my ( $self, $data, $fields ) = @_;
    my $currentRow = $self->{index} - 1;
    croak "No current row" unless ( $currentRow >= 0 );
    $self->{records}->[$currentRow] = [ @{$fields} ];
    return 1;
}

##################################
# truncate()
##################################
sub truncate
{
    return splice @{ $_[0]->{records} }, $_[0]->{index};
}

#####################################
# push_names()
#####################################
sub push_names
{
    my ( $self, $data, $names ) = @_;
    $self->{col_names}     = $names;
    $self->{org_col_names} = [ @{$names} ];
    $self->{col_nums}      = SQL::Eval::Table::_map_colnums($names);
}

#####################################
# drop()
#####################################
sub drop
{
    my ( $self, $data ) = @_;
    my $tname = $self->{NAME};
    delete $data->{Database}->{sql_ram_tables}->{$tname};
    return 1;
}

#####################################
# seek()
#####################################
sub seek
{
    my ( $self, $data, $pos, $whence ) = @_;
    return unless defined $self->{records};
    my ($currentRow) = $self->{index};
    if ( $whence == 0 )
    {
        $currentRow = $pos;
    }
    elsif ( $whence == 1 )
    {
        $currentRow += $pos;
    }
    elsif ( $whence == 2 )
    {
        $currentRow = @{ $self->{records} } + $pos;
    }
    else
    {
        croak $self . "->seek: Illegal whence argument ($whence)";
    }
    if ( $currentRow < 0 )
    {
        croak "Illegal row number: $currentRow";
    }
    $self->{index} = $currentRow;
}

1;