Ejemplo n.º 1
0
 def post_define(self, var):
     """Set the character set information when values are fetched from this variable."""
     c_charset_form = oci.ub1(var.type.charset_form)
     status = oci.OCIAttrSet(var.define_handle, oci.OCI_HTYPE_DEFINE, byref(c_charset_form), 0, 
                         oci.OCI_ATTR_CHARSET_FORM, var.environment.error_handle)
     var.environment.check_for_error(status, "StringVar_PostDefine(): setting charset form")
     var.type.charset_form = c_charset_form.value # warning: mutating shared state. i am not sure why cx oracle does that.
Ejemplo n.º 2
0
    def internal_bind(self):
        """Allocate a variable and bind it to the given statement."""

        if self.is_array:
            alloc_elems = self.allocelems
            actual_elements_ref = byref(self.c_actual_elements)
        else:
            alloc_elems = 0
            actual_elements_ref = oci.POINTER(oci.ub4)()

        # perform the bind
        if self.bound_name:
            buffer = cxBuffer.new_from_object(self.bound_name,
                                              self.environment.encoding)
            status = oci.OCIBindByName(self.bound_cursor_handle,
                                       byref(self.bind_handle),
                                       self.environment.error_handle,
                                       buffer.cast_ptr, buffer.size, self.data,
                                       self.bufferSize, self.type.oracle_type,
                                       self.indicator, self.actual_length,
                                       self.return_code, alloc_elems,
                                       actual_elements_ref, oci.OCI_DEFAULT)
        else:
            status = oci.OCIBindByPos(self.bound_cursor_handle,
                                      byref(self.bind_handle),
                                      self.environment.error_handle,
                                      self.bound_pos, self.data,
                                      self.bufferSize, self.type.oracle_type,
                                      self.indicator, self.actual_length,
                                      self.return_code, alloc_elems,
                                      actual_elements_ref, oci.OCI_DEFAULT)

        self.environment.check_for_error(status, "Variable_InternalBind()")

        if not python3_or_better():
            # set the charset form and id if applicable
            if self.type.charset_form != oci.SQLCS_IMPLICIT:
                c_charset_form = oci.ub1(self.type.charset_form)
                status = oci.OCIAttrSet(self.bind_handle, oci.OCI_HTYPE_BIND,
                                        byref(c_charset_form), 0,
                                        oci.OCI_ATTR_CHARSET_FORM,
                                        self.environment.error_handle)
                self.environment.check_for_error(
                    status, "Variable_InternalBind(): set charset form")
                self.type.charset_form = c_charset_form.value

                c_buffer_size = oci.ub4(self.bufferSize)
                status = oci.OCIAttrSet(self.bind_handle, oci.OCI_HTYPE_BIND,
                                        byref(c_buffer_size), 0,
                                        oci.OCI_ATTR_MAXDATA_SIZE,
                                        self.environment.error_handle)
                self.environment.check_for_error(
                    status, "Variable_InternalBind(): set max data size")
                self.bufferSize = self.maxlength = c_buffer_size.value

        # set the max data size for strings
        self.set_max_data_size()
Ejemplo n.º 3
0
def oracle_timestamp_to_python_date(environment, value):
    """Return a Python date object given an Oracle timestamp."""
    year = oci.sb2()
    month = oci.ub1()
    day = oci.ub1()
    hour = oci.ub1()
    minute = oci.ub1()
    second = oci.ub1()
    fsecond = oci.ub4()
    
    status = oci.OCIDateTimeGetDate(environment.handle, environment.error_handle,
                                    value, byref(year), byref(month), byref(day))
    environment.check_for_error(status, "OracleTimestampToPythonDate(): date portion")
    
    status = oci.OCIDateTimeGetTime(environment.handle, environment.error_handle,
                                    value, byref(hour), byref(minute), byref(second), byref(fsecond))
    environment.check_for_error(status, "OracleTimestampToPythonDate(): time portion")
    
    return datetime(year.value, month.value, day.value, hour.value, minute.value, second.value, fsecond.value / 1000)
