Skip to content

Commit

Permalink
remove duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
ifsnop committed Oct 19, 2015
1 parent b427249 commit 701024d
Showing 1 changed file with 25 additions and 76 deletions.
101 changes: 25 additions & 76 deletions src/Ifsnop/Mysqldump/Mysqldump.php
Original file line number Diff line number Diff line change
Expand Up @@ -1346,10 +1346,7 @@ public function __construct ($dbHandler)

public function databases()
{
if (func_num_args() != 1) {
throw new Exception("Unexpected parameter passed to " . __METHOD__);
}

$this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
$args = func_get_args();
$databaseName = $args[0];

Expand Down Expand Up @@ -1491,66 +1488,45 @@ public function create_procedure($row, $dumpSettings)

public function show_tables()
{
if (func_num_args() != 1) {
throw new Exception("Unexpected parameter passed to " . __METHOD__);
}

$this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
$args = func_get_args();

return "SELECT TABLE_NAME AS tbl_name " .
"FROM INFORMATION_SCHEMA.TABLES " .
"WHERE TABLE_TYPE='BASE TABLE' AND TABLE_SCHEMA='${args[0]}'";
}

public function show_views()
{
if (func_num_args() != 1) {
throw new Exception("Unexpected parameter passed to " . __METHOD__);
}

$this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
$args = func_get_args();

return "SELECT TABLE_NAME AS tbl_name " .
"FROM INFORMATION_SCHEMA.TABLES " .
"WHERE TABLE_TYPE='VIEW' AND TABLE_SCHEMA='${args[0]}'";
}

public function show_triggers()
{
if (func_num_args() != 1) {
throw new Exception("Unexpected parameter passed to " . __METHOD__);
}

$this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
$args = func_get_args();

return "SHOW TRIGGERS FROM `${args[0]}`;";
}

public function show_columns()
{
if (func_num_args() != 1) {
throw new Exception("Unexpected parameter passed to " . __METHOD__);
}

$this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
$args = func_get_args();

return "SHOW COLUMNS FROM `${args[0]}`;";
}

public function show_procedures()
{
if (func_num_args() != 1) {
throw new Exception("Unexpected parameter passed to " . __METHOD__);
}

$this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
$args = func_get_args();

return "SELECT SPECIFIC_NAME AS procedure_name " .
"FROM INFORMATION_SCHEMA.ROUTINES " .
"WHERE ROUTINE_TYPE='PROCEDURE' AND ROUTINE_SCHEMA='${args[0]}'";
}


public function setup_transaction()
{
return "SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ";
Expand All @@ -1568,10 +1544,7 @@ public function commit_transaction()

public function lock_table()
{
if (func_num_args() != 1) {
throw new Exception("Unexpected parameter passed to " . __METHOD__);
}

$this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
$args = func_get_args();
return $this->dbHandler->exec("LOCK TABLES `${args[0]}` READ LOCAL");

Expand All @@ -1584,10 +1557,7 @@ public function unlock_table()

public function start_add_lock_table()
{
if (func_num_args() != 1) {
throw new Exception("Unexpected parameter passed to " . __METHOD__);
}

$this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
$args = func_get_args();

return "LOCK TABLES `${args[0]}` WRITE;" . PHP_EOL;
Expand All @@ -1600,19 +1570,15 @@ public function end_add_lock_table()

public function start_add_disable_keys()
{
if (func_num_args() != 1) {
throw new Exception("Unexpected parameter passed to " . __METHOD__);
}
$this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
$args = func_get_args();
return "/*!40000 ALTER TABLE `${args[0]}` DISABLE KEYS */;" .
PHP_EOL;
}

public function end_add_disable_keys()
{
if (func_num_args() != 1) {
throw new Exception("Unexpected parameter passed to " . __METHOD__);
}
$this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
$args = func_get_args();
return "/*!40000 ALTER TABLE `${args[0]}` ENABLE KEYS */;" .
PHP_EOL;
Expand All @@ -1630,10 +1596,7 @@ public function end_disable_autocommit()

public function add_drop_database()
{
if (func_num_args() != 1) {
throw new Exception("Unexpected parameter passed to " . __METHOD__);
}

$this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
$args = func_get_args();

return "/*!40000 DROP DATABASE IF EXISTS `${args[0]}`*/;" .
Expand All @@ -1642,46 +1605,30 @@ public function add_drop_database()

public function add_drop_trigger()
{
if (func_num_args() != 1) {
throw new Exception("Unexpected parameter passed to " . __METHOD__);
}

$this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
$args = func_get_args();

return "DROP TRIGGER IF EXISTS `${args[0]}`;" . PHP_EOL;
}

public function drop_table()
{
if (func_num_args() != 1) {
throw new Exception("Unexpected parameter passed to " . __METHOD__);
}

$this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
$args = func_get_args();

return "DROP TABLE IF EXISTS `${args[0]}`;" . PHP_EOL;
}

public function drop_view()
{
if (func_num_args() != 1) {
throw new Exception("Unexpected parameter passed to " . __METHOD__);
}

$this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
$args = func_get_args();

return "DROP TABLE IF EXISTS `${args[0]}`;" . PHP_EOL .
"/*!50001 DROP VIEW IF EXISTS `${args[0]}`*/;" . PHP_EOL;
}

public function getDatabaseHeader()
{
if (func_num_args() != 1) {
throw new Exception("Unexpected parameter passed to " . __METHOD__);
}

$this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
$args = func_get_args();

return "--" . PHP_EOL .
"-- Current Database: `${args[0]}`" . PHP_EOL .
"--" . PHP_EOL . PHP_EOL;
Expand Down Expand Up @@ -1717,10 +1664,7 @@ public function parseColumnType($colType)

public function backup_parameters()
{
if (func_num_args() != 1) {
throw new Exception("Unexpected parameter passed to " . __METHOD__);
}

$this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
$args = func_get_args();
$dumpSettings = $args[0];
$ret = "/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;" . PHP_EOL .
Expand All @@ -1743,10 +1687,7 @@ public function backup_parameters()

public function restore_parameters()
{
if (func_num_args() != 1) {
throw new Exception("Unexpected parameter passed to " . __METHOD__);
}

$this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
$args = func_get_args();
$dumpSettings = $args[0];
$ret = "";
Expand All @@ -1765,4 +1706,12 @@ public function restore_parameters()

return $ret;
}

private function check_parameters($num_args, $expected_num_args, $method_name)
{
if ( $num_args != $expected_num_args ) {
throw new Exception("Unexpected parameter passed to $method_name");
}
return;
}
}

0 comments on commit 701024d

Please sign in to comment.