@@ -41,7 +41,8 @@ |
||
41 | 41 | }); |
42 | 42 | $trans->execute('insert into demo default values') |
43 | 43 | ->then(function (CommandResult $result) use ($trans) { |
44 | - if ($result->getAffectedRows() > 0) { |
|
44 | + if ($result->getAffectedRows() > 0) |
|
45 | + { |
|
45 | 46 | $trans->rollback(); |
46 | 47 | } |
47 | 48 | }); |
@@ -136,7 +136,8 @@ discard block |
||
136 | 136 | $this->connector = new Connector($this->config); |
137 | 137 | $this->state = self::STATE_CONNECT_PENDING; |
138 | 138 | $promise = $this->connector->getConnection(); |
139 | - if (!($sock = $this->connector->getSock())) { |
|
139 | + if (!($sock = $this->connector->getSock())) |
|
140 | + { |
|
140 | 141 | return $promise->reject(new Exception('No server connection is currently open')); |
141 | 142 | } |
142 | 143 | $this->loop->addReadStream($sock, [$this->connector, 'connect']); |
@@ -197,7 +198,8 @@ discard block |
||
197 | 198 | */ |
198 | 199 | public function beginTransaction() |
199 | 200 | { |
200 | - if ($this->isStarted()) { |
|
201 | + if ($this->isStarted()) |
|
202 | + { |
|
201 | 203 | $trans = new Transaction($this->connector, $this); |
202 | 204 | |
203 | 205 | return Promise::doResolve($trans); |
@@ -247,8 +249,10 @@ discard block |
||
247 | 249 | 'dbname' => '', |
248 | 250 | ]; |
249 | 251 | $config = array_merge($default, $config); |
250 | - foreach ($config as $key => &$value) { |
|
251 | - if (!$value) { |
|
252 | + foreach ($config as $key => &$value) |
|
253 | + { |
|
254 | + if (!$value) |
|
255 | + { |
|
252 | 256 | unset($config[$key]); |
253 | 257 | continue; |
254 | 258 | } |
@@ -54,32 +54,40 @@ discard block |
||
54 | 54 | |
55 | 55 | public function connect() |
56 | 56 | { |
57 | - switch ($polled = $this->poll()) { |
|
57 | + switch ($polled = $this->poll()) |
|
58 | + { |
|
58 | 59 | case \PGSQL_POLLING_FAILED: |
59 | 60 | return; |
60 | 61 | case \PGSQL_POLLING_OK: |
61 | - if ($this->isConnected() != true) { |
|
62 | + if ($this->isConnected() != true) |
|
63 | + { |
|
62 | 64 | $this->connected = true; |
63 | 65 | $this->conn->resolve($this); |
64 | 66 | |
65 | 67 | return; |
66 | 68 | } |
67 | 69 | $retRsrc = \pg_get_result($this->stream); |
68 | - if ($retRsrc) { |
|
69 | - if (empty($this->retQueue)) { |
|
70 | + if ($retRsrc) |
|
71 | + { |
|
72 | + if (empty($this->retQueue)) |
|
73 | + { |
|
70 | 74 | |
71 | 75 | return; |
72 | 76 | } |
73 | 77 | $ret = array_shift($this->retQueue); |
74 | 78 | $ret->resolve($ret->handle($retRsrc)); |
75 | - } else { |
|
76 | - if (empty($this->queryQueue)) { |
|
79 | + } |
|
80 | + else |
|
81 | + { |
|
82 | + if (empty($this->queryQueue)) |
|
83 | + { |
|
77 | 84 | |
78 | 85 | return; |
79 | 86 | } |
80 | 87 | $query = array_shift($this->queryQueue); |
81 | 88 | $ok = $query->execute($this); |
82 | - if (!$ok) { |
|
89 | + if (!$ok) |
|
90 | + { |
|
83 | 91 | $query->reject(new \Exception('failed')); |
84 | 92 | |
85 | 93 | return; |
@@ -92,7 +100,7 @@ discard block |
||
92 | 100 | } |
93 | 101 | |
94 | 102 | public function prepare($sql) |
95 | - { |
|
103 | + { |
|
96 | 104 | $prepare = new PrepareQuery($sql); |
97 | 105 | $this->appendQuery($prepare); |
98 | 106 | $promise = $prepare->getPromise(); |
@@ -59,12 +59,14 @@ discard block |
||
59 | 59 | |
60 | 60 | public function begin() |
61 | 61 | { |
62 | - if ($this->isOpen()) { |
|
62 | + if ($this->isOpen()) |
|
63 | + { |
|
63 | 64 | return Promise::doResolve($this); |
64 | 65 | } |
65 | 66 | |
66 | 67 | return $this->connector->execute('BEGIN')->success(function (CommandResultStatement $result) { |
67 | - if ($result) { |
|
68 | + if ($result) |
|
69 | + { |
|
68 | 70 | $this->emitter->emit('transaction:begin'); |
69 | 71 | } |
70 | 72 | |
@@ -79,7 +81,8 @@ discard block |
||
79 | 81 | public function commit() |
80 | 82 | { |
81 | 83 | return $this->connector->execute('COMMIT')->success(function (CommandResultStatement $result) { |
82 | - if ($result) { |
|
84 | + if ($result) |
|
85 | + { |
|
83 | 86 | $this->emitter->emit('transaction:end'); |
84 | 87 | } |
85 | 88 | |
@@ -94,7 +97,8 @@ discard block |
||
94 | 97 | public function rollback() |
95 | 98 | { |
96 | 99 | return $this->connector->execute('ROLLBACK')->success(function (CommandResultStatement $result) { |
97 | - if ($result) { |
|
100 | + if ($result) |
|
101 | + { |
|
98 | 102 | $this->emitter->emit('transaction:end'); |
99 | 103 | } |
100 | 104 |
@@ -3,7 +3,7 @@ |
||
3 | 3 | |
4 | 4 | use Dazzle\PgSQL\Connection\ConnectorInterface; |
5 | 5 | |
6 | -interface StatementHandler |
|
6 | +interface StatementHandler |
|
7 | 7 | { |
8 | 8 | public function execute(ConnectorInterface $connector); |
9 | 9 | public function handle($result); |
@@ -9,7 +9,8 @@ |
||
9 | 9 | public function handle($result) |
10 | 10 | { |
11 | 11 | $stat = pg_result_status($result, \PGSQL_STATUS_LONG); |
12 | - switch ($stat) { |
|
12 | + switch ($stat) |
|
13 | + { |
|
13 | 14 | case PGSQL_EMPTY_QUERY: |
14 | 15 | break; |
15 | 16 | case PGSQL_COMMAND_OK: |
@@ -53,7 +53,8 @@ |
||
53 | 53 | public function handle($result) |
54 | 54 | { |
55 | 55 | $stat = pg_result_status($result, \PGSQL_STATUS_LONG); |
56 | - if ($stat != PGSQL_COMMAND_OK) { |
|
56 | + if ($stat != PGSQL_COMMAND_OK) |
|
57 | + { |
|
57 | 58 | return new \Exception('error'); |
58 | 59 | } |
59 | 60 |