Beispiel #1
0
 def test_datetime(self):
     value = datetime(1977, 4, 5, 12, 34, 56, 78)
     self.connection.execute("INSERT INTO datetime_test (dt) VALUES (?)",
                             (value, ))
     result = self.connection.execute("SELECT dt FROM datetime_test")
     variable = DateTimeVariable()
     result.set_variable(variable, result.get_one()[0])
     if not self.supports_microseconds:
         value = value.replace(microsecond=0)
     self.assertEquals(variable.get(), value)
Beispiel #2
0
 def test_datetime(self):
     value = datetime(1977, 4, 5, 12, 34, 56, 78)
     self.connection.execute("INSERT INTO datetime_test (dt) VALUES (?)",
                             (value,))
     result = self.connection.execute("SELECT dt FROM datetime_test")
     variable = DateTimeVariable()
     result.set_variable(variable, result.get_one()[0])
     if not self.supports_microseconds:
         value = value.replace(microsecond=0)
     self.assertEquals(variable.get(), value)
Beispiel #3
0
    def parse_set(self, value, from_db):
        if type(value) is datetime.date:
            warnings.warn("Using datetime.date is deprecated, pass in "
                          "datetime.datetime instead", stacklevel=4)
            value = datetime.datetime(value.year, value.month, value.day)

        return DateTimeVariable.parse_set(self, value, from_db)
Beispiel #4
0
    def parse_set(self, value, from_db):
        # We need to use type here because in py3 datetime is a subclass of
        # date, meaning that it would be considered too and loose its time
        if type(value) is datetime.date:
            warnings.warn("Using datetime.date is deprecated, pass in "
                          "datetime.datetime instead", stacklevel=4)
            value = datetime.datetime(value.year, value.month, value.day)

        return DateTimeVariable.parse_set(self, value, from_db)
Beispiel #5
0
    def parse_set(self, value, from_db):
        # We need to use type here because in py3 datetime is a subclass of
        # date, meaning that it would be considered too and loose its time
        if type(value) is datetime.date:
            warnings.warn(
                "Using datetime.date is deprecated, pass in "
                "datetime.datetime instead",
                stacklevel=4)
            value = datetime.datetime(value.year, value.month, value.day)

        return DateTimeVariable.parse_set(self, value, from_db)
Beispiel #6
0
    def parse_set(self, value, from_db):
        if type(value) is datetime.date:
            value = datetime.datetime(value.year, value.month, value.day)

        return DateTimeVariable.parse_set(self, value, from_db)
Beispiel #7
0
def compile_datetime(compile, expr, state):
    state.parameters.append(DateTimeVariable(expr))
    return "?"
Beispiel #8
0
 def test_datetime_with_none(self):
     self.connection.execute("INSERT INTO datetime_test (dt) VALUES (NULL)")
     result = self.connection.execute("SELECT dt FROM datetime_test")
     variable = DateTimeVariable()
     result.set_variable(variable, result.get_one()[0])
     self.assertEquals(variable.get(), None)
Beispiel #9
0
 def test_datetime_with_none(self):
     self.connection.execute("INSERT INTO datetime_test (dt) VALUES (NULL)")
     result = self.connection.execute("SELECT dt FROM datetime_test")
     variable = DateTimeVariable()
     result.set_variable(variable, result.get_one()[0])
     self.assertEquals(variable.get(), None)