Python cx_Oracle.FIXED_CHAR Examples
The following are 16
code examples of cx_Oracle.FIXED_CHAR().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cx_Oracle
, or try the search function
.
Example #1
Source File: cx_oracle.py From jbox with MIT License | 5 votes |
def on_connect(self): if self.cx_oracle_ver < (5,): # no output type handlers before version 5 return cx_Oracle = self.dbapi def output_type_handler(cursor, name, defaultType, size, precision, scale): # convert all NUMBER with precision + positive scale to Decimal # this almost allows "native decimal" mode. if self.supports_native_decimal and \ defaultType == cx_Oracle.NUMBER and \ precision and scale > 0: return cursor.var( cx_Oracle.STRING, 255, outconverter=self._to_decimal, arraysize=cursor.arraysize) # if NUMBER with zero precision and 0 or neg scale, this appears # to indicate "ambiguous". Use a slower converter that will # make a decision based on each value received - the type # may change from row to row (!). This kills # off "native decimal" mode, handlers still needed. elif self.supports_native_decimal and \ defaultType == cx_Oracle.NUMBER \ and not precision and scale <= 0: return cursor.var( cx_Oracle.STRING, 255, outconverter=self._detect_decimal, arraysize=cursor.arraysize) # allow all strings to come back natively as Unicode elif self.coerce_to_unicode and \ defaultType in (cx_Oracle.STRING, cx_Oracle.FIXED_CHAR): return cursor.var(util.text_type, size, cursor.arraysize) def on_connect(conn): conn.outputtypehandler = output_type_handler return on_connect
Example #2
Source File: cx_oracle.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def on_connect(self): if self.cx_oracle_ver < (5,): # no output type handlers before version 5 return cx_Oracle = self.dbapi def output_type_handler(cursor, name, defaultType, size, precision, scale): # convert all NUMBER with precision + positive scale to Decimal # this almost allows "native decimal" mode. if self.supports_native_decimal and \ defaultType == cx_Oracle.NUMBER and \ precision and scale > 0: return cursor.var( cx_Oracle.STRING, 255, outconverter=self._to_decimal, arraysize=cursor.arraysize) # if NUMBER with zero precision and 0 or neg scale, this appears # to indicate "ambiguous". Use a slower converter that will # make a decision based on each value received - the type # may change from row to row (!). This kills # off "native decimal" mode, handlers still needed. elif self.supports_native_decimal and \ defaultType == cx_Oracle.NUMBER \ and not precision and scale <= 0: return cursor.var( cx_Oracle.STRING, 255, outconverter=self._detect_decimal, arraysize=cursor.arraysize) # allow all strings to come back natively as Unicode elif self.coerce_to_unicode and \ defaultType in (cx_Oracle.STRING, cx_Oracle.FIXED_CHAR): return cursor.var(util.text_type, size, cursor.arraysize) def on_connect(conn): conn.outputtypehandler = output_type_handler return on_connect
Example #3
Source File: base.py From python with Apache License 2.0 | 5 votes |
def _rowfactory(row, cursor): # Cast numeric values as the appropriate Python type based upon the # cursor description, and convert strings to unicode. casted = [] for value, desc in zip(row, cursor.description): if value is not None and desc[1] is Database.NUMBER: precision = desc[4] or 0 scale = desc[5] or 0 if scale == -127: if precision == 0: # NUMBER column: decimal-precision floating point # This will normally be an integer from a sequence, # but it could be a decimal value. if '.' in value: value = decimal.Decimal(value) else: value = int(value) else: # FLOAT column: binary-precision floating point. # This comes from FloatField columns. value = float(value) elif precision > 0: # NUMBER(p,s) column: decimal-precision fixed point. # This comes from IntField and DecimalField columns. if scale == 0: value = int(value) else: value = decimal.Decimal(value) elif '.' in value: # No type information. This normally comes from a # mathematical expression in the SELECT list. Guess int # or Decimal based on whether it has a decimal point. value = decimal.Decimal(value) else: value = int(value) elif desc[1] in (Database.STRING, Database.FIXED_CHAR, Database.LONG_STRING): value = to_unicode(value) casted.append(value) return tuple(casted)
Example #4
Source File: cx_oracle.py From planespotter with MIT License | 5 votes |
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, )
Example #5
Source File: base.py From openhgsenti with Apache License 2.0 | 5 votes |
def _rowfactory(row, cursor): # Cast numeric values as the appropriate Python type based upon the # cursor description, and convert strings to unicode. casted = [] for value, desc in zip(row, cursor.description): if value is not None and desc[1] is Database.NUMBER: precision, scale = desc[4:6] if scale == -127: if precision == 0: # NUMBER column: decimal-precision floating point # This will normally be an integer from a sequence, # but it could be a decimal value. if '.' in value: value = decimal.Decimal(value) else: value = int(value) else: # FLOAT column: binary-precision floating point. # This comes from FloatField columns. value = float(value) elif precision > 0: # NUMBER(p,s) column: decimal-precision fixed point. # This comes from IntField and DecimalField columns. if scale == 0: value = int(value) else: value = decimal.Decimal(value) elif '.' in value: # No type information. This normally comes from a # mathematical expression in the SELECT list. Guess int # or Decimal based on whether it has a decimal point. value = decimal.Decimal(value) else: value = int(value) elif desc[1] in (Database.STRING, Database.FIXED_CHAR, Database.LONG_STRING): value = to_unicode(value) casted.append(value) return tuple(casted)
Example #6
Source File: cx_oracle.py From pyRevit with GNU General Public License v3.0 | 5 votes |
def on_connect(self): if self.cx_oracle_ver < (5,): # no output type handlers before version 5 return cx_Oracle = self.dbapi def output_type_handler(cursor, name, defaultType, size, precision, scale): # convert all NUMBER with precision + positive scale to Decimal # this almost allows "native decimal" mode. if self.supports_native_decimal and \ defaultType == cx_Oracle.NUMBER and \ precision and scale > 0: return cursor.var( cx_Oracle.STRING, 255, outconverter=self._to_decimal, arraysize=cursor.arraysize) # if NUMBER with zero precision and 0 or neg scale, this appears # to indicate "ambiguous". Use a slower converter that will # make a decision based on each value received - the type # may change from row to row (!). This kills # off "native decimal" mode, handlers still needed. elif self.supports_native_decimal and \ defaultType == cx_Oracle.NUMBER \ and not precision and scale <= 0: return cursor.var( cx_Oracle.STRING, 255, outconverter=self._detect_decimal, arraysize=cursor.arraysize) # allow all strings to come back natively as Unicode elif self.coerce_to_unicode and \ defaultType in (cx_Oracle.STRING, cx_Oracle.FIXED_CHAR): return cursor.var(util.text_type, size, cursor.arraysize) def on_connect(conn): conn.outputtypehandler = output_type_handler return on_connect
Example #7
Source File: base.py From python2017 with MIT License | 5 votes |
def _rowfactory(row, cursor): # Cast numeric values as the appropriate Python type based upon the # cursor description, and convert strings to unicode. casted = [] for value, desc in zip(row, cursor.description): if value is not None and desc[1] is Database.NUMBER: precision = desc[4] or 0 scale = desc[5] or 0 if scale == -127: if precision == 0: # NUMBER column: decimal-precision floating point # This will normally be an integer from a sequence, # but it could be a decimal value. if '.' in value: value = decimal.Decimal(value) else: value = int(value) else: # FLOAT column: binary-precision floating point. # This comes from FloatField columns. value = float(value) elif precision > 0: # NUMBER(p,s) column: decimal-precision fixed point. # This comes from IntField and DecimalField columns. if scale == 0: value = int(value) else: value = decimal.Decimal(value) elif '.' in value: # No type information. This normally comes from a # mathematical expression in the SELECT list. Guess int # or Decimal based on whether it has a decimal point. value = decimal.Decimal(value) else: value = int(value) elif desc[1] in (Database.STRING, Database.FIXED_CHAR, Database.LONG_STRING): value = to_unicode(value) casted.append(value) return tuple(casted)
Example #8
Source File: cx_oracle.py From stdm with GNU General Public License v2.0 | 5 votes |
def on_connect(self): if self.cx_oracle_ver < (5,): # no output type handlers before version 5 return cx_Oracle = self.dbapi def output_type_handler(cursor, name, defaultType, size, precision, scale): # convert all NUMBER with precision + positive scale to Decimal # this almost allows "native decimal" mode. if self.supports_native_decimal and \ defaultType == cx_Oracle.NUMBER and \ precision and scale > 0: return cursor.var( cx_Oracle.STRING, 255, outconverter=self._to_decimal, arraysize=cursor.arraysize) # if NUMBER with zero precision and 0 or neg scale, this appears # to indicate "ambiguous". Use a slower converter that will # make a decision based on each value received - the type # may change from row to row (!). This kills # off "native decimal" mode, handlers still needed. elif self.supports_native_decimal and \ defaultType == cx_Oracle.NUMBER \ and not precision and scale <= 0: return cursor.var( cx_Oracle.STRING, 255, outconverter=self._detect_decimal, arraysize=cursor.arraysize) # allow all strings to come back natively as Unicode elif self.coerce_to_unicode and \ defaultType in (cx_Oracle.STRING, cx_Oracle.FIXED_CHAR): return cursor.var(util.text_type, size, cursor.arraysize) def on_connect(conn): conn.outputtypehandler = output_type_handler return on_connect
Example #9
Source File: cx_oracle.py From jarvis with GNU General Public License v2.0 | 5 votes |
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, )
Example #10
Source File: cx_oracle.py From moviegrabber with GNU General Public License v3.0 | 5 votes |
def on_connect(self): if self.cx_oracle_ver < (5,): # no output type handlers before version 5 return cx_Oracle = self.dbapi def output_type_handler(cursor, name, defaultType, size, precision, scale): # convert all NUMBER with precision + positive scale to Decimal # this almost allows "native decimal" mode. if self.supports_native_decimal and \ defaultType == cx_Oracle.NUMBER and \ precision and scale > 0: return cursor.var( cx_Oracle.STRING, 255, outconverter=self._to_decimal, arraysize=cursor.arraysize) # if NUMBER with zero precision and 0 or neg scale, this appears # to indicate "ambiguous". Use a slower converter that will # make a decision based on each value received - the type # may change from row to row (!). This kills # off "native decimal" mode, handlers still needed. elif self.supports_native_decimal and \ defaultType == cx_Oracle.NUMBER \ and not precision and scale <= 0: return cursor.var( cx_Oracle.STRING, 255, outconverter=self._detect_decimal, arraysize=cursor.arraysize) # allow all strings to come back natively as Unicode elif self.coerce_to_unicode and \ defaultType in (cx_Oracle.STRING, cx_Oracle.FIXED_CHAR): return cursor.var(util.text_type, size, cursor.arraysize) def on_connect(conn): conn.outputtypehandler = output_type_handler return on_connect
Example #11
Source File: base.py From GTDWeb with GNU General Public License v2.0 | 4 votes |
def _rowfactory(row, cursor): # Cast numeric values as the appropriate Python type based upon the # cursor description, and convert strings to unicode. casted = [] for value, desc in zip(row, cursor.description): if value is not None and desc[1] is Database.NUMBER: precision, scale = desc[4:6] if scale == -127: if precision == 0: # NUMBER column: decimal-precision floating point # This will normally be an integer from a sequence, # but it could be a decimal value. if '.' in value: value = decimal.Decimal(value) else: value = int(value) else: # FLOAT column: binary-precision floating point. # This comes from FloatField columns. value = float(value) elif precision > 0: # NUMBER(p,s) column: decimal-precision fixed point. # This comes from IntField and DecimalField columns. if scale == 0: value = int(value) else: value = decimal.Decimal(value) elif '.' in value: # No type information. This normally comes from a # mathematical expression in the SELECT list. Guess int # or Decimal based on whether it has a decimal point. value = decimal.Decimal(value) else: value = int(value) # datetimes are returned as TIMESTAMP, except the results # of "dates" queries, which are returned as DATETIME. elif desc[1] in (Database.TIMESTAMP, Database.DATETIME): # Confirm that dt is naive before overwriting its tzinfo. if settings.USE_TZ and value is not None and timezone.is_naive(value): value = value.replace(tzinfo=timezone.utc) elif desc[1] in (Database.STRING, Database.FIXED_CHAR, Database.LONG_STRING): value = to_unicode(value) casted.append(value) return tuple(casted)
Example #12
Source File: cx_oracle.py From planespotter with MIT License | 4 votes |
def _generate_connection_outputtype_handler(self): """establish the default outputtypehandler established at the connection level. """ dialect = self cx_Oracle = dialect.dbapi number_handler = _OracleNUMBER(asdecimal=True).\ _cx_oracle_outputtypehandler(dialect) float_handler = _OracleNUMBER(asdecimal=False).\ _cx_oracle_outputtypehandler(dialect) def output_type_handler(cursor, name, default_type, size, precision, scale): if default_type == cx_Oracle.NUMBER: if not dialect.coerce_to_decimal: return None elif precision == 0 and scale in (0, -127): # ambiguous type, this occurs when selecting # numbers from deep subqueries return cursor.var( cx_Oracle.STRING, 255, outconverter=dialect._detect_decimal, arraysize=cursor.arraysize) elif precision and scale > 0: return number_handler( cursor, name, default_type, size, precision, scale ) else: return float_handler( cursor, name, default_type, size, precision, scale ) # allow all strings to come back natively as Unicode elif dialect.coerce_to_unicode and \ default_type in (cx_Oracle.STRING, cx_Oracle.FIXED_CHAR): return cursor.var( util.text_type, size, cursor.arraysize ) elif dialect.auto_convert_lobs and default_type in ( cx_Oracle.CLOB, cx_Oracle.NCLOB, cx_Oracle.BLOB ): return cursor.var( default_type, size, cursor.arraysize, outconverter=lambda value: value.read() ) return output_type_handler
Example #13
Source File: base.py From luscan-devel with GNU General Public License v2.0 | 4 votes |
def _rowfactory(row, cursor): # Cast numeric values as the appropriate Python type based upon the # cursor description, and convert strings to unicode. casted = [] for value, desc in zip(row, cursor.description): if value is not None and desc[1] is Database.NUMBER: precision, scale = desc[4:6] if scale == -127: if precision == 0: # NUMBER column: decimal-precision floating point # This will normally be an integer from a sequence, # but it could be a decimal value. if '.' in value: value = decimal.Decimal(value) else: value = int(value) else: # FLOAT column: binary-precision floating point. # This comes from FloatField columns. value = float(value) elif precision > 0: # NUMBER(p,s) column: decimal-precision fixed point. # This comes from IntField and DecimalField columns. if scale == 0: value = int(value) else: value = decimal.Decimal(value) elif '.' in value: # No type information. This normally comes from a # mathematical expression in the SELECT list. Guess int # or Decimal based on whether it has a decimal point. value = decimal.Decimal(value) else: value = int(value) # datetimes are returned as TIMESTAMP, except the results # of "dates" queries, which are returned as DATETIME. elif desc[1] in (Database.TIMESTAMP, Database.DATETIME): # Confirm that dt is naive before overwriting its tzinfo. if settings.USE_TZ and value is not None and timezone.is_naive(value): value = value.replace(tzinfo=timezone.utc) elif desc[1] in (Database.STRING, Database.FIXED_CHAR, Database.LONG_STRING): value = to_unicode(value) casted.append(value) return tuple(casted)
Example #14
Source File: cx_oracle.py From jarvis with GNU General Public License v2.0 | 4 votes |
def _generate_connection_outputtype_handler(self): """establish the default outputtypehandler established at the connection level. """ dialect = self cx_Oracle = dialect.dbapi number_handler = _OracleNUMBER(asdecimal=True).\ _cx_oracle_outputtypehandler(dialect) float_handler = _OracleNUMBER(asdecimal=False).\ _cx_oracle_outputtypehandler(dialect) def output_type_handler(cursor, name, default_type, size, precision, scale): if default_type == cx_Oracle.NUMBER: if not dialect.coerce_to_decimal: return None elif precision == 0 and scale in (0, -127): # ambiguous type, this occurs when selecting # numbers from deep subqueries return cursor.var( cx_Oracle.STRING, 255, outconverter=dialect._detect_decimal, arraysize=cursor.arraysize) elif precision and scale > 0: return number_handler( cursor, name, default_type, size, precision, scale ) else: return float_handler( cursor, name, default_type, size, precision, scale ) # allow all strings to come back natively as Unicode elif dialect.coerce_to_unicode and \ default_type in (cx_Oracle.STRING, cx_Oracle.FIXED_CHAR): return cursor.var( util.text_type, size, cursor.arraysize ) elif dialect.auto_convert_lobs and default_type in ( cx_Oracle.CLOB, cx_Oracle.NCLOB, cx_Oracle.BLOB ): return cursor.var( default_type, size, cursor.arraysize, outconverter=lambda value: value.read() ) return output_type_handler
Example #15
Source File: cx_oracle.py From android_universal with MIT License | 4 votes |
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, )
Example #16
Source File: cx_oracle.py From android_universal with MIT License | 4 votes |
def _generate_connection_outputtype_handler(self): """establish the default outputtypehandler established at the connection level. """ dialect = self cx_Oracle = dialect.dbapi number_handler = _OracleNUMBER(asdecimal=True).\ _cx_oracle_outputtypehandler(dialect) float_handler = _OracleNUMBER(asdecimal=False).\ _cx_oracle_outputtypehandler(dialect) def output_type_handler(cursor, name, default_type, size, precision, scale): if default_type == cx_Oracle.NUMBER: if not dialect.coerce_to_decimal: return None elif precision == 0 and scale in (0, -127): # ambiguous type, this occurs when selecting # numbers from deep subqueries return cursor.var( cx_Oracle.STRING, 255, outconverter=dialect._detect_decimal, arraysize=cursor.arraysize) elif precision and scale > 0: return number_handler( cursor, name, default_type, size, precision, scale ) else: return float_handler( cursor, name, default_type, size, precision, scale ) # allow all strings to come back natively as Unicode elif dialect.coerce_to_unicode and \ default_type in (cx_Oracle.STRING, cx_Oracle.FIXED_CHAR): return cursor.var( util.text_type, size, cursor.arraysize ) elif dialect.auto_convert_lobs and default_type in ( cx_Oracle.CLOB, cx_Oracle.NCLOB, cx_Oracle.BLOB ): return cursor.var( default_type, size, cursor.arraysize, outconverter=lambda value: value.read() ) return output_type_handler