dg / dibi

Dibi - smart database abstraction layer
https://dibiphp.com
Other
487 stars 136 forks source link

Sql modificator bug #265

Closed SendiMyrkr closed 6 years ago

SendiMyrkr commented 7 years ago

Description

I guess that next example will be more descriptive. But problěm in result query are double slashes even documentation says that modificator %sql use value "as is"

Steps To Reproduce

// EXAMPLE 1
$sql1 = "SELECT 'de\'longhi ec 850.m' AS word FROM `some_table` WHERE code IN('de\'longhi', 'ec', '850.m') OR part_no IN('de\'longhi', 'ec', '850.m') OR part_no IN('de\'longhi', 'ec', '850.m')";

$dibi->test('INSER INTO some_other_table(`word`) (%sql)', $sql1);

/*
result test(...) is
INSER INTO some_other_table(`word`) (
SELECT 'de\\'longhi ec 850.m' AS word 
FROM `some_table` 
WHERE code IN('de\'longhi', 'ec', '850.m') OR part_no IN('de\\'longhi', 'ec', '850.m') OR part_no
IN('de\'longhi', 'ec', '850.m'))
*/
// EXAMPLE 2
$sql1 = "SELECT 'de\'longhi ec 850.m' AS word FROM `some_table` WHERE code IN('de\'longhi', 'ec', '850.m') OR part_no IN('de\'longhi', 'ec', '850.m')";

$dibi->test('INSER INTO some_other_table(`word`) (%sql)', $sql1);

/*
result test(...) is
INSER INTO some_other_table(`word`) (
SELECT 'de\\'longhi ec 850.m' AS word 
FROM `some_table` 
WHERE code IN('de\'longhi', 'ec', '850.m') OR part_no IN('de\\'longhi', 'ec', '850.m**Alone
quote**))
*/
milo commented 7 years ago

Actually, %sql behaves like %ex. To leave string "really" untouched you must use %SQL. It's not documented, be careful with it.

SendiMyrkr commented 7 years ago

Great. I use it only for queries generated by dibi, so i belive that it's ok. So i guess this can be closed?