Apache-Session

 view release on metacpan or  search on metacpan

lib/Apache/Session/Store/Sybase.pm  view on Meta::CPAN

      ) || die $DBI::errstr;

    
	  # If we open the connection, we close the connection
	  $self->{disconnect} = 1;
	}
    
    # the programmer has to tell us what commit policy to use;
	# note that this should take effect even if the programmer
	# passes us a handle
    $self->{commit} = $session->{args}->{Commit};

	# sets the variable @@textsize to the default, which
	# should be 32K; to test, do this from a isql/sqsh session:
	#
	# > set textsize 0
	# > go
	# > select @@textsize
	# > go
	# 
	# You should see something like:
    # : 
	# :  -----------
    # :        32768
	# 
	# Note that you can also pass an argument ('textsize') for a 
	# larger/smaller text size
	my $textsize = $session->{args}->{textsize} || '0';
	$self->{dbh}->do( "set textsize $textsize" );

}

# Both insert() and update() are modifications to
# Apache::Session::Store::DBI.

# Sybase cannot use placeholders for IMAGE/TEXT field types so you
# must pass the data directly in the SQL rather than using bound
# parameters. Naturally, this negates any usefulness of the
# 'prepare_cached' method used in Apache::Session::Store::DBI, so we
# use a more straightforward sequence to prepare/execute here.

# Also, if you use this storage mechanism, you must also use the
# serializer that puts the data structure into a format that you can
# put directly into the SQL statement (e.g., '0xblahblahblah')

sub insert {
    my $self    = shift;
    my $session = shift;
 
    $self->connection( $session );

    local $self->{dbh}->{RaiseError} = 1;

	my $sth = $self->{dbh}->prepare( qq{ 
                 INSERT INTO sessions (id, a_session) VALUES ( }.$self->{dbh}->quote($session->{data}->{_session_id}).qq{, }.$self->{dbh}->quote($session->{serialized}).qq{ ) } );

    $sth->execute( );
}


sub update {
    my $self    = shift;
    my $session = shift;
 
    $self->connection( $session );

    local $self->{dbh}->{RaiseError} = 1;

	my $sth = $self->{dbh}->prepare( qq{ 
                 UPDATE sessions SET a_session = }.$self->{dbh}->quote($session->{serialized}).qq{ WHERE id = }.$self->{dbh}->quote($session->{data}->{_session_id}) );

    $sth->execute( );
}

sub materialize {
    my $self    = shift;
    my $session = shift;

    $self->connection($session);

    local $self->{dbh}->{RaiseError} = 1;

    $self->{materialize_sth} =
            $self->{dbh}->prepare(qq{
                SELECT a_session FROM sessions WHERE id = }.$self->{dbh}->quote(
$session->{data}->{_session_id}));

    $self->{materialize_sth}->execute;

    my $results = $self->{materialize_sth}->fetchrow_arrayref;

    if (!(defined $results)) {
        die "Object does not exist in the data store";
    }

    $self->{materialize_sth}->finish;

    $session->{serialized} = $results->[0];
}

sub remove {
    my $self    = shift;
    my $session = shift;

    $self->connection($session);

    local $self->{dbh}->{RaiseError} = 1;

    $self->{remove_sth} =
            $self->{dbh}->prepare_cached(qq{
                DELETE FROM sessions WHERE id = }.$self->{dbh}->quote($session->{data}->{_session_id}));

    $self->{remove_sth}->execute;
    $self->{remove_sth}->finish;
}

sub DESTROY {
    my $self = shift;

    if ( $self->{commit} ) {
        $self->{dbh}->commit;



( run in 0.973 second using v1.01-cache-2.11-cpan-39bf76dae61 )