NAME

ApTest::SQLiteFile - Tied-hash SQLite backend for DataFile subclasses

SYNOPSIS

tie(%hash, 'ApTest::SQLiteFile', -Filename => '/path/to/db', -Flags => 0);
    my $handle = tied(%hash);

    $hash{$uuid} = \%filter_data;    # STORE (serialises value as BLOB)
    my $data = $hash{$uuid};         # FETCH (deserialises value)
    delete $hash{$uuid};             # DELETE
    exists $hash{$uuid};             # EXISTS
    my @keys = keys %hash;           # FIRSTKEY / NEXTKEY

    $handle->Lock();                 # BEGIN IMMEDIATE
    $handle->UnLock();               # COMMIT
    $handle->ReadLock();             # BEGIN (deferred)
    $handle->db_sync();              # flush (COMMIT + re-open tx)

DESCRIPTION

A drop-in replacement for MLDBM/ApTest::Sync in DataFile subclasses. Each instance maps to one SQLite file (path.sqlite) containing a single kv_store(key TEXT PK, value BLOB) table. Values are Storable-serialised with optional Compress::Zlib deflate compression; the storage format is indicated by a two-character prefix on the raw column bytes:

"z:" Compress::Zlib deflate compressed nfreeze output (values >= 256 bytes)
"b:" raw nfreeze output, no compression (values < 256 bytes)
"s:" legacy Base64+Storable — readable by FETCH, no longer written
raw JSON / "j:" oldest legacy format — readable by FETCH, no longer written

DELETE journal mode (SQLite default) is used for reliable operation on all filesystems including virtual mounts (virtiofs, NFS, CIFS). busy_timeout replaces the polling loops in DataFile::_flock().

LOCKING

The object's Lock()/UnLock()/ReadLock() methods manage explicit SQLite transactions. DataFile::Lock() and DataFile::Unlock() call these methods on the DBMhandle. The _LOCK_COUNTER reentrancy logic in DataFile ensures Lock/UnLock are only called at depth 0->1 and 1->0, so ApTest::SQLiteFile only needs to handle a single transaction level (no nested savepoints required for the PoC).

Copyright © 2000-2013 Applied Testing and Technology, Inc. All rights reserved.