-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use prepared load statements #44
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
CREATE TABLE projections ( | ||
no SERIAL, | ||
no BIGSERIAL, | ||
name VARCHAR(150) NOT NULL, | ||
position JSONB, | ||
state JSONB, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,11 +32,6 @@ final class PdoStreamIterator implements Iterator | |
*/ | ||
private $statement; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $sql; | ||
|
||
/** | ||
* @var MessageFactory | ||
*/ | ||
|
@@ -57,6 +52,9 @@ final class PdoStreamIterator implements Iterator | |
*/ | ||
private $batchPosition = 0; | ||
|
||
/** | ||
* @var int|null | ||
*/ | ||
private $batchSize; | ||
|
||
/** | ||
|
@@ -78,7 +76,6 @@ public function __construct( | |
PDO $connection, | ||
PDOStatement $statement, | ||
MessageFactory $messageFactory, | ||
array $sql, | ||
?int $batchSize, | ||
int $fromNumber, | ||
int $count, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah ok |
||
|
@@ -87,7 +84,6 @@ public function __construct( | |
$this->connection = $connection; | ||
$this->statement = $statement; | ||
$this->messageFactory = $messageFactory; | ||
$this->sql = $sql; | ||
$this->batchSize = $batchSize; | ||
$this->fromNumber = $fromNumber; | ||
$this->count = $count; | ||
|
@@ -145,9 +141,9 @@ public function next(): void | |
} else { | ||
$limit = $this->fromNumber - $this->batchSize * $this->batchPosition; | ||
} | ||
$this->statement = $this->buildStatement($this->sql, $limit); | ||
|
||
$this->statement = $this->buildStatement($limit); | ||
$this->statement->execute(); | ||
$this->statement->setFetchMode(PDO::FETCH_OBJ); | ||
|
||
$this->currentItem = $this->statement->fetch(); | ||
|
||
|
@@ -184,10 +180,9 @@ public function rewind(): void | |
//Only perform rewind if current item is not the first element | ||
if ($this->currentKey !== 0) { | ||
$this->batchPosition = 0; | ||
$this->statement = $this->buildStatement($this->sql, $this->fromNumber); | ||
|
||
$this->statement = $this->buildStatement($this->fromNumber); | ||
$this->statement->execute(); | ||
$this->statement->setFetchMode(PDO::FETCH_OBJ); | ||
|
||
$this->currentItem = null; | ||
$this->currentKey = -1; | ||
|
@@ -196,25 +191,15 @@ public function rewind(): void | |
} | ||
} | ||
|
||
private function buildStatement(array $sql, int $fromNumber): PDOStatement | ||
private function buildStatement(int $fromNumber): PDOStatement | ||
{ | ||
$limit = $this->count < ($this->batchSize * ($this->batchPosition + 1)) | ||
? $this->count - ($this->batchSize * $this->batchPosition) | ||
: $this->batchSize; | ||
|
||
if ($this->forward) { | ||
$query = $sql['from'] . " WHERE no >= $fromNumber"; | ||
} else { | ||
$query = $sql['from'] . " WHERE no <= $fromNumber"; | ||
} | ||
|
||
if (isset($sql['where'])) { | ||
$query .= ' AND '; | ||
$query .= implode(' AND ', $sql['where']); | ||
} | ||
$query .= ' ' . $sql['orderBy']; | ||
$query .= " LIMIT $limit;"; | ||
$this->statement->bindValue(':fromNumber', $fromNumber, PDO::PARAM_INT); | ||
$this->statement->bindValue(':limit', $limit, PDO::PARAM_INT); | ||
|
||
return $this->connection->prepare($query); | ||
return $this->statement; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see you removed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be
metadata->>
to unquote.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Than it would also match 'true' === true. Right?