6 * A synchronous query executor
8 class Executor
implements ExecutorInterface
16 * @var \SplObjectStorage
21 * @var \pq\Query\WriterInterface
31 * Create a synchronous query executor
32 * @param \pq\Connection $conn
34 function __construct(\pq\Connection
$conn) {
36 $this->observers
= new \SplObjectStorage
;
41 * @return \pq\Connection
43 function getConnection() {
49 * @param \pq\Connection $conn
50 * @return \pq\Query\Executor
52 function setConnection(\pq\Connection
$conn) {
59 * @return WriterInterface
69 function getResult() {
74 * Execute the query synchronously through \pq\Connection::execParams()
75 * @param \pq\Query\WriterInterface $query
76 * @param callable $callback
79 function execute(WriterInterface
$query, callable
$callback) {
81 $this->query
= $query;
83 $this->result
= $this->getConnection()->execParams($query, $query->getParams(), $query->getTypes());
85 return $callback($this->result
);
89 * @implements \SplSubject
90 * @param \SplObserver $observer
92 function attach(\SplObserver
$observer) {
93 $this->observers
->attach($observer);
97 * @implements \SplSubject
98 * @param \SplObserver $observer
100 function detach(\SplObserver
$observer) {
101 $this->observers
->detach($observer);
105 * @implements \SplSubject
108 foreach ($this->observers
as $observer){
109 $observer->update($this);