Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline escape() method to improve performance #277

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 20 additions & 24 deletions src/Ifsnop/Mysqldump/Mysqldump.php
Original file line number Diff line number Diff line change
Expand Up @@ -1059,40 +1059,36 @@ private function prepareColumnValues($tableName, array $row)
$row = call_user_func($this->transformTableRowCallable, $tableName, $row);
}

$dbHandler = $this->dbHandler;
foreach ($row as $colName => $colValue) {
if ($this->transformColumnValueCallable) {
$colValue = call_user_func($this->transformColumnValueCallable, $tableName, $colName, $colValue, $row);
}

$ret[] = $this->escape($colValue, $columnTypes[$colName]);
}
if ($colValue === null) {
$ret[] = "NULL";
continue;
}

return $ret;
}
$colType = $columnTypes[$colName];
if ($this->dumpSettings['hex-blob'] && $colType['is_blob']) {
if ($colType['type'] == 'bit' || $colValue !== '') {
$ret[] = "0x{$colValue}";
} else {
$ret[] = "''";
}
continue;
}

/**
* Escape values with quotes when needed
*
* @param string $tableName Name of table which contains rows
* @param array $row Associative array of column names and values to be quoted
*
* @return string
*/
private function escape($colValue, $colType)
{
if (is_null($colValue)) {
return "NULL";
} elseif ($this->dumpSettings['hex-blob'] && $colType['is_blob']) {
if ($colType['type'] == 'bit' || !empty($colValue)) {
return "0x{$colValue}";
} else {
return "''";
if ($colType['is_numeric']) {
$ret[] = $colValue;
continue;
}
} elseif ($colType['is_numeric']) {
return $colValue;

$ret[] = $dbHandler->quote($colValue);
}

return $this->dbHandler->quote($colValue);
return $ret;
}

/**
Expand Down