You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ca...@codespot.com on 2012/08/19 23:09:56 UTC

[cassandra-dbapi2] push by pcannon@gmail.com - share type objects in cursor.name_info attr on 2012-08-19 21:09 GMT

Revision: e434b96cc6cf
Author:   paul cannon <pa...@datastax.com>
Date:     Sun Aug 19 14:09:48 2012
Log:      share type objects in cursor.name_info attr

http://code.google.com/a/apache-extras.org/p/cassandra-dbapi2/source/detail?r=e434b96cc6cf

Modified:
  /cql/cqltypes.py
  /cql/cursor.py
  /cql/decoders.py

=======================================
--- /cql/cqltypes.py	Sun Aug 19 13:16:40 2012
+++ /cql/cqltypes.py	Sun Aug 19 14:09:48 2012
@@ -149,6 +149,10 @@
      def cass_parameterized_type(cls, full=False):
          return cls.cass_parameterized_type_with(cls.subtypes, full=full)

+# it's initially named with a _ to avoid registering it as a real type, but
+# client programs may want to use the name still for isinstance(), etc
+CassandraType = _CassandraType
+
  class _UnrecognizedType(_CassandraType):
      num_subtypes = 'UNKNOWN'

=======================================
--- /cql/cursor.py	Sun Aug 19 13:16:40 2012
+++ /cql/cursor.py	Sun Aug 19 14:09:48 2012
@@ -42,6 +42,7 @@
      _ddl_re = re.compile("\s*(CREATE|ALTER|DROP)\s+",
                           re.IGNORECASE | re.MULTILINE)
      supports_prepared_queries = False
+    supports_column_types = True
      supports_name_info = True

      def __init__(self, parent_connection):
@@ -110,6 +111,7 @@
          self.rowcount = 0
          self.description = None
          self.name_info = None
+        self.column_types = None

      def execute(self, cql_query, params={}, decoder=None):
          if isinstance(cql_query, unicode):
@@ -153,10 +155,7 @@
              self.rs_idx = 0
              self.rowcount = len(self.result)
              if self.result:
-                self.description, self.name_info, self.column_types = \
-                         
self.decoder.decode_metadata_and_types(self.result[0])
-            else:
-                self.description = None
+                self.get_metadata_info(self.result[0])
          elif response.type == CqlResultType.INT:
              self.result = [(response.num,)]
              self.rs_idx = 0
@@ -176,6 +175,10 @@
          # 'Return values are not defined.'
          return True

+    def get_metadata_info(self, row):
+        self.description, self.name_info, self.column_types = \
+                self.decoder.decode_metadata_and_types(row)
+
      def executemany(self, operation_list, argslist):
          self.__checksock()
          opssize = len(operation_list)
@@ -201,8 +204,7 @@
          else:
              if self.cql_major_version < 3:
                  # (don't bother redecoding descriptions or names otherwise)
-                self.description, self.name_info, self.column_types = \
-                        self.decoder.decode_metadata_and_types(row)
+                self.get_metadata_info(row)
              return self.decoder.decode_row(row, self.column_types)

      def fetchmany(self, size=None):
=======================================
--- /cql/decoders.py	Sun Aug 19 13:16:40 2012
+++ /cql/decoders.py	Sun Aug 19 14:09:48 2012
@@ -56,7 +56,7 @@
                  name = self.name_decode_error(e, namebytes, comparator)
              column_types.append(valdtype)
              description.append((name, validator, None, None, None, None,  
True))
-            name_info.append((namebytes, comparator))
+            name_info.append((namebytes, comptype))

          return description, name_info, column_types