AtteanX-Store-DBI-0.003/ 000755 000765 000024 00000000000 14764061656 014654 5 ustar 00greg staff 000000 000000 AtteanX-Store-DBI-0.003/inc/ 000755 000765 000024 00000000000 14764061652 015421 5 ustar 00greg staff 000000 000000 AtteanX-Store-DBI-0.003/SIGNATURE 000644 000765 000024 00000010047 14764061656 016142 0 ustar 00greg staff 000000 000000 This file contains message digests of all files listed in MANIFEST,
signed via the Module::Signature module, version 0.89.
To verify the content in this distribution, first make sure you have
Module::Signature installed, then type:
% cpansign -v
It will check each file's integrity, as well as the signature's
validity. If "==> Signature verified OK! <==" is not displayed,
the distribution may already have been compromised, and you should
not run its Makefile.PL or Build.PL.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160
SHA256 231e365a175636d86b5fd3c221ab6ef7dd4f90221d882d2daa4feeca92288121 Changes
SHA256 d11eeb015891675776020c76a0a1c86cae0bab64bdeadb7dfeba0447ebc0c623 MANIFEST
SHA256 9348e6a18b008165a5a493bc27b8541e8950b0d1cc80d3693ae3e4aa55f415c7 META.yml
SHA256 5f65e9f44871a5cc5f526e9340cdc02b54f3d73e5fce7eb4d94b555ecc208fb0 Makefile.PL
SHA256 dafc4e443a6bd7fb7452fc631d486bf9b9362a9acc56b3a088435997d1359711 README.md
SHA256 5c3a1aa3150c9b54ba92411d64b0024df0967e92dfc181f5c68f9e38631ac0db bin/attean_dbi
SHA256 cd5397bbe618f5bbd4e12a33b0cf5d21114e771c2dbd0ce28e2135beb52c35a8 inc/Module/Install.pm
SHA256 1b5430a46a35142ef8914d8c745196fca825defc9dfa7e389299bf294613825e inc/Module/Install/AuthorTests.pm
SHA256 798836f9ccb8d204b1be31fc3835631f57e9d818b21a8f0d14bfcfb82ff4a72a inc/Module/Install/Base.pm
SHA256 d64cd4c16f83c5baf11f64a44bea3a0abc060a49da5aba040f0eb01394bf75ab inc/Module/Install/Can.pm
SHA256 668306ae2fad17b3049f885251b8679497c4eb8d5c4b0d13f5c95bda331d1f00 inc/Module/Install/DOAPChangeSets.pm
SHA256 65d7a6098bf3f829e8c1c2865476d3537aa6f0ad0ffc9149e10812c856529043 inc/Module/Install/Fetch.pm
SHA256 70c4b77acab3ff51dfb318110369607cb109e1c319459249623b787cf3859750 inc/Module/Install/Makefile.pm
SHA256 14556386168007ce913e669fc08a332ccdb6140246fd55a90c879b5190c1b57a inc/Module/Install/Metadata.pm
SHA256 63ec8405523ae67c33823dcf4b136a46f0711fb17a8b58b49ddd922ed6b69611 inc/Module/Install/Scripts.pm
SHA256 b986592700675e11c2c62cb41fa24d9f4d15e077a0d317f372efcaa78d68a1d9 inc/Module/Install/Share.pm
SHA256 4c746c02c5cc19bed4c352e76205b4adff4c45ce8310d71294e1b83c059659c2 inc/Module/Install/Win32.pm
SHA256 d3d9b4583243c470ae895defa4c44564485b53693cba1c50ab0320768f443e97 inc/Module/Install/WriteAll.pm
SHA256 a9503b6a76f33ba39f1f045d2705d5ed08536f8132b540d59777ac587f3a4151 lib/AtteanX/Store/DBI.pm
SHA256 bfe7e8e7b04402a8b4701f7061b6bec75b7380c3bbc0ab200de167f4f6b5d74b lib/Test/AtteanX/Store/DBI.pm
SHA256 3f2258c3a0dce58edc586bef7d112f8a264684ce8f522189cc2113992ed7f07c meta/changes.ttl
SHA256 dd0b276f509f5c71d1031f4d27cd78f5d9a8d85f3afd8512c5e0e9b946bcce32 share/database-schema/mysql-create.sql
SHA256 89f829942eb387bb8b569dd2d70412ca28a46c86a00b0b4350eb07d1de343e58 share/database-schema/mysql-drop.sql
SHA256 820c4a16aef52754ed03d036615454ad8eabd09cc25d1ffa1648c679c4e0221e share/database-schema/postgresql-create.sql
SHA256 2de18d403cfd956d62ea6135cd9f15d0507ffa86b1594e4edcd20f842b9f92a3 share/database-schema/postgresql-drop.sql
SHA256 146fb0e54770a44b662808c1a31f6c33127c0aba927bb37c9b147907bf73e4d4 share/database-schema/sqlite-create.sql
SHA256 89f829942eb387bb8b569dd2d70412ca28a46c86a00b0b4350eb07d1de343e58 share/database-schema/sqlite-drop.sql
SHA256 25927a842ddbf2e42c50bc084f3dd407f70671a61f3ebf8a20c0bd378cb9ac93 t/store-dbi-mysql.t
SHA256 d87fedd045ce2d8ab8dac05b2fdccf135cfa6ac082aafab531181431536e0d63 t/store-dbi-postgresql.t
SHA256 4f14567e455b487ec9da1dec6735ec5b0b9099cb4a46f9fe590d466ca183ca16 t/store-dbi-sqlite.t
SHA256 0efbd5cab373833735076832064c6c10f3f5c13216ac0e18347c48e3459223d9 xt/dawg11-mysql.t
SHA256 a2f200695b73565e1e64451528e8005a44be4695e3fa875b6a90afb0e14c68b0 xt/dawg11-postgresql.t
SHA256 1a2829c1f7c9e2c40880d3c2a671f1278d2e16a6edf30f46693852ece5c3c63a xt/dawg11-sqlite.t
SHA256 81dae5e652e694c2acc7d105e32ba5f69edc343b22b2e1d47f95fdef8b441cd3 xt/pod-coverage.t
SHA256 2b04b20ff767801fde2fb6435361dc8ca0a9b60dda6cb0bbd18dd52962e1c1a3 xt/pod.t
-----BEGIN PGP SIGNATURE-----
iF0EAREDAB0WIQSC+8GhU5AgVmDLxA+E8rpUyqjILQUCZ9BjqgAKCRCE8rpUyqjI
LaH7AKCBqPiyVlrjrIO5dtGut5QSyuJPvQCfZsBGY21mxwL8bax5MMr3XkZYYcM=
=GeK4
-----END PGP SIGNATURE-----
AtteanX-Store-DBI-0.003/bin/ 000755 000765 000024 00000000000 14764061652 015420 5 ustar 00greg staff 000000 000000 AtteanX-Store-DBI-0.003/Changes 000644 000765 000024 00000001053 14764061647 016146 0 ustar 00greg staff 000000 000000 AtteanX::Store::DBI
===================
Created: 2016-03-14
Home page:
Bug tracker:
0.003 2025-03-11
- (Update) Fix developer tests to silence warnings.
0.002 2020-12-12
- (Update) Add DBD::SQLite as a test prereq (#6).
- (Update) Remove Math::Cartesian::Product from prereq list (#4).
- (Update) Remove mistakenly added LICENSE file (#5).
- (Update) Update copyright years (#3).
0.001 2020-12-02
- (Addition) Initial release.
AtteanX-Store-DBI-0.003/MANIFEST 000644 000765 000024 00000001731 14764061652 016003 0 ustar 00greg staff 000000 000000 bin/attean_dbi
Changes
inc/Module/Install.pm
inc/Module/Install/AuthorTests.pm
inc/Module/Install/Base.pm
inc/Module/Install/Can.pm
inc/Module/Install/DOAPChangeSets.pm
inc/Module/Install/Fetch.pm
inc/Module/Install/Makefile.pm
inc/Module/Install/Metadata.pm
inc/Module/Install/Scripts.pm
inc/Module/Install/Share.pm
inc/Module/Install/Win32.pm
inc/Module/Install/WriteAll.pm
lib/AtteanX/Store/DBI.pm
lib/Test/AtteanX/Store/DBI.pm
Makefile.PL
MANIFEST This list of files
META.yml
meta/changes.ttl
README.md
share/database-schema/mysql-create.sql
share/database-schema/mysql-drop.sql
share/database-schema/postgresql-create.sql
share/database-schema/postgresql-drop.sql
share/database-schema/sqlite-create.sql
share/database-schema/sqlite-drop.sql
t/store-dbi-mysql.t
t/store-dbi-postgresql.t
t/store-dbi-sqlite.t
xt/dawg11-mysql.t
xt/dawg11-postgresql.t
xt/dawg11-sqlite.t
xt/pod-coverage.t
xt/pod.t
SIGNATURE Public-key signature (added by MakeMaker)
AtteanX-Store-DBI-0.003/meta/ 000755 000765 000024 00000000000 14764061652 015576 5 ustar 00greg staff 000000 000000 AtteanX-Store-DBI-0.003/t/ 000755 000765 000024 00000000000 14764061652 015113 5 ustar 00greg staff 000000 000000 AtteanX-Store-DBI-0.003/xt/ 000755 000765 000024 00000000000 14764061652 015303 5 ustar 00greg staff 000000 000000 AtteanX-Store-DBI-0.003/PaxHeader/README.md 000644 000765 000024 00000000225 13761617237 020101 x ustar 00greg staff 000000 000000 30 mtime=1606885023.242905658
64 LIBARCHIVE.xattr.com.apple.TextEncoding=VVRGLTg7MTM0MjE3OTg0
55 SCHILY.xattr.com.apple.TextEncoding=UTF-8;134217984
AtteanX-Store-DBI-0.003/README.md 000644 000765 000024 00000000626 13761617237 016135 0 ustar 00greg staff 000000 000000 AtteanX::Store::DBI
===================
An Attean quadstore implementation based on relational databases.
Getting Help
------------
A group of perl-rdf developers are usually available in the
[perlrdf IRC channel](irc://irc.perl.org/perlrdf) where we're happy to answer
questions.
You can also:
* Create a new [GitHub Issue](https://github.com/kasei/atteanx-store-dbi/issues) or submit a pull request
AtteanX-Store-DBI-0.003/META.yml 000644 000765 000024 00000002262 14764061647 016127 0 ustar 00greg staff 000000 000000 ---
abstract: 'Database quad-store'
author:
- 'Gregory Todd Williams C<< >>'
- 'Gregory Todd Williams '
build_requires:
DBD::SQLite: 0
ExtUtils::MakeMaker: 6.59
HTTP::Message::PSGI: 0
Test::Exception: 0
Test::LWP::UserAgent: 0
Test::Modern: 0
Test::Moose: 0
Test::More: 0.88
Test::Roo: 0
configure_requires:
ExtUtils::MakeMaker: 6.59
distribution_type: module
dynamic_config: 1
generated_by: 'Module::Install version 1.21'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: AtteanX-Store-DBI
no_index:
directory:
- inc
- share
- t
- xt
requires:
Attean: 0.013
Cache::LRU: 0
DBI: 0
DBIx::MultiStatementDo: 0
File::ShareDir: 0
File::Slurp: 0
List::MoreUtils: 0
Moo: 1.006
MooX::Log::Any: 0
Try::Tiny: 0
Type::Tiny: 0
namespace::clean: 0
perl: 5.14.0
resources:
IRC: irc://irc.perl.org/#perlrdf
bugtracker: https://github.com/kasei/atteanx-store-dbi/issues
homepage: https://metacpan.org/release/AtteanX-Store-DBI/
license: http://dev.perl.org/licenses/
repository: https://github.com/kasei/atteanx-store-dbi/
version: '0.003'
AtteanX-Store-DBI-0.003/lib/ 000755 000765 000024 00000000000 14764061652 015416 5 ustar 00greg staff 000000 000000 AtteanX-Store-DBI-0.003/PaxHeader/Makefile.PL 000644 000765 000024 00000000225 13764534140 020566 x ustar 00greg staff 000000 000000 30 mtime=1607645280.153539003
64 LIBARCHIVE.xattr.com.apple.TextEncoding=VVRGLTg7MTM0MjE3OTg0
55 SCHILY.xattr.com.apple.TextEncoding=UTF-8;134217984
AtteanX-Store-DBI-0.003/Makefile.PL 000644 000765 000024 00000002550 13764534140 016620 0 ustar 00greg staff 000000 000000 use strict;
use warnings;
use inc::Module::Install;
name 'AtteanX-Store-DBI';
all_from 'lib/AtteanX/Store/DBI.pm';
author 'Gregory Todd Williams ';
license 'perl';
test_requires 'Test::Exception' => 0;
test_requires 'Test::Modern' => 0;
test_requires 'Test::Moose' => 0;
test_requires 'Test::More' => 0.88;
test_requires 'Test::Roo' => 0;
test_requires 'HTTP::Message::PSGI' => 0;
test_requires 'Test::LWP::UserAgent' => 0;
test_requires 'DBD::SQLite' => 0;
perl_version '5.014';
requires 'Attean' => 0.013;
requires 'List::MoreUtils' => 0;
requires 'Moo' => 1.006000;
requires 'MooX::Log::Any' => 0;
requires 'namespace::clean' => 0;
requires 'Try::Tiny' => 0;
requires 'Type::Tiny' => 0;
requires 'File::Slurp' => 0;
requires 'File::ShareDir' => 0;
requires 'DBI' => 0;
requires 'Cache::LRU' => 0;
requires 'DBI' => 0;
requires 'DBIx::MultiStatementDo' => 0;
resources(
'homepage' => "https://metacpan.org/release/AtteanX-Store-DBI/",
'repository' => "https://github.com/kasei/atteanx-store-dbi/",
'bugtracker' => "https://github.com/kasei/atteanx-store-dbi/issues",
'IRC' => "irc://irc.perl.org/#perlrdf",
);
author_tests('xt');
install_share;
install_script glob('bin/attean_*');
write_doap_changes "meta/changes.ttl", "Changes", "turtle";
sign;
WriteAll;
AtteanX-Store-DBI-0.003/share/ 000755 000765 000024 00000000000 14764061652 015752 5 ustar 00greg staff 000000 000000 AtteanX-Store-DBI-0.003/share/database-schema/ 000755 000765 000024 00000000000 14764061652 020754 5 ustar 00greg staff 000000 000000 AtteanX-Store-DBI-0.003/share/database-schema/PaxHeader/mysql-create.sql 000644 000765 000024 00000000167 13133671135 026050 x ustar 00greg staff 000000 000000 64 LIBARCHIVE.xattr.com.apple.TextEncoding=VVRGLTg7MTM0MjE3OTg0
55 SCHILY.xattr.com.apple.TextEncoding=UTF-8;134217984
AtteanX-Store-DBI-0.003/share/database-schema/mysql-create.sql 000644 000765 000024 00000001602 13133671135 024072 0 ustar 00greg staff 000000 000000 CREATE TABLE IF NOT EXISTS attean_version (
attean_version VARCHAR(16),
store_version VARCHAR(16),
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
CREATE TABLE IF NOT EXISTS term (
term_id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
`type` ENUM('iri', 'literal', 'blank'),
datatype_id BIGINT REFERENCES term(term_id),
value LONGTEXT NOT NULL,
language TEXT,
INDEX (`type`, datatype_id, value(64), language(64))
) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
CREATE TABLE IF NOT EXISTS quad (
subject BIGINT UNSIGNED NOT NULL REFERENCES term,
predicate BIGINT UNSIGNED NOT NULL REFERENCES term,
object BIGINT UNSIGNED NOT NULL REFERENCES term,
graph BIGINT UNSIGNED NOT NULL REFERENCES term,
PRIMARY KEY (subject, predicate, object, graph),
KEY (predicate,object,graph,subject),
INDEX (graph)
);
AtteanX-Store-DBI-0.003/share/database-schema/PaxHeader/postgresql-drop.sql 000644 000765 000024 00000000167 13133671713 026611 x ustar 00greg staff 000000 000000 64 LIBARCHIVE.xattr.com.apple.TextEncoding=VVRGLTg7MTM0MjE3OTg0
55 SCHILY.xattr.com.apple.TextEncoding=UTF-8;134217984
AtteanX-Store-DBI-0.003/share/database-schema/postgresql-drop.sql 000644 000765 000024 00000000134 13133671713 024632 0 ustar 00greg staff 000000 000000 DROP TABLE quad;
DROP TABLE term;
DROP TYPE TERM_TYPE;
DROP TABLE IF EXISTS attean_version;
AtteanX-Store-DBI-0.003/share/database-schema/PaxHeader/sqlite-create.sql 000644 000765 000024 00000000167 13133667440 026210 x ustar 00greg staff 000000 000000 64 LIBARCHIVE.xattr.com.apple.TextEncoding=VVRGLTg7MTM0MjE3OTg0
55 SCHILY.xattr.com.apple.TextEncoding=UTF-8;134217984
AtteanX-Store-DBI-0.003/share/database-schema/sqlite-create.sql 000644 000765 000024 00000001440 13133667440 024232 0 ustar 00greg staff 000000 000000 CREATE TABLE IF NOT EXISTS attean_version (
attean_version VARCHAR(16),
store_version VARCHAR(16),
created DATETIME DEFAULT CURRENT_TIMESTAMP,
updated DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS term (
term_id INTEGER PRIMARY KEY,
type CHAR(7),
datatype_id BIGINT REFERENCES term(term_id),
value LONGTEXT NOT NULL,
language TEXT
);
CREATE UNIQUE INDEX term_idx ON term (type, datatype_id, language, value);
CREATE TABLE IF NOT EXISTS quad (
subject BIGINT NOT NULL REFERENCES term,
predicate BIGINT NOT NULL REFERENCES term,
object BIGINT NOT NULL REFERENCES term,
graph BIGINT NOT NULL REFERENCES term,
PRIMARY KEY (subject, predicate, object, graph)
);
CREATE INDEX quad_pogs_idx ON quad (predicate,object,graph,subject);
CREATE INDEX quad_g ON quad (graph);
AtteanX-Store-DBI-0.003/share/database-schema/PaxHeader/mysql-drop.sql 000644 000765 000024 00000000167 13133671055 025552 x ustar 00greg staff 000000 000000 64 LIBARCHIVE.xattr.com.apple.TextEncoding=VVRGLTg7MTM0MjE3OTg0
55 SCHILY.xattr.com.apple.TextEncoding=UTF-8;134217984
AtteanX-Store-DBI-0.003/share/database-schema/mysql-drop.sql 000644 000765 000024 00000000106 13133671055 023572 0 ustar 00greg staff 000000 000000 DROP TABLE quad;
DROP TABLE term;
DROP TABLE IF EXISTS attean_version; AtteanX-Store-DBI-0.003/share/database-schema/PaxHeader/sqlite-drop.sql 000644 000765 000024 00000000167 13133672072 025706 x ustar 00greg staff 000000 000000 64 LIBARCHIVE.xattr.com.apple.TextEncoding=VVRGLTg7MTM0MjE3OTg0
55 SCHILY.xattr.com.apple.TextEncoding=UTF-8;134217984
AtteanX-Store-DBI-0.003/share/database-schema/sqlite-drop.sql 000644 000765 000024 00000000106 13133672072 023726 0 ustar 00greg staff 000000 000000 DROP TABLE quad;
DROP TABLE term;
DROP TABLE IF EXISTS attean_version; AtteanX-Store-DBI-0.003/share/database-schema/PaxHeader/postgresql-create.sql 000644 000765 000024 00000000167 13133667350 027112 x ustar 00greg staff 000000 000000 64 LIBARCHIVE.xattr.com.apple.TextEncoding=VVRGLTg7MTM0MjE3OTg0
55 SCHILY.xattr.com.apple.TextEncoding=UTF-8;134217984
AtteanX-Store-DBI-0.003/share/database-schema/postgresql-create.sql 000644 000765 000024 00000001502 13133667350 025133 0 ustar 00greg staff 000000 000000 CREATE TABLE IF NOT EXISTS attean_version (
attean_version VARCHAR(16),
store_version VARCHAR(16),
created TIMESTAMP DEFAULT NOW(),
updated TIMESTAMP DEFAULT NOW()
);
CREATE TYPE TERM_TYPE AS ENUM ('iri', 'literal', 'blank');
CREATE TABLE IF NOT EXISTS term (
term_id SERIAL PRIMARY KEY,
type TERM_TYPE,
datatype_id BIGINT REFERENCES term(term_id),
value TEXT NOT NULL,
language TEXT,
UNIQUE (datatype_id, value, language)
);
CREATE TABLE IF NOT EXISTS quad (
subject BIGINT NOT NULL REFERENCES term,
predicate BIGINT NOT NULL REFERENCES term,
object BIGINT NOT NULL REFERENCES term,
graph BIGINT NOT NULL REFERENCES term,
PRIMARY KEY (subject, predicate, object, graph)
);
CREATE INDEX IF NOT EXISTS quad_graph_idx ON quad (graph);
CREATE INDEX IF NOT EXISTS quad_pogs_idx ON quad (predicate,object,graph,subject);
AtteanX-Store-DBI-0.003/lib/Test/ 000755 000765 000024 00000000000 14764061652 016335 5 ustar 00greg staff 000000 000000 AtteanX-Store-DBI-0.003/lib/AtteanX/ 000755 000765 000024 00000000000 14764061652 016762 5 ustar 00greg staff 000000 000000 AtteanX-Store-DBI-0.003/lib/AtteanX/Store/ 000755 000765 000024 00000000000 14764061652 020056 5 ustar 00greg staff 000000 000000 AtteanX-Store-DBI-0.003/lib/AtteanX/Store/PaxHeader/DBI.pm 000644 000765 000024 00000000425 14764061602 022757 x ustar 00greg staff 000000 000000 30 mtime=1741710210.357637604
69 LIBARCHIVE.xattr.com.apple.lastuseddate#PS=BBrHXwAAAABQw6UjAAAAAA
59 SCHILY.xattr.com.apple.lastuseddate#PS=_ På#
64 LIBARCHIVE.xattr.com.apple.TextEncoding=VVRGLTg7MTM0MjE3OTg0
55 SCHILY.xattr.com.apple.TextEncoding=UTF-8;134217984
AtteanX-Store-DBI-0.003/lib/AtteanX/Store/DBI.pm 000644 000765 000024 00000066067 14764061602 021024 0 ustar 00greg staff 000000 000000 =head1 NAME
AtteanX::Store::DBI - Database quad-store
=head1 VERSION
This document describes AtteanX::Store::DBI version 0.003
=head1 SYNOPSIS
use Attean;
my $store = Attean->get_store('DBI')->new( dbh => $dbh );
=head1 DESCRIPTION
AtteanX::Store::DBI provides a quad-store backed by a relational database.
=head1 ATTRIBUTES
=over 4
=item C<< dbh >>
=back
=cut
use utf8;
use v5.14;
use warnings;
package AtteanX::Store::DBI {
our $VERSION = '0.003';
use Moo;
use DBI;
use Attean 0.013;
use DBI::Const::GetInfoType;
use Type::Tiny::Role;
use Types::Standard qw(Int Str ArrayRef HashRef ConsumerOf InstanceOf);
use Encode;
use Cache::LRU;
use Set::Scalar;
use DBIx::MultiStatementDo;
use List::MoreUtils qw(zip);
use List::Util qw(any all first);
use File::ShareDir qw(dist_dir dist_file);
use File::Slurp;
use Scalar::Util qw(refaddr reftype blessed);
use namespace::clean;
with 'Attean::API::MutableQuadStore';
with 'Attean::API::BulkUpdatableStore';
with 'Attean::API::QuadStore';
with 'Attean::API::CostPlanner';
my @pos_names = Attean::API::Quad->variables;
=head1 ROLES
This class consumes L,
L, and L.
=head1 METHODS
=over 4
=item C<< new ( dbh => $dbh ) >>
Returns a new quad-store object backed by the database referenced by the
supplied database handle.
=cut
has dbh => (is => 'ro', isa => InstanceOf['DBI::db'], required => 1);
has _i2t_cache => (is => 'ro', default => sub { Cache::LRU->new( size => 256 ) });
has _t2i_cache => (is => 'ro', default => sub { Cache::LRU->new( size => 256 ) });
=item C<< init() >>
Create the tables and indexes required for using the database as a quadstore.
=cut
sub init {
my $self = shift;
my $dbh = $self->dbh;
my $batch = DBIx::MultiStatementDo->new( dbh => $dbh );
my $file = $self->create_schema_file or die 'No schema files available for store initialization';
my $sql = read_file($file);
$batch->do($sql);
}
=item C<< temporary_store() >>
Returns a temporary (in-memory, SQLite) store.
=cut
sub temporary_store {
my $class = shift;
my $dbh = DBI->connect('dbi:SQLite:dbname=:memory:', '', '');
my $store = $class->new(dbh => $dbh);
$store->init();
return $store;
}
sub _last_insert_id {
my $self = shift;
my $table = shift;
my $dbh = $self->dbh;
return $dbh->last_insert_id(undef, undef, $table, undef);
}
sub _get_term {
my $self = shift;
my $id = shift;
if (my $term = $self->_i2t_cache->get($id)) {
return $term;
}
my $sth = $self->dbh->prepare('SELECT term.type, term.value, dtterm.value AS datatype, term.language FROM term LEFT JOIN term dtterm ON (term.datatype_id = dtterm.term_id) WHERE term.term_id = ?');
$sth->execute($id);
my $row = $sth->fetchrow_hashref;
my $type = $row->{type};
my $term;
my $value = $row->{value};
my $datatype = $row->{datatype};
my $lang = $row->{language};
if ($type eq 'iri') {
$term = Attean::IRI->new( value => $value );
} elsif ($type eq 'blank') {
$term = Attean::Blank->new( value => $value );
} elsif ($type eq 'literal') {
my %args = (value => $value, datatype => Attean::IRI->new(value => $datatype));
if ($lang) {
$args{language} = $lang;
}
$term = Attean::Literal->new( %args );
}
if ($term) {
$self->_i2t_cache->set($id => $term);
return $term;
}
Carp::confess "Failed to load term values for bad ID " . Dumper($id);
}
sub _get_term_id {
my $self = shift;
my $term = shift;
if (my $id = $self->_t2i_cache->get($term->as_string)) {
return $id;
}
my $dbh = $self->dbh;
my $tid;
if ($term->does('Attean::API::IRI')) {
my $sth = $dbh->prepare('SELECT term_id FROM term WHERE type = ? AND value = ?');
my $value = $term->value;
$sth->execute('iri', $value);
($tid) = $sth->fetchrow_array;
} elsif ($term->does('Attean::API::Blank')) {
my $sth = $dbh->prepare('SELECT term_id FROM term WHERE type = ? AND value = ?');
my $value = $term->value;
$sth->execute('blank', $value);
($tid) = $sth->fetchrow_array;
} elsif ($term->does('Attean::API::Literal')) {
my $dtid = $self->_get_or_create_term_id($term->datatype);
my $sth = $dbh->prepare('SELECT term_id FROM term WHERE type = ? AND value = ? AND datatype_id = ? AND language = ?');
my $value = $term->value;
my $lang = $term->language;
$sth->execute('literal', $value, $dtid, $lang);
($tid) = $sth->fetchrow_array;
}
if (defined($tid)) {
$self->_t2i_cache->set($term->as_string => $tid);
return $tid;
}
return;
}
sub _get_or_create_term_id {
my $self = shift;
my $term = shift;
if (my $id = $self->_t2i_cache->get($term->as_string)) {
return $id;
}
my $dbh = $self->dbh;
my $tid;
my $insert_term_sth = $dbh->prepare('INSERT INTO term (type, value, datatype_id, language) VALUES (?, ?, ?, ?)');
if ($term->does('Attean::API::IRI')) {
my $sth = $dbh->prepare('SELECT term_id FROM term WHERE type = ? AND value = ?');
my $value = $term->value;
$sth->execute('iri', $value);
($tid) = $sth->fetchrow_array;
unless (defined($tid)) {
$insert_term_sth->execute('iri', $value, undef, undef);
$tid = $self->_last_insert_id('term');
}
} elsif ($term->does('Attean::API::Blank')) {
my $sth = $dbh->prepare('SELECT term_id FROM term WHERE type = ? AND value = ?');
my $value = $term->value;
$sth->execute('blank', $value);
($tid) = $sth->fetchrow_array;
unless (defined($tid)) {
$insert_term_sth->execute('blank', $value, undef, undef);
$tid = $self->_last_insert_id('term');
}
} elsif ($term->does('Attean::API::Literal')) {
my $dtid = $self->_get_or_create_term_id($term->datatype);
my $sql = 'SELECT term_id FROM term WHERE type = ? AND value = ? AND datatype_id = ?';
my $value = $term->value;
my @bind = ('literal', $value, $dtid);
my $lang = $term->language;
if ($lang) {
$sql .= ' AND language = ?';
push(@bind, $lang);
}
my $sth = $dbh->prepare($sql);
$sth->execute(@bind);
($tid) = $sth->fetchrow_array;
unless (defined($tid)) {
$insert_term_sth->execute('literal', $value, $dtid, $lang);
$tid = $self->_last_insert_id('term');
}
} else {
die "Failed to get ID for term: " . $term->as_string;
}
if (defined($tid)) {
$self->_t2i_cache->set($term->as_string => $tid);
return $tid;
}
die;
}
=item C<< get_quads ( $subject, $predicate, $object, $graph ) >>
Returns a stream object of all statements matching the specified subject,
predicate and objects. Any of the arguments may be undef to match any value,
or an ARRAY reference of terms that are allowable in the respective quad
position.
=cut
sub get_quads {
my $self = shift;
my @nodes = map { ref($_) eq 'ARRAY' ? $_ : [$_] } @_;
my @where;
my @bind;
foreach my $i (0 .. 3) {
my $name = $pos_names[$i];
my $terms = $nodes[$i];
if (defined($terms)) {
unless (scalar(@$terms) == 1 and not defined($terms->[0])) {
unless (any { $_->does('Attean::API::Variable') } @$terms) {
my @ids = map { $self->_get_term_id($_) } @$terms;
unless (scalar(@ids)) {
return Attean::ListIterator->new( values => [], item_type => 'Attean::API::Quad' );
}
push(@where, "$name IN (" . join(', ', ('?') x scalar(@ids)) . ")");
push(@bind, @ids);
}
}
}
}
my $sql = 'SELECT subject, predicate, object, graph FROM quad';
if (scalar(@where)) {
$sql .= ' WHERE ' . join(' AND ', @where);
}
my $sth = $self->dbh->prepare($sql);
$sth->execute(@bind);
my $ok = 1;
my $sub = sub {
return unless ($ok);
if (my $row = $sth->fetchrow_arrayref) {
my @terms = map { $self->_get_term($_) } @$row;
my $quad = Attean::Quad->new(zip @pos_names, @terms);
return $quad;
}
$ok = 0;
return;
};
my $iter = Attean::CodeIterator->new( generator => $sub, item_type => 'Attean::API::Quad' );
return $iter;
}
=item C<< count_quads ( $subject, $predicate, $object, $graph ) >>
Returns the count of all statements matching the specified subject,
predicate and objects. Any of the arguments may be undef to match any value,
or an ARRAY reference of terms that are allowable in the respective quad
position.
=cut
sub count_quads {
my $self = shift;
my @nodes = map { ref($_) eq 'ARRAY' ? $_ : [$_] } @_;
my @where;
my @bind;
foreach my $i (0 .. 3) {
my $name = $pos_names[$i];
my $terms = $nodes[$i];
if (defined($terms)) {
unless (scalar(@$terms) == 1 and not defined($terms->[0])) {
unless (any { $_->does('Attean::API::Variable') } @$terms) {
my @ids = map { $self->_get_term_id($_) } @$terms;
return 0 unless scalar(@ids);
push(@where, "$name IN (" . join(', ', ('?') x scalar(@ids)) . ")");
push(@bind, @ids);
}
}
}
}
my $sql = 'SELECT COUNT(*) FROM quad';
if (scalar(@where)) {
$sql .= ' WHERE ' . join(' AND ', @where);
}
my $sth = $self->dbh->prepare($sql);
$sth->execute(@bind);
my ($count) = $sth->fetchrow_array;
return $count;
}
=item C<< get_graphs >>
Returns an iterator over the Attean::API::Term objects comprising
the set of graphs of the stored quads.
=cut
sub get_graphs {
my $self = shift;
my $sth = $self->dbh->prepare('SELECT DISTINCT value FROM quad JOIN term ON (quad.graph = term.term_id)');
$sth->execute;
my $sub = sub {
my $row = $sth->fetchrow_arrayref;
return unless ref($row);
my ($value) = @$row;
return Attean::IRI->new(value => $value);
};
return Attean::CodeIterator->new( generator => $sub, item_type => 'Attean::API::Term' );
}
# -----------------------------------------------------------------------------
=item C<< add_quad ( $quad ) >>
Adds the specified C<$quad> to the underlying model.
=cut
sub add_quad {
my $self = shift;
my $st = shift;
my @ids = map { $self->_get_or_create_term_id($_) } $st->values;
if (any { not defined($_) } @ids) {
return;
}
my $type = $self->database_type;
my @bind = @ids;
my $sql = 'INSERT INTO quad (subject, predicate, object, graph) VALUES (?, ?, ?, ?)';
if ($type eq 'sqlite') {
$sql = 'INSERT OR IGNORE INTO quad (subject, predicate, object, graph) VALUES (?, ?, ?, ?)';
} elsif ($type eq 'mysql') {
$sql = 'INSERT IGNORE INTO quad (subject, predicate, object, graph) VALUES (?, ?, ?, ?)';
} elsif ($type eq 'postgresql') {
$sql = 'INSERT INTO quad (subject, predicate, object, graph) SELECT ?, ?, ?, ? WHERE NOT EXISTS (SELECT 1 FROM quad WHERE subject = ? AND predicate = ? AND object = ? AND graph = ?)';
push(@bind, @ids);
}
my $sth = $self->dbh->prepare($sql);
$sth->execute(@bind);
return;
}
=item C<< remove_quad ( $statement ) >>
Removes the specified C<$statement> from the underlying model.
=cut
sub remove_quad {
my $self = shift;
my $st = shift;
my @ids = map { $self->_get_term_id($_) } $st->values;
unless (scalar(@ids) == 4) {
return;
}
unless (all { defined($_) } @ids) {
return;
}
my $sth = $self->dbh->prepare('DELETE FROM quad WHERE subject = ? AND predicate = ? AND object = ? AND graph = ?');
$sth->execute(@ids);
return;
}
=item C<< create_graph( $graph ) >>
This is a no-op function for the memory quad-store.
=cut
sub create_graph {
# no-op on a quad-store
}
=item C<< drop_graph( $graph ) >>
Removes all quads with the given C<< $graph >>.
=cut
sub drop_graph {
my $self = shift;
return $self->clear_graph(@_);
}
=item C<< clear_graph( $graph ) >>
Removes all quads with the given C<< $graph >>.
=cut
sub clear_graph {
my $self = shift;
my $graph = shift;
my $gid = $self->_get_term_id($graph);
return unless defined($gid);
my $sth = $self->dbh->prepare('DELETE FROM quad WHERE graph = ?');
$sth->execute($gid);
return;
}
=item C<< begin_transaction >>
Begin a database transaction.
=cut
sub begin_transaction {
# warn 'begin transaction';
my $self = shift;
$self->dbh->begin_work;
}
=item C<< abort_transaction >>
Rollback the current database transaction.
=cut
sub abort_transaction {
# warn 'abort transaction';
my $self = shift;
$self->dbh->rollback;
}
=item C<< end_transaction >>
Commit the current database transaction.
=cut
sub end_transaction {
# warn 'end transaction';
my $self = shift;
$self->dbh->commit;
}
=item C<< begin_bulk_updates >>
Begin a database transaction.
=cut
sub begin_bulk_updates {
my $self = shift;
$self->dbh->begin_work;
}
=item C<< end_bulk_updates >>
Commit the current database transaction.
=cut
sub end_bulk_updates {
my $self = shift;
$self->dbh->commit;
}
=item C<< database_type >>
Returns the database type name as a string (e.g. 'mysql', 'sqlite', or 'postgresql').
=cut
sub database_type {
my $self = shift;
my $dbh = $self->dbh;
# warn $dbh->get_info($GetInfoType{SQL_DRIVER_NAME});
my $type = lc($dbh->get_info($GetInfoType{SQL_DBMS_NAME}));
return $type;
}
=item C<< initialize_version >>
Insert data into the attean_version table.
=cut
sub initialize_version {
my $self = shift;
my $dbh = $self->dbh;
$dbh->do('DELETE FROM attean_version');
my $sql = 'INSERT INTO attean_version (attean_version, store_version) VALUES (?, ?);';
$dbh->do($sql, undef, $Attean::VERSION, $AtteanX::Store::DBI::VERSION);
}
=item C<< create_schema_file >>
Returns the path to the file containing the database DDL for quadstore creation
for the current database type if available, undef otherwise.
=cut
sub create_schema_file {
my $self = shift;
my $type = $self->database_type;
my $dir = $ENV{ATTEAN_SHAREDIR} || eval { dist_dir('AtteanX-Store-DBI') } || 'share';
my $file = File::Spec->catfile($dir, 'database-schema', sprintf('%s-create.sql', $type));
if (-r $file) {
return $file;
}
return;
}
=item C<< drop_schema_file >>
Returns the path to the file containing the database DDL for quadstore deletion
for the current database type if available, undef otherwise.
=cut
sub drop_schema_file {
my $self = shift;
my $type = $self->database_type;
my $dir = $ENV{ATTEAN_SHAREDIR} || eval { dist_dir('AtteanX-Store-DBI') } || 'share';
my $file = File::Spec->catfile($dir, 'database-schema', sprintf('%s-drop.sql', $type));
if (-r $file) {
return $file;
}
return;
}
=item C<< available_database_types >>
Returns the names of the database types for which the system has schemas
available to create and drop quadstore tables.
=cut
sub available_database_types {
my $self = shift;
my $dir = $ENV{ATTEAN_SHAREDIR} || eval { dist_dir('AtteanX-Store-DBI') } || 'share';
my $pat = File::Spec->catfile($dir, 'database-schema', '*-create.sql');
my @files = glob($pat);
my @types = map { /(\w+)-create.sql/ } @files;
return @types;
}
=item C<< dbi_connect_args ( $type, %args ) >>
=item C<< dbi_connect_args ( %args ) >>
Returns a quad C<< $dsn, $user, $password, \%connect_args >> suitable for
passing to C<< DBI->connect >> to obtain a database handle to be used in
constructing a C<< AtteanX::Store::DBI >> quadstore.
C<< %args >> must contain a value for the C<< database >> key. It may also
contain values for the optional keys: C<< user >>, C<< password >>,
C<< host >>, and C<< port >>.
If invoked as a class method, the C<< $type >> parameter is required, and must
be one of the database types returned by C<< available_database_types >>.
If invoked as an object method, the C<< $type >> parameter must not be
included; this information will be obtained directly from the
C<< AtteanX::Store::DBI >> object.
=cut
sub dbi_connect_args {
my $self = shift;
my $type = blessed($self) ? $self->database_type : shift;
my %args = @_;
my $database = $args{database};
my $user = $args{user};
my $password = $args{password};
my $host = $args{host};
my $port = $args{port};
my $dsn;
my %connect_args;
$connect_args{RaiseError} = 1;
if ($type eq 'mysql') {
$dsn = "DBI:mysql:database=${database}";
if (defined($host)) {
$dsn .= ";host=$host";
}
if (defined($port)) {
$dsn .= ";port=$port";
}
$connect_args{mysql_enable_utf8} = 1;
} elsif ($type eq 'postgresql') {
$dsn = "DBI:Pg:dbname=${database}";
if (defined($host)) {
$dsn .= ";host=$host";
}
if (defined($port)) {
$dsn .= ";port=$port";
}
} elsif ($type eq 'sqlite') {
$dsn = "DBI:SQLite:dbname=${database}";
$connect_args{sqlite_unicode} = 1;
}
return ($dsn, $user, $password, \%connect_args);
}
=item C<< plans_for_algebra( $algebra, $model, $active_graphs, $default_graphs ) >>
For BGP algebras, returns a DBI-specific L object, otherwise
returns undef.
=cut
sub plans_for_algebra {
my $self = shift;
my $algebra = shift;
my $model = shift;
my $active_graphs = shift;
my $default_graphs = shift;
return unless ($algebra);
my %args = @_;
my $counter = $args{dbi_filter_counter}++;
if ($algebra->isa('Attean::Algebra::Filter')) {
my $e = $algebra->expression;
if ($e->isa('Attean::FunctionExpression')) {
if ($e->operator =~ m/IS(IRI|LITERAL|BLANK)/i) {
my $type = lc($1);
my ($operand) = @{ $e->children };
if ($operand->isa('Attean::ValueExpression') and $operand->value->does('Attean::API::Variable')) {
my $var = $operand->value;
if (my ($plan) = $self->plans_for_algebra($algebra->child, $model, $active_graphs, $default_graphs, %args)) {
if ($plan->isa('AtteanX::Store::DBI::Plan')) {
if (exists $plan->variables->{ $var->value }) {
my ($table, $col) = @{ $plan->variables->{ $var->value } };
my $ref = join('.', map { $self->dbh->quote_identifier($_) } ($table, $col));
my $typecol = $self->dbh->quote_identifier('type');
push(@{ $plan->where }, "$ref IN (SELECT term_id FROM term WHERE ${typecol} = ?)");
push(@{ $plan->bindings }, $type);
return $plan;
}
}
}
}
} elsif ($e->operator eq 'STRSTARTS' or $e->operator eq 'CONTAINS') {
my ($varexpr, $pat) = @{ $e->children };
if ($varexpr->isa('Attean::ValueExpression') and $varexpr->value->does('Attean::API::Variable') and $pat->isa('Attean::ValueExpression') and $pat->value->does('Attean::API::Literal')) {
if (my ($plan) = $self->plans_for_algebra($algebra->child, $model, $active_graphs, $default_graphs, %args)) {
if ($plan->isa('AtteanX::Store::DBI::Plan')) {
my $var = $varexpr->value;
my $varname = $var->value;
if (exists $plan->variables->{ $var->value }) {
my ($table, $col) = @{ $plan->variables->{ $var->value } };
my $literal = $pat->value;
my $ref = join('.', map { $self->dbh->quote_identifier($_) } ($table, $col));
my $typecol = $self->dbh->quote_identifier('type');
my $termtable = "tf$counter";
push(@{ $plan->tables }, ['term', $termtable]);
my $db = $self->database_type;
return unless ($db eq 'mysql' or $db eq 'postgresql' or $db eq 'sqlite');
push(@{ $plan->where }, "$ref = $termtable.term_id");
push(@{ $plan->where }, "$termtable.$typecol = ?"); # TODO: Remove this (and the bindings below) if $varexpr is STR(?var) instead of just ?var.
my $op = ($e->operator eq 'STRSTARTS') ? '=' : '>=';
if ($db eq 'mysql') {
push(@{ $plan->where }, "LOCATE(?, $termtable.value) ${op} ?");
push(@{ $plan->bindings }, 'literal');
push(@{ $plan->bindings }, $literal->value);
push(@{ $plan->bindings }, 1);
} elsif ($db eq 'postgresql') {
push(@{ $plan->where }, "STRPOS($termtable.value, ?) ${op} ?");
push(@{ $plan->bindings }, 'literal');
push(@{ $plan->bindings }, $literal->value);
push(@{ $plan->bindings }, 1);
} elsif ($db eq 'sqlite') {
push(@{ $plan->where }, "INSTR($termtable.value, ?) ${op} 1");
push(@{ $plan->bindings }, 'literal');
push(@{ $plan->bindings }, $literal->value);
}
if (my $lang = $literal->language) {
push(@{ $plan->where }, "$termtable.language = ?");
push(@{ $plan->bindings }, $lang);
} else {
my $xs = Attean::IRI->new( value => 'http://www.w3.org/2001/XMLSchema#string' );
my $la = Attean::IRI->new( value => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString' );
my $xid = $self->_get_term_id($xs);
my $lid = $self->_get_term_id($la);
push(@{ $plan->where }, "$termtable.datatype_id IN (?, ?)");
push(@{ $plan->bindings }, $xid, $lid);
}
return $plan;
}
}
}
}
}
}
} elsif ($algebra->isa('Attean::Algebra::BGP') and scalar(@{ $algebra->triples }) > 0) {
my @vars = $algebra->in_scope_variables;
my @triples = @{ $algebra->triples };
my @select;
my @where_joins;
my %seen_vars;
my %source_table_for_var;
my %blanks;
my $tcounter = 0;
my $bcounter = 0;
my @tables;
my %rename_mapping;
my $rename_proj = sub {
my $name = shift;
if ($name =~ /[-._]|\W/) {
my $old = $name;
$name =~ s/_/__/g;
$name =~ s/([-.]|\W)/_d/g;
$name =~ s/([-.]|\W)/'_x' . sprintf('%02x', ord($1))/e;
$rename_mapping{$old} = $name;
}
return $name;
};
Carp::confess Dumper($active_graphs) unless (ref($active_graphs) eq 'ARRAY');
my @graph_ids = map { $self->_get_term_id($_) } @{ $active_graphs };
if (any { not defined($_) } @graph_ids) {
return;
}
my @bind;
my $graph = Attean::Variable->new(value => '___g');
$seen_vars{ $graph->value }++;
my $graph_values = sprintf('(%s)', join(', ', ('?') x scalar(@graph_ids)));
push(@bind, @graph_ids);
my @where = ("t0.graph IN $graph_values");
foreach my $t (@triples) {
my $table = 't' . $tcounter++;
push(@tables, ['quad', $table]);
my @vars;
my $q = $t->as_quadpattern($graph);
my @nodes = $q->values;
foreach my $i (0 .. $#nodes) {
my $node = $nodes[$i];
my $name = $pos_names[$i];
if ($node->does('Attean::API::Variable')) {
my $var = $node;
push(@vars, [$var, $name]);
} elsif ($node->does('Attean::API::Blank')) {
my $id = $node->value;
unless (exists $blanks{$id}) {
my $bname = sprintf('.%s_%d', 'blank', $bcounter++);
$blanks{$id} = Attean::Variable->new(value => $bname);
}
my $var = $blanks{$id};
push(@vars, [$var, $name]);
$seen_vars{ $var->value }++;
} else {
my $id = $self->_get_term_id($node);
return unless defined($id);
push(@where, sprintf('%s.%s = ?', $table, $name));
push(@bind, $id);
}
}
foreach my $vdata (@vars) {
my ($var, $name) = @$vdata;
my $var_name = $rename_proj->( $var->value );
push(@select, [$table, $name, $var_name]) unless ($seen_vars{$var->value}++);
if (my $tt = $source_table_for_var{ $var->value }) {
push(@where_joins, ['=', $tt, [$table, $name]]);
} else {
$source_table_for_var{ $var->value } = [$table, $name];
}
}
}
foreach my $w (@where_joins) {
my ($op, $a, $b) = @$w;
my ($as, $bs) = map { sprintf('%s.%s', @$_) } ($a, $b);
push(@where, join(' ', $as, $op, $bs));
}
return AtteanX::Store::DBI::Plan->new(
store => $self,
select => \@select,
where => \@where,
tables => \@tables,
in_scope_variables => [@vars],
rename_mapping => \%rename_mapping,
bindings => \@bind,
variables => \%source_table_for_var,
);
}
return;
}
=item C<< cost_for_plan( $plan ) >>
Returns the estimated cost for a DBI-specific query plan, undef otherwise.
=cut
sub cost_for_plan {
my $self = shift;
my $plan = shift;
if ($plan->isa('AtteanX::Store::DBI::Plan')) {
return 1; # TODO: actually estimate cost here
}
return;
}
}
package AtteanX::Store::DBI::Plan 0.012 {
use Moo;
use Type::Tiny::Role;
use Types::Standard qw(HashRef ArrayRef InstanceOf Str);
use namespace::clean;
has store => (is => 'ro', isa => InstanceOf['AtteanX::Store::DBI'], required => 1);
has rename_mapping => (is => 'ro', isa => HashRef[Str], default => sub { +{} });
has variables => (is => 'ro', isa => HashRef, required => 1);
has bindings => (is => 'ro', isa => ArrayRef, required => 1);
has select => (is => 'ro', isa => ArrayRef, required => 1);
has where => (is => 'ro', isa => ArrayRef, required => 1);
has tables => (is => 'ro', isa => ArrayRef[ArrayRef[Str]], required => 1);
with 'Attean::API::BindingSubstitutionPlan', 'Attean::API::NullaryQueryTree';
sub plan_as_string {
my $self = shift;
my ($sql, @bind) = $self->sql();
return sprintf('DBI BGP { %s ← (%s) }', $sql, join(', ', @bind));
}
sub sql {
my $self = shift;
my $bind = shift;
my $store = $self->store;
my $dbh = $store->dbh;
my @bind = @{ $self->bindings };
my @where = @{ $self->where };
if ($bind) {
foreach my $var ($bind->variables) {
my $id = $store->_get_term_id($bind->value($var));
return unless defined($id);
if (my $cdata = $self->variables->{ $var }) {
my ($table, $col) = @$cdata;
push(@where, sprintf("%s.%s = ?", $table, $col));
push(@bind, $id);
}
}
}
my @select = map { sprintf("%s.%s AS %s", map { $dbh->quote_identifier( $_ ) } @$_) } @{ $self->select };
unless (scalar(@select)) {
push(@select, '1');
}
my @sql;
push(@sql, 'SELECT');
push(@sql, join(', ', @select));
push(@sql, 'FROM');
push(@sql, join(', ', map { join(' ', @$_) } @{ $self->tables }));
if (scalar(@where)) {
push(@sql, 'WHERE');
push(@sql, join(' AND ', map { "($_)" } @where));
}
my $sql = join(" ", @sql);
return ($sql, @bind);
}
sub substitute_impl {
my $self = shift;
my $model = shift;
my ($sql, @bind) = $self->sql(@_);
my $store = $self->store;
my $dbh = $store->dbh;
# warn "TODO: generatee SQL for BGP: $sql\n";
# warn "======================================================================\n";
# warn "$sql\n";
# warn "======================================================================\n";
my $vars = $self->in_scope_variables;
my $sth = $dbh->prepare($sql);
return sub {
# warn "Generating impl by executing SQL";
my $rv = $sth->execute(@bind);
unless ($rv) {
warn '*** SQL error: ' . $sth->errstr;
die;
}
my $sub = sub {
# warn '=== Iterator invoked';
# use Data::Dumper;
# warn Dumper($sql, \@bind);
if (my $row = $sth->fetchrow_hashref) {
# warn '@@@ Iterator got row';
# warn Dumper($row);
my %bindings;
foreach my $k (@$vars) {
my $key = $self->rename_mapping->{$k} // $k;
my $term = $store->_get_term($row->{$key});
$bindings{$k} = $term;
}
my $r = Attean::Result->new( bindings => \%bindings );
return $r;
} else {
# warn '^^^ Reached end-of-iterator'
}
return;
};
return Attean::CodeIterator->new( generator => $sub, item_type => 'Attean::API::Result', variables => $vars );
};
}
}
1;
__END__
=back
=head1 BUGS
Please report any bugs or feature requests to through the GitHub web interface
at L.
=head1 AUTHOR
Gregory Todd Williams C<< >>
=head1 COPYRIGHT
Copyright (c) 2014--2020 Gregory Todd Williams. This
program is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.
=cut
AtteanX-Store-DBI-0.003/lib/Test/AtteanX/ 000755 000765 000024 00000000000 14764061652 017701 5 ustar 00greg staff 000000 000000 AtteanX-Store-DBI-0.003/lib/Test/AtteanX/Store/ 000755 000765 000024 00000000000 14764061652 020775 5 ustar 00greg staff 000000 000000 AtteanX-Store-DBI-0.003/lib/Test/AtteanX/Store/PaxHeader/DBI.pm 000644 000765 000024 00000000225 14763417346 023705 x ustar 00greg staff 000000 000000 30 mtime=1741561574.496052784
64 LIBARCHIVE.xattr.com.apple.TextEncoding=VVRGLTg7MTM0MjE3OTg0
55 SCHILY.xattr.com.apple.TextEncoding=UTF-8;134217984
AtteanX-Store-DBI-0.003/lib/Test/AtteanX/Store/DBI.pm 000644 000765 000024 00000012354 14763417346 021742 0 ustar 00greg staff 000000 000000 package Test::AtteanX::Store::DBI;
use utf8;
use v5.14;
use warnings;
use Data::Dumper;
use Test::Roo::Role;
use Test::Moose;
use Attean;
use Attean::RDF;
requires 'create_store'; # create_store( quads => \@triples )
sub test_quads {
my @q;
for my $i (0 .. 5) {
push(@q, quad(iri('s'), iri('p'), literal($i), iri('g')));
push(@q, quad(iri('s'), iri('p'), blank("b$i"), iri('g')));
}
my @strings;
push(@strings, literal('Hi'));
push(@strings, langliteral('Hello', 'en'));
push(@strings, langliteral('火星', 'ja'));
push(@strings, dtliteral(787, 'http://www.w3.org/2001/XMLSchema#integer'));
foreach my $s (@strings) {
push(@q, quad(iri('s'), iri('str'), $s, iri('strings')));
}
return \@q;
}
test 'ISLITERAL type constraint SARG' => sub {
my $self = shift;
my $store = $self->create_store(quads => $self->test_quads);
my $model = Attean::QuadModel->new( store => $store );
my $dbh = $store->dbh;
my $typecol = $dbh->quote_identifier('type');
my $algebra = Attean->get_parser('SPARQL')->parse('SELECT * WHERE { ?s ?p ?o FILTER ISLITERAL(?o) }');
my $default_graphs = [iri('g')];
my $planner = Attean::IDPQueryPlanner->new();
my $plan = $planner->plan_for_algebra($algebra, $model, $default_graphs);
isa_ok($plan, 'AtteanX::Store::DBI::Plan');
my ($sql, @bind) = $plan->sql;
like($sql, qr