How to use the databases.pytds.tds.DataError function in databases

To help you get started, we’ve selected a few databases examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Atticuss / SQLViking / databases / pytds / tds.py View on Github external
elif isinstance(value, datetime):
            if IS_TDS73_PLUS(self):
                if value.tzinfo and not self.use_tz:
                    column.type = DateTimeOffset(6)
                else:
                    column.type = DateTime2(6)
            else:
                column.type = DateTimeN(8)
        elif isinstance(value, date):
            if IS_TDS73_PLUS(self):
                column.type = MsDate()
            else:
                column.type = DateTimeN(8)
        elif isinstance(value, time):
            if not IS_TDS73_PLUS(self):
                raise DataError('Time type is not supported on MSSQL 2005 and lower')
            column.type = MsTime(6)
        elif isinstance(value, Decimal):
            column.type = MsDecimal.from_value(value)
        elif isinstance(value, uuid.UUID):
            column.type = MsUnique()
        else:
            raise DataError('Parameter type is not supported: {0}'.format(repr(value)))
        return column
github Atticuss / SQLViking / databases / pytds / tds.py View on Github external
column.type = DateTimeN(8)
        elif isinstance(value, date):
            if IS_TDS73_PLUS(self):
                column.type = MsDate()
            else:
                column.type = DateTimeN(8)
        elif isinstance(value, time):
            if not IS_TDS73_PLUS(self):
                raise DataError('Time type is not supported on MSSQL 2005 and lower')
            column.type = MsTime(6)
        elif isinstance(value, Decimal):
            column.type = MsDecimal.from_value(value)
        elif isinstance(value, uuid.UUID):
            column.type = MsUnique()
        else:
            raise DataError('Parameter type is not supported: {0}'.format(repr(value)))
        return column
github Atticuss / SQLViking / databases / pytds / tds.py View on Github external
column.flags = fDefaultValue
            value = None
        column.value = value
        if value is None:
            column.type = self.conn.NVarChar(1, collation=self.conn.collation)
        elif isinstance(value, bool):
            column.type = BitN()
        elif isinstance(value, six.integer_types):
            if -2 ** 31 <= value <= 2 ** 31 - 1:
                column.type = IntN(4)
            elif -2 ** 63 <= value <= 2 ** 63 - 1:
                column.type = IntN(8)
            elif -10 ** 38 + 1 <= value <= 10 ** 38 - 1:
                column.type = MsDecimal(0, 38)
            else:
                raise DataError('Numeric value out of range')
        elif isinstance(value, float):
            column.type = FloatN(8)
        elif isinstance(value, Binary):
            column.type = self.conn.long_binary_type()
        elif isinstance(value, six.binary_type):
            if self._tds.login.bytes_to_unicode:
                column.type = self.conn.long_string_type(collation=self.conn.collation)
            else:
                column.type = self.conn.long_varchar_type(collation=self.conn.collation)
        elif isinstance(value, six.string_types):
            column.type = self.conn.long_string_type(collation=self.conn.collation)
        elif isinstance(value, datetime):
            if IS_TDS73_PLUS(self):
                if value.tzinfo and not self.use_tz:
                    column.type = DateTimeOffset(6)
                else:
github Atticuss / SQLViking / databases / pytds / tds.py View on Github external
def from_value(cls, value):
        if not (-10 ** 38 + 1 <= value <= 10 ** 38 - 1):
            raise DataError('Decimal value is out of range')
        value = value.normalize()
        _, digits, exp = value.as_tuple()
        if exp > 0:
            scale = 0
            prec = len(digits) + exp
        else:
            scale = -exp
            prec = max(len(digits), scale)
        return cls(scale=scale, prec=prec)
github Atticuss / SQLViking / databases / pytds / tds.py View on Github external
def validate(cls, value):
        if not (cls._min_date <= value <= cls._max_date):
            raise DataError('Date is out of range')
github Atticuss / SQLViking / databases / pytds / tds.py View on Github external
def __init__(self, scale, prec):
        if prec > 38:
            raise DataError('Precision of decimal value is out of range')
        self._scale = scale
        self._prec = prec
        self._size = self._bytes_per_prec[prec]
github Atticuss / SQLViking / databases / pytds / tds.py View on Github external
def write(self, w, val):
        if val.tzinfo:
            if not w.session.use_tz:
                raise DataError('Timezone-aware datetime is used without specifying use_tz')
            val = val.astimezone(w.session.use_tz).replace(tzinfo=None)
        days = (val - self._base_date).days
        minutes = val.hour * 60 + val.minute
        w.pack(self._struct, days, minutes)