diff --git a/momoko/connection.py b/momoko/connection.py index 27c12b5..dcfa164 100644 --- a/momoko/connection.py +++ b/momoko/connection.py @@ -752,7 +752,10 @@ def execute(self, """ kwargs = {"cursor_factory": cursor_factory} if cursor_factory else {} cursor = self.connection.cursor(**kwargs) - cursor.execute(operation, parameters) + if parameters: + cursor.execute(operation, parameters) + else: + cursor.execute(operation) future = Future() callback = partial(self._io_callback, future, cursor) diff --git a/tests.py b/tests.py index e64342c..5d60ce6 100644 --- a/tests.py +++ b/tests.py @@ -127,6 +127,7 @@ def clean_db(self): yield self.conn.execute("DROP TABLE IF EXISTS unit_test_transaction;") yield self.conn.execute("DROP TABLE IF EXISTS unit_test_int_table;") yield self.conn.execute("DROP FUNCTION IF EXISTS unit_test_callproc(integer);") + yield self.conn.execute("DROP FUNCTION IF EXISTS unit_test_callproc_noparams();") def prepare_db(self): yield self.conn.execute( @@ -144,6 +145,12 @@ def prepare_db(self): "RETURN n*n;\n" "END;$BODY$ LANGUAGE plpgsql VOLATILE;" ) + yield self.conn.execute( + "CREATE OR REPLACE FUNCTION unit_test_callproc_noparams()\n" + "RETURNS integer AS $BODY$BEGIN\n" + "RETURN 42;\n" + "END;$BODY$ LANGUAGE plpgsql VOLATILE;" + ) def fill_int_data(self, amount=1000): return self.conn.transaction([ @@ -193,6 +200,15 @@ def test_execute(self): cursor = yield self.conn.execute("SELECT 1, 2, 3") self.assertEqual(cursor.fetchall(), [(1, 2, 3)]) + @gen_test + def test_execute_percent_sign(self): + """ + Testing that momoko does not complain on percent signs when there is no parameters. + Issue #136 + """ + cursor = yield self.conn.execute("SELECT 'a%s'") + self.assertEqual(cursor.fetchall(), [('a%s',)]) + @gen_test def test_ping(self): """Testing ping""" @@ -272,6 +288,12 @@ def test_callproc(self): cursor = yield self.conn.callproc("unit_test_callproc", (64,)) self.assertEqual(cursor.fetchone(), (4096,)) + @gen_test + def test_callproc_noparams(self): + """Testing callproc without parameters""" + cursor = yield self.conn.callproc("unit_test_callproc_noparams") + self.assertEqual(cursor.fetchone(), (42,)) + @gen_test def test_query_error(self): """Testing that execute method propages exception properly"""