CircleOfNice / DoctrineRestDriver

GNU General Public License v3.0
153 stars 44 forks source link

INSERT INTO and UPDATE SET fail with ',' or '=' contained in Values #85

Open SerethiX opened 6 years ago

SerethiX commented 6 years ago

What is this feature about (expected vs actual behaviour)?

  1. Inserting Values that contain , result in an error when building the parameter key value array
    • Expected to be able to insert any string
  2. Update Statements that contain = as or in one of their values fail aswell, they truncate the value
    • Expected to be able to update values with any strin without truncating

How can I reproduce it?

Execute

  1. Execute INSERT INTO foo (bar) VALUES ('foo, bar')
  2. Execute UPDATE foo SET bar = 'x=2'

using this Driver. You will get a warning, that array_combine has different element counts between the two arrays and an error when providing the false return value of array_combine into the JsonFormatter, which expects an array on the encodemethod.

Does it take minutes, hours or days to fix?

It took hours.

Any additional information?

Wrote a simple lexer that detects if the current value is a string (based on changes introduced in #77 ; looks out for '' "" `` to start and end a string), appending everything until the next , after a string ended to the current value, then starting a new one.

Escaping is handled like PDO does it by adding another char of the same type in front of it in SqlQuery::quote(). The lexer then just toggles stringMode off and on again.

The dequoting then takes place in Value::create()

Edited the Tests a little for some more edged cases like single Quotes around a text etc. Also a few more Tests got modified to test for the exact same problems, currently no problems found.