From 20e30fb8d3b088006cd9f630c2a7dcc72078093c Mon Sep 17 00:00:00 2001 From: Jordan Hall Date: Wed, 28 Mar 2018 15:24:54 +0100 Subject: [PATCH] Fixes to countDataRows methods in various sources --- src/Objects/Sources/CSVSource.php | 4 ++-- src/Objects/Sources/PDOSource.php | 12 +++++++++--- src/Objects/Sources/WordPressPostSource.php | 3 +-- src/Objects/Sources/WordPressUserSource.php | 3 +-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Objects/Sources/CSVSource.php b/src/Objects/Sources/CSVSource.php index b77f36e..dbbc44b 100755 --- a/src/Objects/Sources/CSVSource.php +++ b/src/Objects/Sources/CSVSource.php @@ -72,8 +72,8 @@ public function getFields() public function countDataRows() { - $file = new SplFileObject($this->file, 'r'); + $file = new \SplFileObject($this->file, 'r'); $file->seek(PHP_INT_MAX); - return $file->key() + 1; + return $file->key(); } } diff --git a/src/Objects/Sources/PDOSource.php b/src/Objects/Sources/PDOSource.php index 7c0bba7..1a50e18 100644 --- a/src/Objects/Sources/PDOSource.php +++ b/src/Objects/Sources/PDOSource.php @@ -130,12 +130,18 @@ public function getFields() public function countDataRows() { - $sql = $this->getSQL(); + $sql = $this->getSQL([]); $fromPos = strpos($sql, 'from'); $limitPos = strrpos($sql, 'limit'); $sqlSuffix = substr($sql, $fromPos, $limitPos-$fromPos); - $sql = 'count (*) '.$sqlSuffix; - var_dump($sql); die; + $sql = 'select count(*) as countDataRows '.$sqlSuffix; + + $stmt = $this->pdo->prepare($sql); + $stmt->execute(); + + $row = $stmt->fetch(PDO::FETCH_ASSOC); + + return $row['countDataRows']; } } diff --git a/src/Objects/Sources/WordPressPostSource.php b/src/Objects/Sources/WordPressPostSource.php index e8c1b2b..d0c2c82 100644 --- a/src/Objects/Sources/WordPressPostSource.php +++ b/src/Objects/Sources/WordPressPostSource.php @@ -145,12 +145,11 @@ public function getFields() public function countDataRows() { - $sql = $this->getPostSQL(); + $sql = $this->getPostSQL([]); $fromPos = strpos($sql, 'from'); $limitPos = strrpos($sql, 'limit'); $sqlSuffix = substr($sql, $fromPos, $limitPos-$fromPos); $sql = 'count (*) '.$sqlSuffix; - var_dump($sql); die; } } diff --git a/src/Objects/Sources/WordPressUserSource.php b/src/Objects/Sources/WordPressUserSource.php index be20166..aef4659 100644 --- a/src/Objects/Sources/WordPressUserSource.php +++ b/src/Objects/Sources/WordPressUserSource.php @@ -143,12 +143,11 @@ public function getFields() public function countDataRows() { - $sql = $this->getUserSQL(); + $sql = $this->getUserSQL([]); $fromPos = strpos($sql, 'from'); $limitPos = strrpos($sql, 'limit'); $sqlSuffix = substr($sql, $fromPos, $limitPos-$fromPos); $sql = 'count (*) '.$sqlSuffix; - var_dump($sql); die; } }