|
1 | | -import datetime |
2 | | -from decimal import Decimal |
3 | 1 | import intersystems_iris.dbapi._DBAPI as dbapi |
4 | 2 | from . import information_schema as ischema |
| 3 | +from . import types |
5 | 4 | from sqlalchemy import exc |
6 | 5 | from sqlalchemy.orm import aliased |
7 | 6 | from sqlalchemy.engine import default |
@@ -539,110 +538,11 @@ def create_cursor(self): |
539 | 538 | return cursor |
540 | 539 |
|
541 | 540 |
|
542 | | -HOROLOG_ORDINAL = datetime.date(1840, 12, 31).toordinal() |
543 | | - |
544 | | - |
545 | | -class _IRISDate(sqltypes.Date): |
546 | | - def bind_processor(self, dialect): |
547 | | - def process(value): |
548 | | - if value is None: |
549 | | - return None |
550 | | - horolog = value.toordinal() - HOROLOG_ORDINAL |
551 | | - return str(horolog) |
552 | | - |
553 | | - return process |
554 | | - |
555 | | - def result_processor(self, dialect, coltype): |
556 | | - def process(value): |
557 | | - if value is None: |
558 | | - return None |
559 | | - if isinstance(value, str) and '-' in value: |
560 | | - return datetime.datetime.strptime(value, '%Y-%m-%d').date() |
561 | | - horolog = int(value) + HOROLOG_ORDINAL |
562 | | - return datetime.date.fromordinal(horolog) |
563 | | - |
564 | | - return process |
565 | | - |
566 | | - |
567 | | -class _IRISTimeStamp(sqltypes.DateTime): |
568 | | - def bind_processor(self, dialect): |
569 | | - def process(value: datetime.datetime): |
570 | | - if value is not None: |
571 | | - # value = int(value.timestamp() * 1000000) |
572 | | - # value += (2 ** 60) if value > 0 else -(2 ** 61 * 3) |
573 | | - return value.strftime('%Y-%m-%d %H:%M:%S.%f') |
574 | | - return value |
575 | | - |
576 | | - return process |
577 | | - |
578 | | - def result_processor(self, dialect, coltype): |
579 | | - def process(value): |
580 | | - if isinstance(value, str): |
581 | | - if '.' not in value: |
582 | | - value += '.0' |
583 | | - return datetime.datetime.strptime(value, '%Y-%m-%d %H:%M:%S.%f') |
584 | | - if isinstance(value, int): |
585 | | - value -= (2 ** 60) if value > 0 else -(2 ** 61 * 3) |
586 | | - value = value / 1000000 |
587 | | - value = datetime.datetime.utcfromtimestamp(value) |
588 | | - return value |
589 | | - |
590 | | - return process |
591 | | - |
592 | | - |
593 | | -class _IRISDateTime(sqltypes.DateTime): |
594 | | - def bind_processor(self, dialect): |
595 | | - def process(value): |
596 | | - if value is not None: |
597 | | - return value.strftime('%Y-%m-%d %H:%M:%S.%f') |
598 | | - return value |
599 | | - |
600 | | - return process |
601 | | - |
602 | | - def result_processor(self, dialect, coltype): |
603 | | - def process(value): |
604 | | - if isinstance(value, str): |
605 | | - if '.' not in value: |
606 | | - value += '.0' |
607 | | - return datetime.datetime.strptime(value, '%Y-%m-%d %H:%M:%S.%f') |
608 | | - return value |
609 | | - |
610 | | - return process |
611 | | - |
612 | | - |
613 | | -class _IRISTime(sqltypes.DateTime): |
614 | | - def bind_processor(self, dialect): |
615 | | - def process(value): |
616 | | - if value is not None: |
617 | | - return value.strftime('%H:%M:%S.%f') |
618 | | - return value |
619 | | - |
620 | | - return process |
621 | | - |
622 | | - def result_processor(self, dialect, coltype): |
623 | | - def process(value): |
624 | | - if isinstance(value, str): |
625 | | - if '.' not in value: |
626 | | - value += '.0' |
627 | | - return datetime.datetime.strptime(value, '%H:%M:%S.%f').time() |
628 | | - if isinstance(value, int) or isinstance(value, Decimal): |
629 | | - horolog = value |
630 | | - hour = int(horolog // 3600) |
631 | | - horolog -= int(hour * 3600) |
632 | | - minute = int(horolog // 60) |
633 | | - second = int(horolog % 60) |
634 | | - micro = int(value % 1 * 1000000) |
635 | | - return datetime.time(hour, minute, second, micro) |
636 | | - return value |
637 | | - |
638 | | - return process |
639 | | - |
640 | | - |
641 | 541 | colspecs = { |
642 | | - sqltypes.Date: _IRISDate, |
643 | | - sqltypes.DateTime: _IRISDateTime, |
644 | | - sqltypes.TIMESTAMP: _IRISTimeStamp, |
645 | | - sqltypes.Time: _IRISTime, |
| 542 | + sqltypes.Date: types.IRISDate, |
| 543 | + sqltypes.DateTime: types.IRISDateTime, |
| 544 | + sqltypes.TIMESTAMP: types.IRISTimeStamp, |
| 545 | + sqltypes.Time: types.IRISTime, |
646 | 546 | } |
647 | 547 |
|
648 | 548 |
|
|
0 commit comments