Ejemplo n.º 4
0
 def post_define(self, var):
     """Set the character set information when values are fetched from this variable."""
     c_charset_form = oci.ub1(var.type.charset_form)
     status = oci.OCIAttrSet(var.define_handle, oci.OCI_HTYPE_DEFINE,
                             byref(c_charset_form), 0,
                             oci.OCI_ATTR_CHARSET_FORM,
                             var.environment.error_handle)
     var.environment.check_for_error(
         status, "StringVar_PostDefine(): setting charset form")
     var.type.charset_form = c_charset_form.value  # warning: mutating shared state. i am not sure why cx oracle does that.
Ejemplo n.º 5
0
def oracle_timestamp_to_python_date(environment, value):
    """Return a Python date object given an Oracle timestamp."""
    year = oci.sb2()
    month = oci.ub1()
    day = oci.ub1()
    hour = oci.ub1()
    minute = oci.ub1()
    second = oci.ub1()
    fsecond = oci.ub4()

    status = oci.OCIDateTimeGetDate(
        environment.handle, environment.error_handle, value, byref(year), byref(month), byref(day)
    )
    environment.check_for_error(status, "OracleTimestampToPythonDate(): date portion")

    status = oci.OCIDateTimeGetTime(
        environment.handle, environment.error_handle, value, byref(hour), byref(minute), byref(second), byref(fsecond)
    )
    environment.check_for_error(status, "OracleTimestampToPythonDate(): time portion")

    return datetime(year.value, month.value, day.value, hour.value, minute.value, second.value, fsecond.value / 1000)
Ejemplo n.º 6
0
    def internal_bind(self):
        """Allocate a variable and bind it to the given statement."""

        if self.is_array:
            alloc_elems = self.allocelems
            actual_elements_ref = byref(self.c_actual_elements)
        else:
            alloc_elems = 0
            actual_elements_ref = oci.POINTER(oci.ub4)()
        
        # perform the bind
        if self.bound_name:
            buffer = cxBuffer.new_from_object(self.bound_name, self.environment.encoding)
            status = oci.OCIBindByName(self.bound_cursor_handle, byref(self.bind_handle),
                        self.environment.error_handle, buffer.cast_ptr,
                        buffer.size, self.data, self.bufferSize,
                        self.type.oracle_type, self.indicator, self.actual_length,
                        self.return_code, alloc_elems,
                        actual_elements_ref, oci.OCI_DEFAULT)
        else:
            status = oci.OCIBindByPos(self.bound_cursor_handle, byref(self.bind_handle),
                        self.environment.error_handle, self.bound_pos, self.data,
                        self.bufferSize, self.type.oracle_type, self.indicator,
                        self.actual_length, self.return_code, alloc_elems,
                        actual_elements_ref, oci.OCI_DEFAULT)
        
        self.environment.check_for_error(status, "Variable_InternalBind()")

        if not python3_or_better():
            # set the charset form and id if applicable
            if self.type.charset_form != oci.SQLCS_IMPLICIT:
                c_charset_form = oci.ub1(self.type.charset_form)
                status = oci.OCIAttrSet(self.bind_handle, oci.OCI_HTYPE_BIND,
                        byref(c_charset_form), 0, oci.OCI_ATTR_CHARSET_FORM,
                        self.environment.error_handle)
                self.environment.check_for_error(status, "Variable_InternalBind(): set charset form")
                self.type.charset_form = c_charset_form.value
                
                c_buffer_size = oci.ub4(self.bufferSize)
                status = oci.OCIAttrSet(self.bind_handle, oci.OCI_HTYPE_BIND,
                        byref(c_buffer_size), 0, oci.OCI_ATTR_MAXDATA_SIZE,
                        self.environment.error_handle)
                self.environment.check_for_error(status, "Variable_InternalBind(): set max data size")
                self.bufferSize = self.maxlength = c_buffer_size.value

        # set the max data size for strings
        self.set_max_data_size()