def _value(self, offset, amount):
        from lobvar import vt_CLOB, vt_NCLOB
        """Return a portion (or all) of the data in the external LOB variable."""
        lob_type = self.lob_var.type
        
        # modify the arguments
        if offset < 0:
            offset = 1
        
        if amount < 0:
            amount = self._internal_size()
            amount = amount - offset + 1;
            if amount <= 0:
                amount = 1
        
        buffer = self._internal_read(offset, amount)
        
        if lob_type == vt_CLOB:
            #if self.lob_var.environment.fixedWidth:
            #    length = length * self.lob_var.environment.maxBytesPerCharacter
            result = cxString_from_encoded_string(buffer, self.lob_var.environment.encoding)
        elif lob_type == vt_NCLOB:
            result = buffer.decode(self.lob_var.environment.encoding)
        else:
            result = bytes(buffer)

        return result
    def _value(self, offset, amount):
        from lobvar import vt_CLOB, vt_NCLOB
        """Return a portion (or all) of the data in the external LOB variable."""
        lob_type = self.lob_var.type

        # modify the arguments
        if offset < 0:
            offset = 1

        if amount < 0:
            amount = self._internal_size()
            amount = amount - offset + 1
            if amount <= 0:
                amount = 1

        buffer = self._internal_read(offset, amount)

        if lob_type == vt_CLOB:
            #if self.lob_var.environment.fixedWidth:
            #    length = length * self.lob_var.environment.maxBytesPerCharacter
            result = cxString_from_encoded_string(
                buffer, self.lob_var.environment.encoding)
        elif lob_type == vt_NCLOB:
            result = buffer.decode(self.lob_var.environment.encoding)
        else:
            result = bytes(buffer)

        return result
Example #3
0
    def get_value(self, var, pos):
        """Returns the value stored at the given array position."""
        if not python3_or_better():
            types = (vt_Boolean, vt_Integer)
        else:
            types = (vt_Boolean,)

        typed_data = self.get_typed_data(var)

        if var.type in types:
            c_integer_value = ctypes.c_long()
            status = oci.OCINumberToInt(
                var.environment.error_handle,
                byref(typed_data[pos]),
                ctypes.sizeof(c_integer_value),
                oci.OCI_NUMBER_SIGNED,
                byref(c_integer_value),
            )
            integer_value = c_integer_value.value
            var.environment.check_for_error(status, "NumberVar_GetValue(): as integer")

            if not python3_or_better():
                if var.type is vt_Integer:
                    return integer_value

            return bool(integer_value)

        if var.type in (vt_NumberAsString, vt_LongInteger):
            c_string = ctypes.create_string_buffer(200)
            cast_c_string = ctypes.cast(c_string, oci.POINTER(oci.ub1))

            c_string_length = oci.ub4()
            c_string_length.value = ctypes.sizeof(c_string)

            typed_data = self.get_typed_data(var)
            status = oci.OCINumberToText(
                var.environment.error_handle,
                byref(typed_data[pos]),
                var.environment.numberToStringFormatBuffer.cast_ptr,
                var.environment.numberToStringFormatBuffer.size,
                None,
                0,
                byref(c_string_length),
                cast_c_string,
            )
            var.environment.check_for_error(status, "NumberVar_GetValue(): as string")

            python_string = c_string.value

            unicode_str = cxString_from_encoded_string(python_string, var.environment.encoding)

            if var.type is vt_NumberAsString:
                return unicode_str

            try:
                return int(unicode_str)
            except ValueError:
                pass

        return oracle_number_to_python_float(var.environment, byref(typed_data[pos]))
Example #4
0
    def get_value(self, var, pos):
        """Returns the value stored at the given array position."""
        if not python3_or_better():
            types = (vt_Boolean, vt_Integer)
        else:
            types = (vt_Boolean, )

        typed_data = self.get_typed_data(var)

        if var.type in types:
            c_integer_value = ctypes.c_long()
            status = oci.OCINumberToInt(var.environment.error_handle,
                                        byref(typed_data[pos]),
                                        ctypes.sizeof(c_integer_value),
                                        oci.OCI_NUMBER_SIGNED,
                                        byref(c_integer_value))
            integer_value = c_integer_value.value
            var.environment.check_for_error(
                status, "NumberVar_GetValue(): as integer")

            if not python3_or_better():
                if var.type is vt_Integer:
                    return integer_value

            return bool(integer_value)

        if var.type in (vt_NumberAsString, vt_LongInteger):
            c_string = ctypes.create_string_buffer(200)
            cast_c_string = ctypes.cast(c_string, oci.POINTER(oci.ub1))

            c_string_length = oci.ub4()
            c_string_length.value = ctypes.sizeof(c_string)

            typed_data = self.get_typed_data(var)
            status = oci.OCINumberToText(
                var.environment.error_handle, byref(typed_data[pos]),
                var.environment.numberToStringFormatBuffer.cast_ptr,
                var.environment.numberToStringFormatBuffer.size, None, 0,
                byref(c_string_length), cast_c_string)
            var.environment.check_for_error(status,
                                            "NumberVar_GetValue(): as string")

            python_string = c_string.value

            unicode_str = cxString_from_encoded_string(
                python_string, var.environment.encoding)

            if var.type is vt_NumberAsString:
                return unicode_str

            try:
                return int(unicode_str)
            except ValueError:
                pass

        return oracle_number_to_python_float(var.environment,
                                             byref(typed_data[pos]))
 def get_value(self, var, pos):
     base_ptr_address = ctypes.addressof(var.data) + var.bufferSize * pos
     c_length = oci.ub4.from_address(base_ptr_address)
     length = c_length.value
     
     start_address = var.bufferSize * pos + ctypes.sizeof(oci.ub4)
     the_contents = var.data[start_address: start_address + length]
     
     if var.type == vt_LongBinary:
         return bytes(the_contents)
     
     return cxString_from_encoded_string(the_contents, var.environment.encoding)
Example #6
0
    def get_value(self, var, pos):
        base_ptr_address = ctypes.addressof(var.data) + var.bufferSize * pos
        c_length = oci.ub4.from_address(base_ptr_address)
        length = c_length.value

        start_address = var.bufferSize * pos + ctypes.sizeof(oci.ub4)
        the_contents = var.data[start_address:start_address + length]

        if var.type == vt_LongBinary:
            return bytes(the_contents)

        return cxString_from_encoded_string(the_contents,
                                            var.environment.encoding)
    def get_value(self, var, pos):
        """Returns the value stored at the given array position."""
        data_start_index = pos * var.bufferSize # was pointer arithmetic

        the_data = var.data[data_start_index:data_start_index+var.actual_length[pos]]
        if var.type is vt_Binary:
            return the_data
            
        if not python3_or_better():
            if var.type in (vt_FixedNationalChar, vt_NationalCharString):
                return the_data.decode(var.environment.nencoding)
    
        return cxString_from_encoded_string(the_data, var.environment.encoding)
Example #8
0
    def get_value(self, var, pos):
        """Returns the value stored at the given array position."""
        data_start_index = pos * var.bufferSize  # was pointer arithmetic

        the_data = var.data[data_start_index:data_start_index +
                            var.actual_length[pos]]
        if var.type is vt_Binary:
            return the_data

        if not python3_or_better():
            if var.type in (vt_FixedNationalChar, vt_NationalCharString):
                return the_data.decode(var.environment.nencoding)

        return cxString_from_encoded_string(the_data, var.environment.encoding)