def getPyObject(self, set, col, datatype): "Convert Java types into Python ones" if datatype in (Types.VARCHAR, Types.CHAR): return Py.newUnicode(set.getString(col)) elif datatype == Types.TIMESTAMP: # Convert java.sql.TimeStamp into datetime cal = GregorianCalendar() cal.time = set.getTimestamp(col) return datetime.datetime(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND), cal.get(Calendar.MILLISECOND) * 1000) elif datatype == Types.TIME: # Convert java.sql.Time into time cal = GregorianCalendar() cal.time = set.getTime(col) return datetime.time(cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND), cal.get(Calendar.MILLISECOND) * 1000) elif datatype == Types.DATE: # Convert java.sql.Date into datetime cal = GregorianCalendar() cal.time = set.getDate(col) return datetime.date(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH)) else: return FilterDataHandler.getPyObject(self, set, col, datatype)
def _char_slice_to_unicode(self, characters, start, length): """Convert a char[] slice to a PyUnicode instance""" text = Py.newUnicode(String(characters[start:start + length])) return text