Пример #1
0
    def typeCheckAndConvert(self, val, aname, attr):
        #nulls always allowed (unless the db says no)
        if val is None: return val
        if _isDateKind(attr):
            if not (Date.isDateTime(val) or val is SYSDATE):
                val = DateTime.DateTimeFrom(val)
            val = _dateConvertToDB(val, attr)
        elif (_isNumber(attr) and not isinstance(val, types.FloatType)
              and not isinstance(val, types.IntType)):
            raise TypeError, ('trying to assign %s to %s and is not'
                              ' a number') % (val, aname)
        elif _isString(attr) and not isinstance(val, types.StringType):
            raise TypeError, 'trying to assign %s to %s and is not a string' % (
                val, aname)

        return val
Пример #2
0
def _dateConvertFromDB(item):
    if item is None:
        return item
    # MySQLdb will now return DateTime objects is egenix is present.
    if type(item) == DateTime.DateTimeType:
        return item
    if string.find(item, '-') == -1:  #timestamp form
        y = item[:4]
        mo = item[4:6]
        d = item[6:8]
        h = item[8:10]
        mi = item[10:12]
        s = item[12:14]
    else:
        y = item[:4]
        mo = item[5:7]
        d = item[8:10]
        h = item[11:13]
        mi = item[14:16]
        s = item[17:19]
    return DateTime.DateTime(int(y), int(mo), int(d), int(h), int(mi), int(s))
Пример #3
0
def _dateConvertFromDB(dbd):
    return DateTime.localtime(dbd)
Пример #4
0
def _dateConvertFromDB(dbd):
    return DateTime.localtime(dbd)
Пример #5
0
def _dateConvertToDB(dt):
    if dt == PyDBI.SYSDATE:
        dt = DateTime.now()
    return '%04d%02d%02d%02d%02d%02d' % (dt.year, dt.month, dt.day,
                                         dt.hour, dt.minute, dt.second)
Пример #6
0
def _dateConvertToDB(dt):
    if dt == PyDBI.SYSDATE:
        dt = DateTime.now()
    return '%04d%02d%02d%02d%02d%02d' % (dt.year, dt.month, dt.day, dt.hour,
                                         dt.minute, dt.second)
Пример #7
0
def _dateConvertFromDB(val, type):
    if val is None:  # DateTimeFrom can't handle None as an argument
        return None
    return DateTime.DateTimeFrom(sapdbapi.valTranslation[type](val))
Пример #8
0
def _dateConvertFromDB(val, type):
    return DateTime.DateTimeFrom(sapdbapi.valTranslation[type](val))