From d6707344e2ca0677360b153b513868bcb53611db Mon Sep 17 00:00:00 2001 From: Randy Zwitch Date: Thu, 19 Sep 2019 10:24:05 -0400 Subject: [PATCH] Ensure execute() 'operation' argument trimmed before sending (#268) * Move strip() inside function * Test weird spacing and carriage returns --- pymapd/connection.py | 2 +- pymapd/cursor.py | 4 ++++ tests/test_integration.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/pymapd/connection.py b/pymapd/connection.py index 8c6372c..d4b2eba 100644 --- a/pymapd/connection.py +++ b/pymapd/connection.py @@ -286,7 +286,7 @@ def execute(self, operation, parameters=None): c: Cursor """ c = Cursor(self) - return c.execute(operation.strip(), parameters=parameters) + return c.execute(operation, parameters=parameters) def cursor(self): """Create a new :class:`Cursor` object attached to this connection.""" diff --git a/pymapd/cursor.py b/pymapd/cursor.py index 15497a7..cab35f9 100644 --- a/pymapd/cursor.py +++ b/pymapd/cursor.py @@ -101,6 +101,10 @@ def execute(self, operation, parameters=None): ... parameters={"max_qty": 500}) [('RHAT', 100.0), ('IBM', 500.0)] """ + + # https://github.com/omnisci/pymapd/issues/263 + operation = operation.strip() + if parameters is not None: operation = str(_bind_parameters(operation, parameters)) self.rowcount = -1 diff --git a/tests/test_integration.py b/tests/test_integration.py index 97c18ef..7850b60 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -889,3 +889,32 @@ def test_insert_unicode(self, con): c.execute(i1, parameters=second) c.execute('drop table if exists text_holder;') + + def test_execute_leading_space_and_params(self, con): + + # https://github.com/omnisci/pymapd/issues/263 + + """Ensure that leading/trailing spaces in execute statements + don't cause issues + """ + + c = con.cursor() + c.execute('drop table if exists test_leading_spaces;') + create = ('create table test_leading_spaces (the_text text);') + c.execute(create) + first = {"value": "我和我的姐姐吃米饭鸡肉"} + second = {"value": "El camina a case en bicicleta es relajante"} + + i1 = """ + + INSERT INTO test_leading_spaces + + + VALUES ( :value ); + + """ + + c.execute(i1, parameters=first) + c.execute(i1, parameters=second) + + c.execute('drop table if exists test_leading_spaces;')