Skip to content

Commit

Permalink
Fixes to countDataRows methods in various sources
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Hall committed Mar 28, 2018
1 parent cae1b92 commit 20e30fb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Objects/Sources/CSVSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
12 changes: 9 additions & 3 deletions src/Objects/Sources/PDOSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
}
3 changes: 1 addition & 2 deletions src/Objects/Sources/WordPressPostSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
3 changes: 1 addition & 2 deletions src/Objects/Sources/WordPressUserSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 20e30fb

Please sign in to comment.