-
Notifications
You must be signed in to change notification settings - Fork 43
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
INSER INTO and UPDATE SET fixed #86
Conversation
$isString = false; | ||
$stringStartedWith = null; | ||
|
||
while (($char = substr($values, $stringOffset++, 1)) !== false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should try to do this in a more immutable way. Something like this:
$valuesArray = str_split($values);
$isString = false;
$stringStartedWith = null;
return array_reduce($valuesArray, function($dest, $value) use ($isString, $stringStartedWith) {
$stringStartedWith = static::isCharStringDelimiter($char, $stringStartedWith) && !$isString ? $value : null;
$isString = static::isCharStringDelimiter($char, $stringStartedWith) ? !$isString : $isString;
if (!$isString && $value === ',') return array_merge($dest, ['']);
if (!$isString && preg_match('/\s/', $value)) return $dest;
$currentKey = count($dest) - 1;
$newDest = $dest;
$newDest[$currentKey] .= $value;
return $newDest;
}, ['']);
Maybe the code is broken somewhere, but it should nearly be working (hopefully :-D)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, your code is more immutable.
I would like to keep the while loop and not allocate memory for another copy of the values by using str_split.
It's against your code style, but is faster when dealing with bigger chunks of data.
Rest is awesome. Thank you! |
and the use of ',' inside a string value
… modified testcase and excluded ANY whitespace character when Lexer is not in string mode
an unmatched string
Fixes
INSERT INTO...
due toarray_combine
#44Proposed Changes
,
with lexer that detects if the current value is a string and moves on to the next value when hitting a comma outside of a string.=
character, introduced a limit on explode, the value can now be any string, including many many equal chars. There is a LIMIT! In case the column name contains = as a character it will not work.