-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/nuodb/nuodb-python
- Loading branch information
Showing
7 changed files
with
378 additions
and
31 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
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,42 @@ | ||
#!/usr/bin/env python | ||
|
||
import pynuodb; | ||
import unittest; | ||
|
||
from struct import *; | ||
from nuodb_base import NuoBase; | ||
from pynuodb.exception import Error, DataError; | ||
|
||
class NuoDBBlobTest(NuoBase): | ||
|
||
def setUp(self): | ||
NuoBase.setUp(self); | ||
|
||
def tearDown(self): | ||
NuoBase.tearDown(self); | ||
|
||
def _connect(self): | ||
return pynuodb.connect("test", "localhost", "dba", "goalie", options = { "schema" : "hockey" } ); | ||
|
||
def test_blob_prepared(self): | ||
con = self._connect(); | ||
cursor = con.cursor(); | ||
|
||
binary_data = pack('hhl', 1, 2, 3); | ||
|
||
cursor.execute("SELECT ? FROM DUAL", [ binary_data ] ); | ||
row = cursor.fetchone(); | ||
|
||
array1 = unpack('hhl', row[0]); | ||
self.assertEquals(len(array1), 3); | ||
self.assertEquals(array1[2], 3); | ||
|
||
cursor.execute("SELECT ? FROM DUAL", [ pynuodb.Binary(binary_data) ] ); | ||
row = cursor.fetchone(); | ||
|
||
array2 = unpack('hhl', str(row[0])); | ||
self.assertEquals(len(array2), 3); | ||
self.assertEquals(array2[2], 3); | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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,86 @@ | ||
#!/usr/bin/env python | ||
|
||
import pynuodb; | ||
import unittest; | ||
|
||
from nuodb_base import NuoBase; | ||
from pynuodb.exception import Error, DataError; | ||
|
||
class NuoDBCursorTest(NuoBase): | ||
|
||
def setUp(self): | ||
NuoBase.setUp(self); | ||
|
||
def tearDown(self): | ||
NuoBase.tearDown(self); | ||
|
||
def _connect(self): | ||
return pynuodb.connect("test", "localhost", "dba", "goalie", options = { "schema" : "hockey" } ); | ||
|
||
def test_cursor_description(self): | ||
con = self._connect(); | ||
cursor = con.cursor(); | ||
|
||
cursor.execute("SELECT 'abc' AS XYZ , 123 AS `123` FROM DUAL"); | ||
descriptions = cursor.description; | ||
|
||
self.assertEquals(len(descriptions), 2); | ||
self.assertEquals(descriptions[0][0], 'XYZ'); | ||
self.assertEquals(descriptions[0][1], self.driver.STRING); | ||
self.assertEquals(descriptions[0][2], 3); | ||
|
||
|
||
self.assertEquals(descriptions[1][0], '123'); | ||
self.assertEquals(descriptions[1][1], self.driver.NUMBER); | ||
self.assertEquals(descriptions[1][2], 11); | ||
|
||
def test_cursor_rowcount_select(self): | ||
con = self._connect(); | ||
cursor = con.cursor(); | ||
|
||
cursor.execute("SELECT 1 FROM DUAL UNION ALL SELECT 2 FROM DUAL"); | ||
self.assertEquals(cursor.rowcount, -1); | ||
|
||
|
||
def test_insufficient_parameters(self): | ||
|
||
con = self._connect(); | ||
cursor = con.cursor(); | ||
# cursor.execute("SELECT ? FROM DUAL"); | ||
# cursor.execute("SELECT ? FROM DUAL", [0]); | ||
|
||
try: | ||
cursor.execute("SELECT ?, ? FROM DUAL", [1]); | ||
self.fail(); | ||
except TypeError as e: | ||
self.assertIsNotNone(e) | ||
|
||
def test_toomany_parameters(self): | ||
|
||
con = self._connect(); | ||
cursor = con.cursor(); | ||
|
||
try: | ||
cursor.execute("SELECT 1 FROM DUAL", [1]); | ||
self.fail(); | ||
except TypeError as e: | ||
self.assertIsNotNone(e); | ||
|
||
try: | ||
cursor.execute("SELECT ? FROM DUAL", [1,2]); | ||
self.fail(); | ||
except TypeError as e: | ||
self.assertIsNotNone(e); | ||
|
||
def test_incorrect_parameters(self): | ||
|
||
con = self._connect(); | ||
cursor = con.cursor(); | ||
try: | ||
cursor.execute("SELECT ? + 1 FROM DUAL", ['abc']); | ||
self.fail(); | ||
except DataError as e: | ||
self.assertIsNotNone(e); | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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,24 @@ | ||
#!/usr/bin/env python | ||
|
||
import pynuodb | ||
import unittest | ||
|
||
from nuodb_base import NuoBase | ||
from pynuodb.exception import Error, DataError | ||
|
||
class NuoDBGlobalsTest(NuoBase): | ||
|
||
def setUp(self): | ||
NuoBase.setUp(self) | ||
|
||
def tearDown(self): | ||
NuoBase.tearDown(self) | ||
|
||
def test_module_globals(self): | ||
|
||
self.assertEquals(pynuodb.apilevel, '2.0'); | ||
self.assertEquals(pynuodb.threadsafety, 1); | ||
self.assertEquals(pynuodb.paramstyle, 'qmark'); | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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,92 @@ | ||
#!/usr/bin/env python | ||
|
||
import pynuodb; | ||
import unittest; | ||
|
||
from nuodb_base import NuoBase; | ||
|
||
class NuoDBHugeTest(NuoBase): | ||
|
||
def setUp(self): | ||
NuoBase.setUp(self); | ||
|
||
def tearDown(self): | ||
NuoBase.tearDown(self); | ||
|
||
def _connect(self): | ||
return pynuodb.connect("test", "localhost", "dba", "goalie", options = { "schema" : "hockey" } ); | ||
|
||
def test_wide_select(self): | ||
|
||
con = self._connect(); | ||
cursor = con.cursor(); | ||
total_columns = 5120; | ||
|
||
alphabet = "ABCDEFGHIJKLMNOPQRSTUWXYZ"; | ||
select_string = "SELECT "; | ||
|
||
for col in range(1, total_columns + 1): | ||
select_string += "'" + alphabet + str(col) + "'"; | ||
if col < total_columns: | ||
select_string += " , "; | ||
else: | ||
select_string += " FROM DUAL"; | ||
|
||
cursor.execute(select_string); | ||
row = cursor.fetchone(); | ||
|
||
self.assertEquals(len(row), total_columns); | ||
|
||
for col in range(0, total_columns): | ||
self.assertEquals(row[col], alphabet + str(col+1)); | ||
|
||
def test_wide_string(self): | ||
|
||
con = self._connect(); | ||
cursor = con.cursor(); | ||
|
||
total_width = 5120; | ||
alphabet = "ABCDEFGHIJKLMNOPQRSTUWXYZ"; | ||
alphabet_multi = ""; | ||
|
||
for col in range(1, total_width + 1): | ||
alphabet_multi += alphabet; | ||
|
||
select_string = "SELECT '" + alphabet_multi + "' , ? , '" + alphabet_multi + "' = ? FROM DUAL"; | ||
|
||
cursor.execute(select_string, [alphabet_multi, alphabet_multi]); | ||
row = cursor.fetchone(); | ||
self.assertEquals(len(row[0]), total_width * len(alphabet)); | ||
self.assertEquals(len(row[1]), total_width * len(alphabet)); | ||
self.assertEquals(row[2], True); | ||
|
||
def test_long_select(self): | ||
|
||
con = self._connect(); | ||
cursor = con.cursor(); | ||
|
||
cursor.execute("DROP TABLE IF EXISTS ten"); | ||
cursor.execute("DROP TABLE IF EXISTS huge_select"); | ||
|
||
cursor.execute("CREATE TABLE ten (f1 INTEGER)"); | ||
cursor.execute("INSERT INTO ten VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10)"); | ||
|
||
cursor.execute("CREATE TABLE huge_select (f1 INTEGER GENERATED BY DEFAULT AS IDENTITY(s1))"); | ||
cursor.execute("INSERT INTO huge_select SELECT NEXT VALUE FOR s1 FROM ten,ten,ten,ten,ten,ten"); | ||
|
||
cursor.execute("SELECT * FROM huge_select"); | ||
|
||
total_rows = 0; | ||
while (1): | ||
rows = cursor.fetchmany(10000); | ||
if rows == None or len(rows) == 0: | ||
break | ||
total_rows = total_rows + len(rows); | ||
|
||
self.assertEquals(total_rows, 1000000); | ||
|
||
cursor.execute("DROP TABLE ten"); | ||
cursor.execute("DROP TABLE huge_select"); | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.