Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Fixed raising ValueError for queries that contain the%%. #23

Merged
merged 2 commits into from
Oct 1, 2012
Merged
Show file tree
Hide file tree
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 python/umysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -1081,13 +1081,19 @@ PyObject *EscapeQueryArguments(Connection *self, PyObject *inQuery, PyObject *it

iptr ++;

if (*iptr != 's')
if (*iptr != 's' && *iptr != '%')
{
Py_DECREF(iterator);
if (heap) PyObject_Free(obuffer);
return PyErr_Format (PyExc_ValueError, "Found character %c expected %%", *iptr);
}

if (*iptr == '%')
{
*(optr++) = *(iptr)++;
break;
}

iptr ++;

arg = PyIter_Next(iterator);
Expand Down
17 changes: 16 additions & 1 deletion tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,22 @@ def testTextCharsets(self):
self.assertEquals(result, expected)

cnn.close()


def testPercentEscaping(self):
cnn = umysql.Connection()
cnn.connect (DB_HOST, 3306, DB_USER, DB_PASSWD, DB_DB)
rs = cnn.query("SELECT * FROM `tblautoincint` WHERE `test_id` LIKE '%%10%%'")
self.assertEquals([(100, u'piet'), (101, u'piet')], rs.rows)

rs = cnn.query("SELECT * FROM `tblautoincint` WHERE `test_id` LIKE '%%%s%%'", [10])
self.assertEquals([(100, u'piet'), (101, u'piet')], rs.rows)

# SqlAlchemy query style
rs = cnn.query("SELECT * FROM `tblautoincint` WHERE `test_id` LIKE concat(concat('%%', %s), '%%')", [10])
self.assertEquals([(100, u'piet'), (101, 'piet')], rs.rows)

cnn.close()

if __name__ == '__main__':
from guppy import hpy
hp = hpy()
Expand Down