From 7fc0c93720283d1edc5e26ade85b85560caccc16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nil=20Portugu=C3=A9s?= Date: Tue, 23 Sep 2014 13:11:54 +0200 Subject: [PATCH] Defered nicely formatted queries, reducing memory consumption quite a bit --- src/NilPortugues/SqlQueryBuilder/Builder/GenericBuilder.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/NilPortugues/SqlQueryBuilder/Builder/GenericBuilder.php b/src/NilPortugues/SqlQueryBuilder/Builder/GenericBuilder.php index 9fac1e5..0293e0f 100644 --- a/src/NilPortugues/SqlQueryBuilder/Builder/GenericBuilder.php +++ b/src/NilPortugues/SqlQueryBuilder/Builder/GenericBuilder.php @@ -85,8 +85,6 @@ class GenericBuilder implements BuilderInterface public function __construct() { $this->placeholderWriter = WriterFactory::createPlaceholderWriter(); - - $this->sqlFormatter = new Formatter(); } /** @@ -255,6 +253,10 @@ public function write(QueryInterface $query, $resetPlaceholders = true) */ public function writeFormatted(QueryInterface $query) { + if (false === ($this->sqlFormatter instanceof Formatter)) { + $this->sqlFormatter = new Formatter(); + } + return $this->sqlFormatter->format($this->write($query)); }