line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
RDF::Trine::Store::DBI::Pg - PostgreSQL subclass of DBI store |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 VERSION |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
This document describes RDF::Trine::Store::DBI::Pg version 1.017 |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use RDF::Trine::Store::DBI::Pg; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package RDF::Trine::Store::DBI::Pg; |
18
|
|
|
|
|
|
|
|
19
|
68
|
|
|
68
|
|
435
|
use strict; |
|
68
|
|
|
|
|
161
|
|
|
68
|
|
|
|
|
1702
|
|
20
|
68
|
|
|
68
|
|
318
|
use warnings; |
|
68
|
|
|
|
|
147
|
|
|
68
|
|
|
|
|
1529
|
|
21
|
68
|
|
|
68
|
|
317
|
no warnings 'redefine'; |
|
68
|
|
|
|
|
148
|
|
|
68
|
|
|
|
|
1854
|
|
22
|
68
|
|
|
68
|
|
361
|
use base qw(RDF::Trine::Store::DBI); |
|
68
|
|
|
|
|
144
|
|
|
68
|
|
|
|
|
4539
|
|
23
|
|
|
|
|
|
|
|
24
|
68
|
|
|
68
|
|
415
|
use Scalar::Util qw(blessed reftype refaddr); |
|
68
|
|
|
|
|
164
|
|
|
68
|
|
|
|
|
5207
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $VERSION; |
27
|
|
|
|
|
|
|
BEGIN { |
28
|
68
|
|
|
68
|
|
243
|
$VERSION = "1.017"; |
29
|
68
|
|
|
|
|
153
|
my $class = __PACKAGE__; |
30
|
68
|
|
|
|
|
23624
|
$RDF::Trine::Store::STORE_CLASSES{ $class } = $VERSION; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _config_meta { |
34
|
|
|
|
|
|
|
return { |
35
|
0
|
|
|
0
|
|
|
required_keys => [qw(dsn username password name)], |
36
|
|
|
|
|
|
|
fields => { |
37
|
|
|
|
|
|
|
name => { description => 'Model Name', type => 'string' }, |
38
|
|
|
|
|
|
|
dsn => { description => 'DSN', type => 'string', template => 'DBI:Pg:dbname=[%database%]' }, |
39
|
|
|
|
|
|
|
database => { description => 'Database Name', type => 'string' }, |
40
|
|
|
|
|
|
|
username => { description => 'Username', type => 'string' }, |
41
|
|
|
|
|
|
|
password => { description => 'Password', type => 'password' }, |
42
|
|
|
|
|
|
|
driver => { description => 'Driver', type => 'string', value => 'Pg' }, |
43
|
|
|
|
|
|
|
}, |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 METHODS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Beyond the methods documented below, this class inherits methods from the |
50
|
|
|
|
|
|
|
L<RDF::Trine::Store::DBI> class. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=over 4 |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item C<< new_with_config ( \%config ) >> |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Returns a new RDF::Trine::Store object based on the supplied configuration hashref. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub new_with_config { |
63
|
0
|
|
|
0
|
1
|
|
my $proto = shift; |
64
|
0
|
|
|
|
|
|
my $config = shift; |
65
|
0
|
|
|
|
|
|
$config->{storetype} = 'DBI::Pg'; |
66
|
0
|
|
|
|
|
|
return $proto->SUPER::new_with_config( $config ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _column_name { |
70
|
0
|
|
|
0
|
|
|
my $self = shift; |
71
|
0
|
|
|
|
|
|
my @args = @_; |
72
|
0
|
|
|
|
|
|
my $col = lc(join('_', @args)); |
73
|
0
|
|
|
|
|
|
return $col; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item C<< init >> |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Creates the necessary tables in the underlying database. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub init { |
83
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
84
|
0
|
|
|
|
|
|
my $dbh = $self->dbh; |
85
|
0
|
|
|
|
|
|
my $name = $self->model_name; |
86
|
0
|
|
|
|
|
|
my $id = RDF::Trine::Store::DBI::_mysql_hash( $name ); |
87
|
0
|
|
|
|
|
|
my $l = Log::Log4perl->get_logger("rdf.trine.store.dbi"); |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
local($dbh->{AutoCommit}) = 0; |
90
|
0
|
0
|
|
|
|
|
unless ($self->_table_exists("literals")) { |
91
|
0
|
0
|
|
|
|
|
$dbh->do( <<"END" ) || do { $l->trace( $dbh->errstr ); $dbh->rollback; return }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
CREATE TABLE literals ( |
93
|
|
|
|
|
|
|
ID NUMERIC(20) PRIMARY KEY, |
94
|
|
|
|
|
|
|
Value text NOT NULL, |
95
|
|
|
|
|
|
|
Language text NOT NULL DEFAULT '', |
96
|
|
|
|
|
|
|
Datatype text NOT NULL DEFAULT '' |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
END |
99
|
0
|
0
|
|
|
|
|
$dbh->do( <<"END" ) || do { $l->trace( $dbh->errstr ); $dbh->rollback; return }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
CREATE TABLE resources ( |
101
|
|
|
|
|
|
|
ID NUMERIC(20) PRIMARY KEY, |
102
|
|
|
|
|
|
|
URI text NOT NULL |
103
|
|
|
|
|
|
|
); |
104
|
|
|
|
|
|
|
END |
105
|
0
|
0
|
|
|
|
|
$dbh->do( <<"END" ) || do { $l->trace( $dbh->errstr ); $dbh->rollback; return }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
CREATE TABLE bnodes ( |
107
|
|
|
|
|
|
|
ID NUMERIC(20) PRIMARY KEY, |
108
|
|
|
|
|
|
|
Name text NOT NULL |
109
|
|
|
|
|
|
|
); |
110
|
|
|
|
|
|
|
END |
111
|
0
|
0
|
|
|
|
|
$dbh->do( <<"END" ) || do { $l->trace( $dbh->errstr ); $dbh->rollback; return }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
CREATE TABLE models ( |
113
|
|
|
|
|
|
|
ID NUMERIC(20) PRIMARY KEY, |
114
|
|
|
|
|
|
|
Name text NOT NULL |
115
|
|
|
|
|
|
|
); |
116
|
|
|
|
|
|
|
END |
117
|
|
|
|
|
|
|
|
118
|
0
|
0
|
|
|
|
|
$dbh->commit or warn $dbh->errstr; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
0
|
0
|
|
|
|
|
unless ($self->_table_exists("statements${id}")) { |
122
|
0
|
0
|
|
|
|
|
$dbh->do( <<"END" ) || do { $l->trace( $dbh->errstr ); return }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
CREATE TABLE statements${id} ( |
124
|
|
|
|
|
|
|
Subject NUMERIC(20) NOT NULL, |
125
|
|
|
|
|
|
|
Predicate NUMERIC(20) NOT NULL, |
126
|
|
|
|
|
|
|
Object NUMERIC(20) NOT NULL, |
127
|
|
|
|
|
|
|
Context NUMERIC(20) NOT NULL DEFAULT 0, |
128
|
|
|
|
|
|
|
PRIMARY KEY (Subject, Predicate, Object, Context) |
129
|
|
|
|
|
|
|
); |
130
|
|
|
|
|
|
|
END |
131
|
|
|
|
|
|
|
# $dbh->do( "DELETE FROM Models WHERE ID = ${id}") || do { $l->trace( $dbh->errstr ); $dbh->rollback; return }; |
132
|
0
|
|
|
|
|
|
$dbh->do( "INSERT INTO Models (ID, Name) VALUES (${id}, ?)", undef, $name ); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
139
|
|
|
|
|
|
|
__END__ |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=back |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 BUGS |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Please report any bugs or feature requests to through the GitHub web interface |
146
|
|
|
|
|
|
|
at L<https://github.com/kasei/perlrdf/issues>. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 AUTHOR |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Gregory Todd Williams C<< <gwilliams@cpan.org> >> |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 COPYRIGHT |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Copyright (c) 2006-2012 Gregory Todd Williams. This |
155
|
|
|
|
|
|
|
program is free software; you can redistribute it and/or modify it under |
156
|
|
|
|
|
|
|
the same terms as Perl itself. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=cut |