Skip to content

Commit

Permalink
Provide possibility to dump with limit and offset (#3)
Browse files Browse the repository at this point in the history
- fixed order of stmt instructions
- improved limit functionality with the possibility to declare an offset
- fixed PHPUnit tests
  • Loading branch information
bua89 authored Dec 17, 2021
1 parent 78a0207 commit f5f02ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
22 changes: 6 additions & 16 deletions src/Ifsnop/Mysqldump/Mysqldump.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,7 @@ public function setTableLimits(array $tableLimits)
*/
public function getTableLimit($tableName)
{
if (!isset($this->tableLimits[$tableName])) {
return false;
}

$limit = $this->tableLimits[$tableName];
if (!is_numeric($limit)) {
return false;
}

return $limit;
return isset($this->tableLimits[$tableName]) ? $this->tableLimits[$tableName] : false;
}

/**
Expand Down Expand Up @@ -1140,17 +1131,16 @@ private function listValues($tableName)
$stmt .= " WHERE {$condition}";
}

$limit = $this->getTableLimit($tableName);

if ($limit !== false) {
$stmt .= " LIMIT {$limit}";
}

$order = $this->getTableOrder($tableName);
if ($order !== false) {
$stmt .= " ORDER BY {$order}";
}

$limit = $this->getTableLimit($tableName);
if ($limit !== false) {
$stmt .= " LIMIT {$limit}";
}

$resultSet = $this->dbHandler->query($stmt);
$resultSet->setFetchMode(PDO::FETCH_ASSOC);

Expand Down
4 changes: 2 additions & 2 deletions unit-tests/MysqldumpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public function tableSpecificLimitsWork()
$dump->setTableLimits(array(
'users' => 200,
'logs' => 500,
'table_with_invalid_limit' => '41923, 42992'
'table_with_offset' => '41923, 42992'
));

$this->assertEquals(200, $dump->getTableLimit('users'));
$this->assertEquals(500, $dump->getTableLimit('logs'));
$this->assertFalse($dump->getTableLimit('table_with_invalid_limit'));
$this->assertEquals('41923, 42992', $dump->getTableLimit('table_with_offset'));
$this->assertFalse($dump->getTableLimit('table_name_with_no_limit'));
}
}

0 comments on commit f5f02ca

Please sign in to comment.