def make_array(self): """Make the variable an array, ensuring that the type supports arrays.""" if not self.type.can_be_in_array: raise NotSupportedError( "Variable_MakeArray(): type does not support arrays") self.is_array = True
def new(self, cursor, num_elements, type, size): variable_class = mapping_variable_type_to_python_type.get(type) if variable_class is None: raise NotSupportedError('Type %s (%s) not found in mapping to python type' % (type, vt_to_name[type])) var = variable_class(cursor, num_elements, type, size) return var
def set_value(self, array_pos, value): """Set the value of the variable.""" if self.is_array: if array_pos > 0: raise NotSupportedError( "arrays of arrays are not supported by the OCI") return self.set_array_value(value) return self.set_single_value(array_pos, value)
def type_by_python_type(self, cursor, type): """Return a variable type given a Python type object or NULL if the Python type does not have a corresponding variable type.""" if type == NUMBER: if cursor.numbersAsStrings: return vt_NumberAsString else: return vt_Float try: return mapping_python_type_to_variable_type[type] except KeyError: raise NotSupportedError("Variable_TypeByPythonType(): unhandled data type")
def type_by_oracle_data_type(self, oracle_data_type, charset_form): mapping = { oci.SQLT_LNG: vt_LongString, oci.SQLT_RDD: vt_Rowid, oci.SQLT_BIN: vt_Binary, oci.SQLT_LBI: vt_LongBinary, oci.SQLT_NUM: vt_Float, oci.SQLT_VNU: vt_Float, oci.SQLT_DAT: vt_DateTime, oci.SQLT_ODT: vt_DateTime, oci.SQLT_DATE: vt_Timestamp, oci.SQLT_TIMESTAMP: vt_Timestamp, oci.SQLT_TIMESTAMP_TZ: vt_Timestamp, oci.SQLT_TIMESTAMP_LTZ: vt_Timestamp, oci.SQLT_INTERVAL_DS: vt_Interval, oci.SQLT_BLOB: vt_BLOB, oci.SQLT_BFILE: vt_BFILE, oci.SQLT_RSET: vt_Cursor, oci.SQLT_NTY: vt_Object, #oci.SQLT_BFLOAT: vt_NativeFloat, # TODO: removed #ifdef SQLT_BFLOAT #oci.SQLT_IBFLOAT: vt_NativeFloat, #oci.SQLT_BDOUBLE: vt_NativeFloat, #oci.SQLT_IBDOUBLE: vt_NativeFloat, } if oracle_data_type == oci.SQLT_AFC: if not python3_or_better() and charset_form == oci.SQLCS_NCHAR: return vt_FixedNationalChar else: return vt_FixedChar if oracle_data_type == oci.SQLT_CHR: if not python3_or_better() and charset_form == oci.SQLCS_NCHAR: return vt_NationalCharString else: return vt_String if oracle_data_type == oci.SQLT_CLOB: if charset_form == oci.SQLCS_NCHAR: return vt_NCLOB else: return vt_CLOB try: return mapping[oracle_data_type] except KeyError: raise NotSupportedError("Variable_TypeByOracleDataType: unhandled data type %d" % oracle_data_type)
def Time(*args): raise NotSupportedError("Oracle does not support time only variables")
def type_by_value(self, value): """Return a variable type given a Python object or NULL if the Python object does not have a corresponding variable type.""" # handle scalars if value is None: return vt_String, 1, None if isinstance(value, cxString): size = len(value) # assuming cxString_GetSize = len if size > MAX_STRING_CHARS: type = vt_LongString else: type = vt_String return type, size, None if not python3_or_better(): if isinstance(value, unicode): size = len(value) if size > MAX_STRING_CHARS: type = vt_LongString else: type = vt_NationalCharString return type, size, None if isinstance(value, int): return vt_Integer, None, None else: if isinstance(value, bytes): size = len(value) if size > MAX_BINARY_BYTES: type = vt_LongBinary else: type = vt_Binary return type, None, None if isinstance(value, long): return vt_LongInteger, None, None if isinstance(value, float): return vt_Float, None, None if isinstance(value, cxBinary): size = len(value) if size > MAX_BINARY_BYTES: type = vt_LongBinary else: type = vt_Binary return type, size, None if isinstance(value, bool): return vt_Boolean, None, None if isinstance(value, datetime): return vt_DateTime, None, None if isinstance(value, date): return vt_DateTime, None, None if isinstance(value, timedelta): return vt_Interval, None, None from cursor import Cursor is_cursor = isinstance(value, Cursor) if is_cursor: return vt_Cursor, None, None if isinstance(value, Decimal): return vt_NumberAsString, None, None # handle arrays if isinstance(value, list): for element_value in value: if element_value is not None: break var_type, _, _ = self.type_by_value(element_value) num_elements = len(value) size = var_type.size return var_type, size, num_elements raise NotSupportedError("Variable_TypeByValue(): unhandled data type %.*s" % type(value))