Skip to content

Commit

Permalink
Inline escape() method to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Feb 20, 2024
1 parent e489d11 commit 0fac1bd
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions src/Mysqldump.php
Original file line number Diff line number Diff line change
Expand Up @@ -761,35 +761,32 @@ private function prepareColumnValues(string $tableName, array $row): array
$row = call_user_func($this->transformTableRowCallable, $tableName, $row);
}

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

$ret[] = $this->escape($colValue, $columnTypes[$colName]);
}

return $ret;
}

/**
* Escape values with quotes when needed.
*/
private function escape(?string $colValue, array $colType)
{
if (is_null($colValue)) {
return 'NULL';
} elseif ($this->settings->isEnabled('hex-blob') && $colType['is_blob']) {
if ($colType['type'] == 'bit' || !empty($colValue)) {
return sprintf('0x%s', $colValue);
} else {
return "''";
if ($colValue === null) {
$ret[] = "NULL";
continue;
} elseif ($this->settings->isEnabled('hex-blob') && $colType['is_blob']) {
if ($colType['type'] == 'bit' || !empty($colValue)) {
$ret[] = sprintf('0x%s', $colValue);
} else {
$ret[] = "''";
}
continue;
} elseif ($colType['is_numeric']) {
$ret[] = $colValue;
continue;
}
} elseif ($colType['is_numeric']) {
return $colValue;

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

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

/**
Expand Down

0 comments on commit 0fac1bd

Please sign in to comment.