예제 #1
0
    def description(self):
        """Read-only attribute containing a sequence of the following items:

        -   ``name``
        -   ``type_code``
        -   ``display_size``
        -   ``internal_size``
        -   ``precision``
        -   ``scale``
        -   ``null_ok``

        :rtype: tuple
        :returns: A tuple of columns' information.
        """
        if not self._result_set:
            return None

        if not getattr(self._result_set, "metadata", None):
            return None

        row_type = self._result_set.metadata.row_type
        columns = []

        for field in row_type.fields:
            column_info = ColumnInfo(
                name=field.name,
                type_code=field.type_.code,
                # Size of the SQL type of the column.
                display_size=code_to_display_size.get(field.type_.code),
                # Client perceived size of the column.
                internal_size=field._pb.ByteSize(),
            )
            columns.append(column_info)

        return tuple(columns)
예제 #2
0
    def description(self):
        """
        Read-only attribute containing the result columns description
        of a form:

        -   ``name``
        -   ``type_code``
        -   ``display_size``
        -   ``internal_size``
        -   ``precision``
        -   ``scale``
        -   ``null_ok``

        :rtype: tuple
        :returns: The result columns' description.
        """
        if not getattr(self._result_set, "metadata", None):
            return

        columns = []
        for field in self._result_set.metadata.row_type.fields:
            columns.append(
                ColumnInfo(
                    name=field.name,
                    type_code=field.type_.code,
                    # Size of the SQL type of the column.
                    display_size=CODE_TO_DISPLAY_SIZE.get(field.type_.code),
                    # Client perceived size of the column.
                    internal_size=field._pb.ByteSize(),
                )
            )
        return tuple(columns)
예제 #3
0
 def test_get_field_type_text_field(self):
     """
     Tests get field type for text field.
     """
     db_introspection = DatabaseIntrospection(self.connection)
     self.assertEqual(
         db_introspection.get_field_type(
             TypeCode.STRING,
             description=ColumnInfo(
                 name="name",
                 type_code=TypeCode.STRING,
                 internal_size="MAX",
             ),
         ),
         "TextField",
     )