Skip to content

Commit

Permalink
Ensure execute() 'operation' argument trimmed before sending (#268)
Browse files Browse the repository at this point in the history
* Move strip() inside function

* Test weird spacing and carriage returns
  • Loading branch information
Randy Zwitch authored Sep 19, 2019
1 parent d7460c1 commit d670734
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pymapd/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
4 changes: 4 additions & 0 deletions pymapd/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;')

0 comments on commit d670734

Please sign in to comment.