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

INSER INTO and UPDATE SET fixed #86

Closed
wants to merge 14 commits into from
Closed

INSER INTO and UPDATE SET fixed #86

wants to merge 14 commits into from

Conversation

SerethiX
Copy link
Contributor

@SerethiX SerethiX commented Dec 5, 2018

Fixes

Proposed Changes

  • Replace explode on , 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.
  • Update statements truncated content after any second = 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.
  • "De-quoting" regex was broken: newlines inside the value resulted in single quotes kept around the text, newline as the last character didn't trigger this effect.
  • Added Values to the HttpQueryTest as documentation what this method can do.

$isString = false;
$stringStartedWith = null;

while (($char = substr($values, $stringOffset++, 1)) !== false)
Copy link
Member

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)

Copy link
Contributor Author

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.

@TobiasHauck
Copy link
Member

Rest is awesome. Thank you!

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants