示例#1
0
 def setJDBCObject(self, stmt, index, obj, datatype=None):
     "Convert Django-models types into Java ones"
     if datatype is None:
         FilterDataHandler.setJDBCObject(self, stmt, index, obj)
         return
     if datatype == Types.TIMESTAMP and isinstance(obj, basestring):
         # Convert string into java.sql.Timestamp
         # The string is generated by Django using datetime.__str__ ,
         # so the format is year-month-day hour:minute:second.microsecond
         d, t = obj.split(' ')
         hour, minute, second, microsecond = self._hour_minute_second_micro(
             t)
         year, month, day = self._year_month_day(d)
         # FIXME: This ignores microseconds
         obj = Database.Timestamp(year, month, day, hour, minute,
                                  second)  # Database is an alias for zxJDBC
     elif datatype == Types.TIME and isinstance(obj, basestring):
         # Convert string into java.sql.Time
         hour, minute, second, microsecond = self._hour_minute_second_micro(
             obj)
         # FIXME: This ignores microseconds
         obj = Database.Time(int(hour), int(minute), int(second))
     elif datatype == Types.DATE and isinstance(obj, basestring):
         year, month, day = self._year_month_day(obj)
         obj = Database.Date(year, month, day)
     FilterDataHandler.setJDBCObject(self, stmt, index, obj, datatype)
示例#2
0
	def testTimestamp(self):
		"""testing creation of Timestamp"""

		# Java uses milliseconds and Python uses seconds, so adjust the time accordingly

		# seeded with Java
		c = self.calendar()
		o = zxJDBC.TimestampFromTicks(c.getTime().getTime() / 1000L)
		v = zxJDBC.Timestamp(c.get(Calendar.YEAR), c.get(Calendar.MONTH) + 1, c.get(Calendar.DATE),
			c.get(Calendar.HOUR), c.get(Calendar.MINUTE), c.get(Calendar.SECOND))
		assert o.equals(v), "incorrect date conversion using java, got [%ld], expected [%ld]" % (v.getTime(), o.getTime())