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

?as hint #221

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
8 changes: 7 additions & 1 deletion src/Database/SqlPreprocessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SqlPreprocessor
use Nette\SmartObject;

/** @var array */
private const MODE_LIST = ['and', 'or', 'set', 'values', 'order'];
private const MODE_LIST = ['and', 'or', 'set', 'values', 'order', 'as'];

private const ARRAY_MODES = [
'INSERT' => 'values',
Expand Down Expand Up @@ -253,6 +253,12 @@ private function formatValue($value, string $mode = null): string
}
return implode(', ', $vx);

} elseif ($mode === 'as') {
foreach ($value as $k => $v) {
$vx[] = $this->delimite($k) . ' AS ' . $v;
}
return implode(', ', $vx);

} else {
throw new Nette\InvalidArgumentException("Unknown placeholder ?$mode.");
}
Expand Down