The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Symphero::MultiValueDB - 3D database storage

SYNOPSIS

  use Symphero::MultiValueDB;

  my $db=Symphero::MultiValueDB->new(dbh => $dbh, table => 'Users');

  $db->setid('username');

  my $password=$db->get('password');

  $db->put(a => 123, b => 234);

DESCRIPTION

Database support for Symphero::MultiValueHash class. Each accessing and mutating method of SimpleHash and MultiValueHash actually goes into underlying SQL database. No caching is performed (though database may cache data itself).

Database has the following structure (all fields may be BLOBS or have different sizes, no checks of size limitations performed):

  • id

    Data hash ID (customer ID, shopping cart ID or something similar).

  • name

    Parameter name.

  • subname

    Parameter subname, used for multi-value parameters. Will be empty, but not NULL for single value parameters.

  • value

    Parameter value.

It is recommended to make index on `id' and `name' fields together and make primary key of `id', `name' and `subname' together. An example of SQL clause to create table might look like:

 CREATE TABLE ShoppingCarts (
   id char(20) DEFAULT '' NOT NULL,
   name char(40) DEFAULT '' NOT NULL,
   subname char(40) DEFAULT '' NOT NULL,
   value char(200),
   PRIMARY KEY (id,name,subname),
   KEY idname (id,name)
 );

METHODS

All methods of Symphero::MultiValueHash are available with the following changes and additions:

  • new ($@)

    Instead of accepting default values for the hash itself it requires the following parameters:

    -

    dbh

    DBI handler to SQL database.

    -

    table

    Name of the table in that database

    -

    id (optional)

    ID of data block inside the table - shopping cart ID, session ID, user ID or something similar.

    This parameter is optional in new() method, but required to store and retrieve data.

  • getref ($$), getsubref ($$)

    Disabled - always produce warning and return undef. We cannot easily trace if the values reference to which we return would be modified.

  • setid ($$)

    Switches the object to use new data block ID. Must be called if you did not pass "id" into new() method.

  • listids ($$$)

    Return a list of data block IDs for which condition is met. Condition is represented by name-value pair. The following example will return the list of shopping cart IDs for given user:

      use Symphero::MultiValueDB;
       
      my $sdb = Symphero::MultiValueDB->new(...);
       
      my @ids = $sdb->listids(logname => "testuser");
       
      print join(",",@ids),"\n";

EXPORTS

Nothing.

AUTHOR

Andrew Maltsev, <am@xao.com>

SEE ALSO

1 POD Error

The following errors were encountered while parsing the POD:

Around line 886:

You forgot a '=back' before '=head1'