当前位置: 首页>>代码示例>>Python>>正文


Python cx_Oracle.LOB属性代码示例

本文整理汇总了Python中cx_Oracle.LOB属性的典型用法代码示例。如果您正苦于以下问题:Python cx_Oracle.LOB属性的具体用法?Python cx_Oracle.LOB怎么用?Python cx_Oracle.LOB使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在cx_Oracle的用法示例。


在下文中一共展示了cx_Oracle.LOB属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import LOB [as 别名]
def __init__(self,
                 auto_convert_lobs=True,
                 threaded=True,
                 coerce_to_unicode=False,
                 coerce_to_decimal=True,
                 arraysize=50,
                 **kwargs):

        self._pop_deprecated_kwargs(kwargs)

        OracleDialect.__init__(self, **kwargs)
        self.threaded = threaded
        self.arraysize = arraysize
        self.auto_convert_lobs = auto_convert_lobs
        self.coerce_to_unicode = coerce_to_unicode
        self.coerce_to_decimal = coerce_to_decimal

        cx_Oracle = self.dbapi

        if cx_Oracle is None:
            self._include_setinputsizes = {}
            self.cx_oracle_ver = (0, 0, 0)
        else:
            self.cx_oracle_ver = self._parse_cx_oracle_ver(cx_Oracle.version)
            if self.cx_oracle_ver < (5, 0) and self.cx_oracle_ver > (0, 0, 0):
                raise exc.InvalidRequestError(
                    "cx_Oracle version 5.0 and above are supported")

            self._has_native_int = hasattr(cx_Oracle, "NATIVE_INT")

            self._include_setinputsizes = {
                cx_Oracle.NCLOB, cx_Oracle.CLOB, cx_Oracle.LOB,
                cx_Oracle.BLOB, cx_Oracle.FIXED_CHAR,
            }

        self._is_cx_oracle_6 = self.cx_oracle_ver >= (6, ) 
开发者ID:yfauser,项目名称:planespotter,代码行数:38,代码来源:cx_oracle.py

示例2: _pop_deprecated_kwargs

# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import LOB [as 别名]
def _pop_deprecated_kwargs(self, kwargs):
        auto_setinputsizes = kwargs.pop('auto_setinputsizes', None)
        exclude_setinputsizes = kwargs.pop('exclude_setinputsizes', None)
        if auto_setinputsizes or exclude_setinputsizes:
            util.warn_deprecated(
                "auto_setinputsizes and exclude_setinputsizes are deprecated. "
                "Modern cx_Oracle only requires that LOB types are part "
                "of this behavior, and these parameters no longer have any "
                "effect.")
        allow_twophase = kwargs.pop('allow_twophase', None)
        if allow_twophase is not None:
            util.warn.deprecated(
                "allow_twophase is deprecated.  The cx_Oracle dialect no "
                "longer supports two-phase transaction mode."
            ) 
开发者ID:yfauser,项目名称:planespotter,代码行数:17,代码来源:cx_oracle.py

示例3: convert_values

# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import LOB [as 别名]
def convert_values(self, value, field):
        if isinstance(value, Database.LOB):
            value = value.read()
            if field and field.get_internal_type() == 'TextField':
                value = force_text(value)

        # Oracle stores empty strings as null. We need to undo this in
        # order to adhere to the Django convention of using the empty
        # string instead of null, but only if the field accepts the
        # empty string.
        if value is None and field and field.empty_strings_allowed:
            value = ''
        # Convert 1 or 0 to True or False
        elif value in (1, 0) and field and field.get_internal_type() in ('BooleanField', 'NullBooleanField'):
            value = bool(value)
        # Force floats to the correct type
        elif value is not None and field and field.get_internal_type() == 'FloatField':
            value = float(value)
        # Convert floats to decimals
        elif value is not None and field and field.get_internal_type() == 'DecimalField':
            value = util.typecast_decimal(field.format_number(value))
        # cx_Oracle always returns datetime.datetime objects for
        # DATE and TIMESTAMP columns, but Django wants to see a
        # python datetime.date, .time, or .datetime.  We use the type
        # of the Field to determine which to cast to, but it's not
        # always available.
        # As a workaround, we cast to date if all the time-related
        # values are 0, or to time if the date is 1/1/1900.
        # This could be cleaned a bit by adding a method to the Field
        # classes to normalize values from the database (the to_python
        # method is used for validation and isn't what we want here).
        elif isinstance(value, Database.Timestamp):
            if field and field.get_internal_type() == 'DateTimeField':
                pass
            elif field and field.get_internal_type() == 'DateField':
                value = value.date()
            elif field and field.get_internal_type() == 'TimeField' or (value.year == 1900 and value.month == value.day == 1):
                value = value.time()
            elif value.hour == value.minute == value.second == value.microsecond == 0:
                value = value.date()
        return value 
