-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrdfdb.query_4store.inc
85 lines (73 loc) · 2.39 KB
/
rdfdb.query_4store.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* @file
* Query code for 4store engine.
*/
class RdfdbInsertDataQuery_4store extends RdfdbInsertDataQuery {
/**
* Executes the insert data query.
*
* @return
* The number of inserted triples, or FALSE is there were errors.
*/
public function execute() {
// If validation fails, simply return NULL.
// Note that validation routines in preExecute() may throw exceptions instead.
if (!$this->preExecute()) {
return NULL;
}
// In this case, the query is just the triples in turtle format.
$query = $this->triples;
$this->queryOptions['graph'] = $this->graph;
return $this->connection->query_insert($query, $this->queryOptions);
}
}
class RdfdbDeleteDataQuery_4store extends RdfdbDeleteDataQuery {
/**
* Executes the delete data query.
*
* @return
* The number of deleted triples, or FALSE is there were errors.
*/
public function execute() {
// If validation fails, simply return NULL.
// Note that validation routines in preExecute() may throw exceptions instead.
if (!$this->preExecute()) {
return NULL;
}
$query = $this->toString();
$this->connection->query($query, $this->queryOptions);
}
public function toString() {
// Serializes prefixes in prologue if they are given. Otherwise 4store will
// use the prefixes which were defined during the remote endpoint setup.
$prologue = $this->preparePrefixes();
if (!empty($this->graph)) {
return $prologue . 'DELETE FROM <' . $this->graph . '> { ' . $this->triples . ' }';
}
else {
return $prologue . 'DELETE { ' . $this->triples . ' }';
}
}
}
class RdfdbClearQuery_4store extends RdfdbClearQuery {
// This method only exist because of the zombie triples bug in 4store
// @todo remove once this bug has been fixed.
public function execute() {
// If validation fails, simply return NULL.
// Note that validation routines in preExecute() may throw exceptions instead.
if (!$this->preExecute()) {
return NULL;
}
// Deletes the graphs one by one.
if (empty($this->graph)) {
$rs = rdfdb_select('DISTINCT ?g')->where('GRAPH ?g { ?s ?p ?o . } ')->execute();
foreach ($rs['result']['rows'] as $row) {
rdfdb_clear($row['g'])->execute();
}
return;
}
$query = $this->graph;
return $this->connection->query_clear($query, $this->queryOptions);
}
}