Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/nuodb/nuodb-python
Browse files Browse the repository at this point in the history
  • Loading branch information
lbayas committed Jun 11, 2013
2 parents 29133a3 + 3c9c3d4 commit 2fc888d
Show file tree
Hide file tree
Showing 7 changed files with 378 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ NuoDB - Python

[![Build Status](https://travis-ci.org/nuodb/nuodb-python.png?branch=master)](https://travis-ci.org/nuodb/nuodb-python)

This is the official Python pip package for [NuoDB](http://www.nuodb.com). It implements the NuoDB [SQL Protocol](https://github.com/nuodb/nuodb-python/blob/master/SQL_Protocol.md)
This is the official Python package for [NuoDB](http://www.nuodb.com). It implements the NuoDB [SQL Protocol](https://github.com/nuodb/nuodb-python/blob/master/SQL_Protocol.md)

### Requirements

Expand Down
5 changes: 5 additions & 0 deletions run_tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from tests.nuodb_basic_test import *
from tests.nuodb_executionflow_test import *
from tests.nuodb_dbapi20_test import *
from tests.nuodb_transaction_test import *
from tests.nuodb_globals_test import *
from tests.nuodb_cursor_test import *
from tests.nuodb_blob_test import *
from tests.nuodb_huge_test import *

import unittest
import os
Expand Down
42 changes: 42 additions & 0 deletions tests/nuodb_blob_test.py
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()
86 changes: 86 additions & 0 deletions tests/nuodb_cursor_test.py
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()
24 changes: 24 additions & 0 deletions tests/nuodb_globals_test.py
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()
92 changes: 92 additions & 0 deletions tests/nuodb_huge_test.py
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()
Loading

0 comments on commit 2fc888d

Please sign in to comment.