开发者ID:blackye,项目名称:luscan-devel,代码行数:43,代码来源:base.py

示例4: field_cast_sql

# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import LOB [as 别名]
def field_cast_sql(self, db_type):
        if db_type and db_type.endswith('LOB'):
            return "DBMS_LOB.SUBSTR(%s)"
        else:
            return "%s" 
开发者ID:blackye,项目名称:luscan-devel,代码行数:7,代码来源:base.py

示例5: query

# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import LOB [as 别名]
def query(self, db_name=None, sql='', limit_num=0, close_conn=True, **kwargs):
        """返回 ResultSet """
        result_set = ResultSet(full_sql=sql)
        try:
            conn = self.get_connection()
            cursor = conn.cursor()
            if db_name:
                cursor.execute(f"ALTER SESSION SET CURRENT_SCHEMA = {db_name}")
            sql = sql.rstrip(';')
            # 支持oralce查询SQL执行计划语句
            if re.match(r"^explain", sql, re.I):
                cursor.execute(sql)
                # 重置SQL文本,获取SQL执行计划
                sql = f"select PLAN_TABLE_OUTPUT from table(dbms_xplan.display)"
            cursor.execute(sql)
            fields = cursor.description
            if any(x[1] == cx_Oracle.CLOB for x in fields):
                rows = [tuple([(c.read() if type(c) == cx_Oracle.LOB else c) for c in r]) for r in cursor]
                if int(limit_num) > 0:
                    rows = rows[0:int(limit_num)]
            else:
                if int(limit_num) > 0:
                    rows = cursor.fetchmany(int(limit_num))
                else:
                    rows = cursor.fetchall()
            result_set.column_list = [i[0] for i in fields] if fields else []
            result_set.rows = [tuple(x) for x in rows]
            result_set.affected_rows = len(result_set.rows)
        except Exception as e:
            logger.warning(f"Oracle 语句执行报错,语句:{sql},错误信息{traceback.format_exc()}")
            result_set.error = str(e)
        finally:
            if close_conn:
                self.close()
        return result_set 
开发者ID:hhyo,项目名称:Archery,代码行数:37,代码来源:oracle.py

示例6: sqltuningadvisor

# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import LOB [as 别名]
def sqltuningadvisor(self, db_name=None, sql='', close_conn=True, **kwargs):
        """
        add by Jan.song 20200421
        使用DBMS_SQLTUNE包做sql tuning支持
        执行用户需要有advior角色
        返回 ResultSet
        """
        result_set = ResultSet(full_sql=sql)
        task_name = 'sqlaudit' + f'''{threading.currentThread().ident}'''
        task_begin = 0
        try:
            conn = self.get_connection()
            cursor = conn.cursor()
            sql = sql.rstrip(';')
            # 创建分析任务
            create_task_sql = f'''DECLARE
                                  my_task_name VARCHAR2(30);
                                  my_sqltext  CLOB;
                                  BEGIN
                                  my_sqltext := '{sql}';
                                  my_task_name := DBMS_SQLTUNE.CREATE_TUNING_TASK(
                                  sql_text    => my_sqltext,
                                  user_name   => '{db_name}', 
                                  scope       => 'COMPREHENSIVE',
                                  time_limit  => 30,
                                  task_name   => '{task_name}',
                                  description => 'tuning');
                                  DBMS_SQLTUNE.EXECUTE_TUNING_TASK( task_name => '{task_name}');
                                  END;'''
            task_begin = 1
            cursor.execute(create_task_sql)
            # 获取分析报告
            get_task_sql = f'''select DBMS_SQLTUNE.REPORT_TUNING_TASK( '{task_name}') from dual'''
            cursor.execute(get_task_sql)
            fields = cursor.description
            if any(x[1] == cx_Oracle.CLOB for x in fields):
                rows = [tuple([(c.read() if type(c) == cx_Oracle.LOB else c) for c in r]) for r in cursor]
            else:
                rows = cursor.fetchall()
            result_set.column_list = [i[0] for i in fields] if fields else []
            result_set.rows = [tuple(x) for x in rows]
            result_set.affected_rows = len(result_set.rows)
        except Exception as e:
            logger.warning(f"Oracle 语句执行报错,语句:{sql},错误信息{traceback.format_exc()}")
            result_set.error = str(e)
        finally:
            # 结束分析任务
            if task_begin == 1:
                end_sql = f'''DECLARE 
                             begin 
                             dbms_sqltune.drop_tuning_task('{task_name}');
                             end;'''
                cursor.execute(end_sql)
            if close_conn:
                self.close()
        return result_set 
开发者ID:hhyo,项目名称:Archery,代码行数:58,代码来源:oracle.py

示例7: __init__

# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import LOB [as 别名]
def __init__(self,
                 auto_convert_lobs=True,
                 threaded=True,
                 coerce_to_unicode=False,
                 coerce_to_decimal=True,
                 arraysize=50,
                 **kwargs):

        self._pop_deprecated_kwargs(kwargs)

        OracleDialect.__init__(self, **kwargs)
        self.threaded = threaded
        self.arraysize = arraysize
        self.auto_convert_lobs = auto_convert_lobs
        self.coerce_to_unicode = coerce_to_unicode
        self.coerce_to_decimal = coerce_to_decimal

        cx_Oracle = self.dbapi

        if cx_Oracle is None:
            self._include_setinputsizes = {}
            self.cx_oracle_ver = (0, 0, 0)
        else:
            self.cx_oracle_ver = self._parse_cx_oracle_ver(cx_Oracle.version)
            if self.cx_oracle_ver < (5, 2) and self.cx_oracle_ver > (0, 0, 0):
                raise exc.InvalidRequestError(
                    "cx_Oracle version 5.2 and above are supported")

            self._has_native_int = hasattr(cx_Oracle, "NATIVE_INT")

            self._include_setinputsizes = {
                cx_Oracle.NCLOB, cx_Oracle.CLOB, cx_Oracle.LOB,
                cx_Oracle.NCHAR, cx_Oracle.FIXED_NCHAR,
                cx_Oracle.BLOB, cx_Oracle.FIXED_CHAR, cx_Oracle.TIMESTAMP,
                _OracleInteger, _OracleBINARY_FLOAT, _OracleBINARY_DOUBLE
            }

            self._paramval = lambda value: value.getvalue()

            # https://github.com/oracle/python-cx_Oracle/issues/176#issuecomment-386821291
            # https://github.com/oracle/python-cx_Oracle/issues/224
            self._values_are_lists = self.cx_oracle_ver >= (6, 3)
            if self._values_are_lists:
                cx_Oracle.__future__.dml_ret_array_val = True

                def _returningval(value):
                    try:
                        return value.values[0][0]
                    except IndexError:
                        return None

                self._returningval = _returningval
            else:
                self._returningval = self._paramval

        self._is_cx_oracle_6 = self.cx_oracle_ver >= (6, ) 
开发者ID:bkerler,项目名称:android_universal,代码行数:58,代码来源:cx_oracle.py


注:本文中的cx_Oracle.LOB属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。