From 2848c965f9b96642f0c76e3acf93795f09849139 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 4 May 2018 22:32:45 +0200 Subject: [PATCH] Result: added getColumnCount() --- src/Dibi/Result.php | 10 ++++++++++ tests/dibi/Result.meta.phpt | 9 +++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Dibi/Result.php b/src/Dibi/Result.php index fd045b29..35eafffa 100644 --- a/src/Dibi/Result.php +++ b/src/Dibi/Result.php @@ -134,6 +134,16 @@ class Result implements IDataSource } + /** + * Returns the number of columns in a result set. + * @return int + */ + final public function getColumnCount() + { + return count($this->types); + } + + /********************* fetching rows ****************d*g**/ diff --git a/tests/dibi/Result.meta.phpt b/tests/dibi/Result.meta.phpt index 6fe64eaa..036d09bd 100644 --- a/tests/dibi/Result.meta.phpt +++ b/tests/dibi/Result.meta.phpt @@ -11,12 +11,17 @@ require __DIR__ . '/bootstrap.php'; $conn = new Dibi\Connection($config); $conn->loadFile(__DIR__ . "/data/$config[system].sql"); -$info = $conn->query(' +$res = $conn->query(' SELECT products.product_id, orders.order_id, customers.name, products.product_id + 1 AS [xXx] FROM ([products] INNER JOIN [orders] ON [products.product_id] = [orders.product_id]) INNER JOIN [customers] ON [orders.customer_id] = [customers.customer_id] -')->getInfo(); +'); + +$info = $res->getInfo(); + + +Assert::same(4, $res->getColumnCount()); Assert::same(