Changeset: 8b8881fca40b for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8b8881fca40b
Modified Files:
        clients/python/monetdb/sql/connections.py
        clients/python/monetdb/sql/cursors.py
        clients/python/test/capabilities.py
        clients/python/test/runtests.py
Branch: Jul2012
Log Message:

Merged with parallel Jul2012 branch head


diffs (164 lines):

diff --git a/clients/python/monetdb/sql/connections.py 
b/clients/python/monetdb/sql/connections.py
--- a/clients/python/monetdb/sql/connections.py
+++ b/clients/python/monetdb/sql/connections.py
@@ -54,10 +54,10 @@ class Connection:
         if host is not None:
             hostname = host
         self.mapi = mapi.Server()
-        self.autocommit = autocommit
         self.mapi.connect(hostname=hostname, port=int(port), username=username,
             password=password, database=database, language="sql")
-        self.set_autocommit(self.autocommit)
+        self.set_autocommit(autocommit)
+        self.set_sizeheader(True)
         self.use_unicode=use_unicode
 
 
@@ -89,6 +89,14 @@ class Connection:
         self.autocommit = autocommit
 
 
+    def set_sizeheader(self, sizeheader):
+        """
+        Set sizeheader on or off. When enabled monetdb will return
+        the size a type. 'sizeheader' must be a boolean.
+        """
+        self.command("Xsizeheader %s" % int(sizeheader))
+        self.sizeheader = sizeheader
+
 
     def commit(self):
         """
diff --git a/clients/python/monetdb/sql/cursors.py 
b/clients/python/monetdb/sql/cursors.py
--- a/clients/python/monetdb/sql/cursors.py
+++ b/clients/python/monetdb/sql/cursors.py
@@ -407,15 +407,16 @@ class Cursor:
             rows = []
 
             # set up fields for description
-            empty = [None]*columns
-            table_name = empty
-            column_name = empty
-            type = empty
-            display_size = empty
-            internal_size = empty
-            precision = empty
-            scale = empty
-            null_ok = empty
+            table_name = [None]*columns
+            column_name = [None]*columns
+            type_ = [None]*columns
+            display_size = [None]*columns
+            internal_size = [None]*columns
+            precision = [None]*columns
+            scale = [None]*columns
+            null_ok = [None]*columns
+
+            typesizes = [(0,0)]*columns
 
             for line in lines[1:]:
                 if line.startswith(mapi.MSG_HEADER):
@@ -428,17 +429,23 @@ class Cursor:
                     elif identity == "name":
                         column_name = values
                     elif identity == "type":
-                        type = values
+                        type_ = values
                     elif identity == "length":
-                        internal_size = [int(x) for x in values]
-                        display_size = internal_size
+                        pass # not used
+                    elif identity == "typesizes":
+                        typesizes = [[int(j) for j in i.split()] for i in 
values]
+                        internal_size = [x[0] for x in typesizes]
+                        for num, typeelem in enumerate(type_):
+                            if typeelem in ['decimal']:
+                                precision[num] = typesizes[num][0]
+                                scale[num] = typesizes[num][1]
                     else:
                         self.messages.append((InterfaceError,
                             "unknown header field"))
                         self.__exception_handler(InterfaceError,
                                 "unknown header field")
 
-                    self.description = list(zip(column_name, type,
+                    self.description = list(zip(column_name, type_,
                         display_size, internal_size, precision, scale, 
null_ok))
 
                 if line.startswith(mapi.MSG_TUPLE):
diff --git a/clients/python/test/capabilities.py 
b/clients/python/test/capabilities.py
--- a/clients/python/test/capabilities.py
+++ b/clients/python/test/capabilities.py
@@ -122,11 +122,11 @@ class DatabaseTest(unittest.TestCase):
         l = self.cursor.fetchall()
         if self.debug:
             print(l)
-        self.assertEquals(len(l), self.rows)
+        self.assertEqual(len(l), self.rows)
         try:
             for i in range(self.rows):
                 for j in range(len(columndefs)):
-                    self.assertEquals(l[i][j], generator(i,j))
+                    self.assertEqual(l[i][j], generator(i,j))
         finally:
             if not self.debug:
                 self.cursor.execute('drop table %s' % (self.table))
@@ -148,10 +148,10 @@ class DatabaseTest(unittest.TestCase):
         self.connection.commit()
         self.cursor.execute('select * from %s' % self.table)
         l = self.cursor.fetchall()
-        self.assertEquals(len(l), self.rows)
+        self.assertEqual(len(l), self.rows)
         for i in range(self.rows):
             for j in range(len(columndefs)):
-                self.assertEquals(l[i][j], generator(i,j))
+                self.assertEqual(l[i][j], generator(i,j))
         delete_statement = 'delete from %s where col1=%%s' % self.table
         self.cursor.execute(delete_statement, (0,))
         self.cursor.execute('select col1 from %s where col1=%s' % \
diff --git a/clients/python/test/runtests.py b/clients/python/test/runtests.py
--- a/clients/python/test/runtests.py
+++ b/clients/python/test/runtests.py
@@ -80,6 +80,19 @@ class Test_Capabilities(capabilities.Dat
             username=TSTUSERNAME, password=TSTPASSWORD, autocommit=False)
     leak_test = False
 
+    def test_description(self):
+        self.table = self.new_table_name()
+        self.cursor.execute("create table %s (c VARCHAR(1024), d DECIMAL(9,4), 
n VARCHAR(1) NOT NULL)" % self.table);
+        self.cursor.execute("insert into %s VALUES ('test', 12345.1234, 'x')" 
% self.table)
+        self.cursor.execute('select * from %s' % self.table)
+        description = self.cursor.description
+        shouldbe = [
+            ('c', 'varchar', None, 1024, None, None, None),
+            ('d', 'decimal', None, 9, 9, 4, None),
+            ('n', 'varchar', None, 1, None, None, None),
+        ]
+        self.assertEqual(description, shouldbe, "cursor.description is 
incorrect")
+
     def test_bigresult(self):
         self.cursor.execute('select count(*) from tables')
         r = self.cursor.fetchone()
@@ -87,9 +100,7 @@ class Test_Capabilities(capabilities.Dat
         self.cursor.arraysize=1000
         self.cursor.execute('select * from tables, tables')
         r = self.cursor.fetchall()
-        self.assertEquals(len(r), n**2)
-
-
+        self.assertEqual(len(r), n**2)
 
 
 
@@ -122,10 +133,9 @@ class Test_DBAPI20(dbapi20.DatabaseAPI20
     def _connect(self):
         try:
             con = self.driver.connect( *self.connect_args, 
**self.connect_kwargs)
+            return con
         except AttributeError:
             self.fail("No connect method found in self.driver module")
-        finally:
-            return con
 
 
     def tearDown(self):
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to