Esempio n. 1
0
    def new_from_scratch(threaded, events, encoding, nencoding):
        mode = oci.OCI_OBJECT
        if threaded:
            mode |= oci.OCI_THREADED
        #TODO: if EVENTS_SUPPORTED:
        #    if events:
        #        mode |= ociap.OCI_EVENTS

        argtypes = oci.OCIEnvNlsCreate.argtypes
        handle = oci.POINTER(oci.OCIEnv)()

        status = oci.OCIEnvNlsCreate(byref(handle), mode, argtypes[2](),
                                     argtypes[3](), argtypes[4](),
                                     argtypes[5](), 0, None, 0, 0)

        if not handle or (status != oci.OCI_SUCCESS
                          and status != oci.OCI_SUCCESS_WITH_INFO):
            raise InterfaceError("Unable to acquire Oracle environment handle")

        env = Environment(handle)

        c_maxBytesPerCharacter = oci.sb4()
        status = oci.OCINlsNumericInfoGet(handle, env.error_handle,
                                          byref(c_maxBytesPerCharacter),
                                          oci.OCI_NLS_CHARSET_MAXBYTESZ)
        env.check_for_error(status,
                            "Environment_New(): get max bytes per character")
        env.maxBytesPerCharacter = c_maxBytesPerCharacter.value

        env.maxStringBytes = MAX_STRING_CHARS * env.maxBytesPerCharacter

        # acquire whether character set is fixed width
        c_fixedWidth = oci.sb4()
        status = oci.OCINlsNumericInfoGet(handle, env.error_handle,
                                          byref(c_fixedWidth),
                                          oci.OCI_NLS_CHARSET_FIXEDWIDTH)
        env.check_for_error(
            status, "Environment_New(): determine if charset fixed width")
        env.fixedWidth = c_fixedWidth.value

        # determine encodings to use for Unicode values
        env.encoding = env.get_characterset_name(oci.OCI_ATTR_ENV_CHARSET_ID,
                                                 encoding)
        env.nencoding = env.get_characterset_name(oci.OCI_ATTR_ENV_NCHARSET_ID,
                                                  nencoding)

        # fill buffers for number formats
        env.numberToStringFormatBuffer = Environment.set_buffer(
            "TM9", env.encoding)
        env.numberFromStringFormatBuffer = Environment.set_buffer(
            "999999999999999999999999999999999999999999999999999999999999999",
            env.encoding)
        env.nlsNumericCharactersBuffer = Environment.set_buffer(
            "NLS_NUMERIC_CHARACTERS='.,'", env.encoding)

        return env
Esempio n. 2
0
def oracle_interval_to_python_delta(environment, value):
    days = oci.sb4()
    hours = oci.sb4()
    minutes = oci.sb4()
    seconds = oci.sb4()
    fseconds = oci.sb4()
    
    status = oci.OCIIntervalGetDaySecond(environment.handle, environment.error_handle, byref(days), 
                                         byref(hours), byref(minutes), byref(seconds), byref(fseconds),
                                         value)
    environment.check_for_error(status, "OracleIntervalToPythonDelta()")
    seconds = hours.value * 3600 + minutes.value * 60 + seconds.value
    return timedelta(days=days.value, seconds=seconds, microseconds=fseconds.value/1000)
Esempio n. 3
0
    def new_from_scratch(threaded, events, encoding, nencoding):
        mode = oci.OCI_OBJECT
        if threaded:
            mode |= oci.OCI_THREADED
        #TODO: if EVENTS_SUPPORTED:
        #    if events:
        #        mode |= ociap.OCI_EVENTS
        
        argtypes = oci.OCIEnvNlsCreate.argtypes
        handle = oci.POINTER(oci.OCIEnv)()
        
        status = oci.OCIEnvNlsCreate(byref(handle), mode, argtypes[2](), argtypes[3](), argtypes[4](), argtypes[5](), 0, None, 0, 0)

        if not handle or (status != oci.OCI_SUCCESS and status != oci.OCI_SUCCESS_WITH_INFO):
            raise InterfaceError("Unable to acquire Oracle environment handle")

        env = Environment(handle)

        c_maxBytesPerCharacter = oci.sb4()
        status = oci.OCINlsNumericInfoGet(handle, env.error_handle, byref(c_maxBytesPerCharacter), oci.OCI_NLS_CHARSET_MAXBYTESZ)
        env.check_for_error(status, "Environment_New(): get max bytes per character")
        env.maxBytesPerCharacter = c_maxBytesPerCharacter.value
        

        env.maxStringBytes = MAX_STRING_CHARS * env.maxBytesPerCharacter

        # acquire whether character set is fixed width
        c_fixedWidth = oci.sb4()
        status = oci.OCINlsNumericInfoGet(handle, env.error_handle, byref(c_fixedWidth), oci.OCI_NLS_CHARSET_FIXEDWIDTH)
        env.check_for_error(status, "Environment_New(): determine if charset fixed width")
        env.fixedWidth = c_fixedWidth.value
        
        # determine encodings to use for Unicode values
        env.encoding = env.get_characterset_name(oci.OCI_ATTR_ENV_CHARSET_ID, encoding)
        env.nencoding = env.get_characterset_name(oci.OCI_ATTR_ENV_NCHARSET_ID, nencoding)

        # fill buffers for number formats
        env.numberToStringFormatBuffer = Environment.set_buffer("TM9", env.encoding)
        env.numberFromStringFormatBuffer = Environment.set_buffer("999999999999999999999999999999999999999999999999999999999999999", env.encoding)
        env.nlsNumericCharactersBuffer = Environment.set_buffer("NLS_NUMERIC_CHARACTERS='.,'", env.encoding)

        return env
Esempio n. 4
0
def oracle_interval_to_python_delta(environment, value):
    days = oci.sb4()
    hours = oci.sb4()
    minutes = oci.sb4()
    seconds = oci.sb4()
    fseconds = oci.sb4()

    status = oci.OCIIntervalGetDaySecond(
        environment.handle,
        environment.error_handle,
        byref(days),
        byref(hours),
        byref(minutes),
        byref(seconds),
        byref(fseconds),
        value,
    )
    environment.check_for_error(status, "OracleIntervalToPythonDelta()")
    seconds = hours.value * 3600 + minutes.value * 60 + seconds.value
    return timedelta(days=days.value, seconds=seconds, microseconds=fseconds.value / 1000)
Esempio n. 5
0
    def __init__(self, environment, context, retrieve_error):
        self.context = context
        if retrieve_error:
            if environment.error_handle:
                handle = environment.error_handle
                handle_type = oci.OCI_HTYPE_ERROR
            else:
                handle = environment.handle
                handle_type = oci.OCI_HTYPE_ENV

            error_text = ctypes.create_string_buffer(4096)
            error_text_as_ub1_pointer = ctypes.cast(error_text, oci.POINTER(oci.ub1))
            c_code = oci.sb4()
            argtypes = oci.OCIErrorGet.argtypes
            status = oci.OCIErrorGet(handle, 1, argtypes[2](), byref(c_code), error_text_as_ub1_pointer, len(error_text), handle_type)
            self.code = c_code.value
            if status != oci.OCI_SUCCESS:
                raise InternalError("No Oracle error?")

            if not python3_or_better():
                self.message = error_text.value
            else:
                self.message = error_text.decode(environment.encoding)