-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Just handle the result set. Leave the id of the prepared statement in cursor.lastrowid so it can be used with EXEC. See also issue #116.
- Loading branch information
1 parent
3853e87
commit eda6c26
Showing
2 changed files
with
34 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from unittest import TestCase | ||
from pymonetdb import connect | ||
from tests.util import test_args | ||
|
||
|
||
class TestPrepare(TestCase): | ||
def setUp(self): | ||
self.connection = connect(autocommit=False, **test_args) | ||
self.cursor = self.connection.cursor() | ||
|
||
def test_prepare(self): | ||
# It would be nice to have a prepare API but in the mean time we can | ||
# invoke PREPARE and EXEC ourselves. | ||
# | ||
# Note how the id of the newly prepared statement is stashed in | ||
# cursor.lastrowid. | ||
|
||
prepare = "PREPARE SELECT value, 10 * value, 100 * value FROM sys.generate_series(0, ?)" | ||
self.cursor.execute(prepare) | ||
exec_id = self.cursor.lastrowid | ||
|
||
n = 3 | ||
expected = [ | ||
(value, 10 * value, 100 * value) | ||
for value in range(n) | ||
] | ||
self.cursor.execute("EXEC %s(%s)", (exec_id, n)) | ||
received = self.cursor.fetchall() | ||
self.assertEqual(expected, received) |